From 8aefabec2eaa74669773326469bafa705bb7ba9e Mon Sep 17 00:00:00 2001 From: mossimo Date: Tue, 15 Jun 2021 11:39:15 +0800 Subject: [PATCH] try fix macos Accountchange --- .../MacDesktopPlatformServiceImpl.cs | 32 ++++++++++++++++++- .../Services/IDesktopPlatformService.cs | 4 +++ .../Implementation/SteamServiceImpl.cs | 16 +++++----- .../Implementation/HttpProxyServiceImpl.cs | 5 +-- 4 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/ST.Client.Desktop.Mac/Services/Implementation/MacDesktopPlatformServiceImpl.cs b/src/ST.Client.Desktop.Mac/Services/Implementation/MacDesktopPlatformServiceImpl.cs index 273ffbb56..8e05ce78a 100644 --- a/src/ST.Client.Desktop.Mac/Services/Implementation/MacDesktopPlatformServiceImpl.cs +++ b/src/ST.Client.Desktop.Mac/Services/Implementation/MacDesktopPlatformServiceImpl.cs @@ -34,6 +34,32 @@ namespace System.Application.Services.Implementation p.Close(); } + + void IDesktopPlatformService.OpenProcess(string name) + { + var pInfo = new ProcessStartInfo + { + FileName = "open", + Arguments = $"{name}", + }; + pInfo.UseShellExecute = true; + var p = Process.Start(pInfo); + if (p == null) throw new FileNotFoundException(name); + p.Close(); + } + + void IDesktopPlatformService.OpenProcess(string name, string arguments) + { + var pInfo = new ProcessStartInfo + { + FileName = "open", + Arguments = $"{name} \"{arguments}\"", + }; + pInfo.UseShellExecute = true; + var p = Process.Start(pInfo); + if (p == null) throw new FileNotFoundException(name); + p.Close(); + } public void SetSystemSessionEnding(Action action) { @@ -72,7 +98,11 @@ namespace System.Application.Services.Implementation public string? GetSteamProgramPath() { - return null; + var value = string.Format( + "{0}{1}{0}Application{0}Steam.app", + Path.DirectorySeparatorChar, + Environment.UserName); + return value; } public string GetLastSteamLoginUserName() => string.Empty; diff --git a/src/ST.Client.Desktop/Services/IDesktopPlatformService.cs b/src/ST.Client.Desktop/Services/IDesktopPlatformService.cs index bc1d14390..3c7573694 100644 --- a/src/ST.Client.Desktop/Services/IDesktopPlatformService.cs +++ b/src/ST.Client.Desktop/Services/IDesktopPlatformService.cs @@ -43,6 +43,10 @@ namespace System.Application.Services /// void StartProcess(string name, string filePath) => Process.Start(name, $"\"{filePath}\""); + void OpenProcess(string name, string arguments) => Process.Start(name, arguments); + + void OpenProcess(string name) => Process.Start(name); + /// /// 使用文本阅读器打开文件 /// diff --git a/src/ST.Client.Desktop/Services/Implementation/SteamServiceImpl.cs b/src/ST.Client.Desktop/Services/Implementation/SteamServiceImpl.cs index b317b0600..5fece07f9 100644 --- a/src/ST.Client.Desktop/Services/Implementation/SteamServiceImpl.cs +++ b/src/ST.Client.Desktop/Services/Implementation/SteamServiceImpl.cs @@ -42,7 +42,7 @@ namespace System.Application.Services.Implementation readonly IDesktopPlatformService platformService; readonly string? mSteamDirPath; readonly string? mSteamProgramPath; - readonly string[] steamProcess = new[] { "steam", "steamservice", "steamwebhelper" }; + readonly string[] steamProcess = new[] { "steam","steam_osx", "steamservice", "steamwebhelper" }; readonly Lazy _http = new(() => DI.Get()); IHttpService Http => _http.Value; @@ -78,13 +78,13 @@ namespace System.Application.Services.Implementation { foreach (var p in steamProcess) { - var process = Process.GetProcessesByName(p).FirstOrDefault(); - if (process != null) + var process = Process.GetProcessesByName(p); + foreach (var item in process) { - if (process.HasExited == false) + if (item.HasExited == false) { - process.Kill(); - process.WaitForExit(); + item.Kill(); + item.WaitForExit(); } } } @@ -128,9 +128,9 @@ namespace System.Application.Services.Implementation if (!string.IsNullOrEmpty(SteamProgramPath)) { if (!string.IsNullOrEmpty(arguments)) - Process.Start(SteamProgramPath, arguments); + DI.Get().OpenProcess(SteamProgramPath, arguments); else - Process.Start(SteamProgramPath); + DI.Get().OpenProcess(SteamProgramPath); } } diff --git a/src/ST.Client/Services/Implementation/HttpProxyServiceImpl.cs b/src/ST.Client/Services/Implementation/HttpProxyServiceImpl.cs index 63df88ab2..518444f06 100644 --- a/src/ST.Client/Services/Implementation/HttpProxyServiceImpl.cs +++ b/src/ST.Client/Services/Implementation/HttpProxyServiceImpl.cs @@ -314,12 +314,13 @@ namespace System.Application.Services.Implementation Toast.Show(SR.CreateCertificateFaild); return false; } - proxyServer.CertificateManager.RootCertificate.SaveCerCertificateFile(Path.Combine(IOPath.AppDataDirectory, $@"{CertificateName}.Certificate.cer")); + var filePath = Path.Combine(IOPath.AppDataDirectory, $@"{CertificateName}.Certificate.cer"); + proxyServer.CertificateManager.RootCertificate.SaveCerCertificateFile(filePath); proxyServer.CertificateManager.TrustRootCertificate(); proxyServer.CertificateManager.EnsureRootCertificate(); - + return IsCertificateInstalled(proxyServer.CertificateManager.RootCertificate); }