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

Updated self update for Windows

This commit is contained in:
Bryan Roe
2020-11-10 02:50:57 -08:00
parent ef307c7843
commit c14f8111c3
2 changed files with 24 additions and 12 deletions

View File

@@ -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
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.

View File

@@ -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)
{