-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsonConfig.xojo_code
203 lines (148 loc) · 3.67 KB
/
jsonConfig.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
#tag Class
Protected Class jsonConfig
#tag Method, Flags = &h0
Function getPath() As boolean
// defines config file absolute path as string
Dim root As FolderItem
Dim eName As String
// parse application name
If App.ExecutableFile <> Nil Then
eName = App.ExecutableFile.Name.NthField(".",1)
#If Debugbuild Then
eName = eName.Replace("Debug","")
#EndIf
Else
System.Log(System.LogLevelError, "Failed to get executable file name.")
End
// create folder paths
If isGlobal Then
root = SpecialFolder.SharedPreferences
Else
root = SpecialFolder.Preferences
End
If isCopyright Then
root = root.Child(App.Copyright)
Else
root = root.Child(eName)
End
If Not root.Exists Then
root.CreateFolder
End
If root <>Nil Then
folderPath = root.AbsolutePath
root = root.Child(eName + ".config")
If root<>Nil Then
configPath = root.AbsolutePath
Else
System.Log(System.LogLevelError, "Failed to open path to config file.")
End
Else
System.Log(System.LogLevelError, "Failed to open path to config file.")
End
Return True
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function init(CopyrightFolder as Boolean, GlobalConfig as Boolean) As Boolean
// do initial tasks, run once
isCopyright = CopyrightFolder
isGlobal = GlobalConfig
Do
loop until getPath
Return True
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function read() As boolean
Return True
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function write() As Boolean
End Function
#tag EndMethod
#tag Hook, Flags = &h0
Event isChanged(changed as boolean)
#tag EndHook
#tag Note, Name = readme
INITIAL SETTINGS:
jsonConfig.isGlobal (BOOLEAN)
Defines whether the config is user specific or for all the users
jsonConfig.isCopyright (BOOLEAN)
Use contents of the Copyright field instead of executable name in folder definition
#tag EndNote
#tag Property, Flags = &h0
configPath As String
#tag EndProperty
#tag Property, Flags = &h0
folderPath As String
#tag EndProperty
#tag Property, Flags = &h0
isCopyright As Boolean
#tag EndProperty
#tag Property, Flags = &h0
isGlobal As Boolean
#tag EndProperty
#tag Property, Flags = &h0
values As Dictionary
#tag EndProperty
#tag ViewBehavior
#tag ViewProperty
Name="Name"
Visible=true
Group="ID"
InitialValue=""
Type="String"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Index"
Visible=true
Group="ID"
InitialValue="-2147483648"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Super"
Visible=true
Group="ID"
InitialValue=""
Type="String"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Left"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Top"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="configPath"
Visible=false
Group="Behavior"
InitialValue=""
Type="String"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="folderPath"
Visible=false
Group="Behavior"
InitialValue=""
Type="String"
EditorType=""
#tag EndViewProperty
#tag EndViewBehavior
End Class
#tag EndClass