-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect_asset_2.099.ms
1890 lines (1810 loc) · 60.5 KB
/
collect_asset_2.099.ms
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
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
macroScript Collect_asset_2
Buttontext: "Collect Asset"
category:"ModX"
toolTip:"Collect Aasset 2"
Icon:#("CollectAsset",1)
(
title = "Collect Asset v1.2"
--This script created by Morozov Anton
-- Collect all textures and others external files in one folder.
try (destroyDialog ::Collect_asset) catch()
try (destroyDialog ::match_bmp) catch()
try (destroyDialog ::List_assets) catch()
try (destroyDialog ::logform) catch()
try (destroyDialog ::settings) catch()
global Collect_asset, match_bmp, match_bmp2
local pic_1 = pic_2 = ""
local mb_inst, mb_propName
local errors = copied = 0
local exitt = false
local mb_result = #(0,"",false) -- [1] - 0 - cancel, 1 - leave exist, 2 - replace, 3 - rename [2] - filename [3] - boolean - repeat action
GLOBAL_INI_FILENAME = "collect_asset.ini"
G_INIsettings_FILENAME = "ca_settings.ini"
GLOBAL_INI_FILE_PATH = ((getdir #userScripts) + "\\Collect_asset\\")
INIFilename = pathConfig.appendPath GLOBAL_INI_FILE_PATH GLOBAL_INI_FILENAME
INISettingsFilename = pathConfig.appendPath GLOBAL_INI_FILE_PATH G_INIsettings_FILENAME
GLOBAL_7Z_PATH = (GLOBAL_INI_FILE_PATH + "7z\\")
local logfilepath = GLOBAL_INI_FILE_PATH +"log.txt"
G_IFL_FULLPATH = false
G_DIRSELECT = 2
G_Tooltip_Lang = 1
G_CollectPath = ""
if doesFileExist logfilepath == false do
(
try logfile = createFile logfilepath catch()
if logfile != undefined do close logfile
)
try logfile = openfile logfilepath mode:"w" catch()
if logfile != undefined do close logfile
fn printToLogWindow type logtext =
(
if type == "ERR" do logform.TextBox.SelectionColor = (dotnetclass "System.Drawing.Color").FromArgb 180 0 0
if type == "DBG" do logform.TextBox.SelectionColor = (dotnetclass "System.Drawing.Color").FromArgb 100 100 0
if type == "INF" do logform.TextBox.SelectionColor = (dotnetclass "System.Drawing.Color").FromArgb 0 100 0
logform.TextBox.AppendText(type+"::"+logtext+"\n")
logform.TextBox.SelectionColor = logform.TextBox.ForeColor
)
fn logging type logtext msg:false =
(
try logfile = openfile logfilepath mode:"a" encoding:#utf8 catch()
if logfile != undefined do
(
format "%" localtime to:logfile
format "|%|%\n" type logtext to:logfile
close logfile
)
try (
printToLogWindow type logtext
) catch()
if msg do messagebox logtext title:type
)
--function to load variable from ini file
fn loadfromINI inifile section_name var_name =
(
if doesFileExist inifile == false then
(
logging "ERR" ("Do not exist INI file: "+inifile)
undefined
) else
(
local temp_value = ""
logging "INF" ("Loading section: "+section_name+", var: "+var_name+", from file: "+inifile)
temp_value = getINISetting inifile section_name var_name
logging "DBG" ("Result: "+temp_value)
if temp_value == "" then undefined else temp_value
)
)
fn loadVarFromIniFile section_name var_name =
(
loadfromINI INIFilename section_name var_name
)
fn loadVarFromSettingsIniFile section_name var_name =
(
loadfromINI INISettingsFilename section_name var_name
)
--function write variable to ini file
fn writetoINI inifile section_name var_name var_value =
(
if doesFileExist inifile == false do
(
logging "ERR" ("Do not exist INI file "+inifile)
)
temp_value = setINISetting inifile section_name var_name (var_value as string)
if temp_value then logging "INF" ("Write "+var_name+" = "+(var_value as string)+" to INI file "+inifile)
else logging "ERR" ("Can not write "+var_name+" = "+(var_value as string)+" to INI file "+inifile)
temp_value
)
fn writeVarToIniFile section_name var_name var_value =
(
writetoINI INIFilename section_name var_name var_value
)
fn writeVarToSettingsIniFile section_name var_name var_value =
(
writetoINI INISettingsFilename section_name var_name var_value
)
fn Collect_assetOpenUI = (
-- load settings from ini file
tmp = (loadVarFromSettingsIniFile "settings" "IFL_FULLPATH")
if tmp == "true" do G_IFL_FULLPATH = true
if tmp == "false" do G_IFL_FULLPATH = false
tmp = (loadVarFromSettingsIniFile "settings" "G_DIRSELECT")
if tmp != undefined do G_DIRSELECT = tmp as integer
tmp = (loadVarFromSettingsIniFile "settings" "G_Tooltip_Lang")
if tmp != undefined do G_Tooltip_Lang = tmp as integer
local dialogPos = [200,150]
local temp_value = loadVarFromSettingsIniFile "settings" "dialogPos"
if temp_value != undefined do dialogPos = execute (temp_value)
CreateDialog Collect_asset pos:dialogPos
)
FileTypeLights = #(".ies")
FileTypeImg = #(".jpg", ".jpeg", ".bmp", ".tif", ".tiff", ".psd", ".png", ".gif", ".hdr", ".exr",".tga")
fndClasses = #(#(bitmaptex,#filename),
#(camera_map_per_pixel,#zbuffer),
#(VRayHDRI,#HDRIMapName),
#(VRayProxy,#filename),
#(VRayBmpFilter,#bitmap),
#(vray_lens_effects,#glareBitmap,#glareObstacleImage),
#(CoronaProxy,#filename),
#(CProxy,#filename),
#(coronaBitmap,#filename),
#(Alpha_image,#filename),
#(Greyscale_image,#filename),
#(IES_Texture,#file),
#(OctaneProxy,#file),
#(RGB_image,#filename),
#(AlembicObject,#source),
#(point_Cache,#filename),
#(FStormBitmap,#fileName),
#(FStormProxy,#File),
#(proxy,#file),
#(fR_Proxy,#proxyFile),
#(fR_Scatter,#proxyFile),
#(BitmapHDR,#fileName,#fromLUT),
#(Plant,#lbwfile),
#(Forest_Pro,#mapname),
#(Displace,#bitmap),
#(CoronaCam,#lutFilename),
#(BipSlave_Control,#filename),
#(Redshift_Bitmap,#tex0),
#(Redshift_Camera_Map,#tex0),
#(Redshift_Environment,#tex0,#tex1,#tex2,#tex3,#tex4),
#(Redshift_Normal_Map,#tex0),
#(RS_Bitmap,#tex0),
#(RS_Camera_Map,#tex0),
#(RS_Environment,#tex0,#tex1,#tex2,#tex3,#tex4),
#(RS_Normal_Map,#tex0),
#(RS_Sprite,#tex0),
#(proxyGeometry,#file),
#(VolumeGeometry,#file),
#(VRayVolumeGrid,#rendinput))
fn getLightsUnique =
(
local lightsunique = #()
local lightinstances = #()
local instances = #()
for lightt in lights where (finditem lightinstances lightt) == 0 do
(
InstanceMgr.GetInstances lightt &instances
append lightsunique lightt
lightinstances += instances
)
lightsunique
)
LightListUnique = getLightsUnique()
fn getClassesLight =
(
local tmp = #()
local fndlightsprop = #(#ies_file,#webFile,#iesFile,#ies,#profile,#tex0,#tex1,#tex2,#tex3,#tex4,#tex5)
local fnd = false
local c
for c in LightListUnique do
for lightsprop in fndlightsprop do
if isProperty c lightsprop do
(
cls = Classof c
for itmtmp in tmp do
if itmtmp[1] == cls and itmtmp[2] == lightsprop then
(
fnd = true
exit
) else
fnd = false
if not fnd do append tmp #(cls,lightsprop)
)
tmp
)
fndClassesLight = getClassesLight()
fndClasses += fndClassesLight
fndassets = #()
assiflFiles = #()
struct asset (inst, propName, filepath, foundpath, status,type)
struct countStat (okk, found, missing, xref)
struct iflFile (filename)
local counts
fn GetStatusFile file =
(
local k, nullpath=false, existfile
local foundfile = mapPaths.getFullFilePath(filenameFromPath(file))
if getFilenamePath(file) == "" do nullpath = true
existfile = doesFileExist(file)
if existfile do
k = #Ok
if existfile and nullpath do
k = #Found
if existfile == false and foundfile != "" do
k = #Found
if existfile == false and foundfile == "" do
k = #Missing
k
)
fn prgrbar i all statustext =
(
Collect_asset.progress_status.text = statustext
logging "INF" statustext
if i == 0 do i = 1
if i > all do i = all
if all == 0 then precents = 0 else precents = 1000/(all*10 / i)
if precents > 100 then precents = 100
Collect_asset.pb1.value = precents
if (((maxVersion())[1] / 1000) >= 13) do windows.processPostedMessages()
)
function getprop inst cls =
(
local prop, err, found
local err_match1 = "-- Runtime error: Error opening bitmap: "
try
prop = (getproperty inst cls)
catch
(
prop = undefined
err = getCurrentException()
--print err
found = findString err err_match1
if found != undefined do
prop = substring err (err_match1.count+1) (err.count-err_match1.count+1)
)
prop
)
function getFileHash SourceFile =
(
hMethod = dotNetObject "System.Security.Cryptography.MD5CryptoServiceProvider"
f = dotNetObject "System.IO.FileStream" SourceFile (dotNetClass "System.IO.FileMode").Open (dotNetClass "System.IO.FileAccess").Read (dotNetClass "System.IO.FileShare").Read 8192
hMethod.ComputeHash f
hash = hMethod.Hash
f.Close()
buff = dotnetObject "System.Text.StringBuilder"
byte = dotNetClass "System.Byte"
SysString = dotNetClass "System.String"
for hashByte in hash do
(
buff.Append (SysString.Format "{0:X2}" hashByte)
)
buff.ToString()
)
fn isIdenticalFiles file1 file2 =
(
local rtrn = false
if (getFileSize(file1) == getFileSize(file2)) do
if getFileHash file1 == getFileHash file2 do rtrn = true
rtrn
)
fn chk_filename filename =
(
if filename != undefined do
if (finditem #(@"\",@"/"," ") filename[filename.count]) > 0 do filename = ""
filename
)
fn getXrefAsset =
(
statustext = "Get Xref List Asset Files"
local fndXrefAssets = #()
local type = "xref"
for i=1 to xrefs.getXRefFileCount() where xrefs.getXRefFileCount() > 0 do
(
fileassets = #()
tmpXref = xrefs.getXRefFile i
filename = tmpXref.filename
status = (GetStatusFile(filename))
append fndXrefAssets (asset tmpXref #filename filename (mapPaths.getFullFilePath(filenameFromPath(filename))) status type)
if status != #Missing do
(
if status == #Found then filename = mapPaths.getFullFilePath(filenameFromPath(tmpXref.filename))
fileassets = getMAXFileAssetMetadata (filename)
if fileassets != undefined do append fndXrefAssets (asset fileassets #filename filename filename #XRefScene type)
)
prgrbar i (xrefs.getXRefFileCount()) (statustext + " : get XRef Files - " + filenameFromPath(filename))
)
for i=1 to objXRefMgr.recordCount where objXRefMgr.recordCount > 0 do
(
fileassets = #()
tmpXref = objXRefMgr.GetRecord i
filename = tmpXref.srcFileName
status = (GetStatusFile(filename))
append fndXrefAssets (asset tmpXref #srcFileName filename (mapPaths.getFullFilePath(filenameFromPath(filename))) status type)
if status != #Missing do
(
if status == #Found then filename = mapPaths.getFullFilePath(filenameFromPath(filename))
fileassets = getMAXFileAssetMetadata (filename)
append fndXrefAssets (asset fileassets #filename filename filename #XRefScene type)
)
prgrbar i (objXRefMgr.recordCount) (statustext + " : get XRef objects - " + filenameFromPath(filename))
)
prgrbar 0 0 "End Get List Xref Assets"
fndXrefAssets
)
function getAssetFiles =
(
statustext = "Get List Asset Files"
fndassets = #()
local tmp = #()
j = 0
for fndClass in fndClasses do
(
try (tmp = getClassInstances fndClass[1]) catch (tmp = #())
for inst in tmp do
for i=2 to fndClass.count do
(
filename = (getprop inst fndClass[i])
if filename != undefined do
(
if (classof filename) == BitMap do filename = (getproperty filename #filename)
if chk_filename(filename) != "" do
append fndassets (asset inst fndClass[i] filename (mapPaths.getFullFilePath(filenameFromPath(filename))) (GetStatusFile(filename)) "asset")
)
)
j += 1
prgrbar j fndClasses.count (statustext + " : get class - " + fndClass as string)
)
-- === Add Xref files ===
join fndassets (getXrefAsset())
-- === Add V_Ray files ===
--if matchPattern ((classof renderers.current) as string) pattern:"V_Ray_Adv*" do
--(
vrayprop = #(#adv_irradmap_loadFileName, #lightcache_loadFileName, #caustics_loadFileName, #photonMap_loadFileName, #colorMap_lut_path, #gi_uhdCache_file)
for prop in vrayprop do
(
filename = undefined
try (filename = (getproperty renderers.current prop)) catch (tmp = #())
if (chk_filename(filename) != "") and (filename != undefined) do
append fndassets (asset renderers.current prop filename (mapPaths.getFullFilePath(filenameFromPath(filename))) (GetStatusFile(filename)) "vray")
)
--)
--=== Add Motion Flow Bip files ===
try (tmp = getClassInstances Vertical_Horizontal_Turn) catch (tmp = #())
for inst in tmp do
(
snippets = inst.motionFlow.snippets
for snip in snippets do
(
filename = undefined
try (filename = snip.filename) catch ()
if (chk_filename(filename) != "") and (filename != undefined) do
append fndassets (asset snip #filename filename (mapPaths.getFullFilePath(filenameFromPath(filename))) (GetStatusFile(filename)) "bip")
)
)
prgrbar 0 0 "End Get List Asset Files"
)
function getAssetFiles_simple =
(
logging "DBG" "start function getAssetFiles_simple"
local status
fndassets_simple = #()
for ass in fndassets where (findItem #(XRefScene, MixinInterface, Array) (classof ass.inst))==0 do
(
filename = (getprop ass.inst ass.propName)
if filename != undefined do
(
if (classof filename) == BitMap do filename = (getproperty filename #filename)
if ass.status == #XRefScene then status = #XRefScene else status = (GetStatusFile(filename))
if filename != "" do
(
append fndassets_simple (asset ass.inst ass.propName filename (mapPaths.getFullFilePath(filenameFromPath(filename))) status ass.type)
)
)
)
-- === Add Xref files ===
join fndassets_simple (getXrefAsset())
fndassets=fndassets_simple
)
fn seek_files seek_path subfolders =
(
logging "DBG" "start function seek_files"
dir_array = #(seek_path)
if subfolders do
(
for d in dir_array do
join dir_array (GetDirectories (d+"/*"))
)
for ass in fndassets where ass.status == #Missing do
(
filename = ass.filepath
for d in dir_array do
if doesFileExist (d+filenameFromPath(filename)) do
(
ass.foundpath = d+filenameFromPath(filename)
ass.status = #Found
logging "INF" ("Found file: "+ass.foundpath)
counts.found += 1
counts.missing -= 1
)
)
Collect_asset.status.caption = "Ok - "+ counts.okk as string +", Found - "+ counts.found as string +", Missing - "+ counts.missing as string
)
function getAssetFilesSelected =
(
statustext = "Get List Selected Asset Files"
fndassetsSel = #()
local tmp = #()
j = 0
for fndClass in fndClasses do
(
tmp = #()
for obj in selection do
try (tmp += getClassInstances fndClass[1] target:obj) catch ()
for inst in tmp do
for i=2 to fndClass.count do
(
if (getproperty inst fndClass[i]) != undefined do
(
filename = (getproperty inst fndClass[i])
if (classof filename) == BitMap do filename = (getproperty filename #filename)
if filename != "" do
append fndassetsSel (asset inst fndClass[i] filename (mapPaths.getFullFilePath(filenameFromPath(filename))) (GetStatusFile(filename)) "asset")
)
)
j += 1
prgrbar j fndClasses.count (statustext + " : get class - " + fndClass as string)
)
prgrbar 0 0 "End Get List Selected Asset Files"
return fndassetsSel
)
function statusrfr simple:false =
(
local tmpfln = #()
if simple then getAssetFiles_simple() else getAssetFiles()
counts = countStat 0 0 0 0
for ass in fndassets where (appendifunique tmpfln ass.filepath) or (ass.status == #XRefScene) do
(
if ass.status == #Ok do
counts.okk += 1
if ass.status == #Found do
counts.found += 1
if ass.status == #Missing do
counts.missing += 1
if ass.status == #XRefScene do
(
counts.xref += 1
for assxrf in ass.inst where (appendifunique tmpfln assxrf.filename) do
(
if assxrf.filename == "" or assxrf.filename == undefined do
continue
status = GetStatusFile(assxrf.filename)
if status == #Ok do
counts.okk += 1
if status == #Found do
counts.found += 1
if status == #Missing do
counts.missing += 1
)
)
)
Collect_asset.status.caption = "Ok - "+ counts.okk as string +", Found - "+ counts.found as string +", Missing - "+ counts.missing as string
)
fn random_name cnt:12 =
(
local rndname = "_"
local symbols = "0123456789qwertyuiopasdfghjklzxcvbnm"
for i=1 to cnt do rndname += symbols [(random 1 symbols.count)]
rndname
)
fn xrefupdate =
(
logging "INF" ("Start xrefupdate")
for i=1 to xrefs.getXRefFileCount() where xrefs.getXRefFileCount() > 0 do
(
tmpXref = xrefs.getXRefFile i
updateXRef tmpXref
)
for i=1 to objXRefMgr.recordCount where objXRefMgr.recordCount > 0 do
(
tmpXref = objXRefMgr.GetRecord i
tmpXref.update()
)
)
fn relinkfile inst propName newfullpath =
(
logging "DBG" ("Run fn relinkfile :: " + inst as string + " :: " + propName as string + " :: "+ newfullpath)
local prop
prop = getprop inst propName
if prop != undefined do (
if (classof prop) == BitMap then
(
oldfullpath = prop.filename
for i=1 to 3 while toLower(prop.filename) != toLower(newfullpath) do
(
setproperty prop #filename newfullpath
setproperty inst propName prop
try (prop = getproperty inst propName) catch (errors += 1; logging "ERR" ("NOT getproperty from " + inst as string); exit)
)
if toLower(prop.filename) != toLower(newfullpath) then
(
logging "ERR" ("NOT Relink " + oldfullpath as string + " to: " + newfullpath as string)
errors += 1
)
else
logging "INF" ("Relink " + oldfullpath as string + " to: " + newfullpath as string)
)
else (
oldfullpath = prop
for i=1 to 3 while (prop != undefined) and (toLower(prop) != toLower(newfullpath)) do
(
try (setproperty inst propName newfullpath) catch (errors += 1; logging "ERR" ("NOT Relink " + oldfullpath as string + " to: " + newfullpath as string); exit)
try (prop = getprop inst propName) catch (exit)
)
if (prop != undefined) and (toLower(prop) != toLower(newfullpath)) then
(
logging "ERR" ("NOT Relink " + oldfullpath as string + " to: " + newfullpath as string)
errors += 1
)
else
logging "INF" ("Relink " + oldfullpath as string + " to: " + newfullpath as string)
)
)
)
function ResolvePaths =
(
local i=0
for ass in fndassets do
(
prgrbar i fndassets.count ("Resolve Paths : "+filenameFromPath(ass.filepath))
if (keyboard.EscPressed) and (queryBox "you want to abort operation?") then return ()
if ass.status == #Found do relinkfile ass.inst ass.propName ass.foundpath
if ass.status == #XRefScene do
(
upd = false
for assxrf in ass.inst do
(
status = GetStatusFile(assxrf.filename)
if status == #Found do
(
assxrf.filename = mapPaths.getFullFilePath(filenameFromPath(assxrf.filename))
upd = true
)
)
if upd do setMAXFileAssetMetadata ass.foundpath ass.inst
)
i+=1
)
prgrbar 0 0 "End Resolve Paths"
)
function DelMissing =
(
local i=0
local upd = false
for ass in fndassets do
(
if ass.status == #Missing do (
relinkfile ass.inst ass.propName ""
i+=1
prgrbar i counts.missing "Deleting missing paths..."
)
if ass.status == #XRefScene do
(
upd = false
for assxrf in ass.inst do
(
status = GetStatusFile(assxrf.filename)
if status == #Missing do
(
assxrf.filename = ""
upd = true
)
)
if upd do
setMAXFileAssetMetadata ass.foundpath ass.inst
)
if (keyboard.EscPressed) and (queryBox "you want to abort operation?") then return ()
)
prgrbar 0 0 "Missing paths deleted"
)
function chDir dirpath = (
if (doesFileExist dirpath) == false then (
if queryBox("Directory does not exist. Create a Directory?") then
if (makeDir dirpath all:true) then (
logging "INF" ("Create Directory: "+dirpath)
return true
)
else logging "ERR" ("Can not create directory "+dirpath) msg:true
) else (
local str = dirpath
if dirpath.count > 1 do if (substring dirpath (dirpath.count - 1) 2) != ":\\" do str = trimRight dirpath "\\\/"
if isDirectoryWriteable(str) then
return true
else logging "ERR" ("Directory not writeable "+dirpath) msg:true
)
return false
)
function create_Dir dirpath = (
local err = true
if (doesFileExist dirpath) == true then
(
HiddenDOSCommand ("rmdir /S /Q "+dirpath) exitCode:&exitcode
if exitcode != 0 then ( logging "ERR" ("EROR delete dir " + dirpath); err = false;)
)
if (doesFileExist dirpath) == false then
if (makeDir dirpath all:true) == false then (logging "ERR" ("EROR create dir " + dirpath); err = false;)
err
)
fn get_tooltips_lang =
(
local lang = ""
case G_Tooltip_Lang of
(
1: lang = "tootlips_EN"
2: lang = "tootlips_RU"
)
lang
)
--load tooltips for controls
function loadTooltips rolloutt:"Collect_asset" = (
local tooltips_lang = get_tooltips_lang()
tmp_rollout = execute(rolloutt)
for c in tmp_rollout.controls do
(
tmp_name = rolloutt + "_" + c.name
if hasINISetting INIFilename tooltips_lang tmp_name do
c.tooltip = loadVarFromIniFile tooltips_lang tmp_name
)
)
function enableCtrl ctrl = (
if ctrl then
for c in Collect_asset.controls where (classof c == ButtonControl) do c.enabled = true
else
for c in Collect_asset.controls where (classof c == ButtonControl) do c.enabled = false
)
function dim_x bmpin = (
if bmpin.width >= bmpin.height then
330
else
330*(bmpin.width*100 / bmpin.height)/100
)
function dim_y bmpin = (
if bmpin.width <= bmpin.height then
330
else
330*(bmpin.height*100 / bmpin.width)/100
)
function chk_path str = (
--str = toLower str
str = trimleft str
str = trimRight str
banlet = "?*\"<>|\n"
for i=1 to banlet.count where str !="" do
(
str = substituteString str banlet[i] ""
)
str = trimRight str "\\\/"
str += "\\"
if str == "\\" do str = ""
str
)
fn query_match_bmp pc1 pc2 relink =
(
pic_1 = pc1
pic_2 = pc2
mb_result = #(0,"",false) -- [1] - 0 - cancel, 1 - leave exist, 2 - replace, 3 - rename [2] - filename [3] - boolean - repeat action
if relink then createDialog match_bmp modal:true else createDialog match_bmp2 modal:true
if mb_result[1] == 3 do (
if doesFileExist(mb_result[2]) then (
messagebox "File alrady exist. Try another file name \n mb_result[2]"
query_match_bmp pic_1 pic_2
)
)
logging "DBG" ("fn query_match_bmp return "+mb_result as string)
mb_result
)
fn match_bmp_as oldfullpath newfullpath mb_inst mb_propName relink =(
local errors = copied = i = 0
if mb_result[3] == false do mb_result = query_match_bmp oldfullpath newfullpath relink
case mb_result[1] of
(
1: (
if relink do (
relinkfile mb_inst mb_propName newfullpath
logging "INF" ("Use file in new path: "+newfullpath)
)
)
2: (
if (deleteFile newfullpath) and (copyFile oldfullpath newfullpath) then (
if relink do relinkfile mb_inst mb_propName newfullpath
copied = copied+1
logging "INF" ("Replace file done.")
)
else logging "ERR" ("Can not replace the file. Check access "+newfullpath)
)
3: (
if mb_result[3] == false then
rnmfullpath = mb_result[2]
else
do rnmfullpath = getFilenamePath newfullpath + random_name() + getFilenameType newfullpath while doesFileExist(rnmfullpath)
if doesFileExist(rnmfullpath) == false then (
if (copyFile oldfullpath rnmfullpath) then (
relinkfile mb_inst mb_propName rnmfullpath
copied = copied+1
logging "INF" ("Rename file to "+rnmfullpath)
) else logging "ERR" ("Can not save the file. Check access"+rnmfullpath)
) else (
logging "ERR" ("File alrady exist: "+rnmfullpath)
)
)
)
#(copied, errors)
)
fn relink_pointCache filename dirpath =
(
logging "DBG" ("Run fn relink_pointCache " + filename + " " + dirpath)
local newPath = dirpath
local errors = copied = i = 0
files = getFiles (getFilenamePath filename + getFilenameFile filename + "*.mc")
if files.count != 0 do (
mb_result[3] = false
for oldfullpath in files do
(
newfullpath = newPath + filenameFromPath oldfullpath
if (toLower newfullpath) != (toLower oldfullpath) do
(
if doesFileExist(newfullpath) == false then (
if (copyFile oldfullpath newfullpath) then (
logging "INF" ("Copy file from "+oldfullpath+" to "+newfullpath)
copied = copied+1
) else (errors = errors+1; logging "ERR" ("Can not copy file from "+oldfullpath+" to "+newfullpath))
)
else (
if not isIdenticalFiles oldfullpath newfullpath then (
logging "INF" ("Found different files: "+oldfullpath+" "+newfullpath)
if mb_result[3] == false do mb_result = query_match_bmp oldfullpath newfullpath false
case mb_result[1] of
(
1: (
fileLine.filename = newfullpath
upd = true
logging "INF" ("Use file in new path: "+newfullpath)
)
2: (
if (deleteFile newfullpath) and (copyFile oldfullpath newfullpath) then (
fileLine.filename = newfullpath
upd = true
copied = copied+1
logging "INF" ("Replace file done.")
)
else (errors = errors+1; logging "ERR" ("Can not replace the file. Check access "+newfullpath))
)
)
)
)
)
)
mb_result[3] = false
)
#(copied, errors)
)
fn relink_ifl filename dirpath relink fullpath:G_IFL_FULLPATH =
(
assiflFiles = #()
local newPath = dirpath
local errors = copied = i = 0
local file = openFile filename mode:"rt"
if file != undefined then
(
while not eof file do (
append assiflFiles (iflFile (readLine file))
)
close file
-- print assiflFiles
upd = false
for fileLine in assiflFiles do (
if (not matchPattern fileLine.filename pattern:@"*\*") and (doesFileExist(getFilenamePath filename + filenameFromPath fileLine.filename)) then
(
oldfullpath = getFilenamePath filename + filenameFromPath fileLine.filename
)else(
status = GetStatusFile(fileLine.filename)
if status == #Missing do continue
if status == #Found do oldfullpath = mapPaths.getFullFilePath(filenameFromPath(fileLine.filename))
if status == #Ok do oldfullpath = fileLine.filename
)
newfullpath = newPath + filenameFromPath oldfullpath
if (toLower newfullpath) != (toLower oldfullpath) do
(
if doesFileExist(newfullpath) == false then (
if (copyFile oldfullpath newfullpath) then (
if relink do (
fileLine.filename = newfullpath
upd = true
)
logging "INF" ("Copy file from "+oldfullpath+" to "+newfullpath)
copied = copied+1
--print newfullpath
) else errors = errors+1
)
else (
if not isIdenticalFiles oldfullpath newfullpath then (
logging "INF" ("Found different files: "+oldfullpath+" "+newfullpath)
if mb_result[3] == false do mb_result = query_match_bmp oldfullpath newfullpath relink
case mb_result[1] of
(
1: (
fileLine.filename = newfullpath
upd = true
logging "INF" ("Use file in new path: "+newfullpath)
)
2: (
if (deleteFile newfullpath) and (copyFile oldfullpath newfullpath) then (
fileLine.filename = newfullpath
upd = true
copied = copied+1
logging "INF" ("Replace file done.")
)
else logging "ERR" ("Can not replace the file. Check access "+newfullpath)
)
3: (
if mb_result[3] == false then
rnmfullpath = mb_result[2]
else
do rnmfullpath = getFilenamePath newfullpath + random_name() + getFilenameType newfullpath while doesFileExist(rnmfullpath)
if doesFileExist(rnmfullpath) == false then (
if (copyFile oldfullpath rnmfullpath) then (
fileLine.filename = rnmfullpath
upd = true
copied = copied+1
logging "INF" ("Rename file to "+rnmfullpath)
) else logging "ERR" ("Can not save the file. Check access"+rnmfullpath)
) else (
logging "ERR" ("File alrady exist: "+rnmfullpath)
)
)
)
) else (
if relink do (
fileLine.filename = newfullpath
upd = true
)
)
)
)
)
if upd then (
try file = openFile (dirpath + filenameFromPath filename) mode:"w" catch()
if file != undefined then
(
for fileLine in assiflFiles do (
if fullpath then
format "%\n" fileLine.filename to:file
else
format "%\n" (filenameFromPath(fileLine.filename)) to:file
)
close file
) else (
errors = errors+1
logging "ERR" ("Error open file to write: "+filename)
)
)
) else (
errors = errors+1
logging "ERR" ("Error open file to read: "+filename)
)
#(copied, errors)
)
function collect_as dirpath selected relink =
(
mb_result = #(0,"",false) -- [1] - 0 - cancel, 1 - leave exist, 2 - replace, 3 - rename [2] - filename [3] - boolean - repeat action
local prop
if selected do
fndassets = getAssetFilesSelected()
newPath = dirpath
errors = copied = i = 0
for ass in fndassets where (ass.status == #Found or ass.status == #Ok) while not exitt do (
if Collect_asset.chk_exxref.checked and (ass.type == "xref") do continue
if ass.status == #Found do oldfullpath = ass.foundpath
if ass.status == #Ok do oldfullpath = ass.filepath
if chk_filename(oldfullpath)=="" do continue
newfullpath = newPath + filenameFromPath oldfullpath
prgrbar i (counts.okk + counts.found) ("Collect Assets : "+(filenameFromPath newfullpath))
if (keyboard.EscPressed) and (queryBox "you want to abort operation?") then return ()
--format "oldpath: %\n newpath: %\n" oldfullpath newfullpath
if (toLower(getFilenameType oldfullpath)) == ".xml" do (
relink_pointCache oldfullpath dirpath
)
if (toLower newfullpath) != (toLower oldfullpath) then
(
if doesFileExist(newfullpath) == false then (
if (copyFile oldfullpath newfullpath) then (
if relink then
(
relinkfile ass.inst ass.propName newfullpath
logging "INF" ("Copy and Relink file from "+oldfullpath+" to "+newfullpath)
)
else
(
logging "INF" ("Copy file from "+oldfullpath+" to "+newfullpath)
)
copied = copied+1
--print newfullpath
) else (errors = errors+1; logging "ERR" ("Can not copy file from "+oldfullpath+"to"+newfullpath) )
)
else (
if not isIdenticalFiles oldfullpath newfullpath then (
logging "INF" ("Found different files: "+oldfullpath+" "+newfullpath)
resultfn = match_bmp_as oldfullpath newfullpath ass.inst ass.propName relink
copied = copied + resultfn[1]
errors = errors + resultfn[2]
) else (
if relink do
(
relinkfile ass.inst ass.propName newfullpath
logging "INF" ("Relink file from "+oldfullpath+" to "+newfullpath)
)
)
)
)
else
(
if relink do
(
relinkfile ass.inst ass.propName newfullpath
logging "INF" ("Relink file from "+oldfullpath+" to "+newfullpath)
)
)
if (toLower(getFilenameType oldfullpath)) == ".ifl" do (
relink_ifl oldfullpath dirpath relink
)
i+=1
)
prgrbar 0 0 "End Collect Assets"
#(copied, errors)
)
fn collect_as_xref dirpath relink =
(
logging "DBG" ("start collect_as_xref")
newPath = dirpath
errors = copied = i = 0
updall = false
for ass in fndassets where ass.status == #XRefScene while not exitt do
(
upd = false
for assxrf in ass.inst do