-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFile_Util.ks
482 lines (441 loc) · 16.2 KB
/
File_Util.ks
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
CLEARGUIS().
IF HOMECONNECTION:ISCONNECTED {
RUNONCEPATH("1:/lib/lib_file_util.ks").
LOCAL archiveRoot IS PATH("0:/").
LOCAL localRoot IS PATH(CORE:CURRENTVOLUME).
GLOBAL localDirs IS dir_scan(localRoot,FALSE).
GLOBAL archiveDirs IS dir_scan(archiveRoot,FALSE).
LOCAL done IS FALSE.
LOCAL interface IS GUI(500).
SET interface:Y TO 150.
LOCAL ifdSlect IS interface:ADDHBOX.
LOCAL ifdsFile IS ifdSlect:ADDRADIOBUTTON("File Tools",TRUE).
LOCAL ifdsDir IS ifdSlect:ADDRADIOBUTTON("Directory Tools",FALSE).
LOCAL iModeList IS interface:ADDPOPUPMENU().
LOCAL SubMenu IS interface:ADDVBOX.
LOCAL smLabel IS SubMenu:ADDLABEL("").
LOCAL mdWarning IS SubMenu:ADDLABEL("").
LOCAL ddWarning IS SubMenu:ADDLABEL("").
LOCAL smNew IS SubMenu:ADDHBOX.
LOCAL smnLabel IS smNew:ADDLABEL("").
SET smnLabel:STYLE:ALIGN TO "RIGHT".
LOCAL smnName IS smNew:ADDTEXTFIELD("").
SET smnName:STYLE:WIDTH TO 350.
LOCAL smOptions IS SubMenu:ADDVBOX.
LOCAL uvExt IS smOptions:ADDCHECKBOX("Files Must Have Matching Extensions",TRUE).
LOCAL uvPath IS smOptions:ADDCHECKBOX("Files Must Have Matching Paths Ignoring Root",TRUE).
LOCAL uvSize IS smOptions:ADDCHECKBOX("Files Must NOT Have Matching Size",FALSE).
LOCAL uvCompile IS smOptions:ADDCHECKBOX("Compile if Local File Has .ksm Extension",FALSE).
LOCAL iGoButton IS interface:ADDBUTTON("").
LOCAL iWorking IS interface:ADDBUTTON("").
iWorking:HIDE.
LOCAL iLabel0 IS interface:ADDLABEL(" ").
LOCAL iSourceMenu IS interface:ADDVBOX.//set up source interface
LOCAL ismLabel IS iSourceMenu:ADDLABEL("Source").
LOCAL ismVolume IS iSourceMenu:ADDHBOX.
LOCAL ismvLabel IS ismVolume:ADDLABEL("Source Volume: ").
LOCAL ismvList IS ismVolume:ADDPOPUPMENU().
SET ismvList:OPTIONS TO LIST("Archive","Local").
SET ismvList:STYLE:WIDTH TO 300.
LOCAL ismDirectory IS iSourceMenu:ADDHBOX.
LOCAL ismdLabel IS ismDirectory:ADDLABEL("Source Directory: ").
LOCAL ismdList IS ismDirectory:ADDPOPUPMENU().
SET ismdList:STYLE:WIDTH TO 300.
LOCAL ismFile IS iSourceMenu:ADDHBOX.
LOCAL ismfBox IS ismFile:ADDVBOX.
LOCAL ismfbLabel IS ismfBox:ADDLABEL("Source File: ").
LOCAL ismfbSize IS ismfBox:ADDLABEL("").
LOCAL ismfList IS ismFile:ADDPOPUPMENU().
SET ismfList:STYLE:WIDTH TO 300.
LOCAL iDestinationMenu IS interface:ADDVBOX.//set up destination interface
LOCAL idmLabel IS iDestinationMenu:ADDLABEL("Destination").
LOCAL idmVolume IS iDestinationMenu:ADDHBOX.
LOCAL idmvBox IS idmVolume:ADDVBOX.
LOCAL idmvbLabel IS idmvBox:ADDLABEL("Destination Volume: ").
LOCAL idmvbSize IS idmvBox:ADDLABEL("").
LOCAL idmvList IS idmVolume:ADDPOPUPMENU().
SET idmvList:OPTIONS TO LIST("Archive","Local").
SET idmvList:STYLE:WIDTH TO 300.
LOCAL idmDirectory IS iDestinationMenu:ADDHBOX.
LOCAL idmdLabel IS idmDirectory:ADDLABEL("Destination Directory: ").
LOCAL idmdList IS idmDirectory:ADDPOPUPMENU().
SET idmdList:STYLE:WIDTH TO 300.
LOCAL iLabel1 IS interface:ADDLABEL(" ").
LOCAL doneButton IS interface:ADDBUTTON("Done").
//seting up trigers
file_directory_slector(TRUE).
SET ifdsFile:ONTOGGLE TO file_directory_slector@.
SET iModeList:ONCHANGE TO subMenu_slector@.
SET ismvList:INDEX TO 0.
source_dir_slector(ismvList:value).
SET ismvList:ONCHANGE TO source_dir_slector@.
SET ismdList:ONCHANGE TO source_file_slector@.
SET ismfList:ONCHANGE TO source_file_info_updater@.
SET idmvList:INDEX TO 1.
destination_dir_slector(idmvList:value).
SET idmvList:ONCHANGE TO destination_dir_slector@.
SET idmdList:ONCHANGE TO destination_dir_print@.
//mode trigers
GLOBAL modeLex IS LEX().
modeLex:ADD("Copy Files",copy_from_to@).
modeLex:ADD("Compile Files",compile_file_from_to@).
modeLex:ADD("Move Files",move_from_to@).
modeLex:ADD("Delete Files",delete_at@).
modeLex:ADD("Rename Files",rename_file_at@).
modeLex:ADD("Edit Files",edit_file@).
modeLex:ADD("Copy Directory",copy_from_to@).
modeLex:ADD("Move Directory",move_from_to@).
modeLex:ADD("New Directory",new_directory_at@).
modeLex:ADD("Unpack Directory",unpack_directory_at@).
modeLex:ADD("Update Local Volume",update_local_volume@).
modeLex:ADD("Delete Directory",delete_at@).
SET iGoButton:ONCLICK TO run_mode@.
SET doneButton:ONCLICK TO { SET done TO TRUE. }.
interface:SHOW.//set up done waiting on user input
WAIT UNTIL done.
interface:DISPOSE.
FUNCTION run_mode {//calls chosed mode,rebuild of source/destination lists
LOCAL dirRebild IS ifdsDir:PRESSED. //info needed for rebuild
LOCAL menuValue IS ismvList:VALUE. //info needed for rebuild
IF iDestinationMenu:VISIBLE { SET menuValue TO idmvList:VALUE. }
iGoButton:HIDE.
iWorking:SHOW.
LOCAL chosenMode IS iModeList:VALUE.
PRINT " ".
modeLex[chosenMode]:CALL().
PRINT " ".
IF dirRebild AND iSourceMenu:VISIBLE {//rebuild source/destination dir/file lists after a mode runs
IF menuValue = "archive" {
SET archiveDirs TO dir_scan(archiveRoot,FALSE).
}
IF menuValue = "local" {
SET localDirs TO dir_scan(localRoot,FALSE).
}
}
destination_dir_slector(idmvList:VALUE).
source_dir_slector(ismvList:VALUE).//end of rebuild
iWorking:HIDE.
iGoButton:SHOW.
}
FUNCTION file_directory_slector {//cycles mode list betwene file and directory options
PARAMETER slection.
PRINT ifdSlect:RADIOVALUE.
IF ifdSlect:RADIOVALUE = "File Tools" {
SET iModeList:OPTIONS TO LIST("Copy Files","Compile Files","Move Files","Delete Files","Rename Files","Edit Files").
}
IF ifdSlect:RADIOVALUE = "Directory Tools" {
SET iModeList:OPTIONS TO LIST("Copy Directory","Move Directory","New Directory","Unpack Directory","Update Local Volume","Delete Directory").
}
SET iModeList:INDEX TO 0.
subMenu_slector(iModeList:VALUE).
}
FUNCTION subMenu_slector {//changed visable mode
PARAMETER chosenMode.
PRINT "mode: " + chosenMode.
IF ifdsFile:PRESSED {
IF chosenMode = "Copy Files" {
SET smLabel:TEXT TO "Copy File From Source To Destination".
SET iGoButton:TEXT TO "Copy".
SET iWorking:TEXT TO "Copying".
show_hide_inputs(1,1,1,0).
}
IF chosenMode = "Compile Files" {
SET smLabel:TEXT TO "Compile File From Source To Destination".
SET iGoButton:TEXT TO "Compile".
SET iWorking:TEXT TO "Compiling".
show_hide_inputs(1,1,1,0).
}
IF chosenMode = "Move Files" {
SET smLabel:TEXT TO "Move File From Source To Destination".
SET iGoButton:TEXT TO "Move".
SET iWorking:TEXT TO "Moving".
show_hide_inputs(1,1,1,0).
}
IF chosenMode = "Delete Files" {
SET smLabel:TEXT TO "Delete File Set With Source".
SET iGoButton:TEXT TO "Delete".
SET iWorking:TEXT TO "Deleting".
show_hide_inputs(1,0,1,0).
}
IF chosenMode = "Rename Files" {
SET smLabel:TEXT TO "Rename File Set With Source".
SET smnLabel:TEXT TO "New Name: ".
SET iGoButton:TEXT TO "Rename".
SET iWorking:TEXT TO "Renaming".
SET smnName:TEXT TO ismfList:VALUE:NAME.
show_hide_inputs(1,0,1,1).
}
IF chosenMode = "Edit Files" {
SET smLabel:TEXT TO "Edit File Set With Source".
SET iGoButton:TEXT TO "Edit".
SET iWorking:TEXT TO "Editing".
show_hide_inputs(1,0,1,0).
}
} ELSE {
IF chosenMode = "Copy Directory" {
SET smLabel:TEXT TO "Copy Directory From Source To Destination".
SET iGoButton:TEXT TO "Copy".
SET iWorking:TEXT TO "Copying".
show_hide_inputs(1,1,0,0).
}
IF chosenMode = "Move Directory" {
SET smLabel:TEXT TO "Move Directory From Source To Destination".
SET iGoButton:TEXT TO "Move".
SET iWorking:TEXT TO "Moving".
show_hide_inputs(1,1,0,2).
}
IF chosenMode = "New Directory" {
SET smLabel:TEXT TO "Create New Directory At Source".
SET smnLabel:TEXT TO "New Directory: ".
SET iGoButton:TEXT TO "Create".
SET iWorking:TEXT TO "Creating".
SET smnName:TEXT TO "".
show_hide_inputs(1,0,0,1).
}
IF chosenMode = "Unpack Directory" {
SET smLabel:TEXT TO "Unpack Contents of Source Directory in Destination".
SET iGoButton:TEXT TO "Unack".
SET iWorking:TEXT TO "Unacking".
show_hide_inputs(1,1,0,0).
}
IF chosenMode = "Update Local Volume" {
SET smLabel:TEXT TO "Update Local Volume".
SET iGoButton:TEXT TO "Update".
SET iWorking:TEXT TO "Updating".
show_hide_inputs(0,0,0,4).
}
IF chosenMode = "Delete Directory" {
SET smLabel:TEXT TO "Delete Directory Set With Source".
SET iGoButton:TEXT TO "Delete".
SET iWorking:TEXT TO "Deleting".
show_hide_inputs(1,0,0,3).
}
}
}
FUNCTION show_hide_inputs {
PARAMETER ism,idm,ismf,ismx.
IF ism = 1 { iSourceMenu:SHOW. } ELSE { iSourceMenu:HIDE. }
IF idm = 1 { iDestinationMenu:SHOW. } ELSE { iDestinationMenu:HIDE. }
IF ismf = 1 { ismFile:SHOW. } ELSE { ismFile:HIDE. }
IF ismx = 1 { smNew:SHOW. } ELSE { smNew:HIDE. }
IF ismx = 2 { mdWarning:SHOW. } ELSE { mdWarning:HIDE. }
IF ismx = 3 { ddWarning:SHOW. } ELSE { ddWarning:HIDE. }
IF ismx = 4 { smOptions:SHOW. } ELSE { smOptions:HIDE. }
}
FUNCTION source_dir_slector {//build source directory list
PARAMETER vol.
PRINT "Source vol: " +vol.
IF vol = "archive" {
SET ismdList:OPTIONS TO archiveDirs.
} ELSE {
SET ismdList:OPTIONS TO localDirs.
}
SET mdWarning:TEXT TO "NOTE: Can Not Move Directory: " + ismdList:OPTIONS[0].
SET ddWarning:TEXT TO "NOTE: Can Not Delete Directory: " + ismdList:OPTIONS[0].
index_in_range(ismdList).
source_file_slector(ismdList:VALUE).
}
FUNCTION source_file_slector {//build source file list
PARAMETER dir.
PRINT "Source dir: " + dir.
LOCAL fileList IS get_files(dir).
SET ismfList:OPTIONS TO file_filter(fileList).
index_in_range(ismfList).
source_file_info_updater(ismfList:VALUE).
}
FUNCTION source_file_info_updater {//update information about slected source file
PARAMETER sFile.
IF ismfList:OPTIONS:LENGTH <> 0 {
PRINT "Source File: " + sFile.
SET ismfbSize:TEXT TO "File Size: " + sFile:SIZE.
IF iModeList:VALUE = "Rename Files" { SET smnName:TEXT TO sFile:NAME. }
ismfList:SHOW.
} ELSE {
SET ismfbSize:TEXT TO "No Files in Directory".
ismfList:HIDE.
}
}
FUNCTION destination_dir_slector {//build destination directory list
PARAMETER vol.
PRINT "Destination vol: " + vol.
IF vol = "archive" {
SET idmdList:OPTIONS TO archiveDirs.
SET idmvbSize:TEXT TO "Free Space: Infinite".
} ELSE {
SET idmdList:OPTIONS TO localDirs.
SET idmvbSize:TEXT TO "Free Space: " + localRoot:VOLUME:FREESPACE.
}
index_in_range(idmdList).
destination_dir_print(idmdList:VALUE).
}
FUNCTION index_in_range {//keeps INDEX for pupup in range
PARAMETER popup.
IF popup:INDEX < 0 {
SET popup:INDEX TO 0.
} ELSE IF popup:INDEX > (popup:OPTIONS:LENGTH - 1) {
SET popup:INDEX TO popup:OPTIONS:LENGTH - 1.
} ELSE {
SET popup:INDEX TO popup:INDEX.
}
}
FUNCTION destination_dir_print {//did more once
PARAMETER dir.
PRINT "Destination dir: " + dir.
}
FUNCTION copy_from_to {
LOCAL fromPath IS PATH(ismdList:VALUE).
LOCAL toPath IS PATH(idmdList:VALUE).
LOCAL fileName IS ismfList:VALUE:NAME.
IF ifdsFile:PRESSED {
PRINT "Copying File: " + fileName.
PRINT " From: " + fromPath + " To: " + toPath.
COPYPATH(fromPath:COMBINE(fileName),toPath).
} ELSE {
PRINT "Copying Directory From: " + fromPath.
PRINT " To: " + toPath.
COPYPATH(fromPath,toPath).
}
}
FUNCTION move_from_to {
LOCAL fromPath IS PATH(ismdList:VALUE).
LOCAL toPath IS PATH(idmdList:VALUE).
LOCAL fileName IS ismfList:VALUE:NAME.
IF ifdsFile:PRESSED {
PRINT "Moving File: " + fileName.
PRINT " From: " + fromPath + " To: " + toPath.
MOVEPATH(fromPath:COMBINE(fileName),toPath).
} ELSE {
IF ismdList:INDEX = 0 {
PRINT "Can Not Move Root".
} ELSE {
PRINT "Moving Directory: " + fromPath:NAME.
PRINT " From: " + fromPath + " To: " + toPath.
MOVEPATH(fromPath,toPath).
}
}
}
FUNCTION delete_at {
LOCAL fromPath IS PATH(ismdList:VALUE).
LOCAL fileName IS ismfList:VALUE:NAME.
IF ifdsFile:PRESSED {
DELETEPATH(fromPath:COMBINE(fileName)).
PRINT "Deleted File: " + fileName.
PRINT " At: " + fromPath.
} ELSE {
IF ismdList:INDEX = 0 {
PRINT "Can Not Delete Root".
} ELSE {
DELETEPATH(fromPath).
PRINT "Deleted Directory At: " + fromPath.
}
}
}
FUNCTION compile_file_from_to {
LOCAL fromPath IS PATH(ismdList:VALUE).
LOCAL toPath IS PATH(idmdList:VALUE).
LOCAL fileName IS ismfList:VALUE:NAME.
PRINT "Compiling File: " + fileName.
PRINT " From: " + fromPath + " To: " + toPath.
COMPILE (fromPath:COMBINE(fileName)) TO (toPath:COMBINE(name_only(ismfList:VALUE)+".ksm")).
PRINT "Done Compiling: " + fileName.
}
FUNCTION rename_file_at {
LOCAL fromPath IS PATH(ismdList:VALUE).
LOCAL fileName IS ismfList:VALUE:NAME.
LOCAL newName IS smnName:TEXT.
MOVEPATH(fromPath:COMBINE(fileName),fromPath:COMBINE(newName)).
PRINT "Renamed File From: " + fileName.
PRINT " To: " + newName.
PRINT " At: " + fromPath.
}
FUNCTION edit_file {
LOCAL fromPath IS PATH(ismdList:VALUE).
LOCAL fileName IS ismfList:VALUE:NAME.
EDIT(fromPath:COMBINE(fileName)).
PRINT "Editing File: " + fileName.
PRINT " At: " + fromPath.
}
FUNCTION new_directory_at {
LOCAL fromPath IS PATH(ismdList:VALUE).
LOCAL newDirName IS smnName:TEXT.
IF NOT EXISTS(fromPath:COMBINE(newDirName)) {
CREATEDIR(fromPath:COMBINE(newDirName)).
PRINT "Making New Directory: " + newDirName.
PRINT " At: " + fromPath.
} ELSE {
PRINT "Directory Already Exists".
}
SET smnName:TEXT TO "".
}
FUNCTION unpack_directory_at {
LOCAL fromPath IS PATH(ismdList:VALUE).
LOCAL toPath IS PATH(idmdList:VALUE).
PRINT "Unpacking: " + fromPath.
PRINT " At: " + toPath.
LOCAL localFiles IS get_files(fromPath).
LOCAL localFileList IS file_filter(localFiles).
LOCAL localDirList IS dir_filter(localFiles).
FOR lFile IN localFileList { COPYPATH (fromPath:COMBINE(lFile:NAME),toPath). }
FOR dFile IN localDirList { COPYPATH (fromPath:COMBINE(dFile:NAME),toPath). }
}
FUNCTION update_local_volume {
LOCAL notUsePath IS NOT uvPath:PRESSED.
LOCAL notUseSize IS NOT uvSize:PRESSED.
LOCAL notUseExtension IS NOT uvExt:PRESSED.
LOCAL useCompile IS uvCompile:PRESSED.
PRINT "Called Updater".
PRINT " ".
LOCAL lFiles IS dir_scan(localRoot).
LOCAL aFiles IS dir_scan(archiveRoot).
LOCAL lfNameOnly IS name_only(lFiles).
LOCAL afNameOnly IS name_only(aFiles).
LOCAL lfNoRoot IS no_root(lFiles).
LOCAL afNoRoot IS no_root(aFiles).
FROM {LOCAL iL IS 0.} UNTIL iL >= lFiles:LENGTH STEP {SET iL TO iL + 1.} DO {
FROM {LOCAL iA IS 0.} UNTIL iA >= aFiles:LENGTH STEP {SET iA TO iA + 1.} DO {
IF afNameOnly[iA] = lfNameOnly[iL] {//name check
IF notUsePath OR (afNoRoot[iA] = lfNoRoot[iL]) {//path check
IF notUseSize OR (aFiles[iA][1]:SIZE <> lFiles[iL][1]:SIZE) {//size check
IF notUseExtension OR (aFiles[iA][1]:EXTENSION = lFiles[iL][1]:EXTENSION) {//extension check
COPYPATH(aFiles[iA][0]:COMBINE(aFiles[iA][1]:NAME),lFiles[iL][0]).
PRINT "Copying File: " + aFiles[iA][1].
PRINT " From: " + aFiles[iA][0] + " To: " + lFiles[iL][0].
PRINT " ".
}
}
IF useCompile AND (aFiles[iA][1]:EXTENSION = "ks") AND (lFiles[iL][1]:EXTENSION = "ksm") {
PRINT "Compiling File: " + aFiles[iA][1].
PRINT " From: " + aFiles[iA][0] + " To: " + lFiles[iL][0].
COMPILE aFiles[iA][0]:COMBINE(aFiles[iA][1]:NAME) TO lFiles[iL][0]:COMBINE(name_only(lFiles[iL][1]) + ".ksm").
PRINT "Done Compiling: " + aFiles[iA][1].
PRINT " ".
}
}
}
}
}
PRINT "Done Updating Files".
}
FUNCTION get_files {
PARAMETER dir.
LOCAL dirRevert IS PATH().
CD(PATH(dir)).
LOCAL fileList IS LIST().
LIST FILES IN fileList.
WAIT 0.
CD(dirRevert).
RETURN fileList.
}
FUNCTION file_filter {//filters a list for files
PARAMETER rawList.
LOCAL localList IS LIST().
FOR raw IN rawList { IF raw:ISFILE { localList:ADD(raw). } }
RETURN localList.
}
FUNCTION dir_filter {//filters a list for files
PARAMETER rawList.
LOCAL localList IS LIST().
FOR raw IN rawList { IF NOT raw:ISFILE { localList:ADD(raw). } }
RETURN localList.
}
}