forked from adampash/belvedere
/
Main_GUI.ahk
executable file
·901 lines (775 loc) · 29.8 KB
/
Main_GUI.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
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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
;
; AutoHotkey Version: 1.x
; Language: English
; Platform: Windows
; Author: Adam Pash <adam.pash@gmail.com>
; Contributor: Matthew Shorts <mshorts@gmail.com>
;
; Script Name: Main_GUI
;
; This script is the main gui portion of the application. It also has all the logic
; to create, edit, and delete folders and their assigned rules
;
; Some portions Generated using SmartGUI Creator 4.0
;This is the main GUI screen with the tabs, menu options, and status bar
; This window is always identified by Gui, 1
MANAGE:
Gui, 1: Destroy
Gui, 1: +OwnDialogs
Gui, 1: Add, Tab2, w700 h425 vTabs , Folders|Recycle Bin|Preferences
Gui, 1: Menu, MenuBar
;Items found of First Tab
Gui, 1: Tab, 1
Gui, 1: Add, ListView, NoSortHdr x62 y52 w175 h310 vFolders gListRules,Folders|Path
ListFolders := SubStr(Folders, 1, -1)
if (ListFolders != "ERROR")
{
Loop, Parse, ListFolders, |
{
SplitPath, A_LoopField, FileName,,,,FileDrive
;If no name is present we are assuming a root drive
if (FileName = "")
LV_Add(0, FileDrive, A_LoopField)
else
LV_Add(0, FileName, A_LoopField)
}
LV_ModifyCol(1, 171)
LV_ModifyCol(2, 0)
}
Gui, 1: Add, ListView, NoSortHdr x252 y82 w410 h280 vRules gSetActive, Enabled|Rules
Gui, 1: Add, Text, x252 y55, Folder:
Gui, 1: Add, Text, x290 y55 w410 vFolderPath,
Gui, 1: Add, Button, x62 y382 w30 h30 gAddFolder, +
Gui, 1: Add, Button, x92 y382 w30 h30 gRemoveFolder, -
Gui, 1: Add, Button, x30 y185 h30 vMoveUpFolder gMoveUpFolder, /\
Gui, 1: Add, Button, x30 y215 h30 vMoveDownFolder gMoveDownFolder, \/
Gui, 1: Add, Button, x252 y382 w30 h30 gAddRule, +
Gui, 1: Add, Button, x282 y382 w30 h30 gRemoveRule, -
Gui, 1: Add, Button, x312 y382 h30 vEditRule gEditRule, Edit Rule
Gui, 1: Add, Button, x675 y185 h30 vMoveUpRule gMoveUpRule, /\
Gui, 1: Add, Button, x675 y215 h30 vMoveDownRule gMoveDownRule, \/
Gui, 1: Add, Button, x620 y382 h30 vEnableButton gEnableButton, Enable
;Items found on Second Tab
IniRead, RBEnable, rules.ini, Preferences, RBEnable, 0
IniRead, RBEmpty, rules.ini, RecycleBin, RBEmpty, 0
IniRead, RBEmptyTimeValue, rules.ini, RecycleBin, RBEmptyTimeValue, %A_Space%
IniRead, RBEmptyTimeLength, rules.ini, RecycleBin, RBEmptyTimeLength, %A_Space%
StringReplace, thisEmptyTimeLength, NoDefaultDateUnits, %RBEmptyTimeLength%, %RBEmptyTimeLength%|
IniRead, RBLastEmpty, rules.ini, RecycleBin, RBLastEmpty, 0
if RBLastEmpty
FormatTime, DT, %RBLastEmpty%
else
DT :=
Gui, 1: Tab, 2
Gui, 1: Add, Checkbox, x62 y52 w585 vRBEnable gRBEnable Checked%RBEnable%, Allow %APPNAME% to manage my Recycle Bin
Gui, 1: Add, Checkbox, x100 y100 vRBEmpty Checked%RBEmpty%, Empty my Recycle Bin every
Gui, 1: Add, Edit, x255 y100 w70 vRBEmptyTimeValue Number, %RBEmptyTimeValue%
Gui, 1: Add, DropDownList, x325 y100 w65 vRBEmptyTimeLength, %thisEmptyTimeLength%
Gui, 1: Add, Text, x400 y100 vRBLastEmpty, Last Empty: %DT%
Gui, 1: Add, Button, x62 y382 h30 vRBSavePrefs gRBSavePrefs, Save Preferences
GoSub, RBEnable ;Need to Enable/Disable the controls based on first checkbox
;Items found on Third Tab
IniRead, Sleep, rules.ini, Preferences, Sleeptime, 3
IniRead, SleepLength, rules.ini, Preferences, SleeptimeLength, minutes
StringReplace, thisSleeptimeLength, NoDefaultDateUnits, %SleepLength%, %SleepLength%|
IniRead, EnableLogging, rules.ini, Preferences, EnableLogging, 0
IniRead, LogType, rules.ini, Preferences, LogType, %A_Space%
StringReplace, thisLogTypes, LogTypes, %LogType%, %LogType%|
IniRead, GrowlEnabled, rules.ini, Preferences, GrowlEnabled, 0
IniRead, TrayTipEnabled, rules.ini, Preferences, TrayTipEnabled, 0
IniRead, ConfirmExit, rules.ini, Preferences, ConfirmExit, 1
IniRead, Default_Enabled, rules.ini, Preferences, Default_Enabled, 0
IniRead, Default_ConfirmAction, rules.ini, Preferences, Default_ConfirmAction, 0
IniRead, Default_Recursive, rules.ini, Preferences, Default_Recursive, 0
Gui, 1: Tab, 3
Gui, 1: Add, Groupbox, x63 y40 w620 h70, System Options
Gui, 1: Add, Text, x70 y60 w60 h20 , Sleeptime:
Gui, 1: Add, Edit, x130 y58 w70 h20 Number vSleep, %Sleep%
Gui, 1: Add, DropDownList, x200 y58 w65 vSleeptimeLength, %thisSleeptimeLength%
Gui, 1: Add, Checkbox, x70 y90 vConfirmExit Checked%ConfirmExit%, Show confirmation dialog on exit
Gui, 1: Add, Groupbox, x63 y120 w620 h95, Logging/Alert Options
Gui, 1: Add, Checkbox, x70 y140 vEnableLogging Checked%EnableLogging%, Enable logging for this log type:
Gui, 1: Add, DropDownList, x240 y138 w60 vLogType, %thisLogTypes%
Gui, 1: Add, Checkbox, x70 y165 vGrowlEnabled Checked%GrowlEnabled%, Enable support for Growl for Windows (you must restart %APPNAME% for this setting to be applied)
Gui, 1: Add, Checkbox, x70 y190 vTrayTipEnabled Checked%TrayTipEnabled%, Enable support for Notification Area Balloon Tips
Gui, 1: Add, Groupbox, x63 y222 w620 h70, Default Rule Options
Gui, 1: Add, Text, x70 y242, The checked state of the following parameters will be the default for newly created rules:
Gui, 1: Add, Checkbox, x70 y262 w70 h20 vDefault_Enabled Checked%Default_Enabled%, Enabled
Gui, 1: Add, Checkbox, x140 y262 w95 h20 vDefault_ConfirmAction Checked%Default_ConfirmAction%, Confirm Action
Gui, 1: Add, Checkbox, x235 y262 w100 h20 vDefault_Recursive Checked%Default_Recursive%, Recursive
Gui, 1: Add, Groupbox, x63 y300 w620 h70, Command Line Parameters
Gui, 1: Add, Text, x70 y320, %APPNAME% will accept the following command line parameters and corresponding values at runtime:
Gui, 1: Add, Text, x70 y340, %A_Space%%A_Space%%A_Space%-r <integer>%A_Tab%Specifies the number of times you would like %APPNAME% to run then exit quietly.
Gui, 1: Add, Button, x62 y382 h30 vSavePrefs gSavePrefs, Save Preferences
Gui, 1: Add, Button, x580 y382 h30 vVerifyConfig gVerifyConfig, Verify Configuration
;Status Bar with the various sections
Gui, 1: Add, StatusBar
SB_SetParts(650, 74)
Gui, 1: Show, h463 w724, %APPNAME%
GoSub, RefreshVars
Return
;Handles the closure of the screens
; Gui, 1 - Main tabbed interface
; Gui, 2 - Rule create/edit screen
GuiClose:
Gui, 1: Destroy
Gui, 2: Destroy
return
;Lists the folders on the left side of the screen
ListFolders:
ActiveFolder=
Gui, 1: Default
Gui, 1: ListView, Folders
LV_Delete()
IniRead, Folders, rules.ini, Folders, Folders
ListFolders := SubStr(Folders, 1, -1)
Loop, Parse, ListFolders, |
{
SplitPath, A_LoopField, FileName,,,,FileDrive
;If no name is present we are assuming a root drive
if (FileName = "")
LV_Add(0, FileDrive, A_LoopField)
else
LV_Add(0, FileName, A_LoopField)
}
return
;Lists the rules on the right side of the screen for the actively
; selected folder on the left side of the screen
ListRules:
ActiveRule=
Gui, 1: Default
Gui, 1: ListView, Rules
LV_Delete()
if (A_EventInfo != 0)
{
Gui, 1: ListView, Folders
LV_GetText(ActiveFolder, A_EventInfo, 2)
CurrentlySelected = %A_eventinfo%
Len := StrLen(ActiveFolder) - 70
if (Len <= 0)
{
GuiControl, 1: Text, FolderPath, %ActiveFolder%
}
else
{
NewPath := RegExReplace(ActiveFolder, "^(\w+:|\\)(\\[^\\]+\\[^\\]+\\).*(\\[^\\]+\\[^\\]+)$", "$1$2...$3")
GuiControl, 1: Text, FolderPath, %NewPath%
}
}
;Retrieves the rules for the actively selected folder and displays them
; in the rule list on the right side, along with their enabled state
IniRead, RuleNames, rules.ini, %ActiveFolder%, RuleNames, %A_Space%
Gui, 1: ListView, Rules
LV_Delete()
ListRules := SubStr(RuleNames, 1, -1)
Loop, Parse, ListRules, |
{
IniRead, Enabled, rules.ini, %A_LoopField%, Enabled, 0
if (Enabled = 1)
LV_Add(0,"Yes", A_LoopField)
else
LV_Add(0,"No", A_LoopField)
}
GoSub, RefreshVars
return
;Determines the actively selected rule on the right side
; also toggles the enable/disable button dependant on the state
; of the actively selected rule
SetActive:
Gui, 1: ListView, Rules
;Blank out ActiveRule if we get the column headings
if (A_EventInfo = 0)
ActiveRule =
else
LV_GetText(ActiveRule, A_EventInfo, 2)
;Change the button based on the selected rule's enable status
IniRead, Enabled, rules.ini, %ActiveRule%, Enabled, 0
If (Enabled = 1)
GuiControl, 1:, EnableButton, Disable
else
GuiControl, 1:, EnableButton, Enable
return
;Moves folder up in the folder list on the left side of the main GUI
; the order of the folder in this list is the order of precedence
; that the application will process them in
MoveUpFolder:
Gui, 1: +OwnDialogs
Gui, 1: ListView, Folders
; make sure a folder is selected
if (ActiveFolder = "")
{
MsgBox,,Select Folder, Please select a folder to move up.
return
}
SelectedRow := LV_GetNext(RowNumber)
if (SelectedRow = 1) ;if first folder we can't move up any more
return
LV_GetText(SelectedFolder, SelectedRow, 2)
LV_GetText(PreviousFolder, SelectedRow-1, 2)
;Taking the previous folder, replacing with a temp value and then
; replacing with the new folder then writing to the file
IniRead, Folders, rules.ini, Folders, Folders
StringReplace Folders, Folders, |%SelectedFolder%|, |--|
if (SelectedRow = 2)
Folders := RegExReplace(Folders, "^\Q" . PreviousFolder . "\E\|", SelectedFolder . "|")
else
StringReplace Folders, Folders, |%PreviousFolder%|, |%SelectedFolder%|
StringReplace Folders, Folders, |--|, |%PreviousFolder%|
IniWrite, %Folders%, rules.ini, Folders, Folders
;Refresh the list then restore focus and select so that you can
; continue to press the button
Gosub, ListFolders
LV_Modify(SelectedRow-1, "Select")
GuiControl, 1: Focus, Folders
ActiveFolder := SelectedFolder ;overridden because ListFolders zeros it out
return
;Moves folder down in the folder list on the left side of the main GUI
; the order of the folder in this list is the order of precedence
; that the application will process them in
MoveDownFolder:
Gui, 1: +OwnDialogs
Gui, 1: ListView, Folders
; make sure a folder is selected
if (ActiveFolder = "")
{
MsgBox,,Select Folder, Please select a folder to move down.
return
}
SelectedRow := LV_GetNext(RowNumber)
if (SelectedRow = LV_GetCount() or SelectedRow = 0) ;if last or only folder we can't move down any more
return
LV_GetText(SelectedFolder, SelectedRow, 2)
LV_GetText(NextFolder, SelectedRow+1, 2)
;Taking the next folder, replacing with a temp value and then
; replacing with the new folder then writing to the file
IniRead, Folders, rules.ini, Folders, Folders
if (SelectedRow = 1)
Folders := RegExReplace(Folders, "^\Q" . SelectedFolder . "\E\|", "--|")
else
StringReplace Folders, Folders, |%SelectedFolder%|, |--|
StringReplace Folders, Folders, |%NextFolder%|, |%SelectedFolder%|
StringReplace Folders, Folders, --, %NextFolder%
IniWrite, %Folders%, rules.ini, Folders, Folders
;Refresh the list then restore focus and select so that you can
; continue to press the button
Gosub, ListFolders
LV_Modify(SelectedRow+1, "Select")
GuiControl, 1: Focus, Folders
ActiveFolder := SelectedFolder ;overridden because ListFolders zeros it out
return
;Moves rules up in the rule list on the right side of the main GUI
; the order of the rules in this list is the order of precedence
; that the application will process them in
MoveUpRule:
Gui, 1: +OwnDialogs
Gui, 1: ListView, Rules
; make sure a rule is selected
if (ActiveRule = "")
{
MsgBox,,Select Rule, Please select a rule to move up.
return
}
SelectedRow := LV_GetNext(RowNumber)
if (SelectedRow = 1) ;if first rule we can't move up any more
return
LV_GetText(SelectedRule, SelectedRow, 2)
LV_GetText(PreviousRule, SelectedRow-1, 2)
;Taking the previous rule, replacing with a temp value and then
; replacing with the new rule then writing to the file
IniRead, RuleNames, rules.ini, %ActiveFolder%, RuleNames
StringReplace RuleNames, RuleNames, |%SelectedRule%|, |--|
if (SelectedRow = 2)
RuleNames := RegExReplace(RuleNames, "^\Q" . PreviousRule . "\E\|", SelectedRule . "|")
else
StringReplace RuleNames, RuleNames, |%PreviousRule%|, |%SelectedRule%|
StringReplace RuleNames, RuleNames, |--|, |%PreviousRule%|
IniWrite, %RuleNames%, rules.ini, %ActiveFolder%, RuleNames
;Refresh the list then restore focus and select so that you can
; continue to press the button
Gosub, ListRules
LV_Modify(SelectedRow-1, "Select")
GuiControl, 1: Focus, Rules
ActiveRule := SelectedRule ;overridden because ListRules zeros it out
return
;Moves rules down in the rule list on the right side of the main GUI
; the order of the rules in this list is the order of precedence
; that the application will process them in
MoveDownRule:
Gui, 1: +OwnDialogs
Gui, 1: ListView, Rules
; make sure a rule is selected
if (ActiveRule = "")
{
MsgBox,,Select Rule, Please select a rule to move down.
return
}
SelectedRow := LV_GetNext(RowNumber)
if (SelectedRow = LV_GetCount() or SelectedRow = 0) ;if last or only rule we can't move down any more
return
LV_GetText(SelectedRule, SelectedRow, 2)
LV_GetText(NextRule, SelectedRow+1, 2)
IniRead, RuleNames, rules.ini, %ActiveFolder%, RuleNames
if (SelectedRow = 1)
RuleNames := RegExReplace(RuleNames, "^\Q" . SelectedRule . "\E\|", "--|")
else
StringReplace RuleNames, RuleNames, |%SelectedRule%|, |--|
StringReplace RuleNames, RuleNames, |%NextRule%|, |%SelectedRule%|
StringReplace RuleNames, RuleNames, --, %NextRule%
IniWrite, %RuleNames%, rules.ini, %ActiveFolder%, RuleNames
;Refresh the list then restore focus and select so that you can
; continue to press the button
Gosub, ListRules
LV_Modify(SelectedRow+1, "Select")
GuiControl, 1: Focus, Rules
ActiveRule := SelectedRule ;overridden because ListRules zeros it out
return
;Toggles the active state of the selected rule and saves it to the ini
EnableButton:
Gui, 1: +OwnDialogs
; make sure a rule is selected
if (ActiveRule = "")
{
MsgBox,,Select Rule, Please select a rule to enable/disable.
return
}
;Toggle the enabled setting in the ini file
IniRead, Enabled, rules.ini, %ActiveRule%, Enabled, 0
If (Enabled = 1)
IniWrite, 0, rules.ini, %ActiveRule%, Enabled
else
IniWrite, 1, rules.ini, %ActiveRule%, Enabled
Gosub, ListRules
return
;Run when the '+' button is clicked under the folder list
; responsible for showing a selection dialog and saving the folder
AddFolder:
Gui, 1: +OwnDialogs
FileSelectFolder, NewFolder, , 3, Please select a folder for %APPNAME% to monitor
if (NewFolder = "")
return
SaveFolders(NewFolder, Folders)
return
;Run when the '-' button is clicked under the folder list
; responsible for deleting the selected folder and all rules
; associated with that folder
RemoveFolder:
Gui, 1: +OwnDialogs
if (CurrentlySelected = "")
{
Msgbox,,Select Folder, Select the folder you'd like to delete.
return
}
;Confirm the delete, if no then we jump out of here
MsgBox, 4, Delete Folder, Are you sure you would like to delete the folder "%ActiveFolder%" ?
IfMsgBox No
return
;Get the currently selected folder and delete from the screen
Gui, 1: Default
Gui, 1: ListView, Folders
LV_GetText(RemoveFolder, CurrentlySelected, 2)
LV_GetText(RemoveFolderName, CurrentlySelected, 3)
;Delete the selected folder from above from the ini file list
StringReplace, Folders, Folders, %RemoveFolder%|,,
IniWrite, %Folders%, rules.ini, Folders, Folders
;Delete all the rules associated with the selected folder from above
IniRead, RuleNames, rules.ini, %RemoveFolder%, RuleNames
Loop, Parse, RuleNames, |
{
if (A_LoopField != "")
{
StringReplace, AllRuleNames, AllRuleNames, %A_LoopField%|,,
IniDelete, rules.ini, %A_LoopField%
}
}
;Clean-up GUI when folder is removed
GuiControl, 1: Text, FolderPath, %A_Space%
;Rewrite the rule names now that we have delete all of the
; ones associated with this folder
IniWrite, %AllRuleNames%, rules.ini, Rules, AllRuleNames
IniDelete, rules.ini, %RemoveFolder%
Gosub, RefreshVars
Gosub, ListFolders
Log("Folder Removed: " ActiveFolder, "System")
Notify("Folder Removed: " ActiveFolder, "System")
WinNotify("Folder Removed: " ActiveFolder, "System")
Gosub, ListRules
return
;Run when the '-' button is clicked under the rule list
; this is responsible for confirming and completing the actual
; delete from the ini file
RemoveRule:
Gui, 1: +OwnDialogs
if (ActiveRule = "")
{
MsgBox,,Select Rule, Please select a rule to delete.
return
}
;Confirm the delete, and if yes, remove from the screen and ini file
MsgBox, 4, Delete Rule, Are you sure you would like to delete the rule "%ActiveRule%" ?
IfMsgBox No
return
StringReplace, RuleNames, RuleNames, %ActiveRule%|,,
Iniwrite, %RuleNames%, rules.ini, %ActiveFolder%, RuleNames
StringReplace, AllRuleNames, AllRuleNames, %ActiveRule%|,,
Iniwrite, %AllRuleNames%, rules.ini, Rules, AllRulenames
Inidelete, rules.ini, %ActiveRule%
Log("Rule Removed: " ActiveRule, "System")
Notify("Rule Removed: " ActiveRule, "System")
WinNotify("Rule Removed: " ActiveRule, "System")
Gosub, RefreshVars
Gosub, ListRules
return
;Run when the 'Save Preferences' button is clicked on the Preferences tab
; writes the information to the ini file
SavePrefs:
Gui, 1: +OwnDialogs
Gui, 1: Submit, NoHide
SleepTime := Sleep
SleeptimeLength := SleeptimeLength
;Getting old values for enhanced logging prior to writing new ones
IniRead, Old_EnableLogging, rules.ini, Preferences, EnableLogging
IniRead, Old_Sleeptime, rules.ini, Preferences, Sleeptime
IniRead, Old_SleeptimeLength, rules.ini, Preferences, SleeptimeLength
IniRead, Old_GrowlEnabled, rules.ini, Preferences, GrowlEnabled
IniRead, Old_TrayTipEnabled, rules.ini, Preferences, TrayTipEnabled
IniWrite, %Sleep%, rules.ini, Preferences, Sleeptime
IniWrite, %SleeptimeLength%, rules.ini, Preferences, SleeptimeLength
IniWrite, %EnableLogging%, rules.ini, Preferences, EnableLogging
IniWrite, %LogType%, rules.ini, Preferences, LogType
IniWrite, %GrowlEnabled%, rules.ini, Preferences, GrowlEnabled
IniWrite, %TrayTipEnabled%, rules.ini, Preferences, TrayTipEnabled
IniWrite, %ConfirmExit%, rules.ini, Preferences, ConfirmExit
IniWrite, %Default_Enabled%, rules.ini, Preferences, Default_Enabled
IniWrite, %Default_ConfirmAction%, rules.ini, Preferences, Default_ConfirmAction
IniWrite, %Default_Recursive%, rules.ini, Preferences, Default_Recursive
if (EnableLogging <> Old_EnableLogging)
{
if (EnableLogging = 1)
{
if(LogType = "")
{
MsgBox,,Missing Logging Type, Please select a logging type
return
}
Log("Logging has been enabled with type: " . LogType, "System")
Notify("Logging has been enabled with type: " . LogType, "System")
WinNotify("Logging has been enabled with type: " . LogType, "System")
}
else if (EnableLogging = 0)
{
Log("Logging has been disabled", "System")
Notify("Logging has been disabled", "System")
WinNotify("Logging has been disabled", "System")
}
}
Log("Preferences have been saved", "System")
Notify("Preferences have been saved", "System")
WinNotify("Preferences have been saved", "System")
if (Old_Sleeptime <> SleepTime or Old_SleeptimeLength <> SleeptimeLength)
{
Log("Preferences - Sleeptime changed from " . Old_Sleeptime . " " . Old_SleeptimeLength . " to " . SleepTime . " " . SleeptimeLength , "System")
Notify("Preferences - Sleeptime changed from " . Old_Sleeptime . " " . Old_SleeptimeLength . " to " . SleepTime . " " . SleeptimeLength , "System")
WinNotify("Preferences - Sleeptime changed from " . Old_Sleeptime . " " . Old_SleeptimeLength . " to " . SleepTime . " " . SleeptimeLength , "System")
}
if (Old_GrowlEnabled <> GrowlEnabled or Old_TrayTipEnabled <> TrayTipEnabled)
{
MsgBox, 4, Restart?, You must restart %APPNAME% for your new setting to take effect.`nWould you like to restart now?
IfMsgBox No
return
GoSub, Restart
}
MsgBox,,Saved Settings, Your settings have been saved.
return
;Run when the 'Save Preferences' button is clicked on the Recycle Bin tab
; writes the information to the ini file
RBSavePrefs:
Gui, 1: +OwnDialogs
Gui, 1: Submit, NoHide
IniWrite, %RBEnable%, rules.ini, Preferences, RBEnable
;Check to see if all boxes are filled properly
if( RBEnable = 1 )
{
;Check Recycle Bin Empty values are chosen if section is enabled
if (RBEmpty = 1)
{
if (RBEmptyTimeValue = "")
{
MsgBox,,Missing Empty Time, Please insert a time value to empty the Recycle Bin
return
}
else if (RBEmptyTimeLength = "")
{
MsgBox,,Missing Empty Time Length, Please select a time value length to empty the Recycle Bin
return
}
}
}
;Get Old values before writing new ones
IniRead, Old_RBEmptyTimeValue, rules.ini, RecycleBin, RBEmptyTimeValue, 0
IniRead, Old_RBEmptyTimeLength, rules.ini, RecycleBin, RBEmptyTimeLength, %A_Space%
IniWrite, %RBEmpty%, rules.ini, RecycleBin, RBEmpty
IniWrite, %RBEmptyTimeValue%, rules.ini, RecycleBin, RBEmptyTimeValue
IniWrite, %RBEmptyTimeLength%, rules.ini, RecycleBin, RBEmptyTimeLength
IniWrite, %A_Now%, rules.ini, RecycleBin, RBLastEmpty
Log("Recycle Bin - Preferences have been saved", "System")
Notify("Recycle Bin - Preferences have been saved", "System")
WinNotify("Recycle Bin - Preferences have been saved", "System")
if (Old_RBEmptyTimeValue <> RBEmptyTimeValue or Old_RBEmptyTimeLength <> RBEmptyTimeLength)
{
Log("Recycle Bin - Sleeptime changed from " . Old_RBEmptyTimeValue . " " . Old_RBEmptyTimeLength . " to " . RBEmptyTimeValue . " " . RBEmptyTimeLength , "System")
Notify("Recycle Bin - Sleeptime changed from " . Old_RBEmptyTimeValue . " " . Old_RBEmptyTimeLength . " to " . RBEmptyTimeValue . " " . RBEmptyTimeLength , "System")
WinNotify("Recycle Bin - Sleeptime changed from " . Old_RBEmptyTimeValue . " " . Old_RBEmptyTimeLength . " to " . RBEmptyTimeValue . " " . RBEmptyTimeLength , "System")
}
MsgBox,,Saved Settings, Your settings have been saved.
return
;Run when the first check box is clicked on the Recycle Bin tab
; enables all the other GUI options on the page; was added as a precautionary function
RBEnable:
Gui, 1: Submit, NoHide
if (RBEnable = 1)
{
GuiControl, 1: Enable, RBEmpty
GuiControl, 1: Enable, RBEmptyTimeValue
GuiControl, 1: Enable, RBEmptyTimeLength
}
else
{
GuiControl, 1: Disable, RBEmpty
GuiControl, 1: Disable, RBEmptyTimeValue
GuiControl, 1: Disable, RBEmptyTimeLength
}
return
;Essentially this issues a double-click behind the scenes whenever a folder (SysListView321)
; or rule (SysListView322) is single clicked by the user. This allows us to have it selected
; rather than just clicked upon
#IfWinActive, Belvedere
~LButton::
MouseGetPos,,,,ClickedControl
if (ClickedControl = "SysListView321") or (ClickedControl = "SysListView322")
{
Sleep, 10
Click 2
}
return
;A quick routine to update the master Folder list and rule names as well as the status bar
RefreshVars:
IniRead, Folders, rules.ini, Folders, Folders
IniRead, AllRuleNames, rules.ini, Rules, AllRuleNames
ListFolders := SubStr(Folders, 1, -1)
FolderCount := 0
Loop, Parse, ListFolders, |
{
FolderCount++
}
ListRules := SubStr(AllRuleNames, 1, -1)
RuleCount := 0
Loop, Parse, ListRules, |
{
RuleCount++
}
SB_SetText(APPNAME . " is currently managing " . FolderCount . " folders with " . RuleCount . " total rules" , 1)
return
;Responsible for handling a folder that is drag-and-dropped over the folders list
; you can drag both a file or a folder and it will confirm the addition of the folder
; only works on the folder list for the time being
GuiDropFiles:
Gui, 1: +OwnDialogs
;Only accept DnD in the folders list box
if A_GuiControl = Folders
{
StringSplit, F, A_GuiEvent, `n
SplitPath, F1, , NewFolder
MsgBox, 4, Add Folder, Would you like to add the following folder to your folder list?`n %NewFolder%
IfMsgBox Yes
SaveFolders(NewFolder, Folders)
}
Return
;Response for handling the right click event and displaying of the context menu
; used right now for the context menu for all the rules
GuiContextMenu:
;Only displaying for the Rules section right now
if (A_GuiControl = "Rules" and A_EventInfo != 0)
{
Gui, 1: ListView, Folders
FocusedRowNumber := LV_GetNext(0, "F")
LV_GetText(FolderName, FocusedRowNumber, 2)
Menu, ContextMenu, UseErrorLevel ;allows us to try to delete the menu, even if it doesn't exist, by surpressing hard stop
Menu, CopySubmenu, DeleteAll
Menu, MoveSubmenu, DeleteAll
ListFolders := SubStr(Folders, 1, -1)
Loop, Parse, ListFolders, |
{
if (A_LoopField != FolderName)
{
Menu, CopySubmenu, Add, %A_LoopField%, CopyRule
Menu, MoveSubmenu, Add, %A_LoopField%, MoveRule
}
}
Menu, ContextMenu, Add, Copy to, :CopySubmenu
Menu, ContextMenu, Add, Move to, :MoveSubmenu
Menu, ContextMenu, Show, %A_GuiX%, %A_GuiY%
}
Return
;Reponsible for copying a rule from one folder to another
CopyRule:
;Getting the selected rule
Gui, 1: ListView, Rules
FocusedRowNumber := LV_GetNext(0, "F")
LV_GetText(RuleName, FocusedRowNumber, 2)
;getting the current folder
Gui, 1: ListView, Folders
FocusedRowNumber := LV_GetNext(0, "F")
LV_GetText(FolderName, FocusedRowNumber, 2)
;Retrieve the current main settings for the rule selected for editing
IniRead, Folder, rules.ini, %RuleName%, Folder, %A_Space%
IniRead, Action, rules.ini, %RuleName%, Action, %A_Space%
IniRead, Destination, rules.ini, %RuleName%, Destination, %A_Space%
IniRead, Overwrite, rules.ini, %RuleName%, Overwrite, 0
IniRead, Compress, rules.ini, %RuleName%, Compress, 0
IniRead, Matches, rules.ini, %RuleName%, Matches, %A_Space%
IniRead, Enabled, rules.ini, %RuleName%, Enabled, 0
IniRead, ConfirmAction, rules.ini, %RuleName%, ConfirmAction, 0
IniRead, Recursive, rules.ini, %RuleName%, Recursive, 0
IniRead, AttribReadOnly, rules.ini, %ActiveRule%, AttribReadOnly, 0
IniRead, AttribHidden, rules.ini, %ActiveRule%, AttribHidden, 0
IniRead, AttribSystem, rules.ini, %ActiveRule%, AttribSystem, 0
;Loops to determine number of subjects within a rule
NumOfRules := 1
Loop
{
IniRead, MultiRule, rules.ini, %RuleName%, Subject%A_Index%
if (MultiRule != "ERROR")
NumOfRules++
else
break
}
LineNum =
Loop
{
if ((A_Index-1) = NumOfRules)
break
if (A_Index = 1)
RuleNum =
else
RuleNum := A_Index - 1
IniRead, Subject%RuleNum%, rules.ini, %RuleName%, Subject%RuleNum%
IniRead, Verb%RuleNum%, rules.ini, %RuleName%, Verb%RuleNum%
IniRead, Object%RuleNum%, rules.ini, %RuleName%, Object%RuleNum%
IniRead, Units%RuleNum%, rules.ini, %RuleName%, Units%RuleNum%
if (LineNum = "")
LineNum := 0
LineNum++
}
StringReplace, RuleMatchList, AllRuleNames, |,`,,ALL
Loop
{
if RuleName in %RuleMatchList%
{
RegExMatch(RuleName, "^(.*)\s(\((\d+)\))$", Match)
if (Match3 != "")
{
Match3++
RuleName = %Match1% (%Match3%)
}
else
{
RuleName = %RuleName% (1)
}
}
else
{
break
}
}
;write rulename into list for the chosen folder and all rules lists
IniRead, FolderRuleNames, rules.ini, %A_ThisMenuItem%, RuleNames, %A_Space%
IniWrite, %FolderRuleNames%%RuleName%|, rules.ini, %A_ThisMenuItem%, RuleNames
IniWrite, %AllRuleNames%%RuleName%|, rules.ini, Rules, AllRuleNames
;write rule options
IniWrite, %A_ThisMenuItem%\*, rules.ini, %RuleName%, Folder
IniWrite, %Enabled%, rules.ini, %RuleName%, Enabled
IniWrite, %ConfirmAction%, rules.ini, %RuleName%, ConfirmAction
IniWrite, %Recursive%, rules.ini, %RuleName%, Recursive
IniWrite, %Matches%, rules.ini, %RuleName%, Matches
IniWrite, %Action%, rules.ini, %RuleName%, Action
IniWrite, %AttribReadOnly%, rules.ini, %RuleName%, AttribReadOnly
IniWrite, %AttribHidden%, rules.ini, %RuleName%, AttribHidden
IniWrite, %AttribSystem%, rules.ini, %RuleName%, AttribSystem
;only need to write these tags if they need a destination
if (GUIAction != "Send file to Recycle Bin") and (GUIAction != "Delete file")
{
IniWrite, %Destination%, rules.ini, %RuleName%, Destination
IniWrite, %Overwrite%, rules.ini, %RuleName%, Overwrite
IniWrite, %Compress%, rules.ini, %RuleName%, Compress
}
;save the rest of the subject combos
Loop
{
if (A_Index = 1)
thisLine =
else
thisLine := A_Index - 1
if (A_Index > LineNum)
break
if (Subject%thisLine% != "")
{
if (thisLine = "")
RuleNum =
else if (RuleNum = "")
RuleNum := 1
else
RuleNum++
IniWrite, % Subject%thisLine%, rules.ini, %RuleName%, Subject%RuleNum%
IniWrite, % Verb%thisLine%, rules.ini, %RuleName%, Verb%RuleNum%
IniWrite, % Object%thisLine%, rules.ini, %RuleName%, Object%RuleNum%
IniWrite, % Units%thisLine%, rules.ini, %RuleName%, Units%RuleNum%
}
}
Return
;Reponsible for moving a rule from one folder to another
MoveRule:
;Getting the selected rule
Gui, 1: ListView, Rules
FocusedRowNumber := LV_GetNext(0, "F")
LV_GetText(RuleName, FocusedRowNumber, 2)
;getting the current folder
Gui, 1: ListView, Folders
FocusedRowNumber := LV_GetNext(0, "F")
LV_GetText(FolderName, FocusedRowNumber, 2)
;deleting from the current folder
IniRead, RuleNames, rules.ini, %FolderName%, RuleNames
StringReplace, RuleNames, RuleNames, %RuleName%|,,
IniWrite, %RuleNames%, rules.ini, %FolderName%, RuleNames
;creating in the new folder
IniRead, RuleNames, rules.ini, %A_ThisMenuItem%, RuleNames
IniWrite, %RuleNames%%RuleName%|, rules.ini, %A_ThisMenuItem%, RuleNames
;updating rule's own folder path
IniWrite, %A_ThisMenuItem%\*, rules.ini, %RuleName%, Folder
;Refresh the list then restore focus and select so that you can
; continue to press the button
Gosub, ListRules
LV_Modify(SelectedRow-1, "Select")
GuiControl, 1: Focus, Rules
ActiveRule := SelectedRule ;overridden because ListRules zeros it out
Return
;Responsible for checking for duplicate folders and saving the newly added folder to the ini file
SaveFolders(NewFolder, Folders)
{
StringReplace, FoldersMatchList, Folders, |,`,,ALL
if NewFolder in %FoldersMatchList%
{
Msgbox, ,Duplicate Folder, A folder with this name already exists. Please choose a new folder.
return
}
Folders = %Folders%%NewFolder%|
IniWrite, %Folders%, rules.ini, Folders, Folders
IniWrite, %A_Space%, rules.ini, %NewFolder%, RuleNames
Gui, 1: Default
Gui, 1: ListView, Folders
Log("Folder Added: " NewFolder, "System")
Notify("Folder Added: " NewFolder, "System")
WinNotify("Folder Added: " NewFolder, "System")
Gosub, ListFolders
Gosub, RefreshVars
return
}