-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelinker_and_xref.ms
233 lines (216 loc) · 9.25 KB
/
relinker_and_xref.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
(
-- Set debuging to 0 (off) state and define the node struct beeing used in this relinker
-- ****************************************************************************
XRefAssetResolverDebug = 1
ct = 1
Struct theNode ( filePath, nodeLevel = 1, nodeDetails = #(), assetsList = #(), nodeChildren = #() )
-- ****************************************************************************
-- ******* THE HDD READ FUNCTIONS
-- ****************************************************************************
-- READ and DISPLAY IF NEEDED all avalible info on one nodes assets
-- ****************************************************************************
fn listAssetsRecurency myNode =
(
if doesfileexist myNode.filePath then
(
-- CAN DELATE IT -> IT IS DECORATION ONLY
if XRefAssetResolverDebug != 0 then (
thisSpace =" "
thisStar ="*"
for i = 0 to myNode.nodeLevel do (
append thisSpace " "
append thisStar "**"
)
if myNode.nodeLevel == 0 then (
format "** THE ROOT NODE (Level 0 node)\n"
format "** FILE: %\n" myNode.filePath
)
else (
format "% THE CHILD NODE (Level % node) ::\n" (thisStar as string) myNode.nodeLevel
format "% ID: % TYPE: % FILE: %\n" (thisStar as string) (myNode.nodeDetails.assetId) (myNode.nodeDetails.type) (getFilenameFile myNode.nodeDetails.filename)
format "% FILE: %\n" (thisStar as string) (myNode.filePath)
)
)
-- END OF CAN DELATE IT -> IT IS DECORATION ONLY
local tempList = getMAXFileAssetMetadata myNode.filePath
for theItem in tempList do
(
local theType = theItem.type as string
if stricmp theType "xref" == 0 then
(
tmp = theNode (theItem.resolvedFilename) (myNode.nodeLevel+1) theItem
append myNode.nodeChildren tmp
)
else
(
append myNode.assetsList theItem
if XRefAssetResolverDebug == 1 then ( format "%ID:% TYPE: %\n% orgPath.....: %%%\n% resolvedPath: %\n" (thisSpace as string) theItem.assetId theItem.type (thisSpace as string) (getFilenamePath theItem.filename) (getFilenameFile theItem.filename) (getFilenameType theItem.filename) (thisSpace as string) theItem.resolvedFilename )
)
)
)
else
(
format "WARNING:: The XRef file was omitted. \n FILEPATH:: %\n" myNode.filePath
)
)
-- ****************************************************************************
-- READ and DISPLAY IF NEEDED all avalible info on one node, and step through all child items
-- ****************************************************************************
fn theRecursiveLoader myNode =
(
listAssetsRecurency myNode
for nodeItem in myNode.nodeChildren do
(
theRecursiveLoader nodeItem
)
)
-- ****************************************************************************
-- Initialize the TreeBased data model and load 'root node' asset info and xrefs
-- ****************************************************************************
fn createDependencyTree theRootNode =
(
if doesfileexist theRootNode.filePath then
(
theRecursiveLoader theRootNode
)
else (
format "CRITICAL ERROR: The main scene file does not exists or could not been opened for read/wrtite.\n FILEPATH:: %\n" theRootNode.filePath
)
)
-- ****************************************************************************
-- ******* THE HDD WRITE METEADATA FUNCTIONS
-- ****************************************************************************
-- Write the changes to HDD drive -- the assets only;]
-- ****************************************************************************
fn writeUpdatedAssets myNode = (
if doesfileexist myNode.filePath do
(
setMAXFileAssetMetadata myNode.filePath myNode.assetsList
)
)
-- ****************************************************************************
-- Write the changes to HDD drive -- the XrefFiles info only
-- ****************************************************************************
fn writeUpdatedXRefs myNode = (
if doesfileexist myNode.filePath then
(
temp=#();
for pt in myNode.nodeChildren do
(
appendIfUnique temp pt.nodeDetails
)
setMAXFileAssetMetadata myNode.filePath temp
)
)
-- ****************************************************************************
-- Write the changes to HDD drive -- Whole one XRef-file
-- ****************************************************************************
fn writeUpdatedNode myNode = (
writeUpdatedAssets myNode
writeUpdatedXRefs myNode
)
-- ****************************************************************************
-- WRITE WHOLE UPDATED TREE TO HDD
-- ****************************************************************************
fn writeUpdatedTree myRootNode = (
writeUpdatedNode myRootNode
for pt in myRootNode.nodeChildren do (
writeUpdatedTree pt;
)
)
-- ****************************************************************************
-- ******* THE COPY AND UPDATE FUNCTIONS
-- ****************************************************************************
-- GENERATE UNIQUE XREF FILES LIST
-- ****************************************************************************
fn generateXrefsList myRootNode theXrefsList =
(
appendIfUnique theXrefsList (myRootNode.filepath as string)
for pt in myRootNode.nodeChildren do (
generateXrefsList pt theXrefsList;
)
)
-- ****************************************************************************
-- GENERATE UNIQUE ASSETS FILES LIST
-- ****************************************************************************
fn generateAssetsList myRootNode theAssetsList =
(
for pt in myRootNode.assetsList do (
appendIfUnique theAssetsList (pt.resolvedFilename as string)
)
for pt in myRootNode.nodeChildren do (
generateAssetsList pt theAssetsList;
)
)
-- ****************************************************************************
-- COPY AND RELINK FUNCTION
-- ****************************************************************************
fn copyTheNode myNode xrefDir = (
for theItem in myNode.assetsList do
(
if doesfileexist theItem.filename then
(
ct= ct+1
tmp = xrefDir + "\\" + (ct as string) + (filenameFromPath theItem.filename)
copyFile theItem.filename tmp
theItem.filename = (filenameFromPath theItem.filename)
theItem.resolvedFilename = tmp
)
)
if doesfileexist myNode.filepath then
(
ct= ct+1
tmp = xrefDir + "\\" + (ct as string) + (filenameFromPath myNode.filepath)
copyFile myNode.filepath tmp
myNode.filepath = tmp
if myNode.nodeDetails != undefined then
(
myNode.nodeDetails.filename = (filenameFromPath myNode.filepath)
myNode.nodeDetails.resolvedFilename = tmp
)
)
)
-- ****************************************************************************
-- WRITE WHOLE UPDATED TREE TO HDD
-- ****************************************************************************
fn copyTheTree myRootNode xrefDir = (
copyTheNode myRootNode xrefDir
for pt in myRootNode.nodeChildren do (
copyTheTree pt xrefDir;
)
)
-- ****************************************************************************
-- ******* MAIN LOGIC STARTS HERE
-- ****************************************************************************
-- ****************************************************************************
-- Struct theNode [ -- the node model implementation
----- string filePath [no meta] -- existing on HDD Xref file resolved filePath
----- integer nodeLevel [no meta] -- (int) the level of recurance / the item in-tree hight
----- nodeDetails [D][META] --(data) the actual node informations
----- assetsList [D][META] -- (list) actual node assets lists with paths
----- nodeChildren ] [META] -- (list) actual node children xrefs
-- ****************************************************************************
-- ******* [no meta] *** labeled items are for internal use only with no effect on meta-data
-- ******* [META] *** labeled items will update meta-data on node saving
-- ******* [D] *** labeled are AssetMetadataStructDef ( assetId, type, filename, resolvedFilename )
-- ******* *** (getFilenamePath) (getFilenameFile) (getFilenameType)
-- ****************************************************************************
theSourceFile = @"C:\Users\milos\Desktop\xRefScript\mainScene.max" -- the source file
theNewXRefsDir = "d:\\_____" -- new directory with dependencies
myMainNode = theNode theSourceFile 0 -- create main (the root) node item and set file path to theSourceFile
createDependencyTree myMainNode -- create full dependency list on TreeBased stgruct
makeDir theNewXRefsDir all:true -- create dir if it doesn't exist
copyTheTree myMainNode theNewXRefsDir -- tree copy the xrefs and asse4ts
writeUpdatedTree myMainNode -- tree write updated paths to copied assets
-- For checking only - lists all dependencies in new location
myMainNodeCopy = theNode myMainNode.filePath 0
createDependencyTree myMainNodeCopy
-- TO-DO: unique copy files. Now there can be many same-files copied
--theXrefsList =#()
--generateAssetsList myMainNode theXrefsList
--generateXrefsList myMainNode theXrefsList
--for pt in theXrefsList do
--(
--format "path: %\n" pt
--)
)