1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-14 23:33:38 +00:00

!. Fixed more exePath related UTF8 issues

2. Added os.tmpdir() support
3. Added Buffer.toString('utf16')
This commit is contained in:
Bryan Roe
2020-04-30 01:40:03 -07:00
parent bf43bc0c62
commit 07371fed6a
3 changed files with 33 additions and 3 deletions

View File

@@ -4568,7 +4568,9 @@ void MeshAgent_ScriptMode(MeshAgentHostContainer *agentHost, int argc, char **ar
{
// Get the full path name of the JavaScript file
#ifdef WIN32
pathLen = GetFullPathName(argv[1], sizeof(ILibScratchPad2), ILibScratchPad2, NULL);
WCHAR wjsPath[4096];
GetFullPathNameW(ILibUTF8ToWide(argv[1], -1), sizeof(wjsPath) / 2, wjsPath, NULL);
pathLen = WideCharToMultiByte(CP_UTF8, 0, wjsPath, -1, (LPSTR)ILibScratchPad2, sizeof(ILibScratchPad2), NULL, NULL);
#else
if (realpath(argv[1], ILibScratchPad2) != NULL) { pathLen = strnlen_s(ILibScratchPad2, PATH_MAX); }
#endif

View File

@@ -157,6 +157,15 @@ duk_ret_t ILibDuktape_Polyfills_Buffer_toString(duk_context *ctx)
util_tohex2(buffer, (int)bufferLen, tmpBuffer);
duk_push_string(ctx, tmpBuffer);
}
#ifdef WIN32
else if (strcmp(cType, "utf16") == 0)
{
int sz = (MultiByteToWideChar(CP_UTF8, 0, buffer, bufferLen, NULL, 0) * 2);
WCHAR* b = duk_push_fixed_buffer(ctx, sz);
duk_push_buffer_object(ctx, -1, 0, sz, DUK_BUFOBJ_NODEJS_BUFFER);
MultiByteToWideChar(CP_UTF8, 0, buffer, bufferLen, b, sz / 2);
}
#endif
else
{
return(ILibDuktape_Error(ctx, "Unrecognized parameter"));

View File

@@ -465,13 +465,15 @@ void ILibDuktape_ScriptContainer_CheckEmbedded(char **script, int *scriptLen)
// Check if .JS file is integrated with executable
#ifndef __APPLE__
char exePath[_MAX_PATH];
char exePath[_MAX_PATH*2];
#else
char exePath[PATH_MAX+1];
#endif
#ifdef WIN32
GetModuleFileName(NULL, exePath, sizeof(exePath));
WCHAR tmpExePath[_MAX_PATH];
GetModuleFileNameW(NULL, tmpExePath, sizeof(tmpExePath)/2);
WideCharToMultiByte(CP_UTF8, 0, tmpExePath, -1, exePath, sizeof(exePath), NULL, NULL);
#elif defined(__APPLE__)
uint32_t len = sizeof(exePath);
if (_NSGetExecutablePath(exePath, &len) != 0) ILIBCRITICALEXIT(247);
@@ -1815,6 +1817,22 @@ duk_ret_t ILibDuktape_ScriptContainer_OS_hostname(duk_context *ctx)
}
return(1);
}
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);
#elif defined (_POSIX)
#if defined(__APPLE__)
duk_eval_string(ctx, "process.env['TMPDIR']");
if (duk_is_undefined(ctx, -1)) { duk_push_string(ctx, "/private/tmp/"); }
#else
duk_push_string(ctx, "/var/tmp/");
#endif
#endif
return(1);
}
void ILibDuktape_ScriptContainer_OS_Push(duk_context *ctx, void *chain)
{
duk_push_object(ctx); // [os]
@@ -1834,6 +1852,7 @@ void ILibDuktape_ScriptContainer_OS_Push(duk_context *ctx, void *chain)
ILibDuktape_CreateInstanceMethod(ctx, "networkInterfaces", ILibDuktape_ScriptContainer_OS_networkInterfaces, 0);
#endif
ILibDuktape_CreateInstanceMethod(ctx, "hostname", ILibDuktape_ScriptContainer_OS_hostname, 0);
ILibDuktape_CreateInstanceMethod(ctx, "tmpdir", ILibDuktape_tmpdir, 0);
char jsExtras[] = "exports.getPrimaryDnsSuffix = function getPrimaryDnsSuffix()\
{\