; Скрипт для конвертации AutoIt-справки в CHM формате в онлайновую справку с распакованными файлами ; Для скрипта необходимы 4 файла: ; 7z.exe, который можно найти в папке установленного арихиватора 7-zip ; default.css - специальный для онлайн справки ; AutoIt3.chm, UDFs3.chm - обрабатываемые файлы ; Все файлы должны быть в каталоге скрипта #include #include Global $bDebug = False Global $Pattern[6], $Path = @ScriptDir Global $Add_To_index_htm = FileRead($Path & '\Add_To_index.htm') ; файл должен быть без заголовочных тегов, только внутренности Global $hTimerTotal = TimerInit() Global $CountTotal = 0 ;~ If $bDebug Then Opt('TrayIconDebug', 1) Opt('TrayIconDebug', 1) If Not FileExists(@ScriptDir & '\7z.exe') Then MsgBox(0, 'Сообщение', 'Файл 7z.exe в каталоге скрипта не найден') Exit EndIf ; x - извлечь со структурой каталога ; -r - включая подкаталоги ; -o - куда извлекаем ; -y - ответ "Да" при замене одноимённых файлов ; AutoIt3.chm - извлекаемый файл ; html\* путь и маска указывающая что извлекать внутри архива If FileExists($Path & '\UDFs3.chm') Then ; если не найдено, то выход If $bDebug Then ToolTip('Извлечение файла UDFs3.chm', Default, Default, 'Создание онлайн справки (1-2 минуты)', 1) RunWait(@ScriptDir & '\7z.exe x "' & $Path & '\UDFs3.chm" -o"' & $Path & '" html\* -r -y', '', @SW_HIDE) ; можно заккомментировать, чтобы пропустить извлечение UDFs3.chm If FileExists($Path & '\AutoIt3.chm') Then ; файл AutoIt3.chm извлекается при условии извлечения UDFs3.chm If $bDebug Then ToolTip('Извлечение файла AutoIt3.chm') RunWait(@ScriptDir & '\7z.exe x "' & $Path & '\AutoIt3.chm" -o"' & $Path & '" html\* -r -y', '', @SW_HIDE) If FileExists($Path & '\CustomUDFs.chm') Then ; файл CustomUDFs.chm должен извлекаться первым, чтобы перезаписать общие файлы If $bDebug Then ToolTip('Извлечение файла CustomUDFs.chm') RunWait(@ScriptDir & '\7z.exe x "' & $Path & '\CustomUDFs.chm" -o"' & $Path & '" html\* -r -y', '', @SW_HIDE) ; Else ; MsgBox(0, 'Сообщение', 'Файл CustomUDFs.chm не найден') ; Exit EndIf Else MsgBox(0, 'Сообщение', 'Файл AutoIt3.chm не найден') Exit EndIf Else MsgBox(0, 'Сообщение', 'Файл UDFs3.chm не найден') Exit EndIf $Path &= '\html' FileCopy(@ScriptDir & '\default.css', $Path & '\css\', 9) ; копирование стилевого файла default.css для онлайн версии $Pattern[0] = 3 ; обрабатывание до 3-го индекса. Если 5, то удалит кнопки "Копировать" ; текст для удаления кнопки "Открыть" сверху $Pattern[1] = '' ; текст для удаления кнопки "Открыть" снизу $Pattern[2] = '' $Pattern[3] = '' ; текст для удаления кнопки "Копировать в буфер" $Pattern[4] = '' $Pattern[5] = '' $FileList = _FileListToArray($Path & '\libfunctions') If Not @error Then ; переводим тексты в нижний регистр For $i = 1 To $FileList[0] $FileList[$i] = StringLower($FileList[$i]) Next $hTimer = TimerInit() ; переименовываем файлы $err = 0 For $i = 1 To $FileList[0] If FileMove($Path & '\libfunctions\' & $FileList[$i], $Path & '\libfunctions\#@%' & $FileList[$i]) Then If Not FileMove($Path & '\libfunctions\#@%' & $FileList[$i], $Path & '\libfunctions\' & $FileList[$i]) Then $err += 1 EndIf If $bDebug And Not Mod($i, 10) Then ToolTip('ReName ' & $i & ' - ' & $FileList[$i]) ; вывод каждого 10 файла, чтобы не тратило скорость на вывод Next If $bDebug Then If $err > 0 Then MsgBox(0, '', 'Была ошибка при переименовании файлов') MsgBox(0, '', 'Переименование выполнено за ' & Round(TimerDiff($hTimer) / 1000, 2) & ' сек') EndIf $hTimer = TimerInit() $kTotal = _Processing($FileList, 'libfunctions', 'UDF', 1) If $bDebug Then MsgBox(0, '', 'Количество замен в UDF - libfunctions = ' & $kTotal & @CRLF & 'выполнено за ' & Round(TimerDiff($hTimer) / 1000, 2) & ' сек') $CountTotal += $kTotal EndIf $FileList = _FileListToArray($Path & '\keywords') If Not @error Then $hTimer = TimerInit() $kTotal = _Processing($FileList, 'keywords', 'KEY', 0) If $bDebug Then MsgBox(0, '', 'Количество замен в keywords = ' & $kTotal & @CRLF & 'выполнено за ' & Round(TimerDiff($hTimer) / 1000, 2) & ' сек') $CountTotal += $kTotal EndIf $FileList = _FileListToArray($Path & '\userfunctions') If Not @error Then $hTimer = TimerInit() $kTotal = _Processing($FileList, 'userfunctions', 'Custom', 0) ; Вставка в индексный файл, заменой
$index_htm = FileRead($Path & '\index.htm') $index_htm = StringReplace($index_htm, '
' & @CRLF & '
', $Add_To_index_htm) & '

' $index_htm = StringReplace($index_htm, '

', '') ; этой строки нет в новой справке $file = FileOpen($Path & '\index.htm', 2) FileWrite($file, $index_htm) FileClose($file) If $bDebug Then MsgBox(0, '', 'Количество замен в userfunctions = ' & $kTotal & @CRLF & 'выполнено за ' & Round(TimerDiff($hTimer) / 1000, 2) & ' сек') $CountTotal += $kTotal EndIf Local $FileList[2] = [1, 'libfunctions.htm'] ; массив индивидуально выбранных файлов If Not @error Then $hTimer = TimerInit() $kTotal = _Processing($FileList, '', 'Другие', 1) If $bDebug Then MsgBox(0, '', 'Количество замен в "другие" = ' & $kTotal & @CRLF & 'выполнено за ' & Round(TimerDiff($hTimer) / 1000, 2) & ' сек') $CountTotal += $kTotal EndIf $FileList = _FileListToArray($Path & '\functions') If Not @error Then $hTimer = TimerInit() $kTotal = _Processing($FileList, 'functions', 'FUNC', 2) $CountTotal += $kTotal If $bDebug Then $kTotal = @CRLF & @CRLF & 'Количество замен functions = ' & $kTotal & @CRLF & 'выполнено за ' & Round(TimerDiff($hTimer) / 1000, 2) & ' сек' Else $kTotal = '' EndIf EndIf If $bDebug Then ToolTip('') MsgBox(0, 'Создание справки завершено!', 'Общее количество замен = ' & $CountTotal & @CRLF & 'Общее время выполнения = ' & Round(TimerDiff($hTimerTotal) / 60000, 1) & ' мин' & $kTotal) Func _Processing($FileList, $folder, $text, $Tr = 0) Local $i, $kTotal = 0, $aLink, $k, $j, $hFile, $Path0 If $folder Then $Path0 = $Path & '\' & $folder Else $Path0 = $Path EndIf ; заменяем все тексты на тексты в нижнем регистре For $i = 1 To $FileList[0] $html = FileRead($Path0 & '\' & $FileList[$i]) $k = 0 If $bDebug And Not Mod($i, 10) Then ToolTip($text & ' ' & $i & ' - ' & $FileList[$i]) ; вывод каждого 10 файла, чтобы не тратило скорость на вывод $aLink = StringRegExp($html, '( 0 Then $hFile = FileOpen($Path0 & '\' & $FileList[$i], 2) FileWrite($hFile, $html) FileClose($hFile) EndIf $kTotal += $k Next Return $kTotal EndFunc