-
Notifications
You must be signed in to change notification settings - Fork 75
/
Belvedere.ahk
executable file
·409 lines (391 loc) · 10.1 KB
/
Belvedere.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
;
; AutoHotkey Version: 1.x
; Language: English
; Platform: Windows
; Author: Adam Pash <[email protected]>
;
; Script Function:
; Automated file manager
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance force
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
StringCaseSense, On
SetFormat, float, 0.2
GoSub, SetVars
GoSub, TRAYMENU
GoSub, MENUBAR
Gosub, BuildINI
IniRead, Folders, rules.ini, Folders, Folders
IniRead, FolderNames, rules.ini, Folders, FolderNames
IniRead, AllRuleNames, rules.ini, Rules, AllRuleNames
IniRead, SleepTime, rules.ini, Preferences, SleepTime
if (AllRuleNames = "ERROR")
{
AllRuleNames=
}
;main execution loop
Loop
{
;msgbox, running
;Loops through all the rule names for execution
Loop, Parse, AllRuleNames, |
{
thisRule = %A_LoopField%
;msgbox, %thisrule%
NumOfRules := 1
;Loops to determine number of subjects within a rule
Loop
{
IniRead, MultiRule, rules.ini, %thisRule%, Subject%A_Index%
if (MultiRule != "ERROR")
{
NumOfRules++
}
else
{
break
}
}
if (thisRule = "ERROR") or (thisRule = "")
{
continue
}
;msgbox, %thisRule% has %Numofrules% rules
IniRead, Folder, rules.ini, %thisRule%, Folder
IniRead, Enabled, rules.ini, %thisRule%, Enabled
IniRead, ConfirmAction, rules.ini, %thisRule%, ConfirmAction, 0
IniRead, Recursive, rules.ini, %thisRule%, Recursive, 0
IniRead, Action, rules.ini, %thisRule%, Action
IniRead, Destination, rules.ini, %thisRule%, Destination, 0
IniRead, Matches, rules.ini, %thisRule%, Matches
;If rule is not enabled, just skip over it
if (Enabled = 0)
{
continue
}
;MsgBox, %thisRule% is currently running
;Loop to read the subjects, verbs and objects for the list defined
Loop
{
if ((A_Index-1) = NumOfRules)
{
break
}
if (A_Index = 1)
{
RuleNum =
}
else
{
RuleNum := A_Index - 1
}
IniRead, Subject%RuleNum%, rules.ini, %thisRule%, Subject%RuleNum%
IniRead, Verb%RuleNum%, rules.ini, %thisRule%, Verb%RuleNum%
IniRead, Object%RuleNum%, rules.ini, %thisRule%, Object%RuleNum%
}
;msgbox, %subject%, %subject1%, %subject2%
if (Destination != "0")
{
IniRead, Overwrite, rules.ini, %thisRule%, Overwrite
}
;Msgbox, %Subject% %Verb% %Object% %Action% %ConfirmAction% %Recursive%
;Loop through all of the folder contents
Loop %Folder%, 0, %Recursive%
{
Loop
{
if ((A_Index - 1) = NumOfRules)
{
break
}
if (A_Index = 1)
{
RuleNum =
}
else
{
RuleNum := A_Index - 1
}
;msgbox, % subject subject1 subject2
file = %A_LoopFileLongPath%
;MsgBox, %file%
fileName = %A_LoopFileName%
;Subject1 = Fart
;msgbox, % subject%rulenum%
; Below determines the subject of the comparison
if (Subject%RuleNum% = "Name")
{
thisSubject := getName(file)
;msgbox, %thisSubject%
}
else if (Subject%RuleNum% = "Extension")
{
thisSubject := getExtension(file)
;Msgbox, extension: %thissubject%
}
else if (Subject%RuleNum% = "Size")
{
thisSubject := getSize(file)
;msgbox, size %thissubject%
}
else if (Subject%RuleNum% = "Date last modified")
{
thisSubject := getDateLastModified(file)
}
else if (Subject%RuleNum% = "Date last opened")
{
thisSubject := getDateLastOpened(file)
}
else if (Subject%RuleNum% = "Date created")
{
thisSubject := getDateCreated(file)
}
else
{
MsgBox, Subject does not have a match
;msgbox, % subject %rulenum%
}
; Below determines the comparison verb
if (Verb%RuleNum% = "contains")
{
result%RuleNum% := contains(thisSubject, Object%RuleNum%)
}
else if (Verb%RuleNum% = "does not contain")
{
result%RuleNum% := !(contains(thisSubject, Object%RuleNum%))
}
else if (Verb%RuleNum% = "is")
{
result%RuleNum% := isEqual(thisSubject, Object%RuleNum%)
;msgbox, % result%rulenum% . "is rule" . rulenum
;if result%RuleNum%
{
;msgbox, true for %thissubject% and %object%
}
}
else if (Verb%RuleNum% = "matches one of")
{
result%RuleNum% := isOneOf(thisSubject, Object%RuleNum%)
;msgbox, % result%rulenum% . "is rule" . rulenum
}
else if (Verb%RuleNum% = "does not match one of")
{
result%RuleNum% := !(isOneOf(thisSubject, Object%RuleNum%))
;msgbox, % result%rulenum% . "is rule" . rulenum
}
else if (Verb%RuleNum% = "is less than")
{
result%RuleNum% := isLessThan(thisSubject, Object%RuleNum%)
;msgbox, % result%rulenum%
}
else if (Verb%RuleNum% = "is greater than")
{
result%RuleNum% := isGreaterThan(thisSubject, Object%RuleNum%)
}
else if (Verb%RuleNum% = "is not")
{
result%RuleNum% := !(isEqual(thisSubject, Object%RuleNum%))
}
else if (Verb%RuleNum% = "is in the last")
{
result%RuleNum% := isInTheLast(thisSubject, Object%RuleNum%)
}
else if (Verb%RuleNum% = "is not in the last")
{
result%RuleNum% := !isInTheLast(thisSubject, Object%RuleNum%)
;msgbox, % result%RuleNum%
}
}
; Below evaluates result and takes action
Loop
{
;msgbox, %a_index%
if (NumOfRules < A_Index)
{
;msgbox, over
break
}
if (A_Index = 1)
{
RuleNum=
}
else
{
RuleNum := A_Index - 1
}
;msgbox, % result%rulenum% . "is rule " . rulenum
if (Matches = "ALL")
{
if (result%RuleNum% = 0)
{
result := 0
break
}
else
{
result := 1
continue
}
}
else if (Matches = "ANY")
{
if (result%RuleNum% = 1)
{
result := 1
;msgbox, 1
break
}
else
{
result := 0
continue
}
}
}
;Msgbox, result is %result%
if result
{
if (ConfirmAction = 1)
{
MsgBox, 4, Action Confirmation, Are you sure you want to %Action% %fileName% because of rule %thisRule%?
IfMsgBox No
break
}
if (Action = "Move file") or (Action = "Rename file")
{
move(file, Destination, Overwrite)
if errorCheck
{
errorCheck := 0
break
}
}
else if (Action = "Send file to Recycle Bin")
{
recycle(file)
}
else if (Action = "Delete file")
{
;msgbox, delete it!
delete(file)
}
else if (Action = "Copy file")
{
copy(file, Destination, Overwrite)
if errorCheck
{
errorCheck := 0
break
}
}
else if (Action = "Open file")
{
Run, %file%
}
else
{
Msgbox, You've detemerined no action to take.
}
}
else
{
;msgbox, no match
}
StringCaseSense, On
}
}
;msgbox, run
Sleep, %SleepTime%
}
SetVars:
APPNAME = Belvedere
Version = 0.4
AllSubjects = Name||Extension|Size|Date last modified|Date last opened|Date created|
NoDefaultSubject = Name|Extension|Size|Date last modified|Date last opened|Date created|
NameVerbs = is||is not|matches one of|does not match one of|contains|does not contain|
NoDefaultNameVerbs = is|is not|matches one of|does not match one of|contains|does not contain|
NumVerbs = is||is not|is greater than|is less than|
NoDefaultNumVerbs = is|is not|is greater than|is less than|
DateVerbs = is in the last||is not in the last| ; removed is||is not| for now... needs more work implementing
NoDefaultDateVerbs = is in the last|is not in the last|
AllActions = Move file||Rename file|Send file to Recycle Bin|Delete file|Copy file|Open file|
AllActionsNoDefault = Move file|Rename file|Send file to Recycle Bin|Delete file|Copy file|Open file|
SizeUnits = MB||KB
NoDefaultSizeUnits = MB|KB|
DateUnits = minutes||hours|days|weeks
NoDefaultDateUnits = minutes|hours|days|weeks|
MatchList = ALL|ANY|
DeleteApproach = Oldest First|Youngest First|Largest First|Smallest First
IfNotExist,resources
{
FileCreateDir,resources
}
FileInstall, resources\belvedere.ico, resources\belvedere.ico
FileInstall, resources\belvederename.png, resources\belvederename.png
FileInstall, resources\both.png, resources\both.png
Menu, TRAY, Icon, resources\belvedere.ico
BelvederePNG = resources\both.png
return
BuildINI:
IfNotExist, rules.ini
{
IniWrite,%A_Space%,rules.ini, Folders, Folders
IniWrite,%A_Space%,rules.ini, Rules, AllRuleNames
IniWrite,300000,rules.ini, Preferences, Sleeptime
IniWrite,0,rules.ini, Preferences, RBEnable
}
return
TRAYMENU:
Menu,TRAY,NoStandard
Menu,TRAY,DeleteAll
Menu, TRAY, Add, &Manage, MANAGE
Menu, TRAY, Default, &Manage
;Menu,TRAY,Add,&Preferences,PREFS
;Menu,TRAY,Add,&Help,HELP
Menu,TRAY,Add
Menu,TRAY,Add,&About...,ABOUT
Menu,TRAY,Add,E&xit,EXIT
Menu,Tray,Tip,%APPNAME% %Version%
;Menu,TRAY,Icon,resources\tk.ico
Return
MENUBAR:
Menu, FileMenu, Add,E&xit,EXIT
Menu, HelpMenu, Add,&About %APPNAME%,ABOUT
Menu, MenuBar, Add, &File, :FileMenu
Menu, MenuBar, Add, &Help, :HelpMenu
Return
PREFS:
msgbox, tk
return
HELP:
msgbox, tk
return
HOMEPAGE:
Run, http://lifehacker.com/341950/
return
WCHOMEPAGE:
Run, http://what-cheer.com/
return
ABOUT:
Gui,4: Destroy
Gui,4: +owner
Gui,4: Add,Picture,x45 y0,%BelvederePNG%
Gui,4: font, s8, Courier New
Gui,4: Add, Text,x275 y235,%Version%
Gui,4: font, s9, Arial
Gui,4: Add,Text,x10 y250 Center,Belvedere is an automated file managment application`nthat performs actions on files based on user-defined criteria.`nFor example, if a file in your downloads folder`nhasn't been opened in 4 weeks and it's larger than 10MB,`nyou can tell Belvedere to automatically send it to the Recycle Bin.`n`nBelvedere is written by Adam Pash and distributed`nby Lifehacker under the GNU Public License.`nFor details on how to use Belvedere, check out the
Gui,4:Font,underline bold
Gui,4:Add,Text,cBlue gHomepage Center x115 y385,Belvedere homepage
Gui,4:Add,Text,cBlue gWCHomepage Center x105 y400,Icon design by What Cheer
Gui,4: Color,F8FAF0
;Gui 2:+Disabled
Gui,4: Show,auto,About Belvedere
Return
#Include includes\verbs.ahk
#Include includes\subjects.ahk
#Include includes\actions.ahk
#Include includes\Main_GUI.ahk
EXIT:
ExitApp