runProcessDetached() using ShellExecuteExW() instead of CreateProcess().tags/v1.1.1
@@ -28,6 +28,8 @@ bool requestDownload(std::string url, const std::string &filename, float *progre | |||||
std::string encodeUrl(const std::string &s); | std::string encodeUrl(const std::string &s); | ||||
/** Computes the SHA256 of the file at `filename` */ | /** Computes the SHA256 of the file at `filename` */ | ||||
std::string computeSHA256File(const std::string &filename); | std::string computeSHA256File(const std::string &filename); | ||||
/** Gets the path portion of the URL. */ | |||||
std::string urlPath(const std::string &url); | |||||
} // namespace network | } // namespace network | ||||
@@ -188,6 +188,21 @@ std::string computeSHA256File(const std::string &filename) { | |||||
return str; | return str; | ||||
} | } | ||||
std::string urlPath(const std::string &url) { | |||||
CURLU *curl = curl_url(); | |||||
DEFER({ | |||||
curl_url_cleanup(curl); | |||||
}); | |||||
if (curl_url_set(curl, CURLUPART_URL, url.c_str(), 0)) | |||||
return ""; | |||||
char *buf; | |||||
if (curl_url_get(curl, CURLUPART_PATH, &buf, 0)) | |||||
return ""; | |||||
std::string ret = buf; | |||||
curl_free(buf); | |||||
return ret; | |||||
} | |||||
} // namespace network | } // namespace network | ||||
} // namespace rack | } // namespace rack |
@@ -224,17 +224,18 @@ void openFolder(const std::string &path) { | |||||
void runProcessDetached(const std::string &path) { | void runProcessDetached(const std::string &path) { | ||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
STARTUPINFOW startupInfo; | |||||
PROCESS_INFORMATION processInfo; | |||||
std::memset(&startupInfo, 0, sizeof(startupInfo)); | |||||
startupInfo.cb = sizeof(startupInfo); | |||||
std::memset(&processInfo, 0, sizeof(processInfo)); | |||||
SHELLEXECUTEINFOW shExInfo; | |||||
ZeroMemory(&shExInfo, sizeof(shExInfo)); | |||||
shExInfo.cbSize = sizeof(shExInfo); | |||||
shExInfo.lpVerb = L"runas"; | |||||
std::wstring pathW = string::toWstring(path); | std::wstring pathW = string::toWstring(path); | ||||
CreateProcessW(pathW.c_str(), NULL, | |||||
NULL, NULL, false, 0, NULL, NULL, | |||||
&startupInfo, &processInfo); | |||||
shExInfo.lpFile = pathW.c_str(); | |||||
shExInfo.nShow = SW_SHOW; | |||||
if (ShellExecuteExW(&shExInfo)) { | |||||
// Do nothing | |||||
} | |||||
#else | #else | ||||
// Not implemented on Linux or Mac | // Not implemented on Linux or Mac | ||||
assert(0); | assert(0); | ||||
@@ -5,6 +5,7 @@ | |||||
#include <system.hpp> | #include <system.hpp> | ||||
#include <app.hpp> | #include <app.hpp> | ||||
#include <window.hpp> | #include <window.hpp> | ||||
#include <asset.hpp> | |||||
#include <thread> | #include <thread> | ||||
@@ -62,8 +63,11 @@ void update() { | |||||
#if defined ARCH_WIN | #if defined ARCH_WIN | ||||
// Download and launch the installer on Windows | // Download and launch the installer on Windows | ||||
std::string path = asset::user("Rack-setup.exe"); | |||||
std::string filename = string::filename(network::urlPath(downloadUrl)); | |||||
std::string path = asset::user(filename); | |||||
INFO("Download update %s to %s", downloadUrl.c_str(), path.c_str()); | |||||
network::requestDownload(downloadUrl, path, &progress); | network::requestDownload(downloadUrl, path, &progress); | ||||
INFO("Launching update %s", path.c_str()); | |||||
system::runProcessDetached(path); | system::runProcessDetached(path); | ||||
#else | #else | ||||
// Open the browser on Mac and Linux. The user will know what to do. | // Open the browser on Mac and Linux. The user will know what to do. | ||||