From b7ac923b10ed92981dce76d2d9219afd7ee00cca Mon Sep 17 00:00:00 2001 From: Juster Zhu Date: Tue, 9 Jan 2024 17:42:22 +0800 Subject: [PATCH 1/3] fix: The error that cannot be accessed normally due to permission issues due to the setting of Environment.SetEnvironmentVariable to Machine The error that cannot be accessed normally due to permission issues due to the setting of Environment.SetEnvironmentVariable to Machine --- src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs | 2 +- .../Exceptions/CustomException/GeneralUpdateException.cs | 3 +-- .../GeneralUpdate.Core/Exceptions/ThrowExceptionUtility.cs | 6 ++++++ src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs b/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs index aa92529c..d5d74d58 100644 --- a/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs +++ b/src/c#/GeneralUpdate.ClientCore/GeneralClientBootstrap.cs @@ -255,7 +255,7 @@ private void ClearEnvironmentVariable() { try { - Environment.SetEnvironmentVariable("ProcessBase64", null, EnvironmentVariableTarget.Machine); + Environment.SetEnvironmentVariable("ProcessBase64", null, EnvironmentVariableTarget.User); } catch (SecurityException ex) { diff --git a/src/c#/GeneralUpdate.Core/Exceptions/CustomException/GeneralUpdateException.cs b/src/c#/GeneralUpdate.Core/Exceptions/CustomException/GeneralUpdateException.cs index 405337dc..258fc84c 100644 --- a/src/c#/GeneralUpdate.Core/Exceptions/CustomException/GeneralUpdateException.cs +++ b/src/c#/GeneralUpdate.Core/Exceptions/CustomException/GeneralUpdateException.cs @@ -15,8 +15,7 @@ public sealed class GeneralUpdateException : Exception, ISeriali private const String c_args = "Args"; private readonly TExceptionArgs m_args; - public TExceptionArgs Args - { get { return m_args; } } + public TExceptionArgs Args=> m_args; public GeneralUpdateException(String message = null, Exception innerException = null) : this(null, message, innerException) { diff --git a/src/c#/GeneralUpdate.Core/Exceptions/ThrowExceptionUtility.cs b/src/c#/GeneralUpdate.Core/Exceptions/ThrowExceptionUtility.cs index 013a2534..95c7cdbb 100644 --- a/src/c#/GeneralUpdate.Core/Exceptions/ThrowExceptionUtility.cs +++ b/src/c#/GeneralUpdate.Core/Exceptions/ThrowExceptionUtility.cs @@ -10,6 +10,12 @@ public static void ThrowGeneralUpdateException(ExceptionArgs args) #region Common + public static void ThrowIfNull(object obj) + { + if (obj == null) + Throw("Parameter cannot be null"); + } + /// /// Checks if an object is empty and throws an exception if it is /// diff --git a/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs b/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs index 10519c9a..4cc57610 100644 --- a/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs +++ b/src/c#/GeneralUpdate.Core/GeneralUpdateBootstrap.cs @@ -2,6 +2,7 @@ using GeneralUpdate.Core.Domain.Entity; using GeneralUpdate.Core.Domain.Entity.Assembler; using GeneralUpdate.Core.Domain.Enum; +using GeneralUpdate.Core.Exceptions; using GeneralUpdate.Core.Strategys; using GeneralUpdate.Core.Utils; using System; @@ -21,7 +22,7 @@ private void Remote() { try { - var base64 = Environment.GetEnvironmentVariable("ProcessBase64", EnvironmentVariableTarget.Machine); + var base64 = Environment.GetEnvironmentVariable("ProcessBase64", EnvironmentVariableTarget.User); var processInfo = SerializeUtil.Deserialize(base64); Packet = ProcessAssembler.ToPacket(processInfo); Packet.AppType = AppType.UpgradeApp; From 748fb5285f31ad53b951dae018ee4d360bb9d9a2 Mon Sep 17 00:00:00 2001 From: Juster Zhu Date: Tue, 9 Jan 2024 17:46:27 +0800 Subject: [PATCH 2/3] Update WindowsStrategy.cs --- .../Strategys/PlatformWindows/WindowsStrategy.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/c#/GeneralUpdate.Core/Strategys/PlatformWindows/WindowsStrategy.cs b/src/c#/GeneralUpdate.Core/Strategys/PlatformWindows/WindowsStrategy.cs index 33b9e642..02863fdd 100644 --- a/src/c#/GeneralUpdate.Core/Strategys/PlatformWindows/WindowsStrategy.cs +++ b/src/c#/GeneralUpdate.Core/Strategys/PlatformWindows/WindowsStrategy.cs @@ -86,7 +86,7 @@ public override bool StartApp(string appName, int appType) switch (appType) { case AppType.ClientApp: - Environment.SetEnvironmentVariable("ProcessBase64", Packet.ProcessBase64, EnvironmentVariableTarget.Machine); + Environment.SetEnvironmentVariable("ProcessBase64", Packet.ProcessBase64, EnvironmentVariableTarget.User); WaitForProcessToStart(path, 20, ()=> WillMessageManager.Instance.Check()); break; From 59081fef6c1f02694eec59cad43098fa505ac9c6 Mon Sep 17 00:00:00 2001 From: Juster Zhu Date: Tue, 9 Jan 2024 19:37:11 +0800 Subject: [PATCH 3/3] Update MySample.cs --- src/c#/GeneralUpdate.Client/MySample.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/c#/GeneralUpdate.Client/MySample.cs b/src/c#/GeneralUpdate.Client/MySample.cs index d45be174..64fc8ab7 100644 --- a/src/c#/GeneralUpdate.Client/MySample.cs +++ b/src/c#/GeneralUpdate.Client/MySample.cs @@ -19,7 +19,7 @@ internal class MySample { #region 推送功能 - private const string baseUrl = @"http://127.0.0.1:5001"; + private const string baseUrl = @"http://localhost:5051"; private const string hubName = "versionhub"; internal MySample() @@ -113,7 +113,7 @@ private Configinfo GetWindowsConfigInfo() //该对象用于主程序客户端与更新组件进程之间交互用的对象 var config = new Configinfo(); //本机的客户端程序应用地址 - config.InstallPath = @"F:\test\Run"; + config.InstallPath = @"D:\packet\source"; //更新公告网页 config.UpdateLogUrl = "https://www.baidu.com/"; //客户端当前版本号 @@ -125,9 +125,9 @@ private Configinfo GetWindowsConfigInfo() //更新组件更新包下载地址 config.UpdateUrl = $"{baseUrl}/versions/{config.AppType}/{config.ClientVersion}/{config.AppSecretKey}"; //更新程序exe名称 - config.AppName = "AutoUpdate.Core"; + config.AppName = "GeneralUpdate.Core"; //主程序客户端exe名称 - config.MainAppName = "AutoUpdate.ClientCore"; + config.MainAppName = "GeneralUpdate.ClientCore"; //主程序信息 var mainVersion = "1.1.1.1"; //主程序客户端更新包下载地址