-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddNew.ms
270 lines (224 loc) · 10.8 KB
/
AddNew.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
/*
AddNew.ms
Version: 2.52
Created On: November 23, 2002
Created By: Jeff Hanna
Modified On: January 03, 2018
Modified By: Jeff Hanna
tested using 3ds Max 2016
© Copyright 2003, Lodestone Games, LLC. All Rights Reserved.
Adds a new Max scene and any new bitmaps used in that scene to the version control archive.
The files are added in a locked state, to prevent the scene from being checked out of version control by more than one user
at a time.
v2.52 - Updated so the VC* calls to global functions are now VersionControlLib.VC* calls
as that library has properly been made a struct with local functions.
v2.51 - Fixed variable scope on the rltGetDescription dialog. Improper scope was causing the scripts to break on Max 4.2x.
v2.5 - Added checking for the bVCEnableReset variable to control if the scene is reset or not.
v2.4 - Dead development tree, version number skipped.
v2.31 - Fixed the "ReOpen" code to work properly.
v2.3 - Changed from using the persistent global variables to using P4 fstat to check if the file exists.
Now ghosts any menu commands that are not proper after this script has finished.
v2.2 - Changed all VCSubmitAndReOpen() function calls to VCSubmit() function calls to reflect changes in VersionControlLib.ms
Changed all VCSyncAndCheckOut() function calls to VCSync() function calls to reflect changes in VersionControlLib.ms
Removed the local aMaxVersion array. The script now uses the global version of that array.
v2.1 - Added a section to switch the menu ghost variables to false when the file is added.
Removed the Max4/Max5 codepaths for bitmap discovery. Max 5's function doesn't work as well as my code.
v2.0 - Utilized the VCParseCommandResults & VCWriteCommandResults functions in VersionControlLib.ms to display results of the AddNew to the user.
Removed the two included library files. All functions are now made global when those two files are loaded at startup.
(Max 5 only) Changes the title bar to show the status of the file in Version Control after it has been added.
(Max 5 only) Uses the new usedMaps() command to find all bitmaps. This replaces the node-tree walking code I wrote to
do the same thing. That code is still used if the scripts are run on Max 4.
v1.71 - Changed variable names to follow the programming guidelines.
v1.7 - Changed name from "SaveAsToSourceControl" to "AddNew". All "Source Control" and "SC" references changed to "Version Control
and "VC". Changed function call "ConvertArray" to "LSUtilLib.ConvertArrayDOS2Unix" to reflect the change made in LSUtilLib
v1.6 - Fixed a bug with a misnamed variable that was breaking the script.
v1.5 - Copyright information added.
v1.4 - Switched from storing strMaxFileToEdit and strStartMapsFile in the FileProperties page to storing them in the persistent
global variables, "pg_strMaxFilepath" and, "pg_strMapsFilepath".
v1.3 - Changed the function call "ConvertArrays" to "ConvertArray" to reflect the change made in LSUtilLb.
v1.2 - Initial release.
*/
(
--LOCAL VARIABLES
-----------------
local strAddNewVersion = "2.52" -- Version number for display in the Max Listener window
local bExit = false -- Boolean to control whether the script should exit or not.
local bReOpen = false -- Boolean to indicate whether the user wants to immediately re-open the file.
local bExists = false -- Boolean to indicate if the file already exists or not.
aAllMaps = #()
aOtherMaps = #()
aPathnames = #()
aAllPathnames = #()
aFilesToSubmit = #()
aFilesToCheckOut = #()
--GLOBAL VARIABLES
------------------
--INCLUDED FILES
----------------
--ROLLOUTS
----------
-- The change lists are more useful with user-entered descriptions about what was done during the edit session.
rollout rltGetDescription "Version Control"
(
label lblWhatFor "Please enter a change description for this scene."
editText edtUserEntry
button btnOK "OK" enabled:false
on edtUserEntry changed strEntry do
(
VersionControlLib.strChangeDescription = edtUserEntry.text
btnOK.enabled = true
)
on btnOK pressed do
(
destroyDialog rltGetDescription
)
)
--MAIN LOOP
-----------
-- print version information to the listener. Useful if a bug-report needs to be sent.
format "AddNew v% loaded.\n" strAddNewVersion to:Listener
-- Delete the stored last command history.
deleteFile "$temp\\LastCommand.txt"
-- This script is executed as a do-while loop so that it can be exited at any time
do
(
-- Check to see if the file is empty. If so, abort the add process.
if getSaveRequired() == false and maxFileName == "" then
(
bExit = true
exit
)
-- Check the properties of the file to see if it is already under version control.
bExists = VersionControlLib.VCFstatExists (maxFilePath + maxFileName)
--If it already exists, it can not be added a second time.
if bExists == true then
(
-- If the variable exits, then this file is already in source control. It can't be added a second time.
-- Alert the user and exit the script.
messagebox "It appears that this scene already exists in the version control archive.\nThis scene cannot be added a second time." title:"Version Control" beep:false
bExit = true
exit
)
-- If it doesn't exist add it and check it in.
else
(
-- If no filename exists, prompt the user for a name and location to save.
if getSaveRequired() == true and maxFileName == "" then
(
-- If the user cancels the save-as then exit this script
if getMaxSaveFilename() == undefined then
(
bExit = true
exit
)
)
-- If the filename does exist, save the file.
else
(
if getSaveRequired() == true and maxFileName != "" then
(
saveMaxFile (maxFilePath + maxFileName)
)
)
-- The user needs to enter a description of the changes and decide if they want to close the scene.
createDialog rltGetDescription width:250 modal:true
bReOpen = querybox "Would you like to reopen the scene and continue to work on it?" title:"Version Control" beep:false
-- Get a list of all maps used in the scene
aAllMaps = LSUtilLib.GetSceneMaps()
aOtherMaps = LSUtilLib.GetOtherMaps()
aAllMaps = aAllMaps + aOtherMaps
-- Get the bitmap file paths from the maps and then remove any duplicate entries.
aPathnames = LSUtilLib.GetBitmapsFromMaps aAllMaps
-- The Max scene wouldn't be included in the Submit function if it's path and name weren't retrieved and added to the array.
append aPathnames (maxFilePath + maxFileName)
-- Forcing a revert on all files will cause the source control system to revert any file that is unchanged
VersionControlLib.VCRevertUnchanged aPathnames
-- Parse the results of the revert and add the reverted files to an array so they can be re-checked out if the user chooses to re-open the scene
local fileIn = openFile "$temp\\VCRevert.txt" mode:"r"
while not eof fileIn do
(
sTempString = readDelimitedString fileIn "#"
append aFilesToCheckOut sTempString
skipToNextLine fileIn
)
close fileIn
-- Add all new files to the source control archive.
VersionControlLib.VCAdd aPathnames
-- Convert the path names to Unix style relative pathing.
aPathnames = LSUtilLib.ConvertArrayDOS2Unix aPathnames
-- Check the changelist after the revert and build an array, "aFilesToSubmit" from what's left.
aFilesToSubmit = VersionControlLib.VCGetOpenedFiles aPathnames
-- Check to see if the user wanted to continue editng the file
if bReOpen == false then
(
-- If not, then submit the files. Pass and array of files and a boolean indicating
-- whether the submitted files should be reopened or not.
VersionControlLib.VCSubmit aFilesToSubmit false
-- Parse the results of the submit command so they can be displayed.
VersionControlLib.VCParseCommandResults "VCAdd.txt"
VersionControlLib.VCParseCommandResults "VCRevert.txt"
VersionControlLib.VCParseCommandResults "VCSubmit.txt"
-- Possibly display the results of the version control system operations in a dialog.
if VersionControlLib.bVCShowResults == true then
(
messagebox VersionControlLib.strCommandResults title:"Version Control" beep:false
)
-- Save the command results to a disk file for possible later reference.
VersionControlLib.VCWriteCommandResults()
-- Clean up all temporary disk files that were created when the scene was checked out.
VersionControlLib.VCCleanup()
-- Set these boolean global variables to false so the associated menu commands ghost.
VersionControlLib.bVCEnableCheckIn = false
VersionControlLib.bVCEnableAddNew = true
VersionControlLib.bVCEnableRevert = false
VersionControlLib.bVCEnableView = true
-- If requested, reset Max to prevent further editing of the file.
if VersionControlLib.bVCEnableReset == true then resetMaxFile #noPrompt
else
(
-- Change the titlebar of the app to show the version control status.
cui.setAppTitle (maxFilePath + MaxFilename + " - NOT CHECKED OUT FROM VERSION CONTROL. OPENED AS READ ONLY.")
)
-- Exit the script
bExit = true
exit
)
else -- bReOpen == true
(
-- If they did want to continue editing, submit the files and
-- immediately check them out again from the source control archive.
VersionControlLib.VCSubmit aFilesToSubmit true
-- Re-check out the reverted files
LSUtilLib.WriteFile aFilesToCheckOut "$temp\\TempSync.txt" --strTextFile
strDOSEditFile = LSUtilLib.DOSTempPath "$temp\\TempSync.txt" 1 5
HiddenDOSCommand ("p4 -x " + strDOSEditFile + " edit > %temp%\\VCEdit.txt")
deleteFile "$Temp\\TempSync.txt"
-- Parse the results of the submit and Sync commands so they can be displayed.
VersionControlLib.VCParseCommandResults "VCAdd.txt"
VersionControlLib.VCParseCommandResults "VCRevert.txt"
VersionControlLib.VCParseCommandResults "VCSubmit.txt"
VersionControlLib.VCParseCommandResults "VCEdit.txt"
-- Possibly display the results of the version control system operations in a dialog.
if VersionControlLib.bVCShowResults == true then
(
messagebox VersionControlLib.strCommandResults title:"Version Control" beep:false
)
-- Save the command results to a disk file for possible later reference.
VersionControlLib.VCWriteCommandResults()
-- Change the titlebar of the app to show the version control status.
cui.setAppTitle (maxFilePath + MaxFilename + " - CHECKED OUT FROM VERSION CONTROL")
-- Clean up all temporary disk files that were created when the scene was checked out.
VersionControlLib.VCCleanup()
-- Set these boolean global variables to false so the associated menu commands un-ghost.
VersionControlLib.bEnableCheckIn = true
VersionControlLib.bEnableAddNew = false
VersionControlLib.bEnableRevert = true
VersionControlLib.bEnableView = true
-- Exit the script
bExit = true
exit
)
)
)
while bExit == false
)