mirror of
https://github.com/BeyondDimension/SteamTools.git
synced 2026-10-29 16:08:15 +08:00
MacOS EDIT Cer Fix
This commit is contained in:
@@ -7,6 +7,7 @@ using System.Application.Models;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace System.Application.Services.Implementation
|
||||
@@ -21,17 +22,42 @@ namespace System.Application.Services.Implementation
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
bool IPlatformService.AdminShell(string shell)
|
||||
async Task<bool> IPlatformService.AdminShell(string shell)
|
||||
{
|
||||
|
||||
var file = new FileInfo(Path.Combine(IOPath.AppDataDirectory, $@"sudoShell.sh"));
|
||||
int index = 0;
|
||||
if (file.Exists)
|
||||
file.Delete();
|
||||
var vm = new UI.ViewModels.PasswordWindowViewModel();
|
||||
await IShowWindowService.Instance.ShowDialog(CustomWindow.Password, vm, string.Empty, ResizeModeCompat.CanResize);
|
||||
var scriptContent = new Text.StringBuilder();
|
||||
scriptContent.AppendLine($"echo \"{vm.Password}\" | sudo -S {shell}");
|
||||
using (var stream = file.CreateText())
|
||||
{
|
||||
stream.Write(scriptContent);
|
||||
stream.Flush();
|
||||
stream.Dispose();
|
||||
}
|
||||
var pInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = "open",
|
||||
Arguments = $"{Path.Combine(IOPath.AppDataDirectory, $@"hello")} -t=1 -p=\"{shell}\"",
|
||||
FileName = $"/bin/bash",
|
||||
Arguments = file.FullName
|
||||
};
|
||||
pInfo.UseShellExecute = true;
|
||||
//pInfo.UseShellExecute = true;
|
||||
var p = Process.Start(pInfo);
|
||||
if (p == null) throw new FileNotFoundException("Shell");
|
||||
p.Close();
|
||||
p.Exited += (object? _, EventArgs _) =>
|
||||
{
|
||||
if (file.Exists)
|
||||
file.Delete();
|
||||
if (p.ExitCode != 0)
|
||||
IPlatformService.Instance.AdminShell(shell);
|
||||
};
|
||||
if (file.Exists)
|
||||
file.Delete();
|
||||
return true;
|
||||
#if MONO_MAC
|
||||
//return false;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace System.Application.Services
|
||||
{
|
||||
public interface IPlatformService
|
||||
@@ -6,6 +8,6 @@ namespace System.Application.Services
|
||||
|
||||
public static IPlatformService Instance => DI.Get<IPlatformService>();
|
||||
|
||||
bool AdminShell(string str) => throw new PlatformNotSupportedException();
|
||||
Task< bool> AdminShell(string str) => throw new PlatformNotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -345,7 +345,8 @@ namespace System.Application.Services.Implementation
|
||||
proxyServer.CertificateManager.EnsureRootCertificate();
|
||||
if (DI.IsmacOS)
|
||||
{
|
||||
IPlatformService.Instance.AdminShell(filePath);
|
||||
//安装证书
|
||||
IPlatformService.Instance.AdminShell($"security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain {filePath}");
|
||||
}
|
||||
return IsCertificateInstalled(proxyServer.CertificateManager.RootCertificate);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user