mirror of
https://github.com/BeyondDimension/SteamTools.git
synced 2026-10-22 09:36:09 +08:00
update version s
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 此代码由工具生成。
|
||||
// 运行时版本:4.0.30319.42000
|
||||
//
|
||||
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||
// 重新生成代码,这些更改将会丢失。
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Application.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 一个强类型的资源类,用于查找本地化的字符串等。
|
||||
/// </summary>
|
||||
// 此类是由 StronglyTypedResourceBuilder
|
||||
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
|
||||
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
|
||||
// (以 /str 作为命令选项),或重新生成 VS 项目。
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class SR {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal SR() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回此类使用的缓存的 ResourceManager 实例。
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("System.Application.Properties.SR", typeof(SR).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写当前线程的 CurrentUICulture 属性,对
|
||||
/// 使用此强类型资源类的所有资源查找执行重写。
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 echo "Steam++替换升级中..."
|
||||
///taskkill /f /im "{0}"
|
||||
///xcopy /y /c /h /r /s "{1}\*.*" "{2}"
|
||||
///rmdir /s /q "{1}"
|
||||
///"{3}"
|
||||
///del %0 的本地化字符串。
|
||||
/// </summary>
|
||||
internal static string ProgramUpdateCmd_ {
|
||||
get {
|
||||
return ResourceManager.GetString("ProgramUpdateCmd_", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查找类似 更新包解压失败,请打开官网手动更新 的本地化字符串。
|
||||
/// </summary>
|
||||
internal static string UpdateUnpackFail {
|
||||
get {
|
||||
return ResourceManager.GetString("UpdateUnpackFail", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="ProgramUpdateCmd_" xml:space="preserve">
|
||||
<value>echo "Steam++替换升级中..."
|
||||
taskkill /f /im "{0}"
|
||||
xcopy /y /c /h /r /s "{1}\*.*" "{2}"
|
||||
rmdir /s /q "{1}"
|
||||
"{3}"
|
||||
del %0</value>
|
||||
<comment>升级程序CMD命令行</comment>
|
||||
</data>
|
||||
<data name="UpdateUnpackFail" xml:space="preserve">
|
||||
<value>更新包解压失败,请打开官网手动更新</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -1,53 +1,13 @@
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using System;
|
||||
using System.Application.Services;
|
||||
using System.Application.Services.Implementation;
|
||||
using System.Application.UI;
|
||||
using System.Application.UI.ViewModels;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 添加本地化、多语言服务
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("Languages")]
|
||||
public static IServiceCollection AddLocalizationService(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<ILocalizationService, LocalizationServiceImpl>();
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加视图模型组服务
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("Languages")]
|
||||
public static IServiceCollection AddViewModelCollectionService(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton(new ViewModelCollectionServiceImpl(services));
|
||||
services.AddSingleton<IViewModelCollectionService>(s => s.GetRequiredService<ViewModelCollectionServiceImpl>());
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加视图模型
|
||||
/// </summary>
|
||||
/// <typeparam name="TViewModel"></typeparam>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
[Obsolete("Languages")]
|
||||
public static IServiceCollection AddViewModel<TViewModel>(this IServiceCollection services) where TViewModel : ViewModelBase
|
||||
{
|
||||
services.AddSingleton<TViewModel>();
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加桌面端日志实现
|
||||
/// </summary>
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
using System.Application.UI.ViewModels;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
namespace System.Application.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// 本地化、多语言服务
|
||||
/// </summary>
|
||||
[Obsolete("Languages")]
|
||||
public interface ILocalizationService
|
||||
{
|
||||
CultureInfo DefaultCurrentUICulture { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 更改语言
|
||||
/// </summary>
|
||||
/// <param name="cultureName"></param>
|
||||
void ChangeLanguage(string cultureName);
|
||||
|
||||
/// <summary>
|
||||
/// 绑定资源字符串的视图模型组
|
||||
/// </summary>
|
||||
ILocalizationViewModel[] ViewModels { get; }
|
||||
|
||||
public static readonly IList<KeyValuePair<string, string>> Languages;
|
||||
|
||||
static ILocalizationService()
|
||||
{
|
||||
Languages = new Dictionary<string, string>()
|
||||
{
|
||||
{ "", "Auto" },
|
||||
{ "zh-Hans", "Chinese(Simplified)" },
|
||||
{ "zh-Hant", "Chinese(Traditional)" },
|
||||
{ "ja-JP", "Japanese" },
|
||||
{ "ru", "Russian" },
|
||||
}.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
using System.Application.UI.ViewModels;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace System.Application.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// 视图模型组服务
|
||||
/// </summary>
|
||||
[Obsolete("Languages")]
|
||||
public interface IViewModelCollectionService
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取所有的视图模型
|
||||
/// </summary>
|
||||
IEnumerable<ViewModelBase> ViewModels { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 根据类型过滤获取视图模型
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
IEnumerable<T> GetViewModels<T>();
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Application.Models;
|
||||
using System.Application.Properties;
|
||||
using System.Application.UI;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using static System.Application.Services.IAppUpdateService;
|
||||
|
||||
namespace System.Application.Services.Implementation
|
||||
{
|
||||
public abstract class DesktopAppUpdateServiceImpl : AppUpdateServiceImpl
|
||||
{
|
||||
public DesktopAppUpdateServiceImpl(IToast toast, ICloudServiceClient client, IOptions<AppSettings> options) : base(toast, client, options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override Version OSVersion => Environment.OSVersion.Version;
|
||||
|
||||
protected sealed override void OpenInAppStore() => throw new NotImplementedException();
|
||||
|
||||
protected abstract void OnExit();
|
||||
|
||||
protected override void OverwriteUpgrade(string fileName)
|
||||
{
|
||||
var dirPath = Path.Combine(AppContext.BaseDirectory, Path.GetFileNameWithoutExtension(fileName));
|
||||
|
||||
if (Directory.Exists(dirPath))
|
||||
{
|
||||
Directory.Delete(dirPath, true);
|
||||
}
|
||||
|
||||
CurrentProgressValue = 0;
|
||||
|
||||
void OnReport(float value) => CurrentProgressValue = value;
|
||||
|
||||
if (TarGZipHelper.Unpack(fileName, dirPath, progress: new Progress<float>(OnReport)))
|
||||
{
|
||||
ClearProgressValue(MaxProgressValue);
|
||||
|
||||
IOPath.FileTryDelete(fileName);
|
||||
|
||||
OnExit();
|
||||
|
||||
var updateCommandPath = Path.Combine(AppContext.BaseDirectory, "update.cmd");
|
||||
IOPath.FileIfExistsItDelete(updateCommandPath);
|
||||
|
||||
var updateCommand = string.Format(
|
||||
SR.ProgramUpdateCmd_,
|
||||
AppHelper.ProgramName,
|
||||
dirPath,
|
||||
AppContext.BaseDirectory,
|
||||
AppHelper.ProgramName);
|
||||
|
||||
File.WriteAllText(updateCommandPath, updateCommand, Encoding.Default);
|
||||
|
||||
using var p = new Process();
|
||||
p.StartInfo.FileName = updateCommandPath;
|
||||
p.StartInfo.UseShellExecute = false;
|
||||
p.StartInfo.CreateNoWindow = true; // 不显示程序窗口
|
||||
p.StartInfo.Verb = "runas"; // 管理员权限运行
|
||||
p.Start(); // 启动程序
|
||||
}
|
||||
else
|
||||
{
|
||||
toast.Show(SR.UpdateUnpackFail);
|
||||
ClearProgressValue(MaxProgressValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-65
@@ -1,65 +0,0 @@
|
||||
using System.Application.UI.ViewModels;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
namespace System.Application.Services.Implementation
|
||||
{
|
||||
[Obsolete("Languages")]
|
||||
internal sealed class LocalizationServiceImpl : ILocalizationService
|
||||
{
|
||||
readonly IViewModelCollectionService vmss;
|
||||
|
||||
public LocalizationServiceImpl(IViewModelCollectionService vmss)
|
||||
{
|
||||
this.vmss = vmss;
|
||||
DefaultCurrentUICulture = CultureInfo.CurrentUICulture;
|
||||
}
|
||||
|
||||
public CultureInfo DefaultCurrentUICulture { get; }
|
||||
|
||||
ILocalizationViewModel[]? viewModels;
|
||||
|
||||
public ILocalizationViewModel[] ViewModels
|
||||
{
|
||||
get
|
||||
{
|
||||
if (viewModels == null)
|
||||
{
|
||||
viewModels = vmss.GetViewModels<ILocalizationViewModel>().ToArray();
|
||||
}
|
||||
return viewModels;
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsMatch(CultureInfo cultureInfo, string cultureName)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(cultureInfo.Name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (cultureInfo.Name == cultureName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return IsMatch(cultureInfo.Parent, cultureName);
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeLanguage(string cultureName)
|
||||
{
|
||||
if (IsMatch(CultureInfo.CurrentUICulture, cultureName)) return;
|
||||
if (!ViewModels.Any()) return;
|
||||
void ChangeLanguage()
|
||||
{
|
||||
CultureInfo.CurrentUICulture = new CultureInfo(cultureName);
|
||||
foreach (var viewModel in ViewModels)
|
||||
{
|
||||
viewModel.OnChangeLanguage();
|
||||
}
|
||||
}
|
||||
MainThreadDesktop.BeginInvokeOnMainThread(ChangeLanguage);
|
||||
}
|
||||
}
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Application.UI.ViewModels;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace System.Application.Services.Implementation
|
||||
{
|
||||
[Obsolete("Languages")]
|
||||
internal sealed class ViewModelCollectionServiceImpl : IViewModelCollectionService
|
||||
{
|
||||
readonly IEnumerable<ServiceDescriptor> services;
|
||||
|
||||
public ViewModelCollectionServiceImpl(IEnumerable<ServiceDescriptor> services)
|
||||
{
|
||||
this.services = services;
|
||||
}
|
||||
|
||||
public IEnumerable<ViewModelBase> ViewModels => GetViewModels<ViewModelBase>();
|
||||
|
||||
public IEnumerable<T> GetViewModels<T>()
|
||||
{
|
||||
var tType = typeof(T);
|
||||
var vType = typeof(ViewModelBase);
|
||||
var tIsvType = tType == vType;
|
||||
return from s in services
|
||||
where s.ServiceType == s.ImplementationType &&
|
||||
s.Lifetime == ServiceLifetime.Singleton &&
|
||||
tType.IsAssignableFrom(s.ImplementationType) &&
|
||||
(tIsvType || vType.IsAssignableFrom(s.ImplementationType))
|
||||
select (T)DI.Get(s.ServiceType);
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
@@ -29,6 +29,11 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\SR.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>SR.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Update="UI\Resx\AppResources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
@@ -37,6 +42,10 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\SR.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>SR.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Update="UI\Resx\AppResources.resx">
|
||||
<Generator>PublicResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>AppResources.Designer.cs</LastGenOutput>
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
using ReactiveUI;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
namespace System.Application.UI.Resx
|
||||
{
|
||||
/// <summary>
|
||||
/// 提供对多语言资源的访问。
|
||||
/// </summary>
|
||||
[Obsolete("Languages")]
|
||||
public class ResourceService : ReactiveObject
|
||||
{
|
||||
// singleton
|
||||
public static ResourceService Current => new ResourceService();
|
||||
|
||||
/// <summary>
|
||||
/// 支持的语言简写
|
||||
/// </summary>
|
||||
private readonly string[] supportedCultureNames =
|
||||
{
|
||||
"zh-Hans", // Resources.resx
|
||||
"zh-Hant",
|
||||
"en",
|
||||
"ja",
|
||||
"ru",
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 支持的语言Steam平台名称
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, string> supportedCultureSteamNames = new Dictionary<string, string>
|
||||
{
|
||||
{ "zh-Hans","schinese"},
|
||||
{ "zh-Hant","tchinese"},
|
||||
{ "en","english"},
|
||||
{ "ko","koreana"},
|
||||
{ "ja","japanese"},
|
||||
{ "ru","russian"},
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 获取多语种资源。
|
||||
/// </summary>
|
||||
public System.Application.UI.Resx.AppResources Resources { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得受支持的文化。
|
||||
/// </summary>
|
||||
public IReadOnlyCollection<CultureInfo> SupportedCultures { get; }
|
||||
|
||||
private ResourceService()
|
||||
{
|
||||
this.Resources = new System.Application.UI.Resx.AppResources();
|
||||
#pragma warning disable CS8619 // 值中的引用类型的为 Null 性与目标类型不匹配。
|
||||
this.SupportedCultures = this.supportedCultureNames
|
||||
.Select(x =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return CultureInfo.GetCultureInfo(x);
|
||||
}
|
||||
catch (CultureNotFoundException)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.Where(x => x != null)
|
||||
.ToList();
|
||||
#pragma warning restore CS8619 // 值中的引用类型的为 Null 性与目标类型不匹配。
|
||||
System.Application.UI.Resx.AppResources.Culture = this.SupportedCultures.First();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用指定的区域性名称更改资源的区域性。
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
public void ChangeCulture(string name)
|
||||
{
|
||||
System.Application.UI.Resx.AppResources.Culture = this.SupportedCultures.SingleOrDefault(x => x.Name == name);
|
||||
//GeneralSettings.Culture.Value = SteamTools.Properties.Resources.Culture?.Name;
|
||||
this.RaisePropertyChanged(nameof(Resources));
|
||||
}
|
||||
|
||||
public string GetCurrentCultureSteamLanguageName()
|
||||
{
|
||||
return UI.Resx.AppResources.Culture == null ? supportedCultureSteamNames.First().Value : supportedCultureSteamNames[UI.Resx.AppResources.Culture.Name];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
using System.Application.UI.Resx;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace System.Application.UI.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// 本地化、多语言视图模型
|
||||
/// </summary>
|
||||
[Obsolete("Languages")]
|
||||
public interface ILocalizationViewModel
|
||||
{
|
||||
public void OnChangeLanguage()
|
||||
{
|
||||
var properties = GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||
var query = from p in properties
|
||||
let attr = p.GetCustomAttribute<ResStringAttribute>()
|
||||
where p.PropertyType == typeof(string) && attr != null
|
||||
select (p, attr.ResId);
|
||||
foreach (var (p, ResId) in query)
|
||||
{
|
||||
var resId = ResId ?? p.Name;
|
||||
var value = AppResources.ResourceManager.GetString(resId);
|
||||
p.SetValue(this, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
namespace System.Application.UI.ViewModels
|
||||
{
|
||||
[Obsolete("Languages")]
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public sealed class ResStringAttribute : Attribute
|
||||
{
|
||||
public string? ResId { get; }
|
||||
|
||||
public ResStringAttribute(string? resId = null)
|
||||
{
|
||||
ResId = resId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,25 +3,19 @@ using System.Application.Mvvm;
|
||||
|
||||
namespace System.Application.UI.ViewModels
|
||||
{
|
||||
public class ViewModelBase : ReactiveObject, IDisposable, ILocalizationViewModel
|
||||
public class ViewModelBase : ReactiveObject, IDisposable
|
||||
{
|
||||
[NonSerialized] CompositeDisposable? _compositeDisposable;
|
||||
|
||||
[NonSerialized] bool _disposed;
|
||||
|
||||
public ViewModelBase()
|
||||
{
|
||||
ILocalizationViewModel localization = this;
|
||||
localization.OnChangeLanguage();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否在设计器的上下文中运行
|
||||
/// </summary>
|
||||
public static bool IsInDesignMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 释放该实例使用的所有资源
|
||||
/// 释放该实例使用的所有资源
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user