Advertisement
AZJIO

CHM в онлайн

Dec 18th, 2011
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.96 KB | None | 0 0
  1. #include <File.au3>
  2. #include <Array.au3>
  3.  
  4. Global $kTotal
  5.  
  6. $Path=@ScriptDir
  7. $Pattern1='<a href="JavaScript:hhctrl.Click()"><IMG NAME="botton" title="Открыть" style=''margin: 5px 4px 4px 10px;'' src=''../images/Open.gif''" border="0" align=''right''></a>'
  8. $Pattern2='<a href="JavaScript:hhctrl.Click()"><IMG NAME="botton" title="Открыть" style=''margin: 20px 4px 4px 10px;'' src=''../images/Open.gif''" border="0" align=''right''></a>'
  9.  
  10. $FileList=_FileListToArray($Path&'\libfunctions')
  11. If Not @error Then
  12.     ; переводим тексты в нижний регистр
  13.     For $i = 1 to $FileList[0]
  14.         $FileList[$i]=StringLower($FileList[$i])
  15.     Next
  16.  
  17.     ; переименовываем файлы
  18.     $err=0
  19.     For $i = 1 to $FileList[0]
  20.         If FileMove($Path&'\libfunctions\'&$FileList[$i], $Path&'\libfunctions\#@%'&$FileList[$i]) Then
  21.             If Not FileMove($Path&'\libfunctions\#@%'&$FileList[$i], $Path&'\libfunctions\'&$FileList[$i]) Then $err+=1
  22.         EndIf
  23.         ToolTip('ReName '&$i&' - '&$FileList[$i])
  24.     Next
  25.     If $err > 0 Then MsgBox(0, '', 'Была ошибка при переименовании файлов')
  26.     MsgBox(0, '', 'Переименование выполнено')
  27.  
  28.     _Processing($FileList, 'libfunctions', 'UDF', 1)
  29.     MsgBox(0, '', 'Количество замен в UDF - libfunctions = '&$kTotal)
  30. EndIf
  31.  
  32. $FileList=_FileListToArray($Path&'\keywords')
  33. If Not @error Then
  34.     _Processing($FileList, 'keywords', 'KEY', 0)
  35.     MsgBox(0, '', 'Количество замен в keywords = '&$kTotal)
  36. EndIf
  37.  
  38. $FileList=_FileListToArray($Path&'\functions')
  39. If Not @error Then
  40.     _Processing($FileList, 'functions', 'FUNC', 0)
  41.     MsgBox(0, '', 'Количество замен functions = '&$kTotal)
  42. EndIf
  43.  
  44. Func _Processing($FileList, $folder, $text, $Tr=0)
  45.     $kTotal=0
  46.     ; заменяем все тексты на тексты в нижнем регистре
  47.     For $i = 1 to $FileList[0]
  48.         $html = FileRead($Path&'\'&$folder&'\'&$FileList[$i])
  49.         $k=0
  50.         ToolTip($text&' '&$i&' - '&$FileList[$i])
  51.        
  52.         If $Tr Then
  53.             $aLink=StringRegExp($html, '(<a href=".*?\.htm")', 3)
  54.             If Not @error Then
  55.                 For $j = 0 to UBound($aLink)-1
  56.                     $html = StringReplace($html, $aLink[$j], StringLower($aLink[$j])) ; заменит без учёта регистра в нижний регистр
  57.                 Next
  58.             EndIf
  59.         EndIf
  60.        
  61.         $html = StringReplace($html, '::/html/', '../') ; заменит внутренние пути CHM на внешние
  62.         $k+=@extended
  63.        
  64.         ; удалить кнопку "Открыть" сверху
  65.         $html = StringReplace($html, $Pattern1, '') ;
  66.         $k+=@extended
  67.        
  68.         ; удалить кнопку "Открыть" снизу
  69.         $html = StringReplace($html, $Pattern2, '') ;
  70.         $k+=@extended
  71.        
  72.         ; если изменения произошли, то сохраняем в файл
  73.         If $k > 0 Then
  74.             $file = FileOpen($Path&'\'&$folder&'\'&$FileList[$i], 2)
  75.             FileWrite($file, $html)
  76.             FileClose($file)
  77.         EndIf
  78.         $kTotal+=$k
  79.     Next
  80. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement