Repository navigation
Expand file tree
/
Copy pathSmartMath_Config.bas
More file actions
542 lines (457 loc) · 22.6 KB
/
Copy pathSmartMath_Config.bas
File metadata and controls
542 lines (457 loc) · 22.6 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
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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
#include once "SmartMath_Globals.bi"
' -----------------------------------------------------------------------------
' Settings Loading & Saving
' -----------------------------------------------------------------------------
#define SMARTMATH_OPTIONS_PLUGIN_NAME WStr("SmartMath")
#define SMARTMATH_OPT_DECIMALS WStr("Decimals")
#define SMARTMATH_OPT_COLOR WStr("Color")
#define SMARTMATH_OPT_THOUSANDS_SEPARATOR WStr("ThousandsSeparator")
#define SMARTMATH_OPT_COMPLEX_NUMBERS WStr("ComplexNumbers")
#define SMARTMATH_OPT_SHOW_ERRORS WStr("ShowErrors")
#define SMARTMATH_OPT_SYNTAX_HIGHLIGHT WStr("SyntaxHighlight")
#define SMARTMATH_OPT_LOG_PARSED_LINES WStr("LogParsedLines")
#define SMARTMATH_OPT_DECIMAL_SEPARATOR_CHAR WStr("DecimalSeparatorChar")
#define SMARTMATH_OPT_THOUSANDS_SEPARATOR_CHAR WStr("ThousandsSeparatorChar")
#define SMARTMATH_OPT_ARRAY_OUTPUT_SEPARATOR_CHAR WStr("ArrayOutputSeparatorChar")
#define SMARTMATH_ACTIVE_FRAMES_OPTION_NAME WStr("ActiveSmartMathFrames")
const SMARTMATH_OPT_STR_MAX_CHARS = 32
const SMARTMATH_ACTIVE_FRAME_FILE_SEPARATOR as UShort = 10 '' LF
type SMARTMATH_SETTINGS_CACHE
isInitialized as BOOL
hasDecimals as BOOL
hasColor as BOOL
hasThousandsSeparator as BOOL
hasComplexNumbers as BOOL
hasShowErrors as BOOL
hasSyntaxHighlight as BOOL
hasLogParsedLines as BOOL
hasDecimalSeparator as BOOL
hasThousandsSeparatorChar as BOOL
hasArrayOutputSeparator as BOOL
nDecimals as Integer
crResultColor as COLORREF
bUseThousandsSeparator as BOOL
bSupportComplexNumbers as BOOL
bShowErrors as BOOL
bSyntaxHighlight as BOOL
bLogParsedLines as BOOL
sDecimalSeparator as String
sThousandsSeparator as String
sArrayOutputSeparator as String
nActiveFrameFilesLen as Integer
activeFrameFiles(any) as UShort
end type
' note: all the fields are 0-initialized by default, so no need to initialize them manually
dim shared g_settingsCache as SMARTMATH_SETTINGS_CACHE
private sub ResetSettingsCacheReadState()
g_settingsCache.hasDecimals = FALSE
g_settingsCache.hasColor = FALSE
g_settingsCache.hasThousandsSeparator = FALSE
g_settingsCache.hasComplexNumbers = FALSE
g_settingsCache.hasShowErrors = FALSE
g_settingsCache.hasSyntaxHighlight = FALSE
g_settingsCache.hasLogParsedLines = FALSE
g_settingsCache.hasDecimalSeparator = FALSE
g_settingsCache.hasThousandsSeparatorChar = FALSE
g_settingsCache.hasArrayOutputSeparator = FALSE
end sub
private sub CacheSetInt(byref hasValue as BOOL, byref cacheValue as Integer, byval value as Integer)
hasValue = TRUE
cacheValue = value
end sub
private sub CacheSetDword(byref hasValue as BOOL, byref cacheValue as DWORD, byval value as DWORD)
hasValue = TRUE
cacheValue = value
end sub
private sub CacheSetBool(byref hasValue as BOOL, byref cacheValue as BOOL, byval value as BOOL)
hasValue = TRUE
cacheValue = value
end sub
private sub CacheSetString(byref hasValue as BOOL, byref cacheValue as String, byval value as String)
hasValue = TRUE
cacheValue = value
end sub
private sub CacheSetActiveFrameFiles(wszActiveFrameFiles() as UShort, byval nLen as Integer)
erase g_settingsCache.activeFrameFiles
g_settingsCache.nActiveFrameFilesLen = 0
if nLen <= 0 then exit sub
redim g_settingsCache.activeFrameFiles(0 to nLen)
for i as Integer = 0 to nLen - 1
g_settingsCache.activeFrameFiles(i) = wszActiveFrameFiles(i)
next i
g_settingsCache.activeFrameFiles(nLen) = 0
g_settingsCache.nActiveFrameFilesLen = nLen
end sub
private function ActiveFrameFilesSegmentCount(buf() as UShort, byval nLen as Integer) as Integer
if nLen <= 0 then return 0
dim nSegments as Integer = 1
for i as Integer = 0 to nLen - 1
if buf(i) = SMARTMATH_ACTIVE_FRAME_FILE_SEPARATOR then nSegments += 1
next i
return nSegments
end function
private function ActiveFrameFileSegmentHash(buf() as UShort, byval nStart as Integer, byval nLen as Integer) as UInteger
dim h as UInteger = &h811C9DC5
for i as Integer = 0 to nLen - 1
h = h xor cast(UInteger, buf(nStart + i))
h *= &h01000193
next i
return h
end function
private function ActiveFrameFileSegmentsEqual( _
lhs() as UShort, _
byval lhsStart as Integer, _
rhs() as UShort, _
byval rhsStart as Integer, _
byval nLen as Integer _
) as BOOL
for i as Integer = 0 to nLen - 1
if lhs(lhsStart + i) <> rhs(rhsStart + i) then return FALSE
next i
return TRUE
end function
private function CacheMatchesActiveFrameFiles(wszActiveFrameFiles() as UShort, byval nLen as Integer) as BOOL
if nLen <> g_settingsCache.nActiveFrameFilesLen then return FALSE
if nLen <= 0 then return TRUE
dim bExactMatch as BOOL = TRUE
for i as Integer = 0 to nLen - 1
if g_settingsCache.activeFrameFiles(i) <> wszActiveFrameFiles(i) then
bExactMatch = FALSE
exit for
end if
next i
if bExactMatch then return TRUE
dim nCachedSegments as Integer = ActiveFrameFilesSegmentCount(g_settingsCache.activeFrameFiles(), g_settingsCache.nActiveFrameFilesLen)
dim nInputSegments as Integer = ActiveFrameFilesSegmentCount(wszActiveFrameFiles(), nLen)
if nInputSegments <> nCachedSegments then return FALSE
redim cachedStarts(0 to nCachedSegments - 1) as Integer
redim cachedLens(0 to nCachedSegments - 1) as Integer
redim cachedHashes(0 to nCachedSegments - 1) as UInteger
redim cachedMatched(0 to nCachedSegments - 1) as BOOL
dim nSegmentIndex as Integer = 0
dim nSegmentStart as Integer = 0
for i as Integer = 0 to g_settingsCache.nActiveFrameFilesLen
if (i = g_settingsCache.nActiveFrameFilesLen) orelse (g_settingsCache.activeFrameFiles(i) = SMARTMATH_ACTIVE_FRAME_FILE_SEPARATOR) then
cachedStarts(nSegmentIndex) = nSegmentStart
cachedLens(nSegmentIndex) = i - nSegmentStart
cachedHashes(nSegmentIndex) = ActiveFrameFileSegmentHash(g_settingsCache.activeFrameFiles(), nSegmentStart, cachedLens(nSegmentIndex))
cachedMatched(nSegmentIndex) = FALSE
nSegmentIndex += 1
nSegmentStart = i + 1
end if
next i
nSegmentStart = 0
for i as Integer = 0 to nLen
if (i = nLen) orelse (wszActiveFrameFiles(i) = SMARTMATH_ACTIVE_FRAME_FILE_SEPARATOR) then
dim nInputSegmentLen as Integer = i - nSegmentStart
dim nInputSegmentHash as UInteger = ActiveFrameFileSegmentHash(wszActiveFrameFiles(), nSegmentStart, nInputSegmentLen)
dim bFound as BOOL = FALSE
for j as Integer = 0 to nCachedSegments - 1
if cachedMatched(j) = FALSE _
andalso cachedLens(j) = nInputSegmentLen _
andalso cachedHashes(j) = nInputSegmentHash _
andalso ActiveFrameFileSegmentsEqual(wszActiveFrameFiles(), nSegmentStart, g_settingsCache.activeFrameFiles(), cachedStarts(j), nInputSegmentLen) then
cachedMatched(j) = TRUE
bFound = TRUE
exit for
end if
next j
if bFound = FALSE then return FALSE
nSegmentStart = i + 1
end if
next i
return TRUE
end function
private sub EnsureSettingsCacheInitialized()
if g_settingsCache.isInitialized = FALSE then
ResetSettingsCacheReadState()
end if
end sub
private function readStringW( _
byval hOptions as HANDLE, _
byref optionName as WString, _
byref outValue as WString, _
byval outChars as DWORD _
) as Integer
dim poW as PLUGINOPTIONW
poW.pOptionName = strptr(optionName)
poW.dwType = PO_STRING
poW.lpData = cast(UByte ptr, strptr(outValue))
poW.dwData = outChars * 2
dim n as Integer = CInt(SendMessage(g_hMainWnd, AKD_OPTIONW, cast(WPARAM, hOptions), cast(LPARAM, @poW)))
' OutputDebugString("[SmartMath] readStringW: optionName=" & optionName & ", n=" & n & ", outValue=" & outValue)
' PO_STRING: n is the number of bytes copied including the wide trailing L'\0' (2 bytes).
if n < 2 then
return 0
end if
return n - 2
end function
private sub writeStringW( _
byval hOptions as HANDLE, _
byref optionName as WString, _
byref valueText as WString _
)
dim poW as PLUGINOPTIONW
poW.pOptionName = strptr(optionName)
poW.dwType = PO_STRING
poW.lpData = cast(UByte ptr, strptr(valueText))
poW.dwData = (len(valueText) + 1) * 2
SendMessage(g_hMainWnd, AKD_OPTIONW, cast(WPARAM, hOptions), cast(LPARAM, @poW))
end sub
'' Integer options are stored as strings. No validation here — apply limits at each call site.
private function readIntW( _
byval hOptions as HANDLE, _
byref optionName as WString, _
byref outValue as Integer _
) as Integer
dim sBuf as WString * SMARTMATH_OPT_STR_MAX_CHARS
sBuf = WStr("")
dim nBytes as Integer = readStringW(hOptions, optionName, sBuf, SMARTMATH_OPT_STR_MAX_CHARS)
if nBytes <= 0 then return 0
outValue = CInt(Val(Str(sBuf)))
return nBytes
end function
private sub writeIntW( _
byval hOptions as HANDLE, _
byref optionName as WString, _
byval value as Integer _
)
dim sBuf as WString * SMARTMATH_OPT_STR_MAX_CHARS
sBuf = WStr(Str(value))
writeStringW(hOptions, optionName, sBuf)
end sub
private sub LoadIniSingleCharString( _
byval hOptions as HANDLE, _
byref optionName as WString, _
byref defaultPlain as String, _
byref target as String, _
byref hasFlag as BOOL, _
byref cacheStr as String _
)
dim sLocal as WString * SMARTMATH_OPT_STR_MAX_CHARS
sLocal = WStr(defaultPlain)
if readStringW(hOptions, optionName, sLocal, SMARTMATH_OPT_STR_MAX_CHARS) > 0 then
target = Left(sLocal, 1)
CacheSetString(hasFlag, cacheStr, target)
end if
end sub
sub LoadSettings()
' default values before reading the options
g_nDecimals = -1
g_crResultColor = &H008000 ' Green
g_bUseThousandsSeparator = FALSE
g_bSupportComplexNumbers = FALSE
g_bShowErrors = TRUE
g_bSyntaxHighlight = TRUE
g_bLogParsedLines = FALSE
g_sDecimalSeparator = SMARTMATH_DECIMAL_SEPARATOR_DEFAULT
g_sThousandsSeparator = SMARTMATH_THOUSANDS_SEPARATOR_DEFAULT
g_sArrayOutputSeparator = SMARTMATH_ARRAY_OUTPUT_SEPARATOR_DEFAULT
EnsureSettingsCacheInitialized()
ResetSettingsCacheReadState()
' Intentionally keep the has-value flags in the cache as FALSE when options can't be read,
' so the first SaveSettings writes current values.
if g_hMainWnd = 0 then exit sub ' nothing to do
dim hOptions as HANDLE = cast(HANDLE, SendMessage(g_hMainWnd, AKD_BEGINOPTIONSW, POB_READ, cast(LPARAM, strptr(SMARTMATH_OPTIONS_PLUGIN_NAME))))
' OutputDebugString("[SmartMath] hOptions=" & hOptions)
if hOptions = 0 then exit sub ' can not read options
dim iVal as Integer
if readIntW(hOptions, SMARTMATH_OPT_DECIMALS, iVal) > 0 then
if (iVal = -1) orelse (iVal >= 0 andalso iVal <= SMARTMATH_DECIMALS_MAX) then
g_nDecimals = iVal
CacheSetInt(g_settingsCache.hasDecimals, g_settingsCache.nDecimals, g_nDecimals)
end if
end if
if readIntW(hOptions, SMARTMATH_OPT_COLOR, iVal) > 0 then
if iVal >= 0 andalso iVal <= &HFFFFFF then
g_crResultColor = cast(COLORREF, culng(iVal))
CacheSetDword(g_settingsCache.hasColor, g_settingsCache.crResultColor, g_crResultColor)
end if
end if
if readIntW(hOptions, SMARTMATH_OPT_THOUSANDS_SEPARATOR, iVal) > 0 then
if iVal >= 0 then
g_bUseThousandsSeparator = (iVal <> 0)
CacheSetBool(g_settingsCache.hasThousandsSeparator, g_settingsCache.bUseThousandsSeparator, g_bUseThousandsSeparator)
end if
end if
if readIntW(hOptions, SMARTMATH_OPT_COMPLEX_NUMBERS, iVal) > 0 then
if iVal >= 0 then
g_bSupportComplexNumbers = (iVal <> 0)
CacheSetBool(g_settingsCache.hasComplexNumbers, g_settingsCache.bSupportComplexNumbers, g_bSupportComplexNumbers)
end if
end if
if readIntW(hOptions, SMARTMATH_OPT_SHOW_ERRORS, iVal) > 0 then
if iVal >= 0 then
g_bShowErrors = (iVal <> 0)
CacheSetBool(g_settingsCache.hasShowErrors, g_settingsCache.bShowErrors, g_bShowErrors)
end if
end if
if readIntW(hOptions, SMARTMATH_OPT_SYNTAX_HIGHLIGHT, iVal) > 0 then
if iVal >= 0 then
g_bSyntaxHighlight = (iVal <> 0)
CacheSetBool(g_settingsCache.hasSyntaxHighlight, g_settingsCache.bSyntaxHighlight, g_bSyntaxHighlight)
end if
end if
if readIntW(hOptions, SMARTMATH_OPT_LOG_PARSED_LINES, iVal) > 0 then
if iVal >= 0 then
g_bLogParsedLines = (iVal <> 0)
CacheSetBool(g_settingsCache.hasLogParsedLines, g_settingsCache.bLogParsedLines, g_bLogParsedLines)
end if
end if
LoadIniSingleCharString(hOptions, SMARTMATH_OPT_DECIMAL_SEPARATOR_CHAR, SMARTMATH_DECIMAL_SEPARATOR_DEFAULT, _
g_sDecimalSeparator, g_settingsCache.hasDecimalSeparator, g_settingsCache.sDecimalSeparator)
LoadIniSingleCharString(hOptions, SMARTMATH_OPT_THOUSANDS_SEPARATOR_CHAR, SMARTMATH_THOUSANDS_SEPARATOR_DEFAULT, _
g_sThousandsSeparator, g_settingsCache.hasThousandsSeparatorChar, g_settingsCache.sThousandsSeparator)
LoadIniSingleCharString(hOptions, SMARTMATH_OPT_ARRAY_OUTPUT_SEPARATOR_CHAR, SMARTMATH_ARRAY_OUTPUT_SEPARATOR_DEFAULT, _
g_sArrayOutputSeparator, g_settingsCache.hasArrayOutputSeparator, g_settingsCache.sArrayOutputSeparator)
' OutputDebugString("[SmartMath] LoadSettings: g_nDecimals=" & g_nDecimals)
' OutputDebugString("[SmartMath] LoadSettings: g_crResultColor=" & g_crResultColor)
' OutputDebugString("[SmartMath] LoadSettings: g_bUseThousandsSeparator=" & g_bUseThousandsSeparator)
' OutputDebugString("[SmartMath] LoadSettings: g_bSupportComplexNumbers=" & g_bSupportComplexNumbers)
' OutputDebugString("[SmartMath] LoadSettings: g_bShowErrors=" & g_bShowErrors)
' OutputDebugString("[SmartMath] LoadSettings: g_bSyntaxHighlight=" & g_bSyntaxHighlight)
' OutputDebugString("[SmartMath] LoadSettings: g_bLogParsedLines=" & g_bLogParsedLines)
' OutputDebugString("[SmartMath] LoadSettings: g_sDecimalSeparator=" & g_sDecimalSeparator)
' OutputDebugString("[SmartMath] LoadSettings: g_sThousandsSeparator=" & g_sThousandsSeparator)
' OutputDebugString("[SmartMath] LoadSettings: g_sArrayOutputSeparator=" & g_sArrayOutputSeparator)
SendMessage(g_hMainWnd, AKD_ENDOPTIONS, cast(WPARAM, hOptions), 0) ' be sure to close the options handle
Parser_SetSupportComplexNumbers(g_bSupportComplexNumbers)
g_settingsCache.isInitialized = TRUE
end sub
sub SaveSettings()
EnsureSettingsCacheInitialized()
if g_hMainWnd = 0 then exit sub ' nothing to do
dim shouldSaveDecimals as BOOL = (g_settingsCache.hasDecimals = FALSE) orElse (g_settingsCache.nDecimals <> g_nDecimals)
dim shouldSaveColor as BOOL = (g_settingsCache.hasColor = FALSE) orElse (g_settingsCache.crResultColor <> g_crResultColor)
dim shouldSaveThousandsFlag as BOOL = (g_settingsCache.hasThousandsSeparator = FALSE) orElse (g_settingsCache.bUseThousandsSeparator <> g_bUseThousandsSeparator)
dim shouldSaveComplexNumbersFlag as BOOL = (g_settingsCache.hasComplexNumbers = FALSE) orElse (g_settingsCache.bSupportComplexNumbers <> g_bSupportComplexNumbers)
dim shouldSaveShowErrorsFlag as BOOL = (g_settingsCache.hasShowErrors = FALSE) orElse (g_settingsCache.bShowErrors <> g_bShowErrors)
dim shouldSaveSyntaxHighlightFlag as BOOL = (g_settingsCache.hasSyntaxHighlight = FALSE) orElse (g_settingsCache.bSyntaxHighlight <> g_bSyntaxHighlight)
dim shouldSaveLogFlag as BOOL = (g_settingsCache.hasLogParsedLines = FALSE) orElse (g_settingsCache.bLogParsedLines <> g_bLogParsedLines)
dim shouldSaveDecimalSep as BOOL = (g_settingsCache.hasDecimalSeparator = FALSE) orElse (g_settingsCache.sDecimalSeparator <> g_sDecimalSeparator)
dim shouldSaveThousandsSep as BOOL = (g_settingsCache.hasThousandsSeparatorChar = FALSE) orElse (g_settingsCache.sThousandsSeparator <> g_sThousandsSeparator)
dim shouldSaveArraySep as BOOL = (g_settingsCache.hasArrayOutputSeparator = FALSE) orElse (g_settingsCache.sArrayOutputSeparator <> g_sArrayOutputSeparator)
' OutputDebugString("[SmartMath] SaveSettings: shouldSaveDecimals=" & shouldSaveDecimals)
' OutputDebugString("[SmartMath] SaveSettings: shouldSaveColor=" & shouldSaveColor)
' OutputDebugString("[SmartMath] SaveSettings: shouldSaveThousandsFlag=" & shouldSaveThousandsFlag)
' OutputDebugString("[SmartMath] SaveSettings: shouldSaveComplexNumbersFlag=" & shouldSaveComplexNumbersFlag)
' OutputDebugString("[SmartMath] SaveSettings: shouldSaveShowErrorsFlag=" & shouldSaveShowErrorsFlag)
' OutputDebugString("[SmartMath] SaveSettings: shouldSaveSyntaxHighlightFlag=" & shouldSaveSyntaxHighlightFlag)
' OutputDebugString("[SmartMath] SaveSettings: shouldSaveLogFlag=" & shouldSaveLogFlag)
' OutputDebugString("[SmartMath] SaveSettings: shouldSaveDecimalSep=" & shouldSaveDecimalSep)
' OutputDebugString("[SmartMath] SaveSettings: shouldSaveThousandsSep=" & shouldSaveThousandsSep)
' OutputDebugString("[SmartMath] SaveSettings: shouldSaveArraySep=" & shouldSaveArraySep)
' OutputDebugString("[SmartMath] SaveSettings: cache: hasDecimalSeparator=" & g_settingsCache.hasDecimalSeparator & " sDecimalSeparator=" & g_settingsCache.sDecimalSeparator)
' OutputDebugString("[SmartMath] SaveSettings: cache: hasThousandsSeparatorChar=" & g_settingsCache.hasThousandsSeparatorChar & " sThousandsSeparator=" & g_settingsCache.sThousandsSeparator)
' OutputDebugString("[SmartMath] SaveSettings: cache: hasArrayOutputSeparator=" & g_settingsCache.hasArrayOutputSeparator & " sArrayOutputSeparator=" & g_settingsCache.sArrayOutputSeparator)
if (shouldSaveDecimals = FALSE) _
andalso (shouldSaveColor = FALSE) _
andalso (shouldSaveThousandsFlag = FALSE) _
andalso (shouldSaveComplexNumbersFlag = FALSE) _
andalso (shouldSaveShowErrorsFlag = FALSE) _
andalso (shouldSaveSyntaxHighlightFlag = FALSE) _
andalso (shouldSaveLogFlag = FALSE) _
andalso (shouldSaveDecimalSep = FALSE) _
andalso (shouldSaveThousandsSep = FALSE) _
andalso (shouldSaveArraySep = FALSE) then
exit sub ' nothing to save
end if
dim hOptions as HANDLE = cast(HANDLE, SendMessage(g_hMainWnd, AKD_BEGINOPTIONSW, POB_SAVE, cast(LPARAM, strptr(SMARTMATH_OPTIONS_PLUGIN_NAME))))
if hOptions = 0 then exit sub ' can not save options
dim sVal as WString * SMARTMATH_OPT_STR_MAX_CHARS
if shouldSaveDecimals then
writeIntW(hOptions, SMARTMATH_OPT_DECIMALS, g_nDecimals)
CacheSetInt(g_settingsCache.hasDecimals, g_settingsCache.nDecimals, g_nDecimals)
end if
if shouldSaveColor then
writeIntW(hOptions, SMARTMATH_OPT_COLOR, CInt(clngint(culng(g_crResultColor))))
CacheSetDword(g_settingsCache.hasColor, g_settingsCache.crResultColor, g_crResultColor)
end if
if shouldSaveThousandsFlag then
writeIntW(hOptions, SMARTMATH_OPT_THOUSANDS_SEPARATOR, IIf(g_bUseThousandsSeparator, 1, 0))
CacheSetBool(g_settingsCache.hasThousandsSeparator, g_settingsCache.bUseThousandsSeparator, g_bUseThousandsSeparator)
end if
if shouldSaveComplexNumbersFlag then
writeIntW(hOptions, SMARTMATH_OPT_COMPLEX_NUMBERS, IIf(g_bSupportComplexNumbers, 1, 0))
CacheSetBool(g_settingsCache.hasComplexNumbers, g_settingsCache.bSupportComplexNumbers, g_bSupportComplexNumbers)
end if
if shouldSaveShowErrorsFlag then
writeIntW(hOptions, SMARTMATH_OPT_SHOW_ERRORS, IIf(g_bShowErrors, 1, 0))
CacheSetBool(g_settingsCache.hasShowErrors, g_settingsCache.bShowErrors, g_bShowErrors)
end if
if shouldSaveSyntaxHighlightFlag then
writeIntW(hOptions, SMARTMATH_OPT_SYNTAX_HIGHLIGHT, IIf(g_bSyntaxHighlight, 1, 0))
CacheSetBool(g_settingsCache.hasSyntaxHighlight, g_settingsCache.bSyntaxHighlight, g_bSyntaxHighlight)
end if
if shouldSaveLogFlag then
writeIntW(hOptions, SMARTMATH_OPT_LOG_PARSED_LINES, IIf(g_bLogParsedLines, 1, 0))
CacheSetBool(g_settingsCache.hasLogParsedLines, g_settingsCache.bLogParsedLines, g_bLogParsedLines)
end if
if shouldSaveDecimalSep then
sVal = WStr(g_sDecimalSeparator)
writeStringW(hOptions, SMARTMATH_OPT_DECIMAL_SEPARATOR_CHAR, sVal)
CacheSetString(g_settingsCache.hasDecimalSeparator, g_settingsCache.sDecimalSeparator, g_sDecimalSeparator)
end if
if shouldSaveThousandsSep then
sVal = WStr(g_sThousandsSeparator)
writeStringW(hOptions, SMARTMATH_OPT_THOUSANDS_SEPARATOR_CHAR, sVal)
CacheSetString(g_settingsCache.hasThousandsSeparatorChar, g_settingsCache.sThousandsSeparator, g_sThousandsSeparator)
end if
if shouldSaveArraySep then
sVal = WStr(g_sArrayOutputSeparator)
writeStringW(hOptions, SMARTMATH_OPT_ARRAY_OUTPUT_SEPARATOR_CHAR, sVal)
CacheSetString(g_settingsCache.hasArrayOutputSeparator, g_settingsCache.sArrayOutputSeparator, g_sArrayOutputSeparator)
end if
SendMessage(g_hMainWnd, AKD_ENDOPTIONS, cast(WPARAM, hOptions), 0) ' be sure to close the options handle
g_settingsCache.isInitialized = TRUE
end sub
function LoadSettings_ActiveFrames(wszActiveFrameFiles() as UShort) as Integer
erase wszActiveFrameFiles
CacheSetActiveFrameFiles(wszActiveFrameFiles(), 0)
if g_hMainWnd = 0 then return 0 ' nothing to do
dim hOptions as HANDLE = cast(HANDLE, SendMessage(g_hMainWnd, AKD_BEGINOPTIONSW, POB_READ, cast(LPARAM, strptr(SMARTMATH_OPTIONS_PLUGIN_NAME))))
if hOptions = 0 then return 0 ' can not read options
dim poW as PLUGINOPTIONW
poW.pOptionName = strptr(SMARTMATH_ACTIVE_FRAMES_OPTION_NAME)
poW.dwType = PO_BINARY
poW.lpData = 0
poW.dwData = 0
dim nBytesRequired as Integer = CInt(SendMessage(g_hMainWnd, AKD_OPTIONW, cast(WPARAM, hOptions), cast(LPARAM, @poW)))
if nBytesRequired <= 0 then
SendMessage(g_hMainWnd, AKD_ENDOPTIONS, cast(WPARAM, hOptions), 0)
return 0
end if
dim nCharsCapacity as Integer = (nBytesRequired + 1) \ 2
redim wszActiveFrameFiles(0 to nCharsCapacity)
poW.lpData = cast(UByte ptr, @wszActiveFrameFiles(0))
poW.dwData = nBytesRequired
dim nBytesRead as Integer = CInt(SendMessage(g_hMainWnd, AKD_OPTIONW, cast(WPARAM, hOptions), cast(LPARAM, @poW)))
SendMessage(g_hMainWnd, AKD_ENDOPTIONS, cast(WPARAM, hOptions), 0)
if nBytesRead <= 0 then
erase wszActiveFrameFiles
return 0
end if
dim nCharsRead as Integer = nBytesRead \ 2
if nCharsRead > nCharsCapacity then nCharsRead = nCharsCapacity
wszActiveFrameFiles(nCharsRead) = 0
CacheSetActiveFrameFiles(wszActiveFrameFiles(), nCharsRead)
return nCharsRead
end function
sub SaveSettings_ActiveFrames(wszActiveFrameFiles() as UShort, byval nLen as Integer)
if g_hMainWnd = 0 then exit sub ' nothing to do
if CacheMatchesActiveFrameFiles(wszActiveFrameFiles(), nLen) then exit sub
dim hOptions as HANDLE = cast(HANDLE, SendMessage(g_hMainWnd, AKD_BEGINOPTIONSW, POB_SAVE, cast(LPARAM, strptr(SMARTMATH_OPTIONS_PLUGIN_NAME))))
if hOptions = 0 then exit sub ' can not save options
dim poW as PLUGINOPTIONW
poW.pOptionName = strptr(SMARTMATH_ACTIVE_FRAMES_OPTION_NAME)
poW.dwType = PO_BINARY
if nLen > 0 then
poW.lpData = cast(UByte ptr, @wszActiveFrameFiles(0))
else
poW.lpData = 0
end if
poW.dwData = (nLen) * 2
SendMessage(g_hMainWnd, AKD_OPTIONW, cast(WPARAM, hOptions), cast(LPARAM, @poW))
SendMessage(g_hMainWnd, AKD_ENDOPTIONS, cast(WPARAM, hOptions), 0)
CacheSetActiveFrameFiles(wszActiveFrameFiles(), nLen)
end sub