From af3a1846963a160223ebac8fbf0041a62c8487d8 Mon Sep 17 00:00:00 2001 From: Bryan Roe Date: Tue, 1 Dec 2020 14:48:59 -0800 Subject: [PATCH] Added system language query to Windows Service Installer --- meshservice/ServiceMain.c | 9 +++++- microstack/ILibParsers.c | 65 ++++++++++++++++++++++++--------------- microstack/ILibParsers.h | 1 + 3 files changed, 49 insertions(+), 26 deletions(-) diff --git a/meshservice/ServiceMain.c b/meshservice/ServiceMain.c index dcc218d..051560b 100644 --- a/meshservice/ServiceMain.c +++ b/meshservice/ServiceMain.c @@ -1041,6 +1041,11 @@ INT_PTR CALLBACK DialogHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP case WM_INITDIALOG: { char selfexe[_MAX_PATH]; + char *lang = NULL; + void *chain = ILibCreateChain(); + ILibChain_PartialStart(chain); + duk_context *ctx = ILibDuktape_ScriptContainer_InitializeJavaScriptEngineEx(0, 0, chain, NULL, NULL, "", NULL, NULL, chain); + if (duk_peval_string(ctx, "require('util-language').current;") == 0) { lang = (char*)duk_safe_to_string(ctx, -1); } // Get current executable path WCHAR wselfexe[MAX_PATH]; @@ -1168,7 +1173,9 @@ INT_PTR CALLBACK DialogHandler(HWND hDlg, UINT message, WPARAM wParam, LPARAM lP } SetWindowTextA(GetDlgItem(hDlg, IDC_STATUSTEXT), txt); if (mshfile != NULL) { free(mshfile); } - + Duktape_SafeDestroyHeap(ctx); + ILibStopChain(chain); + ILibStartChain(chain); return (INT_PTR)TRUE; } case WM_COMMAND: diff --git a/microstack/ILibParsers.c b/microstack/ILibParsers.c index 69d679a..3cb1a2d 100644 --- a/microstack/ILibParsers.c +++ b/microstack/ILibParsers.c @@ -990,6 +990,7 @@ typedef struct ILibBaseChain #else int WatchDogTerminator[2]; #endif + int preInitialized; int selectTimeout; void *node; int lastDescriptorCount; @@ -3623,34 +3624,16 @@ void ILibChain_RemoveWaitHandle(void *chain, HANDLE h) } #endif -/*! \fn ILibStartChain(void *Chain) -\brief Starts a Chain -\par -This method will use the current thread. This thread will be refered to as the -microstack thread. All events and processing will be done on this thread. This method -will not return until ILibStopChain is called. -\param Chain The chain to start -*/ -ILibExportMethod void ILibStartChain(void *Chain) +void ILibChain_PartialStart(void *Chain) { + if (Chain == NULL) { return; } ILibBaseChain *chain = (ILibBaseChain*)Chain; ILibChain_Link *module; ILibChain_Link_Hook *nodeHook; - fd_set readset; - fd_set errorset; - fd_set writeset; - #ifdef WIN32 - HANDLE selectHandles[FD_SETSIZE]; - memset(selectHandles, 0, sizeof(selectHandles)); memset(chain->WaitHandles, 0, sizeof(chain->WaitHandles)); #endif - struct timeval tv; - int slct; - int vX; - - if (Chain == NULL) { return; } chain->PreSelectCount = chain->PostSelectCount = 0; #if defined(WIN32) @@ -3662,7 +3645,7 @@ ILibExportMethod void ILibStartChain(void *Chain) chain->ChainThreadID = pthread_self(); #endif - if (gILibChain == NULL) {gILibChain = Chain;} // Set the global instance if it's not already set + if (gILibChain == NULL) { gILibChain = Chain; } // Set the global instance if it's not already set #if defined(ILibChain_WATCHDOG_TIMEOUT) #ifdef WIN32 chain->WatchDogTerminator = CreateEvent(NULL, TRUE, FALSE, NULL); @@ -3685,10 +3668,6 @@ ILibExportMethod void ILibStartChain(void *Chain) // // Use this thread as if it's our own. Keep looping until we are signaled to stop // - FD_ZERO(&readset); - FD_ZERO(&errorset); - FD_ZERO(&writeset); - #if defined(_POSIX) // // For posix, we need to use a pipe to force unblock the select loop @@ -3702,6 +3681,42 @@ ILibExportMethod void ILibStartChain(void *Chain) #endif chain->RunningFlag = 1; + chain->preInitialized = 1; +} + + +/*! \fn ILibStartChain(void *Chain) +\brief Starts a Chain +\par +This method will use the current thread. This thread will be refered to as the +microstack thread. All events and processing will be done on this thread. This method +will not return until ILibStopChain is called. +\param Chain The chain to start +*/ +ILibExportMethod void ILibStartChain(void *Chain) +{ + ILibBaseChain *chain = (ILibBaseChain*)Chain; + if (Chain == NULL) { return; } + if (chain->preInitialized == 0) { ILibChain_PartialStart(Chain); } + + ILibChain_Link *module; + ILibChain_Link_Hook *nodeHook; + + fd_set readset; + fd_set errorset; + fd_set writeset; + + struct timeval tv; + int slct; + int vX; + + // + // Use this thread as if it's our own. Keep looping until we are signaled to stop + // + FD_ZERO(&readset); + FD_ZERO(&errorset); + FD_ZERO(&writeset); + while (chain->TerminateFlag == 0) { slct = 0; diff --git a/microstack/ILibParsers.h b/microstack/ILibParsers.h index b31dab2..f24d69a 100644 --- a/microstack/ILibParsers.h +++ b/microstack/ILibParsers.h @@ -1091,6 +1091,7 @@ int ILibIsRunningOnChainThread(void* chain); void ILibChain_InitDescriptorCount(void *chain); int ILibChain_GetDescriptorCount(void *chain); + void ILibChain_PartialStart(void *chain); ILibExportMethod void ILibStartChain(void *chain); ILibExportMethod void ILibStopChain(void *chain); #ifdef WIN32