Skip to content

Commit 41c87af

Browse files
author
runrevali
committed
[[ SB Inclusions ]] Add resource mapping functionality to deploy command, and store any mappings in in MCdispatcher
1 parent efc6548 commit 41c87af

File tree

6 files changed

+88
-3
lines changed

6 files changed

+88
-3
lines changed

engine/src/capsule.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ enum MCCapsuleSectionType
9797
// Startup script to be executed after all stacks have loaded but before
9898
// the main stack is opened.
9999
kMCCapsuleSectionTypeStartupScript,
100+
101+
// AL-2015-02-10: [[ Standalone Inclusions ]] Library consists of the mappings from universal names
102+
// of resources to their platform-specific paths relative to the executable.
103+
kMCCapsuleSectionTypeLibrary,
100104
};
101105

102106
// Each section begins with a header that defines its type and length. This is

engine/src/deploy.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ bool MCDeployWriteCapsule(const MCDeployParameters& p_params, MCDeployFileRef p_
162162
t_success = MCDeployCapsuleDefineFromFile(t_capsule, kMCCapsuleSectionTypeAuxiliaryStack, t_aux_stackfiles[i]);
163163
}
164164

165+
// AL-2015-02-10: [[ Standalone Inclusions ]] Add the resource mappings, if any.
166+
if (t_success)
167+
for(uint32_t i = 0; i < p_params . library_count && t_success; i++)
168+
t_success = MCDeployCapsuleDefine(t_capsule, kMCCapsuleSectionTypeLibrary, p_params . library[i], MCCStringLength(p_params . library[i]) + 1);
169+
165170
// Now add the externals, if any
166171
if (t_success)
167172
for(uint32_t i = 0; i < p_params . external_count && t_success; i++)
@@ -501,6 +506,9 @@ Exec_stat MCIdeDeploy::exec(MCExecPoint& ep)
501506
t_stat = fetch_filepath(ep2, t_array, "stackfile", t_params . stackfile);
502507
if (t_stat == ES_NORMAL)
503508
t_stat = fetch_filepath_array(ep2, t_array, "auxiliary_stackfiles", t_params . auxiliary_stackfiles, t_params . auxiliary_stackfile_count);
509+
// AL-2015-02-10: [[ Standalone Inclusions ]] Fetch the resource mappings, if any.
510+
if (t_stat == ES_NORMAL)
511+
t_stat = fetch_cstring_array(ep2, t_array, "library", t_params . library, t_params . library_count);
504512
if (t_stat == ES_NORMAL)
505513
t_stat = fetch_cstring_array(ep2, t_array, "externals", t_params . externals, t_params . external_count);
506514
if (t_stat == ES_NORMAL)

engine/src/deploy.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ struct MCDeployParameters
4949
// The list of redirection mappings
5050
char **redirects;
5151
uint32_t redirect_count;
52-
52+
53+
// AL-2015-02-10: [[ Standalone Inclusions ]] The list of resource mappings.
54+
char **library;
55+
uint32_t library_count;
56+
5357
// On Windows, the icon files to be inserted into the resource directory.
5458
char *app_icon;
5559
char *doc_icon;

engine/src/dispatch.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ MCDispatch::MCDispatch()
9898
m_externals = nil;
9999

100100
m_transient_stacks = nil;
101+
102+
// AL-2015-02-10: [[ Standalone Inclusions ]] Add resource mapping array to MCDispatch. This stores
103+
// any universal name / relative path pairs included in a standalone executable for locating included
104+
// resources.
105+
m_library_mapping = new MCVariableValue;
106+
m_library_mapping -> assign_new_array(TABLE_SIZE);
101107
}
102108

103109
MCDispatch::~MCDispatch()
@@ -119,6 +125,8 @@ MCDispatch::~MCDispatch()
119125
delete enginedir;
120126

121127
delete m_externals;
128+
// AL-2015-02-10: [[ Standalone Inclusions ]] Delete library mapping
129+
delete m_library_mapping;
122130
}
123131

124132
bool MCDispatch::isdragsource(void)
@@ -2277,3 +2285,41 @@ MCFontlist *MCFontlistGetCurrent(void)
22772285
}
22782286

22792287
////////////////////////////////////////////////////////////////////////////////
2288+
2289+
// AL-2015-02-10: [[ Standalone Inclusions ]] Add functions to fetch relative paths present
2290+
// in the resource mapping array of MCdispatcher.
2291+
void MCDispatch::addlibrarymapping(const char *p_mapping)
2292+
{
2293+
const char *t_separator;
2294+
t_separator = strchr(p_mapping, ':');
2295+
2296+
char *t_name;
2297+
MCCStringCloneSubstring(p_mapping, t_separator - p_mapping, t_name);
2298+
2299+
t_separator++;
2300+
char *t_target;
2301+
MCCStringCloneSubstring(t_separator, strlen(t_separator), t_target);
2302+
2303+
MCExecPoint ep(nil, nil, nil);
2304+
ep . setstaticcstring(t_target);
2305+
2306+
m_library_mapping -> store_element(ep, t_name);
2307+
2308+
delete t_name;
2309+
delete t_target;
2310+
}
2311+
2312+
bool MCDispatch::fetchlibrarymapping(const char *p_name, char*& r_path)
2313+
{
2314+
MCExecPoint ep(nil, nil, nil);
2315+
if (!m_library_mapping -> has_element(ep, p_name))
2316+
return nil;
2317+
2318+
if (m_library_mapping -> fetch_element(ep, p_name) != ES_NORMAL)
2319+
return false;
2320+
if (ep . getsvalue() == MCnullmcstring)
2321+
return false;
2322+
2323+
r_path = ep . getsvalue() . clone();
2324+
return true;
2325+
}

engine/src/dispatch.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class MCDispatch : public MCObject
5757

5858
static MCImage *imagecache;
5959

60+
// AL-2015-02-10: [[ Standalone Inclusions ]] Add resource mapping array to MCDispatch object.
61+
MCVariableValue *m_library_mapping;
6062
public:
6163
MCDispatch();
6264
// virtual functions from MCObject
@@ -223,7 +225,12 @@ class MCDispatch : public MCObject
223225
{
224226
return stacks;
225227
}
226-
228+
229+
// AL-2015-02-10: [[ Standalone Inclusions ]] Add functions to fetch relative paths present
230+
// in the resource mapping array of MCdispatcher.
231+
void addlibrarymapping(const char *p_mapping);
232+
bool fetchlibrarymapping(const char *p_name, char*& r_path);
233+
227234
private:
228235
// MW-2012-02-17: [[ LogFonts ]] Actual method which performs a load stack. This
229236
// is wrapped by readfile to handle logical font table.

engine/src/mode_standalone.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,23 @@ bool MCStandaloneCapsuleCallback(void *p_self, const uint8_t *p_digest, MCCapsul
210210
delete t_external;
211211
}
212212
break;
213-
213+
214+
// AL-2015-02-10: [[ Standalone Inclusions ]] Fetch a resource mapping and add it to the array stored in MCdispatcher.
215+
case kMCCapsuleSectionTypeLibrary:
216+
{
217+
char *t_mapping;
218+
t_mapping = new char[p_length];
219+
if (IO_read_bytes(t_mapping, p_length, p_stream) != IO_NORMAL)
220+
{
221+
MCresult -> sets("failed to read library mapping");
222+
return false;
223+
}
224+
225+
MCdispatcher -> addlibrarymapping(t_mapping);
226+
delete t_mapping;
227+
}
228+
break;
229+
214230
case kMCCapsuleSectionTypeStartupScript:
215231
{
216232
char *t_script;

0 commit comments

Comments
 (0)