This repository has been archived by the owner on Nov 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.xojo_code
427 lines (372 loc) · 11.9 KB
/
App.xojo_code
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#tag Class
Protected Class App
Inherits Application
#tag Event
Sub Close()
// Save the preferences when the app quits
if app.saveConfig = 1 then
If Not Preferences.Save Then
MsgBox("Could not save preferences.")
End If
end if
End Sub
#tag EndEvent
#tag Event
Sub Open()
'initiate Preference
#if DebugBuild then
PreferencesModule.Initialize("wowam_debug")
#else
PreferencesModule.Initialize("wowam")
#endif
'Set default preferences on firstload
If Not Preferences.Load Then
Preferences.wowpath = "false"
Preferences.addonpath = "false"
Preferences.configVersion = 018
Preferences.logging = "false" 'v0.2.1
Preferences.sync = "false"
Preferences.checkonstart = "false"
Preferences.columnsizes = "250, 100, 85, 300, 1*"
Preferences.proxy = "false"
Preferences.proxyServer = "none"
Preferences.proxyPort = "none"
Preferences.proxyUser = "none"
Preferences.proxyUser = "none"
Preferences.proxyPassword = "none"
Preferences.cloudSave = "true"
Preferences.lastSync = "Never" 'v0.2.1
Preferences.userID = "none" 'v0.2.1
Preferences.autoUpdate = "true"
Preferences.windowMaxed = "false"
Preferences.windowWidth = 1045
Preferences.windowHeight = 327
Preferences.windowL = 0
Preferences.windowT = 0
End If
'config file compatibility
if Preferences.configVersion < app.configMinVersion then
PreferencesModule.Log("StartUp","Config-File is old and should be updated")
updateConfig
end if
'update pref prozedure (temporary)
if Preferences.proxy = "none" then
Preferences.proxy = "false"
Preferences.proxyServer = "none"
Preferences.proxyUser = "none"
Preferences.proxyUser = "none"
end if
if Preferences.cloudSave = "none" then
Preferences.cloudSave = "false"
end if
'check if the wow path is set
if Preferences.wowpath = "false" then
'set the folder dialog options
Dim dlg As New SelectFolderDialog
dlg.ActionButtonCaption = "Select"
dlg.Title = "Select your World of Warcraft folder"
dlg.PromptText = "Select your World of Warcraft folder"
dlg.InitialDirectory = SpecialFolder.Documents
Dim f As FolderItem
f = dlg.ShowModal
If f <> Nil Then
Dim checkfile as FolderItem
checkfile = f
'windows check
#if TargetWindows then
checkfile = checkfile.Child("wow.exe")
#endif
'macos check
#if TargetMacOS then
checkfile = checkfile.Child("World of Warcraft.app")
#endif
'check if wow exists and then save the paths
If checkfile.Exists = False Then
MsgBox "World of Warcraft was not found in this folder!"
Quit
else
Preferences.wowpath = EncodeBase64( FolderItem( f ).GetSaveInfo(nil) )
f = f.Child("interface").Child("addons")
Preferences.addonpath = EncodeBase64( FolderItem( f ).GetSaveInfo(nil) )
End If
Else
Msgbox "You have to choose your World of Warcraft location! WoWAM will not work without it."
Quit
End If
end if
'proxy handling
if Preferences.proxy = "true" then
app.proxy_server = Preferences.proxyServer
app.proxy_port = Preferences.proxyPort
app.proxy_user = Preferences.proxyUser
app.proxy_password = Preferences.proxyPassword
end if
'set window sizes
if not Preferences.windowMaxed = "true" then
Dim width as Integer = Preferences.windowWidth
Dim height as Integer = Preferences.windowHeight
main.Width = width
main.Height = height
if Preferences.windowL > 0 then
main.Left = Preferences.windowL
main.Top = Preferences.windowT
else
'center window
main.Left = (Screen(0).AvailableWidth-main.Width)/2
main.Top = (Screen(0).AvailableHeight-main.Height)/2
end if
else
main.FullScreen = false
main.Maximize
end if
End Sub
#tag EndEvent
#tag Method, Flags = &h0
Function FindRow(searchString as String, aListbox as Listbox) As integer
'search a string in a listbox and returns the row number on a match
dim i,j as Integer
dim FoundAt as Integer
for i = 0 to aListbox .listcount -1
for j = 0 to aListbox.columnCount
if FindWholeWord( aListbox .cell(i,j), searchString) = True then
FoundAt = i
exit
end
next
next
if FoundAt >=0 then
return FoundAt
else
return -1
end if
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function FindWholeWord(source As string, find As string) As boolean
Dim rg as New RegEx
Dim myMatch as RegExMatch
rg.SearchPattern=find
myMatch=rg.search(source)
if myMatch <> Nil then
return True
else
return False
End if
exception err as RegExException
MsgBox err.message
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function getFilesByExt(fFolder As FolderItem, sExtension As String, Optional bRecursive As Boolean) As FolderItem()
// Returns FolderItem() with items from bRecursive fFolder that have File Extension sExtension
Dim fWrk, fResult(), fRecursive() As FolderItem
Dim sNameParts() As String
If fFolder <> Nil And fFolder.Directory Then
// Use iItems to speed things up
Dim iItems As Integer = fFolder.Count
For i As Integer = 1 To iItems
// Use fTmp to speed things up
fWrk = fFolder.Item(i)
If fWrk.Directory Then
If bRecursive Then
// Go recursive
fRecursive = getFilesByExt(fWrk, sExtension, bRecursive)
Dim iItemsR As Integer = fRecursive.Ubound
For r As Integer = 0 To iItemsR
fResult.Append(fRecursive(r))
Next
End If
Else
// Add to fResult() if Extension matches
sNameParts = Split(fWrk.Name, ".")
If sNameParts.Ubound > 0 And sNameParts.Pop = sExtension Then
fResult.Append(fWrk)
End If
End If
Next
End If
Return fResult()
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function getPatreonLink(source as string) As string
'figures out the patreon link https?:\/\/(?:www.)?patreon\.com\/([^<\/]+)
Dim RegExer as New RegEx
Dim RegExerMatch as New RegExMatch
Dim Result as String
RegExer.SearchPattern="https?:\/\/(?:www.)?patreon\.com\/([^<\/]+)"
RegExerMatch=RegExer.search(source)
if RegExerMatch <> Nil then
result = RegExerMatch.SubExpressionString(0)
end if
if result = "" then
result = "none"
end if
return result
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function getRegex(source as String, search as String) As string
Dim RegExer as New RegEx
Dim RegExerMatch as New RegExMatch
Dim Result as String
'search addon name
RegExer.SearchPattern=search
RegExerMatch=RegExer.search(source)
if RegExerMatch <> Nil then
result = RegExerMatch.SubExpressionString(1)
else
result = "nomatch"
end if
return result
End Function
#tag EndMethod
#tag Method, Flags = &h0
Sub updateConfig()
'this is the configUpdater part
Dim Version as String = Preferences.configVersion
'config fails on version entry and will be reset
If Version = "none" then
Dim appFolder As FolderItem = SpecialFolder.ApplicationData.Child(gAppName).Child("wowam.pref")
msgbox "Your config is completely outdated, and needs to be reset! Please restart the WoW Addon Manager."
appFolder.Delete()
If appFolder.LastErrorCode > 0 then
MsgBox Str(appFolder.LastErrorCode)
End if
app.saveConfig = 0
Quit
end if
'update to version 021
If Version = "18" then
Preferences.logging = "false"
Preferences.lastSync = "Never"
Preferences.userID = "none"
Preferences.configVersion = 021
End If
End Sub
#tag EndMethod
#tag Property, Flags = &h0
configMinVersion As Integer = 21
#tag EndProperty
#tag Property, Flags = &h0
loaded As Integer = 0
#tag EndProperty
#tag Property, Flags = &h0
proxy_password As string
#tag EndProperty
#tag Property, Flags = &h0
proxy_port As integer
#tag EndProperty
#tag Property, Flags = &h0
proxy_server As string
#tag EndProperty
#tag Property, Flags = &h0
proxy_user As string
#tag EndProperty
#tag Property, Flags = &h0
refreshIsRunning As Integer = 0
#tag EndProperty
#tag Property, Flags = &h0
saveConfig As Integer = 1
#tag EndProperty
#tag Property, Flags = &h0
swAddonsURL As String
#tag EndProperty
#tag Property, Flags = &h0
swgetAddonURL As String
#tag EndProperty
#tag Property, Flags = &h0
swSyncURL As String
#tag EndProperty
#tag Property, Flags = &h0
swUpateURL As String
#tag EndProperty
#tag Property, Flags = &h0
UpdateInitiater As Kaju.UpdateInitiater
#tag EndProperty
#tag Constant, Name = kEditClear, Type = String, Dynamic = False, Default = \"&Delete", Scope = Public
#Tag Instance, Platform = Windows, Language = Default, Definition = \"&Delete"
#Tag Instance, Platform = Linux, Language = Default, Definition = \"&Delete"
#tag EndConstant
#tag Constant, Name = kFileQuit, Type = String, Dynamic = False, Default = \"&Quit", Scope = Public
#Tag Instance, Platform = Windows, Language = Default, Definition = \"E&xit"
#tag EndConstant
#tag Constant, Name = kFileQuitShortcut, Type = String, Dynamic = False, Default = \"", Scope = Public
#Tag Instance, Platform = Mac OS, Language = Default, Definition = \"Cmd+Q"
#Tag Instance, Platform = Linux, Language = Default, Definition = \"Ctrl+Q"
#tag EndConstant
#tag ViewBehavior
#tag ViewProperty
Name="configMinVersion"
Group="Behavior"
InitialValue="018"
Type="Integer"
#tag EndViewProperty
#tag ViewProperty
Name="loaded"
Group="Behavior"
InitialValue="0"
Type="Integer"
#tag EndViewProperty
#tag ViewProperty
Name="proxy_password"
Group="Behavior"
Type="string"
EditorType="MultiLineEditor"
#tag EndViewProperty
#tag ViewProperty
Name="proxy_port"
Group="Behavior"
Type="integer"
#tag EndViewProperty
#tag ViewProperty
Name="proxy_server"
Group="Behavior"
Type="string"
EditorType="MultiLineEditor"
#tag EndViewProperty
#tag ViewProperty
Name="proxy_user"
Group="Behavior"
Type="string"
EditorType="MultiLineEditor"
#tag EndViewProperty
#tag ViewProperty
Name="refreshIsRunning"
Group="Behavior"
InitialValue="0"
Type="Integer"
#tag EndViewProperty
#tag ViewProperty
Name="saveConfig"
Group="Behavior"
InitialValue="1"
Type="Integer"
#tag EndViewProperty
#tag ViewProperty
Name="swAddonsURL"
Group="Behavior"
InitialValue="https://wowam.sys-worx.net/addons.php"
Type="String"
#tag EndViewProperty
#tag ViewProperty
Name="swgetAddonURL"
Group="Behavior"
InitialValue="https://wowam.sys-worx.net/getAddonUrl.php"
Type="String"
#tag EndViewProperty
#tag ViewProperty
Name="swSyncURL"
Group="Behavior"
InitialValue="https://wowam.sys-worx.net/sync.php"
Type="String"
#tag EndViewProperty
#tag ViewProperty
Name="swUpateURL"
Group="Behavior"
InitialValue="https://wowam.sys-worx.net/UpdateInformation.json"
Type="String"
#tag EndViewProperty
#tag EndViewBehavior
End Class
#tag EndClass