diff --git a/meshcore/agentcore.c b/meshcore/agentcore.c index bb2b531..925031a 100644 --- a/meshcore/agentcore.c +++ b/meshcore/agentcore.c @@ -2480,18 +2480,17 @@ void MeshServer_selfupdate_continue(MeshAgentHostContainer *agent) printf("%s", duk_safe_to_string(agent->meshCoreCtx, -1)); } } + + // Check updater version + if (agent->JSRunningAsService == 0) + { + char* updateFilePath = MeshAgent_MakeAbsolutePath(agent->exePath, ".update.exe"); // uses ILibScratchPad2 + duk_push_sprintf(agent->meshCoreCtx, "require('agent-installer').updaterVersion('%s');", updateFilePath); // [code] + if (duk_peval(agent->meshCoreCtx) == 0) { agent->updaterVersion = duk_get_int(agent->meshCoreCtx, -1); } // [version] + duk_pop(agent->meshCoreCtx); // ... + } #endif - - //// Check updater version - //if (agent->JSRunningAsService == 0) - //{ - // char* updateFilePath = MeshAgent_MakeAbsolutePath(agent->exePath, ".update.exe"); // uses ILibScratchPad2 - // duk_push_sprintf(agent->meshCoreCtx, "require('agent-installer').updaterVersion('%s');", updateFilePath); // [code] - // if (duk_peval(agent->meshCoreCtx) == 0) { agent->updaterVersion = duk_get_int(agent->meshCoreCtx, -1); } // [version] - // duk_pop(agent->meshCoreCtx); // ... - //} - #ifndef WIN32 if (duk_peval_string(agent->meshCoreCtx, "require('MeshAgent').getStartupOptions();") == 0) // [obj] { @@ -5583,7 +5582,14 @@ int MeshAgent_Start(MeshAgentHostContainer *agentHost, int paramLen, char **para if (agentHost->logUpdate != 0) { ILIBLOGMESSSAGE("SelfUpdate -> Updating..."); } #ifdef WIN32 // Windows Service Updater - sprintf_s(ILibScratchPad, sizeof(ILibScratchPad), "%s -update:*%s %s", updateFilePath, agentHost->JSRunningAsService != 0 ? "S" : "C", startParms == NULL ? "" : (char*)ILibMemory_Extra(startParms)); + if (agentHost->updaterVersion == 0) + { + sprintf_s(ILibScratchPad, sizeof(ILibScratchPad), "%s -update:\"%s\"", updateFilePath, agentHost->exePath); + } + else + { + sprintf_s(ILibScratchPad, sizeof(ILibScratchPad), "%s -update:*%s %s", updateFilePath, agentHost->JSRunningAsService != 0 ? "S" : "C", startParms == NULL ? "" : (char*)ILibMemory_Extra(startParms)); + } if (!CreateProcessW(NULL, ILibUTF8ToWide(ILibScratchPad, -1), NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &info, &processInfo)) { // We triedI to execute a bad executable... not good. Lets try to recover. diff --git a/meshservice/ServiceMain.c b/meshservice/ServiceMain.c index f6e55cd..c1f89ef 100644 --- a/meshservice/ServiceMain.c +++ b/meshservice/ServiceMain.c @@ -554,7 +554,13 @@ int wmain(int argc, char* wargv[]) CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); - + if (argc > 1 && strcasecmp(argv[1], "-updaterversion") == 0) + { + DWORD dummy; + WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), "1\n", 2, &dummy, NULL); + wmain_free(argv); + return(0); + } #if defined(_LINKVM) if (argc > 1 && strcasecmp(argv[1], "-kvm0") == 0) {