chore: 提取 helper 方法

This commit is contained in:
uye
2025-04-20 16:31:29 +08:00
parent 085444f25f
commit 73801e5eae
4 changed files with 23 additions and 19 deletions

View File

@@ -62,11 +62,7 @@ namespace MaaWpfGui.Extensions
public static string ToLocalTimeString(this DateTime dt, string? format = null)
{
var dateTimeFormat = CustomCultureInfo.Name.ToLowerInvariant() switch
{
"en-us" => "yyyy/MM/dd",
_ => CustomCultureInfo.DateTimeFormat.ShortDatePattern,
};
var dateTimeFormat = LocalizationHelper.FormatDateTime(DateTime.Now);
return string.IsNullOrEmpty(format)
? dt.ToLocalTime().ToString($"{dateTimeFormat} HH:mm:ss", CustomCultureInfo)

View File

@@ -195,5 +195,25 @@ namespace MaaWpfGui.Helper
return cheersBuilder.ToString();
}
public static string FormatResourceVersion(string? resourceVersion, DateTime resourceDateTime)
{
return CustomCultureInfo.Name.ToLowerInvariant() switch
{
"zh-cn" => $" - {resourceVersion}{resourceDateTime:#MMdd}",
"zh-tw" => $" - {resourceVersion}{resourceDateTime:#MMdd}",
"en-us" => $" - {resourceDateTime:dd/MM} {resourceVersion}",
_ => $" - {resourceDateTime.ToString(CustomCultureInfo.DateTimeFormat.ShortDatePattern.Replace("yyyy", string.Empty).Trim('/', '.'))} {resourceVersion}",
};
}
public static string FormatDateTime(DateTime dateTime)
{
return CustomCultureInfo.Name.ToLowerInvariant() switch
{
"en-us" => dateTime.ToString("yyyy/MM/dd"),
_ => dateTime.ToString(CustomCultureInfo.DateTimeFormat.ShortDatePattern),
};
}
}
}

View File

@@ -194,13 +194,7 @@ namespace MaaWpfGui.Models
var releaseNote = data["data"]?["release_note"]?.ToString();
_logger.Information($"New version found: {version:yyyy-MM-dd+HH:mm:ss.fff}, {releaseNote}");
releaseNote = LocalizationHelper.CustomCultureInfo.Name.ToLowerInvariant() switch
{
"zh-cn" => $"「{releaseNote}{version:#MMdd}」",
"zh-tw" => $"「{releaseNote}{version:#MMdd}」",
"en-us" => $"「{version:dd/MM} {releaseNote}」",
_ => $"「{version.ToString(LocalizationHelper.CustomCultureInfo.DateTimeFormat.ShortDatePattern.Replace("yyyy", string.Empty).Trim('/', '.'))} {releaseNote}」",
};
releaseNote = LocalizationHelper.FormatResourceVersion(releaseNote, version);
SettingsViewModel.VersionUpdateSettings.NewResourceFoundInfo = string.Format(LocalizationHelper.GetString("MirrorChyanResourceUpdateShortTip"), releaseNote);

View File

@@ -739,13 +739,7 @@ namespace MaaWpfGui.ViewModels.UI
}
string resourceVersion = !string.IsNullOrEmpty(VersionUpdateSettings.ResourceVersion)
? LocalizationHelper.CustomCultureInfo.Name.ToLowerInvariant() switch
{
"zh-cn" => $" - {VersionUpdateSettings.ResourceVersion}{VersionUpdateSettings.ResourceDateTime:#MMdd}",
"zh-tw" => $" - {VersionUpdateSettings.ResourceVersion}{VersionUpdateSettings.ResourceDateTime:#MMdd}",
"en-us" => $" - {VersionUpdateSettings.ResourceDateTime:dd/MM} {VersionUpdateSettings.ResourceVersion}",
_ => $" - {VersionUpdateSettings.ResourceDateTime.ToString(LocalizationHelper.CustomCultureInfo.DateTimeFormat.ShortDatePattern.Replace("yyyy", string.Empty).Trim('/', '.'))} {VersionUpdateSettings.ResourceVersion}",
}
? LocalizationHelper.FormatResourceVersion(VersionUpdateSettings.ResourceVersion, VersionUpdateSettings.ResourceDateTime)
: string.Empty;
rvm.WindowTitle = $"{updateTip}{prefix}MAA{currentConfiguration} - {VersionUpdateSettingsUserControlModel.CoreVersion}{resourceVersion}{connectConfigName}{connectAddress}{clientName}";
}