Browse Source

Finish auto-updater on Windows. Add network::urlPath(). Reimplement

runProcessDetached() using ShellExecuteExW() instead of CreateProcess().
tags/v1.1.1
Andrew Belt 5 years ago
parent
commit
a5e1ac75f8
4 changed files with 32 additions and 10 deletions
  1. +2
    -0
      include/network.hpp
  2. +15
    -0
      src/network.cpp
  3. +10
    -9
      src/system.cpp
  4. +5
    -1
      src/updater.cpp

+ 2
- 0
include/network.hpp View File

@@ -28,6 +28,8 @@ bool requestDownload(std::string url, const std::string &filename, float *progre
std::string encodeUrl(const std::string &s);
/** Computes the SHA256 of the file at `filename` */
std::string computeSHA256File(const std::string &filename);
/** Gets the path portion of the URL. */
std::string urlPath(const std::string &url);


} // namespace network


+ 15
- 0
src/network.cpp View File

@@ -188,6 +188,21 @@ std::string computeSHA256File(const std::string &filename) {
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 rack

+ 10
- 9
src/system.cpp View File

@@ -224,17 +224,18 @@ void openFolder(const std::string &path) {

void runProcessDetached(const std::string &path) {
#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);
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
// Not implemented on Linux or Mac
assert(0);


+ 5
- 1
src/updater.cpp View File

@@ -5,6 +5,7 @@
#include <system.hpp>
#include <app.hpp>
#include <window.hpp>
#include <asset.hpp>
#include <thread>


@@ -62,8 +63,11 @@ void update() {

#if defined ARCH_WIN
// 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);
INFO("Launching update %s", path.c_str());
system::runProcessDetached(path);
#else
// Open the browser on Mac and Linux. The user will know what to do.


Loading…
Cancel
Save