Skip to content

Commit f06e1d2

Browse files
author
Fraser J. Gordon
committed
Refactor creation of MCDeployParameters structure
1 parent f31aa86 commit f06e1d2

2 files changed

Lines changed: 108 additions & 90 deletions

File tree

engine/src/deploy.cpp

Lines changed: 90 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,94 @@ extern Boolean InitSSLCrypt(void);
9090

9191
////////////////////////////////////////////////////////////////////////////////
9292

93+
bool MCDeployParameters::InitWithArray(MCExecContext &ctxt, MCArrayRef p_array)
94+
{
95+
MCStringRef t_temp_string;
96+
MCArrayRef t_temp_array;
97+
98+
if (!ctxt.CopyOptElementAsFilepath(p_array, MCNAME("engine_ppc"), false, t_temp_string))
99+
return false;
100+
MCValueAssign(engine_ppc, t_temp_string);
101+
MCValueRelease(t_temp_string);
102+
103+
if (!ctxt.CopyOptElementAsFilepath(p_array, MCNAME("engine_x86"), false, t_temp_string))
104+
return false;
105+
MCValueAssign(engine_x86, t_temp_string);
106+
MCValueRelease(t_temp_string);
107+
108+
if (MCStringIsEmpty(engine_ppc) && MCStringIsEmpty(engine_x86))
109+
{
110+
if (!ctxt.CopyElementAsFilepath(p_array, MCNAME("engine"), false, t_temp_string))
111+
return false;
112+
MCValueAssign(engine, t_temp_string);
113+
MCValueRelease(t_temp_string);
114+
}
115+
116+
if (!ctxt.CopyElementAsFilepath(p_array, MCNAME("stackfile"), false, t_temp_string))
117+
return false;
118+
MCValueAssign(stackfile, t_temp_string);
119+
MCValueRelease(t_temp_string);
120+
121+
if (!ctxt.CopyElementAsFilepathArray(p_array, MCNAME("auxillary_stackfiles"), false, t_temp_array))
122+
return false;
123+
MCValueAssign(auxillary_stackfiles, t_temp_array);
124+
MCValueRelease(t_temp_array);
125+
126+
if (!ctxt.CopyElementAsArray(p_array, MCNAME("externals"), false, t_temp_array))
127+
return false;
128+
MCValueAssign(externals, t_temp_array);
129+
MCValueRelease(t_temp_array);
130+
131+
if (!ctxt.CopyOptElementAsString(p_array, MCNAME("startup_script"), false, startup_script))
132+
return false;
133+
MCValueAssign(startup_script, t_temp_string);
134+
MCValueRelease(t_temp_string);
135+
136+
if (!ctxt.CopyElementAsArray(p_array, MCNAME("redirects"), false, t_temp_array))
137+
return false;
138+
MCValueAssign(redirects, t_temp_array);
139+
MCValueRelease(t_temp_array);
140+
141+
if (!ctxt.CopyOptElementAsFilepath(p_array, MCNAME("appicon"), false, t_temp_string))
142+
return false;
143+
MCValueAssign(app_icon, t_temp_string);
144+
MCValueRelease(t_temp_string);
145+
146+
if (!ctxt.CopyOptElementAsFilepath(p_array, MCNAME("docicon"), false, t_temp_string))
147+
return false;
148+
MCValueAssign(doc_icon, t_temp_string);
149+
MCValueRelease(t_temp_string);
150+
151+
if (!ctxt.CopyOptElementAsFilepath(p_array, MCNAME("manifest"), false, t_temp_string))
152+
return false;
153+
MCValueAssign(manifest, t_temp_string);
154+
MCValueRelease(t_temp_string);
155+
156+
if (!ctxt.CopyOptElementAsFilepath(p_array, MCNAME("payload"), false, t_temp_string))
157+
return false;
158+
MCValueAssign(payload, t_temp_string);
159+
MCValueRelease(t_temp_string);
160+
161+
if (!ctxt.CopyOptElementAsFilepath(p_array, MCNAME("spill"), false, t_temp_string))
162+
return false;
163+
MCValueAssign(spill, t_temp_string);
164+
MCValueRelease(t_temp_string);
165+
166+
if (!ctxt.CopyElementAsFilepath(p_array, MCNAME("output"), false, t_temp_string))
167+
return false;
168+
MCValueAssign(output, t_temp_string);
169+
MCValueRelease(t_temp_string);
170+
171+
if (!ctxt.CopyElementAsArray(p_array, MCNAME("version"), false, t_temp_array))
172+
return false;
173+
MCValueAssign(version_info, t_temp_array);
174+
MCValueRelease(t_temp_array);
175+
176+
return true;
177+
}
178+
179+
////////////////////////////////////////////////////////////////////////////////
180+
93181
static bool MCDeployWriteDefinePrologueSection(const MCDeployParameters& p_params, MCDeployCapsuleRef p_capsule)
94182
{
95183
MCCapsulePrologueSection t_prologue;
@@ -127,7 +215,7 @@ bool MCDeployWriteCapsule(const MCDeployParameters& p_params, MCDeployFileRef p_
127215
// Open the spill file, if required
128216
MCDeployFileRef t_spill;
129217
t_spill = NULL;
130-
if (t_success && p_params . spill != nil && !MCDeployFileOpen(p_params . spill, kMCSOpenFileModeWrite, t_spill))
218+
if (t_success && !MCStringIsEmpty(p_params . spill) && !MCDeployFileOpen(p_params . spill, kMCSOpenFileModeWrite, t_spill))
131219
t_success = MCDeployThrow(kMCDeployErrorNoSpill);
132220

133221
// First create our deployment capsule
@@ -362,65 +450,7 @@ Exec_stat MCIdeDeploy::exec(MCExecPoint& ep)
362450
MCExecContext ctxt(ep);
363451

364452
MCDeployParameters t_params;
365-
366-
MCStringRef t_temp;
367-
if (t_stat == ES_NORMAL)
368-
if (!ctxt.CopyOptElementAsFilepath(*t_array, MCNAME("engine_ppc"), false, t_params.engine_ppc))
369-
t_stat = ES_ERROR;
370-
if (t_stat == ES_NORMAL)
371-
if (!ctxt.CopyOptElementAsFilepath(*t_array, MCNAME("engine_x86"), false, t_params.engine_x86))
372-
t_stat = ES_ERROR;
373-
if (t_stat == ES_NORMAL && MCStringIsEmpty(t_params.engine_ppc) && MCStringIsEmpty(t_params.engine_x86))
374-
if (!ctxt.CopyElementAsFilepath(*t_array, MCNAME("engine"), false, t_params.engine))
375-
t_stat = ES_ERROR;
376-
377-
if (t_stat == ES_NORMAL)
378-
if (!ctxt.CopyElementAsFilepath(*t_array, MCNAME("stackfile"), false, t_params.stackfile))
379-
t_stat = ES_ERROR;
380-
if (t_stat == ES_NORMAL)
381-
if (!ctxt.CopyElementAsFilepathArray(*t_array, MCNAME("auxillary_stackfiles"), false, t_params.auxillary_stackfiles))
382-
t_stat = ES_ERROR;
383-
if (t_stat == ES_NORMAL)
384-
if (!ctxt.CopyElementAsArray(*t_array, MCNAME("externals"), false, t_params.externals))
385-
t_stat = ES_ERROR;
386-
387-
if (t_stat == ES_NORMAL)
388-
if (!ctxt.CopyOptElementAsString(*t_array, MCNAME("startup_script"), false, t_params.startup_script))
389-
t_stat = ES_ERROR;
390-
391-
if (t_stat == ES_NORMAL)
392-
if (!ctxt.CopyElementAsArray(*t_array, MCNAME("redirects"), false, t_params.redirects))
393-
t_stat = ES_ERROR;
394-
395-
if (t_stat == ES_NORMAL)
396-
if (!ctxt.CopyOptElementAsFilepath(*t_array, MCNAME("appicon"), false, t_params.app_icon))
397-
t_stat = ES_ERROR;
398-
if (t_stat == ES_NORMAL)
399-
if (!ctxt.CopyOptElementAsFilepath(*t_array, MCNAME("docicon"), false, t_params.doc_icon))
400-
t_stat = ES_ERROR;
401-
402-
if (t_stat == ES_NORMAL)
403-
if (!ctxt.CopyOptElementAsFilepath(*t_array, MCNAME("manifest"), false, t_params.manifest))
404-
t_stat = ES_ERROR;
405-
406-
if (t_stat == ES_NORMAL)
407-
if (!ctxt.CopyOptElementAsFilepath(*t_array, MCNAME("payload"), false, t_params.payload))
408-
t_stat = ES_ERROR;
409-
410-
if (t_stat == ES_NORMAL)
411-
if (!ctxt.CopyOptElementAsFilepath(*t_array, MCNAME("spill"), false, t_params.spill))
412-
t_stat = ES_ERROR;
413-
414-
if (t_stat == ES_NORMAL)
415-
if (!ctxt.CopyElementAsFilepath(*t_array, MCNAME("output"), false, t_params.output))
416-
t_stat = ES_ERROR;
417-
418-
if (t_stat == ES_NORMAL)
419-
{
420-
MCAutoArrayRef t_version;
421-
if (!ctxt.CopyElementAsArray(*t_array, MCNAME("version"), false, &t_version))
422-
t_params.version_info = MCValueRetain(*t_version);
423-
}
453+
t_params.InitWithArray(ctxt, *t_array);
424454

425455
// If platform is iOS and we are not Mac then error
426456
#ifndef _MACOSX

engine/src/deploy.h

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -73,57 +73,45 @@ struct MCDeployParameters
7373

7474
MCDeployParameters()
7575
{
76-
engine = nil;
77-
engine_x86 = nil;
78-
engine_ppc = nil;
79-
version_info = nil;
80-
stackfile = nil;
81-
auxillary_stackfiles = nil;
82-
externals = nil;
83-
startup_script = nil;
76+
engine = MCValueRetain(kMCEmptyString);
77+
engine_x86 = MCValueRetain(kMCEmptyString);
78+
engine_ppc = MCValueRetain(kMCEmptyString);
79+
version_info = MCValueRetain(kMCEmptyArray);
80+
stackfile = MCValueRetain(kMCEmptyString);
81+
auxillary_stackfiles = MCValueRetain(kMCEmptyArray);
82+
externals = MCValueRetain(kMCEmptyArray);
83+
startup_script = MCValueRetain(kMCEmptyString);
8484
timeout = 0;
85-
redirects = nil;
86-
app_icon = nil;
87-
doc_icon = nil;
88-
manifest = nil;
89-
payload = nil;
90-
spill = nil;
91-
output = nil;
85+
redirects = MCValueRetain(kMCEmptyArray);
86+
app_icon = MCValueRetain(kMCEmptyString);
87+
doc_icon = MCValueRetain(kMCEmptyString);
88+
manifest = MCValueRetain(kMCEmptyString);
89+
payload = MCValueRetain(kMCEmptyString);
90+
spill = MCValueRetain(kMCEmptyString);
91+
output = MCValueRetain(kMCEmptyString);
9292
}
9393

9494
~MCDeployParameters()
9595
{
96-
if (engine != nil)
9796
MCValueRelease(engine);
98-
if (engine_x86 != nil)
9997
MCValueRelease(engine_x86);
100-
if (engine_ppc != nil)
10198
MCValueRelease(engine_ppc);
102-
if (version_info != nil)
10399
MCValueRelease(version_info);
104-
if (stackfile != nil)
105100
MCValueRelease(stackfile);
106-
if (auxillary_stackfiles != nil)
107101
MCValueRelease(auxillary_stackfiles);
108-
if (externals != nil)
109102
MCValueRelease(externals);
110-
if (startup_script != nil)
111103
MCValueRelease(startup_script);
112-
if (redirects != nil)
113104
MCValueRelease(redirects);
114-
if (app_icon != nil)
115105
MCValueRelease(app_icon);
116-
if (doc_icon != nil)
117106
MCValueRelease(doc_icon);
118-
if (manifest != nil)
119107
MCValueRelease(manifest);
120-
if (payload != nil)
121108
MCValueRelease(payload);
122-
if (spill != nil)
123109
MCValueRelease(spill);
124-
if (output != nil)
125110
MCValueRelease(output);
126111
}
112+
113+
// Creates using an array of parameters
114+
bool InitWithArray(MCExecContext &ctxt, MCArrayRef p_array);
127115
};
128116

129117
Exec_stat MCDeployToWindows(const MCDeployParameters& p_params);

0 commit comments

Comments
 (0)