mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-06 00:13:33 +00:00
1. Added support for UTF8 wnvironment variables for window's child_process
2. Updated message-box and toaster to support UTF8 on Windows
This commit is contained in:
@@ -489,7 +489,7 @@ duk_ret_t ILibDuktape_ChildProcess_execFile(duk_context *ctx)
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
p = ILibProcessPipe_Manager_SpawnProcessEx3(manager, target, args, spawnType, (void*)(ILibPtrCAST)(uint64_t)(uid < 0 ? 0 : uid), 0);
|
||||
p = ILibProcessPipe_Manager_SpawnProcessEx4(manager, target, args, spawnType, (void*)(ILibPtrCAST)(uint64_t)(uid < 0 ? 0 : uid), envargs, 0);
|
||||
#else
|
||||
p = ILibProcessPipe_Manager_SpawnProcessEx4(manager, target, args, spawnType, (void*)(ILibPtrCAST)(uint64_t)uid, envargs, 0);
|
||||
#endif
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -173,10 +173,15 @@ static inline void ignore_result(uintptr_t result) { (void)result; }
|
||||
#ifdef WIN32
|
||||
char *ILibWideToUTF8Ex(WCHAR* wstr, int wstrCharacterLen, char *buffer, int bufferLen);
|
||||
#define ILibWideToUTF8(wstr, wstrCharacterLen) ILibWideToUTF8Ex(wstr, wstrCharacterLen, NULL, 0)
|
||||
char *ILibWideToUTF8_stupidEx(WCHAR* wstr, int wstrBYTESIZE, char *buffer, int bufferLen);
|
||||
#define ILibWideToUTF8_stupid(wstr, wstrBYTESIZE) ILibWideToUTF8_stupidEx(wstr, wstrBYTESIZE, NULL, 0)
|
||||
WCHAR* ILibUTF8ToWideEx(char* str, int len, WCHAR* buffer, int bufferCharacterSize);
|
||||
#define ILibUTF8ToWide(utf8string, len) ILibUTF8ToWideEx(utf8string, len, NULL, 0)
|
||||
#define ILibUTF8ToWideCount(utf8string) MultiByteToWideChar(CP_UTF8, 0, (LPCCH)utf8string, -1, NULL, 0)
|
||||
#define ILibUTF8ToWideCountEx(utf8string, outBuffer, outBufferLen) MultiByteToWideChar(CP_UTF8, 0, (LPCCH)utf8string, -1, outBuffer, outBufferLen)
|
||||
|
||||
// The following two methods are for the special case, when only the bytes count is known, not the character count.
|
||||
char *ILibWideToUTF8_stupidEx(WCHAR* wstr, int wstrBYTESIZE, char *buffer, int bufferLen);
|
||||
#define ILibWideToUTF8_stupid(wstr, wstrBYTESIZE) ILibWideToUTF8_stupidEx(wstr, wstrBYTESIZE, NULL, 0)
|
||||
|
||||
#else
|
||||
#define ILibWideToUTF8(wstr, len) (wstr)
|
||||
#define ILibWideToUTF8Ex(wstr, len, buffer, sz) (wstr)
|
||||
|
||||
@@ -578,9 +578,36 @@ ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_
|
||||
info.dwFlags |= STARTF_USESTDHANDLES;
|
||||
}
|
||||
|
||||
if (((spawnType == ILibProcessPipe_SpawnTypes_DEFAULT || spawnType == ILibProcessPipe_SpawnTypes_DETACHED) && !CreateProcessW(ILibUTF8ToWideEx(target, -1, tmp1, (int)sizeof(tmp1)/2), ILibUTF8ToWideEx(parms, -1, tmp2, (int)sizeof(tmp2)/2), NULL, NULL, spawnType == ILibProcessPipe_SpawnTypes_DETACHED ? FALSE: TRUE, CREATE_NO_WINDOW | (needSetSid !=0? (DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP) : 0x00), envvars, NULL, &info, &processInfo)) ||
|
||||
(spawnType != ILibProcessPipe_SpawnTypes_DEFAULT && !CreateProcessAsUserW(userToken, ILibUTF8ToWideEx(target, -1, tmp1, (int)sizeof(tmp1)/2), ILibUTF8ToWideEx(parms, -1, tmp2, (int)sizeof(tmp2)/2), NULL, NULL, TRUE, CREATE_NO_WINDOW | (needSetSid != 0 ? (DETACHED_PROCESS| CREATE_NEW_PROCESS_GROUP) : 0x00), envvars, NULL, &info, &processInfo)))
|
||||
if (envvars != NULL)
|
||||
{
|
||||
WCHAR *wideEnv;
|
||||
int tmpCnt;
|
||||
int envCount = 0;
|
||||
void *envCurrent = envvars;
|
||||
while (envCurrent != NULL && ((char**)envCurrent)[0] != NULL)
|
||||
{
|
||||
envCount += (ILibUTF8ToWideCount(((char**)envCurrent)[0]) + ILibUTF8ToWideCount(((char**)envCurrent)[1]) + ILibUTF8ToWideCount("="));
|
||||
envCurrent = (void*)((char*)envCurrent + 2 * sizeof(char*));
|
||||
}
|
||||
wideEnv = (WCHAR*)ILibMemory_SmartAllocate(2* envCount);
|
||||
tmpCnt = 0;
|
||||
|
||||
envCurrent = envvars;
|
||||
while (envCurrent != NULL && ((char**)envCurrent)[0] != NULL)
|
||||
{
|
||||
tmpCnt += (ILibUTF8ToWideCountEx(((char**)envCurrent)[0], wideEnv + tmpCnt, (int)ILibMemory_Size(wideEnv) / 2) - 1);
|
||||
tmpCnt += (ILibUTF8ToWideCountEx("=", wideEnv + tmpCnt, ((int)ILibMemory_Size(wideEnv) / 2) - tmpCnt) - 1);
|
||||
tmpCnt += ILibUTF8ToWideCountEx(((char**)envCurrent)[1], wideEnv + tmpCnt, ((int)ILibMemory_Size(wideEnv) / 2) - tmpCnt);
|
||||
envCurrent = (void*)((char*)envCurrent + 2 * sizeof(char*));
|
||||
}
|
||||
envvars = wideEnv;
|
||||
}
|
||||
|
||||
|
||||
if (((spawnType == ILibProcessPipe_SpawnTypes_DEFAULT || spawnType == ILibProcessPipe_SpawnTypes_DETACHED) && !CreateProcessW(ILibUTF8ToWideEx(target, -1, tmp1, (int)sizeof(tmp1)/2), ILibUTF8ToWideEx(parms, -1, tmp2, (int)sizeof(tmp2)/2), NULL, NULL, spawnType == ILibProcessPipe_SpawnTypes_DETACHED ? FALSE: TRUE, CREATE_UNICODE_ENVIRONMENT | CREATE_NO_WINDOW | (needSetSid !=0? (DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP) : 0x00), envvars, NULL, &info, &processInfo)) ||
|
||||
(spawnType != ILibProcessPipe_SpawnTypes_DEFAULT && !CreateProcessAsUserW(userToken, ILibUTF8ToWideEx(target, -1, tmp1, (int)sizeof(tmp1)/2), ILibUTF8ToWideEx(parms, -1, tmp2, (int)sizeof(tmp2)/2), NULL, NULL, TRUE, CREATE_UNICODE_ENVIRONMENT | CREATE_NO_WINDOW | (needSetSid != 0 ? (DETACHED_PROCESS| CREATE_NEW_PROCESS_GROUP) : 0x00), envvars, NULL, &info, &processInfo)))
|
||||
{
|
||||
int ll = GetLastError();
|
||||
if (spawnType != ILibProcessPipe_SpawnTypes_DETACHED)
|
||||
{
|
||||
ILibProcessPipe_FreePipe(retVal->stdErr);
|
||||
@@ -591,10 +618,11 @@ ILibProcessPipe_Process ILibProcessPipe_Manager_SpawnProcessEx4(ILibProcessPipe_
|
||||
ILibMemory_Free(retVal);
|
||||
if (token != NULL) { CloseHandle(token); }
|
||||
if (userToken != NULL) { CloseHandle(userToken); }
|
||||
if (envvars != NULL) { ILibMemory_Free(envvars); }
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
|
||||
if (envvars != NULL) { ILibMemory_Free(envvars); }
|
||||
if (allocParms != 0) { free(parms); }
|
||||
if (spawnType != ILibProcessPipe_SpawnTypes_DETACHED)
|
||||
{
|
||||
|
||||
@@ -52,7 +52,7 @@ function Toaster()
|
||||
case 'win32':
|
||||
{
|
||||
var cid;
|
||||
retVal.options = { };
|
||||
retVal.options = { env: { _title: title, _caption: caption } };
|
||||
try
|
||||
{
|
||||
retVal.options.uid = tsid == null ? require('user-sessions').consoleUid() : tsid;
|
||||
|
||||
Reference in New Issue
Block a user