-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCommandLine.ls
158 lines (147 loc) · 5.12 KB
/
CommandLine.ls
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
on setMemberTypes types
global memberTypes
if the count of types = 0 then
errorMsg("Please specify at least one member type to export")
else if the count of types = 1 and types.getAt(1) = "all" then
enableAllCategories()
else
set msg = "Unknown member type:"
set allTypes = the value of field "MemberTypes"
set allCategories = getAllProps(the value of field "MemberCategories")
repeat with t in types
if t starts "#" then
set memberType = value(t)
if allTypes.getPos(memberType) > 0 then
memberTypes.setaProp(memberType, True)
else
errorMsg(msg && t)
end if
else
if t = "3d" then set t = "shockwave3d"
set memberCategory = symbol(t)
if allCategories.getPos(memberCategory) > 0 then
updateCategory(memberCategory, True)
else
errorMsg(msg && t)
end if
end if
end repeat
end if
end
on setExportFormats formats
global exportFormats
set allFormats = the value of field "ExportFormats"
repeat with fmt in formats
set fmt = symbol(fmt)
if allFormats.getPos(fmt) > 0 then
exportFormats.setaProp(fmt, True)
else
errorMsg("Unknown export format:" && fmt)
end if
end repeat
end
on parseCommandLineArgs argsList
set parsedArgs = propList()
set argName = EMPTY
set argVals = list()
repeat with arg in argsList
if char 1 to 2 of arg = "--" then
set argName = arg
delete char 1 to 2 of argName
set argVals = parsedArgs.getaProp(argName)
if argVals = VOID then
set argVals = list()
end if
else if char 1 of arg = "-" and the number of chars in arg = 2 then
parsedArgs.setaProp(char 2 of arg, list())
else
argVals.append(arg)
end if
parsedArgs.setaProp(argName, argVals)
end repeat
return parsedArgs
end
on setFlagOpt optName, optVal
global exportOptions
if the count of optVal > 0 then
errorMsg("Unknown arguments after" && optName & ":" && optVal)
else
exportOptions.setaProp(optName, True)
end if
end
on processCommandLineArgs args
global fxObj, consoleMode, movieFiles, castFiles, exportFolder
set options = parseCommandLineArgs(args)
if the count of options = 0 or the runMode = "Author" then return
repeat with i = 1 to the count of options
set optName = options.getPropAt(i)
set optVal = options.getAt(i)
case optName of
"help", "h": printInfo(True)
"version", "v": printInfo(False)
"debug": set the debugPlaybackEnabled = True
"cli": set consoleMode = True
"no-cli": set consoleMode = False
-- File paths can be passed without an option name
"files", EMPTY: processSelection(optVal)
"folders": set inputFolders = optVal
"movies": set movies = optVal
"casts": set casts = optVal
"output-folder": set exportFolderOpt = optVal
"member-types": setMemberTypes(optVal)
"formats": setExportFormats(optVal)
"include-names": setFlagOpt(#exportWithNames, optVal)
"decompile": setFlagOpt(#decompile, optVal)
"dismiss-dialogs": setFlagOpt(#dismissDialogs, optVal)
"text-to-images": setFlagOpt(#textToImages, optVal)
otherwise: errorMsg("Unknown option:" && optName)
end case
end repeat
if listP(inputFolders) then
repeat with folderPath in inputFolders
if fxObj.fx_FolderExists(folderPath) then
processSelection(getDirFilesInFolder(folderPath))
else
errorMsg("The specified input folder does not exist:" && folderPath)
end if
end repeat
end if
if listP(movies) then
checkFilesExist(movies)
appendItems(movieFiles, movies)
end if
if listP(casts) then
checkFilesExist(casts)
appendItems(castFiles, casts)
end if
if consoleMode then
close the window
-- User won't be able to set these options via the UI; fail immediately
if the count of movieFiles = 0 and the count of castFiles = 0 then
errorMsg("Please specify at least one Director movie or cast file to export from")
end if
if voidP(exportFolder) and voidP(exportFolderOpt) then
if not setDefaultExportFolder() then errorMsg("Please specify an output folder path to export to")
end if
end if
if listP(exportFolderOpt) then
if the count of exportFolderOpt = 1 then
if not setExportFolder(exportFolderOpt.getAt(1)) then
errorMsg("The specified output folder does not exist or is not writable")
set exportFolder = EMPTY
end if
else
errorMsg("Please specify exactly one folder path to export to. If the path contains spaces, wrap it in quotes.")
end if
end if
end
on printInfo includeHelp
infoMsg(the movieAboutInfo)
if includeHelp then
infoMsg("Usage:" && the applicationName && "[files...] [options...]")
repeat with i = 1 to the number of lines of field "CmdLineHelp"
infoMsg(SPACE & line i of field "CmdLineHelp")
end repeat
end if
quit() -- halt() seems to sometimes not work from a prepareMovie handler
end