Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
Pass wait pid instead of wait parent to update.exe
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Feb 26, 2024
1 parent cab227b commit 7ed4eaa
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 53 deletions.
28 changes: 25 additions & 3 deletions for-cpp/Velopack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,9 @@ int subprocess_alive(struct subprocess_s *const process) {
#define WIN32_LEAN_AND_MEAN
#define PATH_MAX MAX_PATH
#include <Windows.h>
#endif // VELO_MSVC
#elif defined(__unix__) || defined(__APPLE__) && defined(__MACH__)
#include <unistd.h> // For getpid on UNIX-like systems
#endif

static std::string nativeCurrentOsName()
{
Expand Down Expand Up @@ -1356,7 +1358,7 @@ static void nativeStartProcessFireAndForget(const std::vector<std::string> *comm
// }
// accumulatedData.erase(0, pos + 1);
// }
// }
// }
// });

// return outputThread;
Expand All @@ -1382,6 +1384,18 @@ static std::string nativeStartProcessBlocking(const std::vector<std::string> *co
return buffer.str();
}

static int32_t nativeCurrentProcessId()
{
#if defined(_WIN32)
return GetCurrentProcessId();
#elif defined(__unix__) || defined(__APPLE__) && defined(__MACH__)
return getpid();
#else
#error "Unsupported platform"
return -1; // Indicate error or unsupported platform
#endif
}

namespace Velopack
{
#if UNICODE
Expand Down Expand Up @@ -1435,6 +1449,7 @@ namespace Velopack

#include <algorithm>
#include <cstdlib>
#include <format>
#include <regex>
#include <stdexcept>
#include "Velopack.hpp"
Expand Down Expand Up @@ -1918,6 +1933,12 @@ void Platform::startProcessFireAndForget(const std::vector<std::string> * comman
}
nativeStartProcessFireAndForget(command_line); }

int Platform::getCurrentProcessId()
{
int ret = 0;
ret = nativeCurrentProcessId(); return ret;
}

std::string Platform::getCurrentProcessPath()
{
std::string ret{""};
Expand Down Expand Up @@ -2243,7 +2264,8 @@ void UpdateManagerSync::waitExitThenApplyUpdates(std::string assetPath, bool sil
command.push_back("--silent");
}
command.push_back("apply");
command.push_back("--wait");
command.push_back("--waitPid");
command.push_back(std::format("{}", Platform::getCurrentProcessId()));
if (!assetPath.empty()) {
command.push_back("--package");
command.push_back(assetPath);
Expand Down
13 changes: 1 addition & 12 deletions for-cpp/Velopack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,9 @@ class JsonParser
class Platform
{
public:
/**
* Starts a new process and sychronously reads/returns its output.
*/
static std::string startProcessBlocking(const std::vector<std::string> * command_line);
/**
* Starts a new process and returns immediately.
*/
static void startProcessFireAndForget(const std::vector<std::string> * command_line);
/**
* Returns the path of the current process.
*/
static int getCurrentProcessId();
static std::string getCurrentProcessPath();
static bool fileExists(std::string path);
static bool isInstalled();
Expand All @@ -224,9 +216,6 @@ class Platform
static bool isWindows();
static bool isLinux();
static bool isOsx();
/**
* Returns the name of the operating system.
*/
static std::string getOsName();
static void exit(int code);
private:
Expand Down
18 changes: 13 additions & 5 deletions for-cs/Velopack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,6 @@ public JsonNode ParseValue()
static class Platform
{

/// <summary>Starts a new process and sychronously reads/returns its output.</summary>
public static string StartProcessBlocking(List<string> command_line)
{
if (command_line.Count == 0)
Expand All @@ -581,7 +580,6 @@ public static string StartProcessBlocking(List<string> command_line)
ret = NativeMethods.NativeStartProcessBlocking(command_line); return StrTrim(ret);
}

/// <summary>Starts a new process and returns immediately.</summary>
public static void StartProcessFireAndForget(List<string> command_line)
{
if (command_line.Count == 0)
Expand All @@ -591,7 +589,12 @@ public static void StartProcessFireAndForget(List<string> command_line)
NativeMethods.NativeStartProcessFireAndForget(command_line);
}

/// <summary>Returns the path of the current process.</summary>
public static int GetCurrentProcessId()
{
int ret = 0;
ret = NativeMethods.NativeCurrentProcessId(); return ret;
}

public static string GetCurrentProcessPath()
{
string ret = "";
Expand Down Expand Up @@ -731,7 +734,6 @@ public static bool IsOsx()
return GetOsName() == "darwin";
}

/// <summary>Returns the name of the operating system.</summary>
public static string GetOsName()
{
string ret = "";
Expand Down Expand Up @@ -1067,7 +1069,8 @@ public void WaitExitThenApplyUpdates(string assetPath, bool silent, bool restart
command.Add("--silent");
}
command.Add("apply");
command.Add("--wait");
command.Add("--waitPid");
command.Add($"{Platform.GetCurrentProcessId()}");
if (assetPath.Length > 0)
{
command.Add("--package");
Expand Down Expand Up @@ -1186,6 +1189,11 @@ public async Task DownloadUpdatesAsync(UpdateInfo updateInfo, Action<int> progre

static class NativeMethods
{
public static int NativeCurrentProcessId()
{
return Process.GetCurrentProcess().Id;
}

public static void NativeExitProcess(int code)
{
Environment.Exit(code);
Expand Down
23 changes: 10 additions & 13 deletions for-js/Velopack.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ function emitLines(stream) {
function nativeDoesFileExist(path) {
return fs.existsSync(path);
}
function nativeCurrentProcessId() {
return process.pid;
}
function nativeGetCurrentProcessPath() {
return process.execPath;
}
Expand Down Expand Up @@ -578,9 +581,6 @@ _JsonParser_text = new WeakMap(), _JsonParser_position = new WeakMap(), _JsonPar
};
class Platform {
constructor() { }
/**
* Starts a new process and sychronously reads/returns its output.
*/
static startProcessBlocking(command_line) {
if (command_line.length == 0) {
throw new Error("Command line is empty");
Expand All @@ -589,18 +589,17 @@ class Platform {
ret = nativeStartProcessBlocking(command_line);
return _a.strTrim(ret);
}
/**
* Starts a new process and returns immediately.
*/
static startProcessFireAndForget(command_line) {
if (command_line.length == 0) {
throw new Error("Command line is empty");
}
nativeStartProcessFireAndForget(command_line);
}
/**
* Returns the path of the current process.
*/
static getCurrentProcessId() {
let ret = 0;
ret = nativeCurrentProcessId();
return ret;
}
static getCurrentProcessPath() {
let ret = "";
ret = nativeGetCurrentProcessPath();
Expand Down Expand Up @@ -668,9 +667,6 @@ class Platform {
static isOsx() {
return _a.getOsName() == "darwin";
}
/**
* Returns the name of the operating system.
*/
static getOsName() {
let ret = "";
ret = nativeCurrentOsName();
Expand Down Expand Up @@ -1013,7 +1009,8 @@ export class UpdateManagerSync {
command.push("--silent");
}
command.push("apply");
command.push("--wait");
command.push("--waitPid");
command.push(`${Platform.getCurrentProcessId()}`);
if (assetPath.length > 0) {
command.push("--package");
command.push(assetPath);
Expand Down
25 changes: 12 additions & 13 deletions for-js/Velopack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ function nativeDoesFileExist(path: string): boolean {
return fs.existsSync(path);
}

function nativeCurrentProcessId(): number {
return process.pid;
}

function nativeGetCurrentProcessPath(): string {
return process.execPath;
}
Expand Down Expand Up @@ -633,9 +637,6 @@ class JsonParser {
class Platform {
private constructor() {}

/**
* Starts a new process and sychronously reads/returns its output.
*/
public static startProcessBlocking(command_line: readonly string[]): string {
if (command_line.length == 0) {
throw new Error("Command line is empty");
Expand All @@ -645,9 +646,6 @@ class Platform {
return Platform.strTrim(ret);
}

/**
* Starts a new process and returns immediately.
*/
public static startProcessFireAndForget(
command_line: readonly string[],
): void {
Expand All @@ -657,9 +655,12 @@ class Platform {
nativeStartProcessFireAndForget(command_line);
}

/**
* Returns the path of the current process.
*/
public static getCurrentProcessId(): number {
let ret: number = 0;
ret = nativeCurrentProcessId();
return ret;
}

public static getCurrentProcessPath(): string {
let ret: string = "";
ret = nativeGetCurrentProcessPath();
Expand Down Expand Up @@ -771,9 +772,6 @@ class Platform {
return Platform.getOsName() == "darwin";
}

/**
* Returns the name of the operating system.
*/
public static getOsName(): string {
let ret: string = "";
ret = nativeCurrentOsName();
Expand Down Expand Up @@ -1119,7 +1117,8 @@ export class UpdateManagerSync {
command.push("--silent");
}
command.push("apply");
command.push("--wait");
command.push("--waitPid");
command.push(`${Platform.getCurrentProcessId()}`);
if (assetPath.length > 0) {
command.push("--package");
command.push(assetPath);
Expand Down
11 changes: 7 additions & 4 deletions src/Platform.fu
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

static class Platform
{
/// Starts a new process and sychronously reads/returns its output.
public static string() StartProcessBlocking(List<string()> command_line) throws Exception
{
if (command_line.Count == 0) {
Expand All @@ -13,7 +12,6 @@ static class Platform
return StrTrim(ret);
}

/// Starts a new process and returns immediately.
public static void StartProcessFireAndForget(List<string()> command_line) throws Exception
{
if (command_line.Count == 0) {
Expand All @@ -22,7 +20,13 @@ static class Platform
native { VMACRO_NativeStartProcessFireAndForget(command_line); }
}

/// Returns the path of the current process.
public static int GetCurrentProcessId()
{
int ret = 0;
native { ret = VMACRO_NativeCurrentProcessId(); }
return ret;
}

public static string() GetCurrentProcessPath()
{
string() ret = "";
Expand Down Expand Up @@ -131,7 +135,6 @@ static class Platform
public static bool IsLinux() { return GetOsName() == "linux"; }
public static bool IsOsx() { return GetOsName() == "darwin"; }

/// Returns the name of the operating system.
public static string() GetOsName()
{
string() ret = "";
Expand Down
3 changes: 2 additions & 1 deletion src/UpdateManager.fu
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ public class UpdateManagerSync
command.Add("--silent");
}
command.Add("apply");
command.Add("--wait");
command.Add("--waitPid");
command.Add($"{Platform.GetCurrentProcessId()}");

if (assetPath.Length > 0) {
command.Add("--package");
Expand Down
4 changes: 4 additions & 0 deletions src/include/ts_begin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ function nativeDoesFileExist(path: string): boolean {
return fs.existsSync(path);
}

function nativeCurrentProcessId(): number {
return process.pid;
}

function nativeGetCurrentProcessPath(): string {
return process.execPath;
}
Expand Down
18 changes: 16 additions & 2 deletions src/include/velopack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
#define WIN32_LEAN_AND_MEAN
#define PATH_MAX MAX_PATH
#include <Windows.h>
#endif // VELO_MSVC
#elif defined(__unix__) || defined(__APPLE__) && defined(__MACH__)
#include <unistd.h> // For getpid on UNIX-like systems
#endif

static std::string nativeCurrentOsName()
{
Expand Down Expand Up @@ -123,7 +125,7 @@ static void nativeStartProcessFireAndForget(const std::vector<std::string> *comm
// }
// accumulatedData.erase(0, pos + 1);
// }
// }
// }
// });

// return outputThread;
Expand All @@ -149,6 +151,18 @@ static std::string nativeStartProcessBlocking(const std::vector<std::string> *co
return buffer.str();
}

static int32_t nativeCurrentProcessId()
{
#if defined(_WIN32)
return GetCurrentProcessId();
#elif defined(__unix__) || defined(__APPLE__) && defined(__MACH__)
return getpid();
#else
#error "Unsupported platform"
return -1; // Indicate error or unsupported platform
#endif
}

namespace Velopack
{
#if UNICODE
Expand Down
Loading

0 comments on commit 7ed4eaa

Please sign in to comment.