提交 54a9d6a7 编写于 作者: A Aigio Liu

🚑 requireAdministrator

上级 c949aab6
Subproject commit bb189f273cf34a4b30a71c38214704c31fad82fb Subproject commit 2f425293bd3b793e9a97c90fa9374385a9f280a6
Subproject commit 74cbe2535ce8ffada2781e0b1c7032c6f3d56637 Subproject commit 9453c1c9111f190b6f9d240d15ed29280bc2e9d7
<?xml version="1.0" encoding="utf-8"?><assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"><assemblyIdentity version="1.0.0.0" name="BeyondDimension.WattToolkit.AppHost"/><trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"><security><requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"><requestedExecutionLevel level="asInvoker" uiAccess="false" /></requestedPrivileges></security></trustInfo><compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"><application><supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" /><supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" /><supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" /><supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" /><supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" /></application></compatibility></assembly> <?xml version="1.0" encoding="utf-8"?><assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"><assemblyIdentity version="1.0.0.0" name="BeyondDimension.WattToolkit.AppHost"/><trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"><security><requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"><requestedExecutionLevel level="requireAdministrator" uiAccess="false" /></requestedPrivileges></security></trustInfo><compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"><application><supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" /><supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" /><supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" /><supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" /><supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" /></application></compatibility></assembly>
\ No newline at end of file \ No newline at end of file
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<DefineConstants>AVALONIA;$(DefineConstants)</DefineConstants> <DefineConstants>AVALONIA;$(DefineConstants)</DefineConstants>
<ApplicationId>net.steampp.app</ApplicationId> <ApplicationId>net.steampp.app</ApplicationId>
<ServerGarbageCollection>false</ServerGarbageCollection> <ServerGarbageCollection>false</ServerGarbageCollection>
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.StartsWith('net3')) OR $(TargetFramework.StartsWith('net4')) OR $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'"> <PropertyGroup Condition="$(TargetFramework.StartsWith('net3')) OR $(TargetFramework.StartsWith('net4')) OR $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
......
<?xml version="1.0" encoding="utf-8"?><assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"><assemblyIdentity version="1.0.0.0" name="BeyondDimension.WattToolkit.App"/><trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"><security><requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"><requestedExecutionLevel level="requireAdministrator" uiAccess="false" /></requestedPrivileges></security></trustInfo><compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"><application><supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" /><supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" /><supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" /><supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" /><supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" /></application></compatibility></assembly>
\ No newline at end of file
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<SelfContained>false</SelfContained> <SelfContained>false</SelfContained>
<DefineConstants>APP_REVERSE_PROXY;$(DefineConstants)</DefineConstants> <DefineConstants>APP_REVERSE_PROXY;$(DefineConstants)</DefineConstants>
<ApplicationIcon>..\..\res\icons\app\v2\Icon.ico</ApplicationIcon> <ApplicationIcon>..\..\res\icons\app\v2\Icon.ico</ApplicationIcon>
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'"> <PropertyGroup Condition="'$(Configuration)'=='Release'">
......
<?xml version="1.0" encoding="utf-8"?><assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"><assemblyIdentity version="1.0.0.0" name="BeyondDimension.WattToolkit.Accelerator"/><trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"><security><requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3"><requestedExecutionLevel level="requireAdministrator" uiAccess="false" /></requestedPrivileges></security></trustInfo><compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"><application><supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" /><supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" /><supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" /><supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" /><supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" /></application></compatibility></assembly>
\ No newline at end of file
...@@ -197,7 +197,9 @@ sealed partial class CertificateManagerImpl : ICertificateManager ...@@ -197,7 +197,9 @@ sealed partial class CertificateManagerImpl : ICertificateManager
if (!result || RootCertificate == null) if (!result || RootCertificate == null)
{ {
Log.Error(TAG, "Failed to create certificate"); Log.Error(TAG, "Failed to create certificate");
toast.Show(IPCToastService.ToastText.CreateCertificateFaild); toast.Show(
IPCToastService.ToastIcon.Error,
IPCToastService.ToastText.CreateCertificateFaild);
return false; return false;
} }
......
...@@ -35,7 +35,10 @@ sealed class DomainResolver : IDomainResolver ...@@ -35,7 +35,10 @@ sealed class DomainResolver : IDomainResolver
} }
catch (Exception ex) catch (Exception ex)
{ {
toast.ShowAppend(IPCToastService.ToastText.CommunityFix_DNSErrorNotify, Environment.NewLine + "ExceptionMessage: " + ex.Message); toast.ShowAppend(
IPCToastService.ToastIcon.Error,
IPCToastService.ToastText.CommunityFix_DNSErrorNotify,
Environment.NewLine + "ExceptionMessage: " + ex.Message);
//INotificationService.Instance.Notify(AppResources.CommunityFix_DNSErrorNotify + Environment.NewLine + "Exception Message :" + ex.Message, NotificationType.Message); //INotificationService.Instance.Notify(AppResources.CommunityFix_DNSErrorNotify + Environment.NewLine + "Exception Message :" + ex.Message, NotificationType.Message);
throw; throw;
} }
......
namespace BD.WTTS;
public static class HashStringHelper
{
public static string GetSha256HashString(string text) => string.IsNullOrEmpty(text)
? string.Empty
: SHA512.Create().ComputeHash(Encoding.UTF8.GetBytes(text))
.Aggregate("", (current, x) => current + $"{x:x2}");
public static string GetSha256HashString(byte[] b) => b.Length == 0
? string.Empty
: SHA512.Create().ComputeHash(b).Aggregate("", (current, x) => current + $"{x:x2}");
public static string GetFileMd5(string filePath)
{
using var md5 = MD5.Create();
using var stream = File.OpenRead(filePath);
return stream.Length != 0 ? BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLowerInvariant() : "0";
}
}
...@@ -27,9 +27,10 @@ public static class RegexHelper ...@@ -27,9 +27,10 @@ public static class RegexHelper
accFile = PathHelper.ExpandEnvironmentVariables(accFile); accFile = PathHelper.ExpandEnvironmentVariables(accFile);
regex = ExpandRegex(regex); regex = ExpandRegex(regex);
// The "file" is a registry key // The "file" is a registry key
if (OperatingSystem.IsWindows() && accFile.StartsWith("REG:")) #if WINDOWS
if (accFile.StartsWith("REG:"))
{ {
var res = RegistryKeyHelper.ReadRegistryKey(accFile[4..]); var res = Registry2.ReadRegistryKey(accFile[4..]);
if (res == null) if (res == null)
return null; return null;
switch (res) switch (res)
...@@ -37,12 +38,13 @@ public static class RegexHelper ...@@ -37,12 +38,13 @@ public static class RegexHelper
case string s: case string s:
return s; return s;
case byte[] bytes: case byte[] bytes:
return HashStringHelper.GetSha256HashString(bytes); return Hashs.String.SHA256(bytes);
default: default:
Log.Warn(nameof(RegexHelper), $"REG was read, and was returned something that is not a string or byte array! {accFile}."); Log.Warn(nameof(RegexHelper), $"REG was read, and was returned something that is not a string or byte array! {accFile}.");
return res?.ToString(); return res?.ToString();
} }
} }
#endif
// Handle wildcards // Handle wildcards
if (accFile.Contains('*')) if (accFile.Contains('*'))
......
namespace BD.WTTS;
public static class RegistryKeyHelper
{
public static string ByteArrayToString(byte[] ba) => BitConverter.ToString(ba).Replace("-", "");
public static byte[] StringToByteArray(string hex)
{
var numberChars = hex.Length;
var bytes = new byte[numberChars / 2];
for (var i = 0; i < numberChars; i += 2)
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
return bytes;
}
[SupportedOSPlatform("windows")]
public static RegistryKey? ExpandRegistryAbbreviation(string abv)
{
return abv switch
{
"HKCR" => Registry.ClassesRoot,
"HKCU" => Registry.CurrentUser,
"HKLM" => Registry.LocalMachine,
"HKCC" => Registry.CurrentConfig,
"HKPD" => Registry.PerformanceData,
_ => null
};
}
/// <summary>
/// Break an encoded registry key into it's separate parts
/// </summary>
/// <param name="encodedPath">HKXX\\path:SubKey</param>
[SupportedOSPlatform("windows")]
private static (RegistryKey, string, string) ExplodeRegistryKey(string encodedPath)
{
var rootKey = ExpandRegistryAbbreviation(encodedPath[..4]); // Get HKXX
encodedPath = encodedPath[5..]; // Remove HKXX\\
var path = encodedPath.Split(":")[0];
var subKey = encodedPath.Split(":")[1];
return (rootKey, path, subKey);
}
/// <summary>
/// Read the value of a Registry key (Requires special path)
/// </summary>
/// <param name="encodedPath">HKXX\\path:SubKey</param>
[SupportedOSPlatform("windows")]
public static object? ReadRegistryKey(string encodedPath)
{
var (rootKey, path, subKey) = ExplodeRegistryKey(encodedPath);
try
{
return rootKey.OpenSubKey(path)?.GetValue(subKey);
}
catch (Exception e)
{
Log.Error(nameof(RegistryKeyHelper), e, "ReadRegistryKey failed");
return null;
}
}
/// <summary>
/// Read the value of a Registry key (Requires special path)
/// </summary>
/// <param name="encodedPath">HKXX\\path:SubKey</param>
[SupportedOSPlatform("windows")]
public static bool TryReadRegistryKey(string encodedPath, out object? value)
{
value = ReadRegistryKey(encodedPath);
return value != null;
}
/// <summary>
/// Sets the value of a Registry key (Requires special path)
/// </summary>
/// <param name="encodedPath">HKXX\\path:subkey</param>
/// <param name="value">Value, or empty to "clear"</param>
[SupportedOSPlatform("windows")]
public static bool SetRegistryKey(string encodedPath, string value = "")
{
var (rootKey, path, subKey) = ExplodeRegistryKey(encodedPath);
try
{
using var key = rootKey.CreateSubKey(path);
if (value.StartsWith("(hex)"))
{
value = value[6..];
key?.SetValue(subKey, StringToByteArray(value));
}
else
key?.SetValue(subKey, value);
}
catch (Exception e)
{
Log.Error(nameof(RegistryKeyHelper), e, "SetRegistryKey failed");
return false;
}
return true;
}
[SupportedOSPlatform("windows")]
public static bool DeleteRegistryKey(string encodedPath)
{
var (rootKey, path, subKey) = ExplodeRegistryKey(encodedPath);
try
{
using var key = rootKey.OpenSubKey(path, true);
key?.DeleteValue(subKey);
}
catch (Exception e)
{
Log.Error(nameof(RegistryKeyHelper), e, "DeleteRegistryKey failed");
return false;
}
return true;
}
}
...@@ -35,23 +35,26 @@ public sealed class BasicPlatformSwitcher : IPlatformSwitcher ...@@ -35,23 +35,26 @@ public sealed class BasicPlatformSwitcher : IPlatformSwitcher
} }
// Get unique ID from IDs file if unique ID is a registry key. Set if exists. // Get unique ID from IDs file if unique ID is a registry key. Set if exists.
if (OperatingSystem.IsWindows() && platform.UniqueIdType is UniqueIdType.REGKEY && !string.IsNullOrEmpty(platform.UniqueIdPath)) #if WINDOWS
if (platform.UniqueIdType is UniqueIdType.REGKEY && !string.IsNullOrEmpty(platform.UniqueIdPath))
{ {
var uniqueId = JTokenHelper.ReadDict(platform.FullName).FirstOrDefault(x => x.Value == accName).Key; var uniqueId = JTokenHelper.ReadDict(platform.FullName).FirstOrDefault(x => x.Value == accName).Key;
if (!string.IsNullOrEmpty(uniqueId) && !RegistryKeyHelper.SetRegistryKey(platform.UniqueIdPath, uniqueId)) // Remove "REG:" and read data if (!string.IsNullOrEmpty(uniqueId) && !Registry2.SetRegistryKey(platform.UniqueIdPath, uniqueId)) // Remove "REG:" and read data
{ {
Toast.Show(ToastIcon.Info, AppResources.Info_AccountAlreadyLogin); Toast.Show(ToastIcon.Info, AppResources.Info_AccountAlreadyLogin);
return false; return false;
} }
} }
#endif
var regJson = platform.UniqueIdPath.StartsWith("REG:") ? JTokenHelper.ReadRegJson(platform.RegJsonPath(accName)) : new Dictionary<string, string>(); var regJson = platform.UniqueIdPath.StartsWith("REG:") ? JTokenHelper.ReadRegJson(platform.RegJsonPath(accName)) : new Dictionary<string, string>();
foreach (var (accFile, savedFile) in platform.LoginFiles) foreach (var (accFile, savedFile) in platform.LoginFiles)
{ {
// The "file" is a registry key // The "file" is a registry key
if (OperatingSystem.IsWindows() && accFile.StartsWith("REG:")) #if WINDOWS
if (accFile.StartsWith("REG:"))
{ {
if (!regJson.ContainsKey(accFile)) if (!regJson.ContainsKey(accFile))
{ {
...@@ -61,13 +64,14 @@ public sealed class BasicPlatformSwitcher : IPlatformSwitcher ...@@ -61,13 +64,14 @@ public sealed class BasicPlatformSwitcher : IPlatformSwitcher
var regValue = regJson[accFile] ?? ""; var regValue = regJson[accFile] ?? "";
if (!RegistryKeyHelper.SetRegistryKey(accFile[4..], regValue)) // Remove "REG:" and read data if (!Registry2.SetRegistryKey(accFile[4..], regValue)) // Remove "REG:" and read data
{ {
Toast.Show(ToastIcon.Error, AppResources.Error_WriteRegistryFailed); Toast.Show(ToastIcon.Error, AppResources.Error_WriteRegistryFailed);
return false; return false;
} }
continue; continue;
} }
#endif
// The "file" is a JSON value // The "file" is a JSON value
if (accFile.StartsWith("JSON")) if (accFile.StartsWith("JSON"))
...@@ -178,20 +182,22 @@ public sealed class BasicPlatformSwitcher : IPlatformSwitcher ...@@ -178,20 +182,22 @@ public sealed class BasicPlatformSwitcher : IPlatformSwitcher
private bool DeleteFileOrFolder(string accFile, PlatformAccount platform) private bool DeleteFileOrFolder(string accFile, PlatformAccount platform)
{ {
// The "file" is a registry key // The "file" is a registry key
if (OperatingSystem.IsWindows() && accFile.StartsWith("REG:")) #if WINDOWS
if (accFile.StartsWith("REG:"))
{ {
// If set to clear LoginCache for account before adding (Enabled by default): // If set to clear LoginCache for account before adding (Enabled by default):
if (platform.IsRegDeleteOnClear) if (platform.IsRegDeleteOnClear)
{ {
if (RegistryKeyHelper.DeleteRegistryKey(accFile[4..])) return true; if (Registry2.DeleteRegistryKey(accFile[4..])) return true;
} }
else else
{ {
if (RegistryKeyHelper.SetRegistryKey(accFile[4..])) return true; if (Registry2.SetRegistryKey(accFile[4..])) return true;
} }
Toast.Show(ToastIcon.Error, AppResources.Error_WriteRegistryFailed); Toast.Show(ToastIcon.Error, AppResources.Error_WriteRegistryFailed);
return false; return false;
} }
#endif
// The "file" is a JSON value // The "file" is a JSON value
if (accFile.StartsWith("JSON")) if (accFile.StartsWith("JSON"))
...@@ -369,18 +375,20 @@ public sealed class BasicPlatformSwitcher : IPlatformSwitcher ...@@ -369,18 +375,20 @@ public sealed class BasicPlatformSwitcher : IPlatformSwitcher
foreach (var (accFile, savedFile) in platform.LoginFiles) foreach (var (accFile, savedFile) in platform.LoginFiles)
{ {
if (accFile.StartsWith("REG:") && OperatingSystem.IsWindows()) #if WINDOWS
if (accFile.StartsWith("REG:"))
{ {
// Remove "REG: " and read data // Remove "REG: " and read data
if (RegistryKeyHelper.TryReadRegistryKey(accFile[4..], out var response)) if (Registry2.TryReadRegistryKey(accFile[4..], out var response))
{ {
// Write registry value to provided file // Write registry value to provided file
if (response is string s) regJson[accFile] = s; if (response is string s) regJson[accFile] = s;
else if (response is byte[] ba) regJson[accFile] = "(hex) " + RegistryKeyHelper.ByteArrayToString(ba); else if (response is byte[] ba) regJson[accFile] = $"(hex) {ba.ToHexString()}";
else Log.Error(nameof(BasicPlatformSwitcher), $"Unexpected registry type encountered (2)! {response.GetType()}"); else Log.Error(nameof(BasicPlatformSwitcher), $"Unexpected registry type encountered (2)! {response?.GetType()}");
} }
continue; continue;
} }
#endif
if (accFile.StartsWith("JSON")) if (accFile.StartsWith("JSON"))
{ {
...@@ -443,11 +451,11 @@ public sealed class BasicPlatformSwitcher : IPlatformSwitcher ...@@ -443,11 +451,11 @@ public sealed class BasicPlatformSwitcher : IPlatformSwitcher
public string? GetUniqueId(PlatformAccount platform) public string? GetUniqueId(PlatformAccount platform)
{ {
if (OperatingSystem.IsWindows() && #if WINDOWS
platform.UniqueIdType is UniqueIdType.REGKEY && if (platform.UniqueIdType is UniqueIdType.REGKEY &&
!string.IsNullOrEmpty(platform.UniqueIdPath)) !string.IsNullOrEmpty(platform.UniqueIdPath))
{ {
var r = RegistryKeyHelper.ReadRegistryKey(platform.UniqueIdPath[4..]); var r = Registry2.ReadRegistryKey(platform.UniqueIdPath[4..]);
if (r == null) if (r == null)
return null; return null;
...@@ -456,12 +464,13 @@ public sealed class BasicPlatformSwitcher : IPlatformSwitcher ...@@ -456,12 +464,13 @@ public sealed class BasicPlatformSwitcher : IPlatformSwitcher
case string s: case string s:
return s; return s;
case byte[] b: case byte[] b:
return HashStringHelper.GetSha256HashString(b); return Hashs.String.SHA256(b);
default: default:
Log.Warn(nameof(BasicPlatformSwitcher), $"{platform.FullName} Unexpected registry type encountered (1)! {r.GetType()}"); Log.Warn(nameof(BasicPlatformSwitcher), $"{platform.FullName} Unexpected registry type encountered (1)! {r.GetType()}");
return null; return null;
} }
} }
#endif
if (string.IsNullOrEmpty(platform.UniqueIdPath)) if (string.IsNullOrEmpty(platform.UniqueIdPath))
return null; return null;
...@@ -519,13 +528,16 @@ public sealed class BasicPlatformSwitcher : IPlatformSwitcher ...@@ -519,13 +528,16 @@ public sealed class BasicPlatformSwitcher : IPlatformSwitcher
} }
else if (platform.UniqueIdType is UniqueIdType.FILE_MD5) // TODO: TEST THIS! -- This is used for static files that do not change throughout the lifetime of an account login. else if (platform.UniqueIdType is UniqueIdType.FILE_MD5) // TODO: TEST THIS! -- This is used for static files that do not change throughout the lifetime of an account login.
{ {
uniqueId = HashStringHelper.GetFileMd5(uniqueIdPath.Contains('*') var filePath = uniqueIdPath.Contains('*')
? Directory.GetFiles(Path.GetDirectoryName(uniqueIdPath) ?? string.Empty, Path.GetFileName(uniqueIdPath)).First() ? Directory.GetFiles(Path.GetDirectoryName(uniqueIdPath) ?? string.Empty, Path.GetFileName(uniqueIdPath)).First()
: uniqueIdPath); : uniqueIdPath;
using var fileStream = IOPath.OpenRead(filePath);
fileStream.ThrowIsNull();
uniqueId = fileStream.Length != 0 ? Hashs.String.MD5(fileStream) : "0";
} }
} }
else if (uniqueId != "") else if (uniqueId != "")
uniqueId = HashStringHelper.GetSha256HashString(uniqueId); uniqueId = string.IsNullOrEmpty(uniqueId) ? string.Empty : Hashs.String.SHA512(uniqueId);
return uniqueId; return uniqueId;
} }
......
#if WINDOWS
// ReSharper disable once CheckNamespace
namespace Microsoft.Win32;
public static class RegistryKeyExtensions
{
/// <summary>
/// 读取注册表值
/// </summary>
/// <param name="registryKey"></param>
/// <param name="path"></param>
/// <param name="name"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string Read(this RegistryKey registryKey, string path, string name)
{
var rk = registryKey.OpenSubKey(path);
if (rk != null)
{
var value = rk.GetValue(name)?.ToString();
rk.Close();
return value ?? string.Empty;
}
return string.Empty;
}
/// <summary>
/// 新增或修改注册表值
/// </summary>
/// <param name="registryKey"></param>
/// <param name="path"></param>
/// <param name="name"></param>
/// <param name="value"></param>
/// <param name="valueKind"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AddOrUpdate(this RegistryKey registryKey, string path, string name, string value, RegistryValueKind valueKind)
{
var rk = registryKey.OpenSubKey(path, true);
if (rk != null) // 该项必须已存在
{
rk.SetValue(name, value, valueKind);
rk.Close();
}
}
}
#endif
\ No newline at end of file
using static BD.WTTS.Services.IPCToastService; using static BD.WTTS.Services.IPCToastService;
using AppResources = BD.WTTS.Client.Resources.Strings; using AppResources = BD.WTTS.Client.Resources.Strings;
using BDToastIcon = BD.Common.Enums.ToastIcon;
using ToastIcon = BD.WTTS.Services.IPCToastService.ToastIcon;
// ReSharper disable once CheckNamespace // ReSharper disable once CheckNamespace
namespace BD.WTTS.Services.Implementation; namespace BD.WTTS.Services.Implementation;
...@@ -14,43 +16,59 @@ partial class IPCMainProcessServiceImpl : IPCToastService ...@@ -14,43 +16,59 @@ partial class IPCMainProcessServiceImpl : IPCToastService
_ => string.Empty, _ => string.Empty,
}; };
public void Show(ToastText text, int? duration = null) public void Show(ToastIcon icon, ToastText text, int? duration = null)
{ {
Toast.Show(GetText(text), duration); var icon_ = (BDToastIcon)icon;
var text_ = GetText(text);
Toast.Show(icon_, text_, duration);
} }
public void Show(ToastText text, ToastLength duration) public void Show(ToastIcon icon, ToastText text, ToastLength duration)
{ {
Toast.Show(GetText(text), duration); var icon_ = (BDToastIcon)icon;
var text_ = GetText(text);
Toast.Show(icon_, text_, duration);
} }
public void Show(ToastText text, int? duration = null, params string?[] args) public void Show(ToastIcon icon, ToastText text, int? duration = null, params string?[] args)
{ {
Toast.Show(GetText(text).Format(args), duration); var icon_ = (BDToastIcon)icon;
var text_ = GetText(text).Format(args);
Toast.Show(icon_, text_, duration);
} }
public void Show(ToastText text, ToastLength duration, params string?[] args) public void Show(ToastIcon icon, ToastText text, ToastLength duration, params string?[] args)
{ {
Toast.Show(GetText(text).Format(args), duration); var icon_ = (BDToastIcon)icon;
var text_ = GetText(text).Format(args);
Toast.Show(icon_, text_, duration);
} }
public void Show(ToastText text, params string?[] args) public void Show(ToastIcon icon, ToastText text, params string?[] args)
{ {
Toast.Show(GetText(text).Format(args)); var icon_ = (BDToastIcon)icon;
var text_ = GetText(text).Format(args);
Toast.Show(icon_, text_);
} }
public void ShowAppend(ToastText text, int? duration = null, string? appendText = null) public void ShowAppend(ToastIcon icon, ToastText text, int? duration = null, string? appendText = null)
{ {
Toast.Show(GetText(text) + appendText, duration); var icon_ = (BDToastIcon)icon;
var text_ = GetText(text) + appendText;
Toast.Show(icon_, text_, duration);
} }
public void ShowAppend(ToastText text, ToastLength duration, string? appendText) public void ShowAppend(ToastIcon icon, ToastText text, ToastLength duration, string? appendText)
{ {
Toast.Show(GetText(text) + appendText, duration); var icon_ = (BDToastIcon)icon;
var text_ = GetText(text) + appendText;
Toast.Show(icon_, text_, duration);
} }
public void ShowAppend(ToastText text, string? appendText) public void ShowAppend(ToastIcon icon, ToastText text, string? appendText)
{ {
Toast.Show(GetText(text) + appendText); var icon_ = (BDToastIcon)icon;
var text_ = GetText(text) + appendText;
Toast.Show(icon_, text_);
} }
} }
\ No newline at end of file
...@@ -21,11 +21,16 @@ partial class WindowsPlatformServiceImpl ...@@ -21,11 +21,16 @@ partial class WindowsPlatformServiceImpl
var proxyEnable = $"\"ProxyEnable\"=dword:{(state ? "00000001" : "00000000")}"; var proxyEnable = $"\"ProxyEnable\"=dword:{(state ? "00000001" : "00000000")}";
var hasIpAndProt = ip != null && port >= 0; var hasIpAndProt = ip != null && port >= 0;
var proxyServer = hasIpAndProt ? $"\"proxyServer\"=\"{ip}:{port}\"" : ""; var proxyServer = hasIpAndProt ? $"\"proxyServer\"=\"{ip}:{port}\"" : "";
var reg = $"Windows Registry Editor Version 5.00{Environment.NewLine}[HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings]{Environment.NewLine}{proxyEnable}{Environment.NewLine}{(state ? $"{ProxyOverride}{Environment.NewLine}" : "")}{proxyServer}"; string contents =
$"""
Windows Registry Editor Version 5.00
; {AssemblyInfo.Trademark} BD.WTTS.Services.Implementation.WindowsPlatformServiceImpl.SetAsSystemProxy
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings]
{proxyEnable}
{(state ? $"{ProxyOverride}{Environment.NewLine}" : "")}{proxyServer}
""";
var path = IOPath.GetCacheFilePath(CacheTempDirName, "SwitchProxy", FileEx.Reg); var path = IOPath.GetCacheFilePath(CacheTempDirName, "SwitchProxy", FileEx.Reg);
File.WriteAllText(path, reg, Encoding.UTF8); StartProcessRegedit(path, contents);
var p = StartProcessRegedit($"/s \"{path}\"");
IOPath.TryDeleteInDelay(p, path);
return true; return true;
} }
catch (Exception ex) catch (Exception ex)
...@@ -46,11 +51,15 @@ partial class WindowsPlatformServiceImpl ...@@ -46,11 +51,15 @@ partial class WindowsPlatformServiceImpl
try try
{ {
var regAutoConfigUrl = state ? $"\"AutoConfigURL\"=\"{url}\"" : "\"AutoConfigURL\"=\"\""; var regAutoConfigUrl = state ? $"\"AutoConfigURL\"=\"{url}\"" : "\"AutoConfigURL\"=\"\"";
var reg = $"Windows Registry Editor Version 5.00{Environment.NewLine}[HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings]{Environment.NewLine}{regAutoConfigUrl}"; string contents =
$"""
Windows Registry Editor Version 5.00
; {AssemblyInfo.Trademark} BD.WTTS.Services.Implementation.WindowsPlatformServiceImpl.SetAsSystemPACProxy
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings]
{regAutoConfigUrl}
""";
var path = IOPath.GetCacheFilePath(CacheTempDirName, "SwitchPacProxy", FileEx.Reg); var path = IOPath.GetCacheFilePath(CacheTempDirName, "SwitchPacProxy", FileEx.Reg);
File.WriteAllText(path, reg, Encoding.UTF8); StartProcessRegedit(path, contents);
var p = StartProcessRegedit($"/s \"{path}\"");
IOPath.TryDeleteInDelay(p, path);
return true; return true;
} }
catch (Exception ex) catch (Exception ex)
......
...@@ -42,9 +42,25 @@ sealed partial class WindowsPlatformServiceImpl : IPlatformService ...@@ -42,9 +42,25 @@ sealed partial class WindowsPlatformServiceImpl : IPlatformService
/// </summary> /// </summary>
/// <param name="args"></param> /// <param name="args"></param>
/// <returns></returns> /// <returns></returns>
[Obsolete("use StartProcessRegedit(string path, string content, int millisecondsDelay)", true)]
public static Process? StartProcessRegedit(string? args) public static Process? StartProcessRegedit(string? args)
=> Process2.Start(Regedit, args, workingDirectory: _windir.Value); => Process2.Start(Regedit, args, workingDirectory: _windir.Value);
/// <summary>
/// 带参数(可选/null)启动 %windir%\regedit.exe 并等待退出后删除文件
/// </summary>
/// <param name="path"></param>
public static void StartProcessRegedit(
string path,
string contents,
int millisecondsDelay = 3700)
{
File.WriteAllText(path, contents, Encoding.UTF8);
var args = $"/s \"{path}\"";
var p = Process2.Start(Regedit, args, workingDirectory: _windir.Value);
IOPath.TryDeleteInDelay(p, path, millisecondsDelay, millisecondsDelay);
}
/// <summary> /// <summary>
/// 带参数(可选/null)启动 %windir%\explorer.exe /// 带参数(可选/null)启动 %windir%\explorer.exe
/// </summary> /// </summary>
......
...@@ -49,16 +49,21 @@ sealed class SteamServiceImpl2 : SteamServiceBaseImpl, ISteamConnectService ...@@ -49,16 +49,21 @@ sealed class SteamServiceImpl2 : SteamServiceBaseImpl, ISteamConnectService
return platform.StartAsInvoker(fileName, arguments); return platform.StartAsInvoker(fileName, arguments);
} }
protected override void SetSteamCurrentUser(string userName) protected sealed override void SetSteamCurrentUser(string userName)
{ {
#if WINDOWS #if WINDOWS
if (DesktopBridge.IsRunningAsUwp) if (DesktopBridge.IsRunningAsUwp)
{ {
var reg = $"Windows Registry Editor Version 5.00{Environment.NewLine}[HKEY_CURRENT_USER\\Software\\Valve\\Steam]{Environment.NewLine}\"AutoLoginUser\"=\"{userName}\""; string contents =
$"""
Windows Registry Editor Version 5.00
; {AssemblyInfo.Trademark} BD.WTTS.Services.Implementation.SteamServiceImpl2.SetSteamCurrentUser
[HKEY_CURRENT_USER\Software\Valve\Steam]
"AutoLoginUser"="{userName}"
"RememberPassword"=dword:00000001
""";
var path = IOPath.GetCacheFilePath(WindowsPlatformServiceImpl.CacheTempDirName, "SwitchSteamUser", FileEx.Reg); var path = IOPath.GetCacheFilePath(WindowsPlatformServiceImpl.CacheTempDirName, "SwitchSteamUser", FileEx.Reg);
File.WriteAllText(path, reg, Encoding.UTF8); WindowsPlatformServiceImpl.StartProcessRegedit(path, contents);
var p = WindowsPlatformServiceImpl.StartProcessRegedit($"/s \"{path}\"");
IOPath.TryDeleteInDelay(p, path);
return; return;
} }
#endif #endif
......
// ReSharper disable once CheckNamespace
namespace BD.WTTS.Services;
partial interface IPCPlatformService
{
}
\ No newline at end of file
...@@ -18,19 +18,50 @@ public interface IPCToastService ...@@ -18,19 +18,50 @@ public interface IPCToastService
CommunityFix_OnRunCatch, CommunityFix_OnRunCatch,
} }
void Show(ToastText text, int? duration = null); /// <summary>
/// Toast 显示的图标
/// </summary>
enum ToastIcon : byte
{
/// <summary>
/// 无图标
/// </summary>
None,
/// <summary>
/// ℹ
/// </summary>
Info,
/// <summary>
/// ✅
/// </summary>
Success,
/// <summary>
/// ⚠️
/// </summary>
Warning,
/// <summary>
/// ❌
/// </summary>
Error,
}
void Show(ToastIcon icon, ToastText text, int? duration = null);
void Show(ToastText text, ToastLength duration); void Show(ToastIcon icon, ToastText text, ToastLength duration);
void Show(ToastText text, int? duration = null, params string?[] args); void Show(ToastIcon icon, ToastText text, int? duration = null, params string?[] args);
void Show(ToastText text, ToastLength duration, params string?[] args); void Show(ToastIcon icon, ToastText text, ToastLength duration, params string?[] args);
void Show(ToastText text, params string?[] args); void Show(ToastIcon icon, ToastText text, params string?[] args);
void ShowAppend(ToastText text, int? duration = null, string? appendText = null); void ShowAppend(ToastIcon icon, ToastText text, int? duration = null, string? appendText = null);
void ShowAppend(ToastText text, ToastLength duration, string? appendText); void ShowAppend(ToastIcon icon, ToastText text, ToastLength duration, string? appendText);
void ShowAppend(ToastText text, string? appendText); void ShowAppend(ToastIcon icon, ToastText text, string? appendText);
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册