forked from autohotkey-docs-translation/v2-de
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile_chm.ahk
58 lines (48 loc) · 1.67 KB
/
compile_chm.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#NoEnv
SetBatchLines, -1
SetWorkingDir, % A_ScriptDir
if (A_PtrSize = 8) {
try
RunWait "%A_AhkPath%\..\AutoHotkeyU32.exe" "%A_ScriptFullPath%"
catch
MsgBox 16,, This script must be run with AutoHotkey 32-bit, due to use of the ScriptControl COM component.
ExitApp
}
; Change this path if the loop below doesn't find your hhc.exe,
; or leave it as-is if hhc.exe is somewhere in %PATH%.
hhc := "hhc.exe"
; Try to find hhc.exe, since it's not in %PATH% by default.
for i, env_var in ["ProgramFiles", "ProgramFiles(x86)", "ProgramW6432"]
{
EnvGet Programs, %env_var%
if (Programs && FileExist(checking := Programs "\HTML Help Workshop\hhc.exe"))
{
hhc := checking
break
}
}
; Convert files to ISO-8859-1 because chm doesn't support UTF-8
TempDir := A_Temp "\compile_chm\"
FileCreateDir, % TempDir
Loop, Files, *.*, DR
if !(A_LoopFileFullPath ~= ".git")
FileCreateDir, % TempDir A_LoopFileFullPath
FileEncoding, UTF-8
Loop, Files, *.*, FR
{
if (A_LoopFileExt = "htm")
{
FileRead, filecontent, % A_LoopFileLongPath
StringReplace, filecontent, filecontent, "text/html; charset=UTF-8", "text/html; charset=ISO-8859-1"
FileAppend, % filecontent, % TempDir A_LoopFileFullPath, CP28591
}
else
FileCopy, % A_LoopFileLongPath, % TempDir A_LoopFileFullPath
}
; Rebuild Index.hhk and Table of Contents.hhc.
RunWait "%A_AhkPath%" "%TempDir%static\source\CreateFiles4Help.ahk"
RunWait "%A_AhkPath%" "static\source\CreateFiles4Help.ahk"
; Compile AutoHotkey.chm.
RunWait %hhc% "%TempDir%\Project.hhp"
FileMove, %TempDir%\AutoHotkey.chm, %A_ScriptDir%\AutoHotkey.chm, 1
FileRemoveDir, % TempDir, 1