mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Compare commits
2 Commits
097c1df2cc
...
65275b52a7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
65275b52a7 | ||
|
|
f90ad8bb42 |
@@ -2,8 +2,8 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Velopack.Logging;
|
||||
@@ -29,7 +29,8 @@ namespace Velopack.Locators
|
||||
{
|
||||
_currentProcess ??= Process.GetCurrentProcess();
|
||||
var fileName = _currentProcess.MainModule?.FileName ??
|
||||
throw new InvalidOperationException($"Could not determine process path, please construct {nameof(IVelopackLocator)} manually.");
|
||||
throw new InvalidOperationException(
|
||||
$"Could not determine process path, please construct {nameof(IVelopackLocator)} manually.");
|
||||
return Path.GetFullPath(fileName);
|
||||
}
|
||||
|
||||
@@ -41,8 +42,7 @@ namespace Velopack.Locators
|
||||
|
||||
public void StartProcess(string exePath, IEnumerable<string> args, string? workDir, bool showWindow)
|
||||
{
|
||||
var psi = new ProcessStartInfo()
|
||||
{
|
||||
var psi = new ProcessStartInfo() {
|
||||
CreateNoWindow = true,
|
||||
FileName = exePath,
|
||||
WorkingDirectory = workDir,
|
||||
@@ -55,27 +55,26 @@ namespace Velopack.Locators
|
||||
|
||||
_logger.Info($"Process started with ID: {p.Id}");
|
||||
|
||||
if (VelopackRuntimeInfo.IsWindows)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (VelopackRuntimeInfo.IsWindows) {
|
||||
try {
|
||||
// this is an attempt to work around a bug where the restarted app fails to come to foreground.
|
||||
if (!AllowSetForegroundWindow(p.Id))
|
||||
_logger.LogWarning("Failed to allow Update.exe to set foreground window.");
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning("Failed to allow Update.exe to set foreground window. (This is not generally concerning.)");
|
||||
} catch (Exception ex) {
|
||||
_logger.LogWarning(ex, "Error occurred while trying to allow Update.exe to set foreground window.");
|
||||
}
|
||||
}
|
||||
|
||||
if (p.HasExited)
|
||||
{
|
||||
|
||||
if (p.HasExited) {
|
||||
_logger.Error($"Process {p.Id} has already exited.");
|
||||
}
|
||||
}
|
||||
|
||||
public void Exit(int exitCode) => Environment.Exit(exitCode);
|
||||
public void Exit(int exitCode)
|
||||
{
|
||||
if (!VelopackRuntimeInfo.InUnitTestRunner) {
|
||||
Environment.Exit(exitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,32 @@
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Velopack.Locators
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides an abstraction for process-related operations, allowing for platform-specific implementations.
|
||||
/// </summary>
|
||||
public interface IProcessImpl
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the full path to the current process executable.
|
||||
/// </summary>
|
||||
/// <returns>The full path to the current process executable.</returns>
|
||||
string GetCurrentProcessPath();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the process ID of the current process.
|
||||
/// </summary>
|
||||
/// <returns>The process ID of the current process.</returns>
|
||||
uint GetCurrentProcessId();
|
||||
|
||||
/// <summary>
|
||||
/// Starts a new process with the specified executable path, arguments, and options.
|
||||
/// </summary>
|
||||
/// <param name="exePath">The path to the executable to start.</param>
|
||||
/// <param name="args">The command-line arguments to pass to the process.</param>
|
||||
/// <param name="workDir">The working directory for the new process.</param>
|
||||
/// <param name="showWindow">Whether to show a window for the new process.</param>
|
||||
void StartProcess(string exePath, IEnumerable<string> args, string workDir, bool showWindow);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -202,11 +202,11 @@ namespace Velopack
|
||||
var version = SemanticVersion.Parse(args[1]);
|
||||
hook(version);
|
||||
log.Info("Completed hook, exiting...");
|
||||
Exit(0);
|
||||
locator.Process.Exit(0);
|
||||
return;
|
||||
} catch (Exception ex) {
|
||||
log.Error(ex, $"Error occurred executing user defined Velopack hook. ({args[0]})");
|
||||
Exit(-1);
|
||||
locator.Process.Exit(-1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -232,7 +232,7 @@ namespace Velopack
|
||||
if (!restarted && _autoApply) {
|
||||
log.Info("Auto apply is true, so restarting to apply update...");
|
||||
UpdateExe.Apply(locator, latestLocal, false, locator.Process.GetCurrentProcessId(), true, args);
|
||||
Exit(0);
|
||||
locator.Process.Exit(0);
|
||||
} else {
|
||||
log.Info("Pre-condition failed, we will not restart to apply updates. (restarted: " + restarted + ", autoApply: " + _autoApply + ")");
|
||||
}
|
||||
@@ -273,10 +273,5 @@ namespace Velopack
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void Exit(int code)
|
||||
{
|
||||
VelopackLocator.GetCurrentOrCreateDefault().Process.Exit(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Runtime.Versioning;
|
||||
using System.Text.RegularExpressions;
|
||||
using AsmResolver.PE;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Velopack.Core;
|
||||
using Velopack.Core.Abstractions;
|
||||
@@ -83,6 +84,10 @@ public class WindowsPackCommandRunner : PackageBuilder<WindowsPackOptions>
|
||||
var stubPath = Path.Combine(packDir, Path.GetFileNameWithoutExtension(mainExeName) + "_ExecutionStub.exe");
|
||||
CreateExecutableStubForExe(mainPath, stubPath);
|
||||
|
||||
Options.TargetRuntime.Architecture = Options.TargetRuntime.HasArchitecture
|
||||
? Options.TargetRuntime.Architecture
|
||||
: GetMachineForBinary(MainExePath);
|
||||
|
||||
return Task.FromResult(packDir);
|
||||
}
|
||||
|
||||
@@ -339,7 +344,6 @@ public class WindowsPackCommandRunner : PackageBuilder<WindowsPackOptions>
|
||||
private void CompileWixTemplateToMsi(Action<int> progress, DirectoryInfo portableDirectory, string msiFilePath)
|
||||
{
|
||||
var templateData = MsiBuilder.ConvertOptionsToTemplateData(
|
||||
MainExePath,
|
||||
portableDirectory,
|
||||
GetShortcuts(),
|
||||
GetRuntimeDependencies(),
|
||||
@@ -347,6 +351,19 @@ public class WindowsPackCommandRunner : PackageBuilder<WindowsPackOptions>
|
||||
MsiBuilder.CompileWixMsi(Log, templateData, progress, msiFilePath);
|
||||
}
|
||||
|
||||
protected virtual RuntimeCpu GetMachineForBinary(string path)
|
||||
{
|
||||
var image = PEImage.FromFile(path);
|
||||
|
||||
if (image.MachineType.HasFlag(AsmResolver.PE.File.Headers.MachineType.Amd64))
|
||||
return RuntimeCpu.x64;
|
||||
|
||||
if (image.MachineType.HasFlag(AsmResolver.PE.File.Headers.MachineType.Arm64))
|
||||
return RuntimeCpu.arm64;
|
||||
|
||||
return RuntimeCpu.x86;
|
||||
}
|
||||
|
||||
protected override string[] GetMainExeSearchPaths(string packDirectory, string mainExeName)
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -4,7 +4,6 @@ using System.Runtime.Versioning;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml;
|
||||
using AsmResolver.PE;
|
||||
using HandlebarsDotNet;
|
||||
using Markdig;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -106,7 +105,7 @@ public static class MsiBuilder
|
||||
return rv;
|
||||
}
|
||||
|
||||
public static MsiTemplateData ConvertOptionsToTemplateData(string mainExePath, DirectoryInfo portableDir, ShortcutLocation shortcuts,
|
||||
public static MsiTemplateData ConvertOptionsToTemplateData(DirectoryInfo portableDir, ShortcutLocation shortcuts,
|
||||
string runtimeDeps, WindowsPackOptions options)
|
||||
{
|
||||
// WiX Identifiers may contain ASCII characters A-Z, a-z, digits, underscores (_), or
|
||||
@@ -120,13 +119,7 @@ public static class MsiBuilder
|
||||
if (string.IsNullOrWhiteSpace(msiVersion)) {
|
||||
msiVersion = $"{parsedVersion.Major}.{parsedVersion.Minor}.{parsedVersion.Patch}.0";
|
||||
}
|
||||
|
||||
RuntimeCpu runtimeCpu = options.TargetRuntime.Architecture;
|
||||
if (runtimeCpu == RuntimeCpu.Unknown) {
|
||||
runtimeCpu = GetMachineForBinary(mainExePath);
|
||||
options.TargetRuntime.Architecture = runtimeCpu;
|
||||
}
|
||||
|
||||
|
||||
return new MsiTemplateData() {
|
||||
WixId = wixId,
|
||||
AppId = options.PackId,
|
||||
@@ -135,8 +128,8 @@ public static class MsiBuilder
|
||||
AppMsiVersion = msiVersion,
|
||||
AppVersion = parsedVersion.ToFullString(),
|
||||
SourceDirectoryPath = portableDir.FullName,
|
||||
Is64Bit = runtimeCpu is RuntimeCpu.x64,
|
||||
IsArm64 = runtimeCpu is RuntimeCpu.arm64,
|
||||
Is64Bit = options.TargetRuntime.Architecture is not RuntimeCpu.x86 and not RuntimeCpu.Unknown,
|
||||
IsArm64 = options.TargetRuntime.Architecture is RuntimeCpu.arm64,
|
||||
InstallForAllUsers = options.InstLocation.HasFlag(InstallLocation.PerMachine),
|
||||
InstallForCurrentUser = options.InstLocation.HasFlag(InstallLocation.PerUser),
|
||||
UpgradeCodeGuid = GuidUtil.CreateGuidFromHash($"{options.PackId}:UpgradeCode").ToString(),
|
||||
@@ -155,17 +148,6 @@ public static class MsiBuilder
|
||||
WelcomeMessage = GetPlainTextMessage(options.InstWelcome),
|
||||
LicenseRtfFilePath = GetLicenseRtfPath(options.InstLicense, portableDir.Parent),
|
||||
};
|
||||
|
||||
static RuntimeCpu GetMachineForBinary(string path)
|
||||
{
|
||||
var image = PEImage.FromFile(path);
|
||||
|
||||
if (image.MachineType.HasFlag(AsmResolver.PE.File.Headers.MachineType.Amd64))
|
||||
return RuntimeCpu.x64;
|
||||
if (image.MachineType.HasFlag(AsmResolver.PE.File.Headers.MachineType.Arm64))
|
||||
return RuntimeCpu.arm64;
|
||||
return RuntimeCpu.x86;
|
||||
}
|
||||
}
|
||||
|
||||
[SupportedOSPlatform("windows")]
|
||||
|
||||
Reference in New Issue
Block a user