1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-06 00:13:33 +00:00

1. Fixed bug with os.tmpdir()

2. Updated ScriptMode, so current durrectory is not changed to script path
3. Fixed process.cwd() on windows to support UTF8
This commit is contained in:
Bryan Roe
2020-04-30 11:51:41 -07:00
parent 8268fdf33a
commit cf91d6c709
3 changed files with 72 additions and 21 deletions

View File

@@ -4584,18 +4584,6 @@ void MeshAgent_ScriptMode(MeshAgentHostContainer *agentHost, int argc, char **ar
strncpy_s(jsPath, ILibMemory_GetExtraMemorySize(jsPath), ILibScratchPad2, ILibMemory_GetExtraMemorySize(jsPath));
scriptArgs[0] = jsPath;
#ifdef WIN32
i = ILibString_LastIndexOf(ILibScratchPad2, pathLen, "\\", 1);
#else
i = ILibString_LastIndexOf(ILibScratchPad2, pathLen, "/", 1);
#endif
ILibScratchPad2[i] = 0;
#ifdef WIN32
SetCurrentDirectory(ILibScratchPad2);
#else
ignore_result(chdir(ILibScratchPad2));
#endif
// Parse arguments. Handle the ones we can, others will be passed to the JavaScript engine.
for (i = 2; i < argc; ++i)
{

View File

@@ -863,16 +863,23 @@ duk_ret_t ILibDuktape_ScriptContainer_Process_Kill(duk_context *ctx)
duk_ret_t ILibDuktape_Process_cwd(duk_context *ctx)
{
#ifdef WIN32
GetCurrentDirectoryA((DWORD)sizeof(ILibScratchPad), ILibScratchPad);
duk_push_string(ctx, ILibScratchPad);
return(1);
#elif defined(_POSIX)
GetCurrentDirectoryW((DWORD)sizeof(ILibScratchPad)/2, (LPWSTR)ILibScratchPad);
ILibDuktape_String_PushWideString(ctx, ILibScratchPad, 0);
#else
ignore_result((uintptr_t)getcwd(ILibScratchPad, sizeof(ILibScratchPad)));
duk_push_string(ctx, ILibScratchPad);
return(1);
#else
return(ILibDuktape_Error(ctx, "Error"));
#endif
duk_get_prop_string(ctx, -1, "concat"); // [string][concat]
duk_swap_top(ctx, -2); // [concat][this]
#ifdef WIN32
duk_push_string(ctx, "\\");
#else
duk_push_string(ctx, "/");
#endif
duk_call_method(ctx, 1);
return(1);
}
#ifdef _POSIX
@@ -1822,7 +1829,7 @@ duk_ret_t ILibDuktape_tmpdir(duk_context *ctx)
#ifdef WIN32
WCHAR tmp[1024];
if (GetTempPathW(sizeof(tmp) / 2, (LPWSTR)tmp) == 0) { return(ILibDuktape_Error(ctx, "Error getting temp folder")); }
ILibDuktape_String_PushWideString(ctx, (char*)tmp, -1);
ILibDuktape_String_PushWideString(ctx, (char*)tmp, 0);
#elif defined (_POSIX)
#if defined(__APPLE__)
duk_eval_string(ctx, "process.env['TMPDIR']");

View File

@@ -149,4 +149,60 @@ function addMsh(options)
}
}
module.exports = addMsh;
try
{
module.exports = addMsh;
}
catch(e)
{
// We were run from the command line
var outputFile = null;
var inputFile = null;
var msh = null;
for (var i = 1; i < process.argv.length; i += 2)
{
switch (process.argv[i])
{
case '-o':
outputFile = process.argv[i + 1];
break;
case '-i':
inputFile = process.argv[i + 1];
break;
default:
console.log('unrecognized parameter: ' + process.argv[i]);
break;
}
}
if (process.argv.length != 5 || outputFile == null || inputFile == null)
{
console.log('usage: ' + process.execPath.split(process.platform == 'win32' ? '\\' : '/').pop() + ' MSH_Installer.js -o outputFile -i mshFile');
process.exit();
}
try
{
msh = require('fs').readFileSync(inputFile);
}
catch(e)
{
console.log('Unable to read ' + inputFile, e);
process.exit();
}
var options =
{
destinationStream: require('fs').createWriteStream(outputFile, { flags: 'wb' }),
sourceFileName: process.execPath,
msh: msh
};
console.log('Creating MSH integrated binary...');
options.destinationStream.on('close', function () { console.log('DONE'); process.exit(); });
addMsh(options);
}