diff options
author | Adam Ierymenko <adam.ierymenko@zerotier.com> | 2014-02-26 14:37:21 -0800 |
---|---|---|
committer | Adam Ierymenko <adam.ierymenko@zerotier.com> | 2014-02-26 14:37:21 -0800 |
commit | 2203958798ca151cfde348254d8d18a5ca471e31 (patch) | |
tree | 983cb049da0b17598f66f0f61c044114d6b28de0 /windows | |
parent | 268ec8d1e0a01459eb7f04e0652f26bb7b597ba6 (diff) | |
download | infinitytier-2203958798ca151cfde348254d8d18a5ca471e31.tar.gz infinitytier-2203958798ca151cfde348254d8d18a5ca471e31.zip |
Windows auto-updater invocation works... time to try an installer!
Diffstat (limited to 'windows')
-rw-r--r-- | windows/ZeroTierOne/ZeroTierOneService.cpp | 55 | ||||
-rw-r--r-- | windows/ZeroTierOne/ZeroTierOneService.h | 5 |
2 files changed, 37 insertions, 23 deletions
diff --git a/windows/ZeroTierOne/ZeroTierOneService.cpp b/windows/ZeroTierOne/ZeroTierOneService.cpp index f2a83cbd..daff0bb0 100644 --- a/windows/ZeroTierOne/ZeroTierOneService.cpp +++ b/windows/ZeroTierOne/ZeroTierOneService.cpp @@ -67,40 +67,24 @@ restart_node: _node = (ZeroTier::Node *)0; } std::string msiPath; - const char *msiPathTmp = n->reasonForTermination(); - if (msiPathTmp) - msiPath = msiPathTmp; + if (n) { + const char *msiPathTmp = n->reasonForTermination(); + if (msiPathTmp) + msiPath = msiPathTmp; + } delete n; - // Write a batch file to ensure the service is stopped if ((!msiPath.length())||(!ZeroTier::Utils::fileExists(msiPath.c_str()))) { WriteEventLogEntry("auto-update failed: no msi path provided by Node",EVENTLOG_ERROR_TYPE); Sleep(5000); goto restart_node; } - std::string bat(ZeroTier::ZT_DEFAULTS.defaultHomePath + "\\InstallAndRestartService.bat"); - FILE *batf = fopen(bat.c_str(),"wb"); - if (!batf) { + + if (!doStartUpgrade(msiPath)) { WriteEventLogEntry("auto-update failed: unable to create InstallAndRestartService.bat",EVENTLOG_ERROR_TYPE); Sleep(5000); goto restart_node; } - fprintf(batf,"TIMEOUT.EXE /T 1 /NOBREAK\r\n"); - fprintf(batf,"NET.EXE STOP \"ZeroTier One\"\r\n"); - fprintf(batf,"MSIEXEC.EXE /i \"%s\" /qn\r\n",msiPath.c_str()); - fprintf(batf,"NET.EXE START \"ZeroTier One\"\r\n"); - fclose(batf); - - // Execute updater, which will update and restart service - STARTUPINFOA si; - PROCESS_INFORMATION pi; - memset(&si,0,sizeof(si)); - memset(&pi,0,sizeof(pi)); - if (!CreateProcessA(NULL,const_cast <LPSTR>((std::string("CMD.EXE /c \"") + bat + "\"").c_str()),NULL,NULL,FALSE,CREATE_NO_WINDOW|CREATE_NEW_PROCESS_GROUP,NULL,NULL,&si,&pi)) { - WriteEventLogEntry("auto-update failed: unable to execute InstallAndRestartService.bat",EVENTLOG_ERROR_TYPE); - Sleep(5000); - goto restart_node; - } // Terminate service to allow updater to update Stop(); @@ -133,6 +117,31 @@ restart_node: _lock.unlock(); } +bool ZeroTierOneService::doStartUpgrade(const std::string &msiPath) +{ + std::string msiLog(ZeroTier::ZT_DEFAULTS.defaultHomePath + "\\LastUpdateLog.txt"); + ZeroTier::Utils::rm(msiLog); + + std::string bat(ZeroTier::ZT_DEFAULTS.defaultHomePath + "\\InstallAndRestartService.bat"); + FILE *batf = fopen(bat.c_str(),"wb"); + if (!batf) + return false; + fprintf(batf,"TIMEOUT.EXE /T 1 /NOBREAK\r\n"); + fprintf(batf,"NET.EXE STOP \"ZeroTier One\"\r\n"); + fprintf(batf,"MSIEXEC.EXE /i \"%s\" /l* \"%s\" /qn\r\n",msiPath.c_str(),msiLog.c_str()); + fprintf(batf,"NET.EXE START \"ZeroTier One\"\r\n"); + fclose(batf); + + STARTUPINFOA si; + PROCESS_INFORMATION pi; + memset(&si,0,sizeof(si)); + memset(&pi,0,sizeof(pi)); + if (!CreateProcessA(NULL,const_cast <LPSTR>((std::string("CMD.EXE /c \"") + bat + "\"").c_str()),NULL,NULL,FALSE,CREATE_NO_WINDOW|CREATE_NEW_PROCESS_GROUP,NULL,NULL,&si,&pi)) + return false; + + return true; +} + void ZeroTierOneService::OnStart(DWORD dwArgc, LPSTR *lpszArgv) { if (_node) diff --git a/windows/ZeroTierOne/ZeroTierOneService.h b/windows/ZeroTierOne/ZeroTierOneService.h index 5e0180ba..042a398a 100644 --- a/windows/ZeroTierOne/ZeroTierOneService.h +++ b/windows/ZeroTierOne/ZeroTierOneService.h @@ -29,6 +29,8 @@ #include "ServiceBase.h" +#include <string> + #include "../../node/Node.hpp" #include "../../node/Defaults.hpp" #include "../../node/Thread.hpp" @@ -54,6 +56,9 @@ public: void threadMain() throw(); + // Returns false on failure. + static bool doStartUpgrade(const std::string &msiPath); + protected: virtual void OnStart(DWORD dwArgc, PSTR *pszArgv); virtual void OnStop(); |