-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmergeIt.ahk
163 lines (138 loc) · 5.13 KB
/
mergeIt.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
inputFile := "start.user.js"
saveAs := "sangupackage.user.js"
; Save current changes
Send ^s
FileEncoding, UTF-8-RAW ; If it crashes here, you've got the wrong version of Autohotkey - see readme
workingDirectory = %A_WorkingDir%
SetWorkingDir, %A_ScriptDir%
; savePaths - to configure in merge.ini (make sure to end the paths with a \ or it might silently do nothing
IniRead, savePath, mergeIt.ini, SavePaths, operaSavePath, C:\CloudDrives\Dropbox\Personal\!Programming\OperaUserScripts\
IniRead, firefoxLocation, mergeIt.ini, SavePaths, firefoxSavePath, C:\Users\Wouter\AppData\Roaming\Mozilla\Firefox\Profiles\xtz5hi2x.default\gm_scripts\Sangu_Package\sangupackage.user.js
IniRead, sourceLocation, mergeIt.ini, Site, sourceLocation, C:\Users\Wouter\AppData\Roaming\Mozilla\Firefox\Profiles\xtz5hi2x.default\gm_scripts\Sangu_Package\sangupackage.user.js
IniRead, chromeRunSavePath, mergeIt.ini, SavePaths, chromeRunSavePath, C:\CloudDrives\Dropbox\Personal\!Programming\OperaUserScripts\
IniRead, chromeInstallSavePath, mergeIt.ini, SavePaths, chromeInstallSavePath, C:\CloudDrives\Dropbox\Personal\!Programming\UnixCode\TribalWars\sangupackage-release
; update version
versionFileName = version.txt
newVersion := GetNewVersion(versionFileName)
; MsgBox FINALOK: %newVersion%
UpdateVersion(newVersion, versionFileName)
;signature: ParseAndSaveFile(inputFile, savePath, saveFileName)
ParseAndSaveFile(inputFile, savePath, saveAs)
; release version does not include build nr
StringSplit, versionArray, newVersion, .
newReleaseVersion = %versionArray1%.%versionArray2%.%versionArray3%
UpdateVersion(newReleaseVersion, versionFileName)
; RELEASE COPIES
ParseAndSaveFile("release.user.js", sourceLocation, saveAs)
ParseAndSaveFile(sourceLocation . "sp-config-dist.json", sourceLocation, "sp-config.json")
ParseAndSaveFile(sourceLocation . "sangupackageversion_toMerge.php", sourceLocation, "sangupackageversion.php")
; Autocopy for chrome WEB STORE
ParseAndSaveFile("start.user.js", chromeInstallSavePath, saveAs)
;FileCopy, %sourceLocation%%saveAs%, %chromeInstallSavePath%, 1
;FileCopy, greasemonkey\manifest.json, %chromeInstallSavePath%, 1
;FileCopy, greasemonkey\favicon.png, %chromeInstallSavePath%, 1
UpdateVersion(newVersion, versionFileName)
; BUILD COPIES
; Autocopy to Firefox greasemonkey directory
; I *really* *really* should've used something else but Autohotkey for this
FileCopy, %savePath%%saveAs%, %firefoxlocation%, 1
; Autocopy for local Chrome script refresh(with manifest.json)
FileCopy, %savePath%%saveAs%, %chromeRunSavePath%, 1
FileCopy, greasemonkey\manifest.json, %chromeRunSavePath%, 1
FileCopy, greasemonkey\favicon.png, %chromeRunSavePath%, 1
; Check it in browser :)
SetTitleMatchMode RegEx
IfWinExist, ^.* \(\d+\|\d+\) - Tribal Wars - .*$
{
WinActivate
Send {F5}
}
; Restore system state
SetWorkingDir, workingDirectory
; Below are functions etc
GetNewVersion(versionFileName)
{
currentVersion =
FileRead, currentVersion, %versionFileName%
StringReplace, currentVersion, currentVersion,`r`n,,A
StringSplit, versionNumber, currentVersion, .
versionNumber4 := versionNumber4 + 1
newVersion = %versionNumber1%.%versionNumber2%.%versionNumber3%.%versionNumber4%
return %newVersion%
}
UpdateVersion(newVersion, versionFileName)
{
FileDelete, %versionFileName%
FileAppend, %newVersion%, %versionFileName%
}
ParseFile(fileName, indentCount)
{
if not FileExist(fileName)
{
MsgBox Couldn't find: %fileName% - exitting
ExitApp
}
replacedFile =
Loop, Read, %fileName%
{
replacedFile .= ParseLine(A_LoopReadLine, indentCount) . "`r"
}
StringTrimRight, replacedFile, replacedFile, 1
return %replacedFile%
}
ParseLine(line, indentCount)
{
found =
FoundInclude := RegExMatch(line, "(^\s*)?//\<!--@@INCLUDE "".*"" INDENT=\d //--\>", found)
if FoundInclude
{
; //<!--@@INCLUDE "\importit.txt" INDENT=X //-->
toIncludeFileName := RegExReplace(found, "^\s*")
StringMid, toIncludeFileName, toIncludeFileName, 18 ; jump till filename
closingQuotePosition := InStr(toIncludeFileName, """")
StringMid, newIndent, toIncludeFileName, closingQuotePosition + 9 ; Jump to indent
StringMid, newIndent, newIndent, 1, 1 ; Get indent
StringMid, toIncludeFileName, toIncludeFileName, 1, closingQuotePosition - 1 ; Get filename
If toIncludeFileName
{
toIncludeContent := ParseFile(toIncludeFileName, newIndent)
StringReplace, line, line, %found%, %toIncludeContent%
}
else
{
StringReplace, line, line, %found%
}
}
else
{
currentDateReplacer := "//<!--@@INCLUDE CURRENTDATE //-->"
IfInString, line, %currentDateReplacer%
{
currentDate =
FormatTime, currentDate, , d MMMM yyyy
StringReplace, line, line, %currentDateReplacer%, %currentDate%
}
else if indentCount
{
Loop %indentCount%
{
;line := " " . line
line := A_TAB . line
}
}
}
return %line%
}
SaveFile(fileContent, savePath, saveFileName)
{
FileDelete, %savePath%%saveFileName%
FileAppend, %fileContent%, %savePath%%saveFileName%
}
ParseAndSaveFile(inputFile, savePath, saveFileName)
{
;MsgBox %inputFile%, %savePath%, %saveFileName%
formattedOutput := ParseFile(inputFile, 0)
SaveFile(formattedOutput, savePath, saveFileName)
return %formattedOutput%
}
return