-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.ahk
More file actions
352 lines (309 loc) · 9.97 KB
/
MainWindow.ahk
File metadata and controls
352 lines (309 loc) · 9.97 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
class MainWindow extends CGUI
{
logoFile := ""
; picture
picLogo := this.AddControl("Picture", "picLogo", "w200 h220 x5 y5 border cRed")
; labels:
labelName := this.AddControl("Text", "labelName", "w100 x210 y15", "Name:")
labelType := this.AddControl("Text", "labelType", "w100 xp yp+30", "Type:")
labelGUID := this.AddControl("Text", "labelGUID", "w100 xp yp+30", "Unique ID:")
labelVersion := this.AddControl("Text", "labelVersion", "w100 xp yp+30", "Version:")
labelDescription := this.AddControl("Text", "labelDescription", "w100 xp yp+30", "Description:")
labelAuthors := this.AddControl("Text", "labelAuthors", "w100 xp+550 yp-120", "Authors:")
labelDependencies := this.AddControl("Text", "labelDependencies", "w100 xp yp+180", "Dependencies:")
labelTags := this.AddControl("Text", "labelTags", "w100 xp yp+180", "Tags:")
labelLinks := this.AddControl("Text", "labelLinks", "w100 xp yp+180", "Links:")
labelRequirements := this.AddControl("Text", "labelRequirements", "w100 xp yp+180", "Requirements:")
labelSrcFiles := this.AddControl("Text", "labelSrcFiles", "w100 x10 y250", "Source files:")
labelDocFiles := this.AddControl("Text", "labelDocFiles", "w100 xp yp+230", "Documentation files:")
; info:
infoGUID := this.AddControl("Edit", "infoGUID", "x310 y75 w400 readonly")
; input:
inputName := this.AddControl("Edit", "inputName", "x310 y15 w400")
inputTypeLib := this.AddControl("Radio", "inputTypeLib", "xp yp+30 w100 checked", "Library")
inputTypeApp := this.AddControl("Radio", "inputTypeApp", "xp+105 yp w100", "Application")
inputVerMajor := this.AddControl("Edit", "inputVerMajor", "xp-105 y105 w80")
init_inputVerMajor := this.inputVerMajor.AddUpdown(0, 1000)
inputVerMinor := this.AddControl("Edit", "inputVerMinor", "xp+80 yp w80")
init_inputVerMinor := this.inputVerMinor.AddUpdown(0, 1000)
inputVerUpdate := this.AddControl("Edit", "inputVerUpdate", "xp+80 yp w80")
init_inputVerUpdate := this.inputVerUpdate.AddUpdown(0, 1000)
inputVerBugfix := this.AddControl("Edit", "inputVerBugfix", "xp+80 yp w80")
init_inputVerBugfix := this.inputVerBugfix.AddUpdown(0, 1000)
inputVerExtra := this.AddControl("Edit", "inputVerExtra", "xp+80 yp w80")
inputDescription:= this.AddControl("Edit", "inputDescription", "xp-320 yp+30 w400 r6")
; lists:
listAuthors := this.AddControl("ListView", "listAuthors", "w490 h125 x745 y40", "name|user name|homepage|email")
listDependencies := this.AddControl("ListView", "listDependencies", "wp hp xp yp+180", "name|version|id")
listTags := this.AddControl("ListView", "listTags", "wp hp xp yp+180", "tag")
listLinks := this.AddControl("ListView", "listLinks", "wp hp xp yp+180", "name|description|URL")
listRequirements := this.AddControl("ListView", "listRequirements", "wp hp xp yp+180", "type|value")
listSrcFiles := this.AddControl("ListView", "listSrcFiles", "w700 h175 x10 y275 -ReadOnly", "file name|path")
listDocFiles := this.AddControl("ListView", "listDocFiles", "wp hp xp yp+230 -ReadOnly", "file name|path")
; add buttons:
addAuthors := this.AddControl("Button", "addAuthors", "w245 x745 y165", "Add")
addDependencies := this.AddControl("Button", "addDependencies", "wp xp yp+180", "Add")
addTags := this.AddControl("Button", "addTags", "wp xp yp+180", "Add")
addLinks := this.AddControl("Button", "addLinks", "wp xp yp+180", "Add")
addRequirements := this.AddControl("Button", "addRequirements", "wp xp yp+180", "Add")
addSrcFiles := this.AddControl("Button", "addSrcFiles", "w350 x10 y450", "Add")
addDocFiles := this.AddControl("Button", "addDocFiles", "wp xp yp+230", "Add")
; remove buttons:
removeAuthors := this.AddControl("Button", "removeAuthors", "w245 x990 y165", "Remove")
removeDependencies := this.AddControl("Button", "removeDependencies", "wp xp yp+180", "Remove")
removeTags := this.AddControl("Button", "removeTags", "wp xp yp+180", "Remove")
removeLinks := this.AddControl("Button", "removeLinks", "wp xp yp+180", "Remove")
removeRequirements := this.AddControl("Button", "removeRequirements", "wp xp yp+180", "Remove")
removeSrcFiles := this.AddControl("Button", "removeSrcFiles", "w350 x360 y450", "Remove")
removeDocFiles := this.AddControl("Button", "removeDocFiles", "wp xp yp+230", "Remove")
; cancel/OK:
generateCancel := this.AddControl("Button", "generateCancel", "w245 h40 x280 y795", "Cancel")
generateDef := this.AddControl("Button", "generateDef", "wp hp x280 yp+45", "Generate definition")
generatePack := this.AddControl("Button", "generatePack", "wp hp x280 yp+45", "Generate package")
; settings:
DestroyOnClose := true
Title := "UUO definition file generator"
MaximizeBox := true
WindowColor := "0xE1EBFF"
__New()
{
GUID_Create(guid), this.infoGUID.Text := GUID_ToString(&guid)
}
generateCancel_Click()
{
this.Destroy()
}
generateDef_Click()
{
file := "test.adl" ; todo
this.GenerateDefinitionFile(file)
MsgBox 4, Ununoctium, Saved definition to %file%. Open containing directory?
IfMsgBox, Yes
{
SplitPath file,, dir
Run %dir%
}
}
generatePack_Click()
{
file := A_WorkingDir "\test.adl" ; todo
outFile := A_WorkingDir "\test.zip"
this.GenerateDefinitionFile(file)
_wd := A_WorkingDir
SetWorkingDir % _td := this.TempDir()
MsgBox % _td
; move files into tempdir
for each, row in this.listSrcFiles.Items
{
this.deepCopy(row[2], row[1])
;FileCopy % row[2], % row[1]
}
for each, row in this.listDocFiles.Items
{
this.deepCopy(row[2], row[1])
;FileCopy % row[2], % row[1]
}
pack := new ALD.PackageGenerator(file)
pack.Package(outFile)
; delete tempdir
FileRemoveDir %_td%, 1
SetWorkingDir %_wd%
MsgBox 4, Ununoctium, Package created at %outFile%. Open containing directory?
IfMsgBox, Yes
{
SplitPath outFile,, dir
Run %dir%
}
}
deepCopy(src, dest)
{
dir := ""
StringSplit parts, dest, \
if (parts0 > 1)
{
Loop % parts0 - 1
{
if (!InStr(FileExist(parts%A_Index%), "D"))
FileCreateDir % dir (dir .= "\" parts%A_Index%)
}
}
FileCopy %src%, %dest%, 1
}
TempDir()
{
Loop
{
dir := A_Temp "\UUO_" A_Index
} until (!FileExist(dir))
FileCreateDir %dir%
return dir
}
GenerateDefinitionFile(file)
{
obj := new ALD.DefinitionGenerator()
, obj.Name := this.inputName.Text
, obj.GUID := this.infoGUID.Text
, obj.Description := this.inputDescription.Text
, obj.LogoFile := this.logoFile
_type := this.inputTypeApp.GetSelectedRadioButton()
if (_type == this.inputTypeApp)
obj.Type := "app"
else
obj.Type := "lib"
_version := ""
for each, field in ["Major", "Minor", "Update", "Bugfix"]
{
if (this["inputVer" . field].Text == "")
break
_version .= ((A_Index == 1) ? "" : ".") . this["inputVer" . field].Text
}
if (this.inputVerExtra.Text != "")
_version .= (_version == "" ? "" : A_Space) . this.inputVerExtra.Text
obj.Version := _version
Loop % this.listAuthors.Items.Count
{
row := this.listAuthors.Items[A_Index]
author := { "name" : row[1] }
if (row[2] != "")
author["user-name"] := row[2]
if (row[3] != "")
author["homepage"] := row[3]
if (row[4] != "")
author["email"] := row[4]
obj.Authors.Insert(author)
}
for each, row in this.listDependencies.Items
{
; todo!
}
for each, row in this.listRequirements.Items
{
; todo!
}
for each, row in this.listSrcFiles.Items
{
obj.SrcFiles.Insert({ "path" : row[1] })
}
for each, row in this.listDocFiles.Items
{
obj.DocFiles.Insert({ "path" : row[1] })
}
for each, row in this.listTags.Items
{
obj.Tags.Insert({ "name" : row[1] })
}
for each, row in this.listLinks.Items
{
obj.Links.Insert({ "name" : row[1], "description" : row[2], "href" : row[3] })
}
obj.Write()
obj.SaveToFile(file)
}
; handlers:
PostDestroy()
{
ExitApp
}
picLogo_Click()
{
FileSelectFile logo, 3, % this.RootDir, Select the package logo, Images (*.jpg; *.jpeg; *.bmp; *.png; *.ico; *.cur; *.ani; *.scr; *.gif; *.tif; *.exif; *.wmf; *.emf)
if (ErrorLevel || !logo)
return
this.logoFile := this.picLogo.Picture := logo
}
addAuthors_Click()
{
dialog := new AuthorDialog(new Delegate(this, "onAuthorCreated"))
dialog.Owner := this.hwnd
dialog.Show()
}
onAuthorCreated(name, user, mail, url)
{
this.listAuthors.Items.Add("", name, user, mail, url)
}
removeAuthors_Click()
{
this.removeSelectedListItems(this.listAuthors)
}
addSrcFiles_Click()
{
this.addFiles(this.listSrcFiles)
}
addDocFiles_Click()
{
this.addFiles(this.listDocFiles)
}
removeSrcFiles_Click()
{
this.removeSelectedListItems(this.listSrcFiles)
}
removeDocFiles_Click()
{
this.removeSelectedListItems(this.listDocFiles)
}
addFiles(list)
{
FileSelectFile files, M3, % this.RootDir, Select the new file(s) to add.
if (!ErrorLevel && files != "")
{
Loop parse, files, `n
{
if (A_Index == 1)
{
if (this.RootDir != A_LoopField) ; todo!
root := A_LoopField . "\"
continue
}
SplitPath A_LoopField, file
list.Items.Add("", file, root . A_LoopField)
}
}
Loop 2
list.ModifyCol(A_Index, "AutoHdr")
}
shortenFilePaths()
{
for each, row in this.listSrcFiles.Items
{
if (InStr(row[1], this.RootDir) == 1) ; starts with root dir
{
row[1] := SubStr(row[1], StrLen(this.RootDir) + 2, StrLen(row[1]))
}
}
for each, row in this.listDocFiles.Items
{
if (InStr(row[1], this.RootDir) == 1) ; starts with root dir
{
row[1] := SubStr(row[1], StrLen(this.RootDir) + 2, StrLen(row[1]))
}
}
}
addTags_Click()
{
InputBox tag, Add a new tag, Enter the name of the new tag...
if (!ErrorLevel && tag != "")
{
; search if already included
for each, row in this.listTags.Items
{
if (row[1] = tag)
{
this.listTags.SelectedItem := row
return
}
}
this.listTags.Items.Add("", tag)
}
}
removeTags_Click()
{
this.removeSelectedListItems(this.listTags)
}
removeSelectedListItems(list)
{
for each, item in list.SelectedItems
{
list.Items.Delete(item)
}
}
}