From a5896264fae29e952517da519502ab6103c9bbfe Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Sat, 18 Jan 2014 10:17:15 -0800 Subject: [PATCH] Builds on Windows now. --- node/SoftwareUpdater.cpp | 27 ++++++++++++++--------- windows/SelfTest/SelfTest.vcxproj | 12 ++++++---- windows/SelfTest/SelfTest.vcxproj.filters | 12 ++++++++++ 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/node/SoftwareUpdater.cpp b/node/SoftwareUpdater.cpp index 85190cca6..db884d803 100644 --- a/node/SoftwareUpdater.cpp +++ b/node/SoftwareUpdater.cpp @@ -182,7 +182,6 @@ void SoftwareUpdater::_cbHandleGetLatestVersionBinary(void *arg,int code,const s return; } -#ifdef __UNIX_LIKE__ size_t lastSlash = url.rfind('/'); if (lastSlash == std::string::npos) { // sanity check, shouldn't happen LOG("software update aborted: invalid URL"); @@ -191,30 +190,36 @@ void SoftwareUpdater::_cbHandleGetLatestVersionBinary(void *arg,int code,const s } std::string updatesDir(_r->homePath + ZT_PATH_SEPARATOR_S + "updates.d"); std::string updatePath(updatesDir + ZT_PATH_SEPARATOR_S + url.substr(lastSlash + 1)); +#ifdef __WINDOWS__ + CreateDirectoryA(updatesDir.c_str(),NULL); +#else mkdir(updatesDir.c_str(),0755); +#endif - int fd = ::open(updatePath.c_str(),O_WRONLY|O_CREAT|O_TRUNC,0755); - if (fd <= 0) { + FILE *upf = fopen(updatePath.c_str(),"wb"); + if (!upf) { LOG("software update aborted: unable to open %s for writing",updatePath.c_str()); upd->_status = UPDATE_STATUS_IDLE; return; } - if ((long)::write(fd,body.data(),body.length()) != (long)body.length()) { + if (fwrite(body.data(),body.length(),1,upf) != 1) { LOG("software update aborted: unable to write to %s",updatePath.c_str()); upd->_status = UPDATE_STATUS_IDLE; + fclose(upf); + Utils::rm(updatePath); return; } - ::close(fd); + fclose(upf); + +#ifdef __UNIX_LIKE__ ::chmod(updatePath.c_str(),0755); +#endif + // We exit with this reason code and the path as the text. It is the + // caller's responsibility (main.c) to pick this up and do the right + // thing. upd->_status = UPDATE_STATUS_IDLE; - _r->node->terminate(Node::NODE_RESTART_FOR_UPGRADE,updatePath.c_str()); -#endif - -#ifdef __WINDOWS__ - todo; -#endif } } // namespace ZeroTier diff --git a/windows/SelfTest/SelfTest.vcxproj b/windows/SelfTest/SelfTest.vcxproj index fa7885b08..a223d9602 100644 --- a/windows/SelfTest/SelfTest.vcxproj +++ b/windows/SelfTest/SelfTest.vcxproj @@ -19,6 +19,8 @@ + + @@ -64,6 +66,8 @@ + + @@ -168,7 +172,7 @@ Console true - $(SolutionDir)\ext\bin\libcrypto\win32-vs2012\libeay32.lib;wsock32.lib;ws2_32.lib;%(AdditionalDependencies) + wsock32.lib;ws2_32.lib;winhttp.lib;Iphlpapi.lib;Rpcrt4.lib;%(AdditionalDependencies) @@ -183,7 +187,7 @@ Console true - $(SolutionDir)\ext\bin\libcrypto\win32-vs2012\libeay32.lib;wsock32.lib;ws2_32.lib;%(AdditionalDependencies) + wsock32.lib;ws2_32.lib;winhttp.lib;Iphlpapi.lib;Rpcrt4.lib;%(AdditionalDependencies) @@ -202,7 +206,7 @@ true true true - wsock32.lib;ws2_32.lib;iphlpapi.lib;$(SolutionDir)\ext\bin\libcrypto\win32-vs2012\libeay32.lib;%(AdditionalDependencies) + wsock32.lib;ws2_32.lib;winhttp.lib;Iphlpapi.lib;Rpcrt4.lib;%(AdditionalDependencies) false @@ -222,7 +226,7 @@ true true true - wsock32.lib;ws2_32.lib;iphlpapi.lib;$(SolutionDir)\ext\bin\libcrypto\win64-vs2012\libeay32.lib;%(AdditionalDependencies) + wsock32.lib;ws2_32.lib;winhttp.lib;Iphlpapi.lib;Rpcrt4.lib;%(AdditionalDependencies) false diff --git a/windows/SelfTest/SelfTest.vcxproj.filters b/windows/SelfTest/SelfTest.vcxproj.filters index 572568eda..38981ab05 100644 --- a/windows/SelfTest/SelfTest.vcxproj.filters +++ b/windows/SelfTest/SelfTest.vcxproj.filters @@ -140,6 +140,12 @@ Header Files + + Header Files + + + Header Files + @@ -226,5 +232,11 @@ Source Files + + Source Files + + + Source Files + \ No newline at end of file