提交 3bd116ca 编写于 作者: A Aigio Liu

🎨 Misc

上级 f3ff7852
文件已添加
......@@ -94,24 +94,20 @@ false
#endif
#if !APP_HOST
#region Modules/Plugins
public const string Accelerator = "Accelerator";
#if !APP_HOST
public const string GameAccount = "GameAccount";
public const string GameList = "GameList";
public const string SteamIdleCard = "SteamIdleCard";
#endif
public const string ArchiSteamFarmPlus = "ArchiSteamFarmPlus";
#if !APP_HOST
public const string Authenticator = "Authenticator";
public const string GameTools = "GameTools";
......@@ -126,8 +122,9 @@ false
public const string AuthenticatorId = "00000000-0000-0000-0000-000000000005";
public const string GameToolsId = "00000000-0000-0000-0000-000000000006";
public const string SteamIdleCardId = "00000000-0000-0000-0000-000000000007";
#endif
#endregion
#endif
}
\ No newline at end of file
......@@ -9,4 +9,7 @@
<GCConserveMemory enabled="9"/>
<legacyCorruptedStateExceptionsPolicy enabled="true"/>
</runtime>
<appSettings>
<add key="d" value="7.0.10"/>
</appSettings>
</configuration>
\ No newline at end of file
......@@ -22,6 +22,15 @@
<ApplicationIcon Condition="'$(Configuration)'=='Debug'">..\..\res\icons\app\v3\Icon.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup Condition=" $(TargetFramework.StartsWith('net4')) OR $(TargetFramework.StartsWith('net3')) ">
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\WattToolkit.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('net4')) OR $(TargetFramework.StartsWith('net3')) ">
<Reference Include="System.Configuration" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<AllowedReferenceRelatedFileExtensions>
<!-- Prevent default XML and PDB files copied to output in RELEASE.
......
......@@ -3,6 +3,9 @@
// https://github.com/dotnet/runtime/blob/main/docs/design/features/host-error-codes.md
// https://github.com/dotnet/samples/blob/91355ef22a10ec614a2e8daefd68785066860d57/core/hosting/src/NativeHost/nativehost.cpp
#if NETFRAMEWORK
using System.Configuration;
#endif
using static BD.WTTS.AssemblyInfo;
using static BD.WTTS.Client.Resources.Strings;
......@@ -11,10 +14,22 @@ namespace BD.WTTS;
static unsafe partial class Program
{
public const string dotnet_version_major = "7";
public const string dotnet_version_minor = "0";
public const string dotnet_version_build = "10";
public const string dotnet_version = $"{dotnet_version_major}.{dotnet_version_minor}.{dotnet_version_build}";
static Program()
{
dotnet_version_major = "7";
dotnet_version_minor = "0";
dotnet_version_build = "10";
dotnet_version = $"{dotnet_version_major}.{dotnet_version_minor}.{dotnet_version_build}";
}
//#if NETFRAMEWORK
public static string dotnet_version_major, dotnet_version_minor, dotnet_version_build, dotnet_version;
//#else
// public const string dotnet_version_major = "7";
// public const string dotnet_version_minor = "0";
// public const string dotnet_version_build = "10";
// public const string dotnet_version = $"{dotnet_version_major}.{dotnet_version_minor}.{dotnet_version_build}";
//#endif
const string dotnet_runtime = "Microsoft.NETCore.App";
const string aspnetcore_runtime = "Microsoft.AspNetCore.App";
......@@ -23,32 +38,32 @@ static unsafe partial class Program
const string dotnet_type = "BD.WTTS.Program, Steam++";
const string dotnet_type_method = "CustomEntryPoint";
/// <summary>
/// 是否依赖 AspNetCore
/// </summary>
/// <returns></returns>
static bool RequireAspNetCore(string baseDirectory)
{
foreach (var moduleName in new[] {
// 依赖 AspNetCore 的模块名
Accelerator,
ArchiSteamFarmPlus,
})
{
var module_path =
#if NET35
PathCombine
#else
Path.Combine
#endif
(baseDirectory, "modules", moduleName);
if (Directory.Exists(module_path) && !PathIsDirectoryEmpty(module_path))
{
return true;
}
}
return false;
}
// /// <summary>
// /// 是否依赖 AspNetCore
// /// </summary>
// /// <returns></returns>
// static bool RequireAspNetCore(string baseDirectory)
// {
// foreach (var moduleName in new[] {
// // 依赖 AspNetCore 的模块名
// Accelerator,
// ArchiSteamFarmPlus,
// })
// {
// var module_path =
//#if NET35
// PathCombine
//#else
// Path.Combine
//#endif
// (baseDirectory, "modules", moduleName);
// if (Directory.Exists(module_path) && !PathIsDirectoryEmpty(module_path))
// {
// return true;
// }
// }
// return false;
// }
#if NETFRAMEWORK
[DllImport("shlwapi.dll", EntryPoint = "PathIsDirectoryEmptyW", SetLastError = true, CharSet = CharSet.Unicode)]
......@@ -165,7 +180,7 @@ static unsafe partial class Program
#endif
static void DownloadDotNetRuntime()
{
const string urlFormat1 = $"https://dotnet.microsoft.com/{{0}}/download/dotnet/{dotnet_version_major}.{dotnet_version_minor}";
string urlFormat1 = $"https://dotnet.microsoft.com/{{0}}/download/dotnet/{dotnet_version_major}.{dotnet_version_minor}";
var url = string.Format(urlFormat1, GetLang());
OpenCoreByProcess(url);
}
......@@ -196,7 +211,7 @@ static unsafe partial class Program
{
Console.WriteLine(ex);
Console.ReadLine();
return 500;
return (int)ExitCode.InternalServerError;
}
}
#endif
......@@ -219,6 +234,50 @@ static unsafe partial class Program
Console.WriteLine($"Environment.Version: {Environment.Version}");
#endif
#if NETFRAMEWORK
try
{
var dotnet_version_ = ConfigurationManager.AppSettings["d"];
if (!
#if !NET35
string.
#endif
IsNullOrWhiteSpace(dotnet_version_) &&
dotnet_version_.Length < sbyte.MaxValue)
{
var dotnet_version__ = dotnet_version_.Split('.');
int major, minor, build;
switch (dotnet_version__.Length)
{
case 1:
dotnet_version_major = (int.TryParse(dotnet_version__[0], out major) ? major : 0).ToString();
dotnet_version_minor = dotnet_version_build = "0";
dotnet_version = $"{dotnet_version_major}.0.0";
break;
case 2:
dotnet_version_major = (int.TryParse(dotnet_version__[0], out major) ? major : 0).ToString();
dotnet_version_minor = (int.TryParse(dotnet_version__[1], out minor) ? minor : 0).ToString();
dotnet_version_build = "0";
dotnet_version = $"{dotnet_version_major}.{dotnet_version_minor}.0";
break;
case 3:
dotnet_version_major = (int.TryParse(dotnet_version__[0], out major) ? major : 0).ToString();
dotnet_version_minor = (int.TryParse(dotnet_version__[1], out minor) ? minor : 0).ToString();
dotnet_version_build = (int.TryParse(dotnet_version__[2], out build) ? build : 0).ToString();
dotnet_version = $"{dotnet_version_major}.{dotnet_version_minor}.{dotnet_version_build}";
break;
}
}
}
catch
{
}
if (dotnet_version == default)
return (int)ExitCode.Failure_read_dotnet_version;
#endif
var baseDirectory =
#if NET46_OR_GREATER || NETCOREAPP
AppContext.BaseDirectory;
......@@ -229,7 +288,8 @@ static unsafe partial class Program
if (args.Length == 0 && !CompatibilityCheck(baseDirectory))
return 0;
var requireAspNetCore = RequireAspNetCore(baseDirectory);
//var requireAspNetCore = RequireAspNetCore(baseDirectory);
const bool requireAspNetCore = true;
string hostfxr_path, dotnet_runtime_path, aspnetcore_runtime_path, config_path, dotnetlib_path;
// STEP 0: Search HostFxr
......@@ -372,6 +432,16 @@ static unsafe partial class Program
#endif
}
var fvi = FileVersionInfo.GetVersionInfo(dotnetlib_path);
if (fvi.Comments != Description)
return (int)ExitCode.Failure_fvi_Description;
if (fvi.CompanyName != Company)
return (int)ExitCode.Failure_fvi_Company;
if (fvi.LegalCopyright != Copyright)
return (int)ExitCode.Failure_fvi_Copyright;
if (fvi.LegalTrademarks != Trademark)
return (int)ExitCode.Failure_fvi_Trademark;
delegate* unmanaged[Cdecl]<nint, nint, out nint, int> init_fptr;
delegate* unmanaged[Cdecl]<nint, hostfxr_delegate_type, out delegate* unmanaged[Cdecl]<nint, nint, nint, nint, nint, out delegate* unmanaged[Cdecl]<nint, int, int>, int>, int> get_delegate_fptr;
delegate* unmanaged[Cdecl]<nint, int> close_fptr;
......@@ -507,11 +577,20 @@ static unsafe partial class Program
enum ExitCode
{
InternalServerError = 5500,
Failure_load_hostfxr = 5701,
Failure_get_dotnet_load_assembly,
Failure_load_assembly_and_get_function_pointer,
FrameworkMissingFailure,
EntryPointFileNotFound,
Failure_read_dotnet_version,
Failure_fvi_Description,
Failure_fvi_Company,
Failure_fvi_Copyright,
Failure_fvi_Trademark,
}
#if NETFRAMEWORK
......
......@@ -9,7 +9,7 @@ static class ObfuscarHelper
static void WriteConfig(string dirPath)
{
var xml =
"""
$"""
<?xml version='1.0'?>
<Obfuscator>
<!-- 输入的工作路径,采用如约定的 Windows 下的路径表示法,如以下表示当前工作路径 -->
......@@ -42,14 +42,15 @@ static class ObfuscarHelper
<Var name="RegenerateDebugInfo" value="false" />
<Var name="OptimizeMethods" value="true" />
<Var name="SuppressIldasm" value="true" />
<Var name="KeyFile" value="{Path.Combine(ProjectUtils.ProjPath, "WattToolkit.snk")}" />
<!-- 需要进行混淆的程序集,可以传入很多个,如传入一排排 -->
<!-- <Module file="$(InPath)\Lib1.dll" /> -->
<!-- <Module file="$(InPath)\Lib2.dll" /> -->
<Module file="$(InPath)\Steam++.exe" />
</Obfuscator>
"""u8;
""";
File.WriteAllBytes(Path.Combine(dirPath, configFileName), xml.ToArray());
File.WriteAllBytes(Path.Combine(dirPath, configFileName), Encoding.UTF8.GetBytes(xml));
}
public static void Start(string dirPath)
......
......@@ -3,7 +3,7 @@ namespace BD.WTTS.Services;
partial interface IPlatformService
{
#region LinuxEtcIssue
#region LinuxEtc
#if LINUX
......@@ -45,6 +45,7 @@ partial interface IPlatformService
{
const string Deepin = "Deepin";
const string Ubuntu = "Ubuntu";
const string SteamOS = "SteamOS";
const string ReleaseKey_PRETTY_NAME = "PRETTY_NAME";
const string ReleaseKey_NAME = "NAME";
......@@ -55,9 +56,42 @@ partial interface IPlatformService
const string ReleaseKey_ID_LIKE = "ID_LIKE";
const string ReleaseKey_HOME_URL = "HOME_URL";
const string ReleaseKey_BUG_REPORT_URL = "BUG_REPORT_URL";
// NAME="SteamOS"
// PRETTY_NAME="SteamOS"
// VERSION_CODENAME=holo
// ID=steamos
// ID_LIKE=arch
// ANSI_COLOR="1;35"
// HOME_URL="https://www.steampowered.com/"
// DOCUMENTATION_URL="https://support.steampowered.com/"
// SUPPORT_URL="https://support.steampowered.com/"
// BUG_REPORT_URL="https://support.steampowered.com/"
// LOGO=steamos
// VARIANT_ID=steamdeck
// BUILD_ID=20230508.1
// VERSION_ID=3.4.8
// PRETTY_NAME="Deepin 20.9"
// NAME="Deepin"
// VERSION_ID="20.9"
// VERSION="20.9"
// VERSION_CODENAME="apricot"
// ID=Deepin
// HOME_URL="https://www.deepin.org/"
// BUG_REPORT_URL="https://bbs.deepin.org/"
enum Distribution : ushort
{
SteamOS = 1,
Ubuntu,
Deepin,
}
}
string? GetLinuxReleaseValue(string key)
static string? GetLinuxReleaseValue(string key)
{
foreach (var item in EtcOSRelease.Value)
{
......@@ -67,6 +101,37 @@ partial interface IPlatformService
return default;
}
private static readonly Lazy<string?> _LinuxReleaseId = new(() =>
{
var value = GetLinuxReleaseValue(LinuxConstants.ReleaseKey_ID);
return value;
});
static string? LinuxReleaseId => _LinuxReleaseId.Value;
private static readonly Lazy<LinuxConstants.Distribution> _LinuxDistribution = new(() =>
{
var value = LinuxReleaseId;
if (!string.IsNullOrWhiteSpace(value) &&
value.Length < sbyte.MaxValue)
{
var bytes = Encoding.UTF8.GetBytes(value);
Utf8StringComparerOrdinalIgnoreCase comparer = new();
if ("steamos"u8.SequenceEqual(bytes, comparer))
return LinuxConstants.Distribution.SteamOS;
else if ("ubuntu"u8.SequenceEqual(bytes, comparer))
return LinuxConstants.Distribution.Ubuntu;
else if ("Deepin"u8.SequenceEqual(bytes, comparer))
return LinuxConstants.Distribution.Deepin;
}
return default;
});
/// <summary>
/// 获取当前 Linux 发行版
/// </summary>
LinuxConstants.Distribution LinuxDistribution => _LinuxDistribution.Value;
#endif
#endregion
......
......@@ -74,7 +74,7 @@ partial class AboutPageViewModel
}
#elif MACCATALYST || IOS || MACOS
#elif LINUX
var linuxOSRelease = platformService.GetLinuxReleaseValue(IPlatformService.LinuxConstants.ReleaseKey_PRETTY_NAME);
var linuxOSRelease = IPlatformService.GetLinuxReleaseValue(IPlatformService.LinuxConstants.ReleaseKey_PRETTY_NAME);
if (!string.IsNullOrWhiteSpace(linuxOSRelease))
{
b.Append(linuxOSRelease);
......
......@@ -30,10 +30,9 @@ public sealed partial class AboutPageViewModel : TabItemViewModel
{
string? osName;
#if LINUX
var platformService = IPlatformService.Instance;
osName = platformService.GetLinuxReleaseValue(IPlatformService.LinuxConstants.ReleaseKey_NAME);
osName = IPlatformService.GetLinuxReleaseValue(IPlatformService.LinuxConstants.ReleaseKey_NAME);
if (!string.IsNullOrWhiteSpace(osName)) return osName;
osName = platformService.GetLinuxReleaseValue(IPlatformService.LinuxConstants.ReleaseKey_ID);
osName = IPlatformService.GetLinuxReleaseValue(IPlatformService.LinuxConstants.ReleaseKey_ID);
if (!string.IsNullOrWhiteSpace(osName)) return osName;
#endif
osName = DeviceInfo2.OSName();
......
// ReSharper disable once CheckNamespace
using dotnetCampus.Ipc.CompilerServices.Attributes;
namespace BD.WTTS.UI.ViewModels;
public sealed partial class MainWindowViewModel : WindowViewModel
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册