-
Notifications
You must be signed in to change notification settings - Fork 72
/
Settings.ahk
83 lines (76 loc) · 2.01 KB
/
Settings.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
;Settings Saved in AppData or A_scriptDir ("portable mode")
Settings_File(sf:="settings.json") {
if !FileExist(d:=(A_AppData "\aspdm"))
FileCreateDir, % d
f:=d "\" sf
return f
}
Settings_Get() {
f:=Settings_File()
if !FileExist(f) {
;Save default settings
Settings_Save(Settings_Default())
}
FileRead,s, % f
return Settings_Validate(JSON_ToObj(s))
}
Settings_Validate(j) {
j_default:=Settings_Default()
vars:="stdlib_folder|userlib_folder|customlib_folder|local_repo|local_archive|hide_installed|Show_AllPackSources|only_show_stdlib|package_source|package_sources|Check_ClientUpdates|ContentSensitiveSearch|DefaultLibMode|RememberLibMode"
loop,Parse,vars,`|
if (!j.Haskey(A_LoopField))
j[A_LoopField]:=j_default[A_LoopField]
return j
}
Settings_Default(key="") {
j:={stdlib_folder: RegExReplace(A_AhkPath,"\w+\.exe","lib")
,userlib_folder: A_MyDocuments "\AutoHotkey\Lib"
,customlib_folder: A_MyDocuments "\AutoHotkey\aspdm\Lib"
,local_repo: A_AppData "\aspdm\repo"
,local_archive: A_AppData "\aspdm\archive"
,hide_installed: true
,Show_AllPackSources: false
,only_show_stdlib: false
,package_source: "aspdm.ahkscript.org"
,package_sources: ["aspdm.ahkscript.org","aspdm.2fh.co","aspdm.1eko.com"]
,Check_ClientUpdates: true
,ContentSensitiveSearch: true
,DefaultLibMode: "Global"
,RememberLibMode: false}
if (key=="")
return j
return j[key]
}
Settings_Save(j) {
s:=JSON_FromObj(j)
f:=Settings_File()
FileDelete, % f
if ( FileExist(f) && (ErrorLevel) )
return ErrorLevel
FileAppend, % s, % f
return ErrorLevel
}
Settings_InstallGet(f) {
f := f . "\aspdm.json"
if !FileExist(f) {
Settings_InstallSave(f,false)
}
FileRead,s, % f
j:=JSON_ToObj(s)
if IsObject(j.installed)
return j
return j:={installed:{}}
}
Settings_InstallSave(f,j) {
if (j)
j.installed:=Util_ArraySort(j.installed)
else
j := {installed:{}}
s:=JSON_FromObj(j)
f := f . "\aspdm.json"
FileDelete, % f
if ( FileExist(f) && (ErrorLevel) )
return ErrorLevel
FileAppend, % s, % f
return ErrorLevel
}