Skip to content

Commit

Permalink
code clean & force utf8 encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Scighost committed Dec 8, 2024
1 parent 656f567 commit c53a9ba
Show file tree
Hide file tree
Showing 28 changed files with 73 additions and 67 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@

# CS8618: 在退出构造函数时,不可为 null 的字段必须包含非 null 值。请考虑声明为可以为 null。
dotnet_diagnostic.CS8618.severity = none

# MVVMTK0049: Using [INotifyPropertyChanged] is not AOT compatible for WinRT
dotnet_diagnostic.MVVMTK0049.severity = none

# CS9264: 退出构造函数时,不可为 null 的属性必须包含非 null 值。请考虑添加 ‘required’ 修饰符,或将属性声明为可为 null,或添加 ‘[field: MaybeNull, AllowNull]’ 特性。
dotnet_diagnostic.CS9264.severity = none
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,4 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml
.idea/
6 changes: 3 additions & 3 deletions src/Starward.Core/Gacha/GachaLogClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ public async Task<GenshinGachaWiki> GetGenshinGachaInfoAsync(GameBiz gameBiz, st
{
lang = LanguageUtil.FilterLanguage(lang);
GenshinGachaWiki wiki;
if (gameBiz.IsChinaOfficial() && lang is "zh-cn")
if (gameBiz.IsChinaServer() && lang is "zh-cn")
{
const string url = "https://api-takumi.mihoyo.com/event/platsimulator/config?gids=2&game=hk4e";
wiki = await CommonGetAsync<GenshinGachaWiki>(url, cancellationToken);
Expand All @@ -385,7 +385,7 @@ public async Task<StarRailGachaWiki> GetStarRailGachaInfoAsync(GameBiz gameBiz,
{
lang = LanguageUtil.FilterLanguage(lang);
StarRailGachaWiki wiki;
if (gameBiz.IsChinaOfficial() && lang is "zh-cn")
if (gameBiz.IsChinaServer() && lang is "zh-cn")
{
const string url = "https://api-takumi.mihoyo.com/event/rpgsimulator/config?game=hkrpg";
wiki = await CommonGetAsync<StarRailGachaWiki>(url, cancellationToken);
Expand Down Expand Up @@ -425,7 +425,7 @@ public async Task<GenshinGachaWiki> GetZZZGachaInfoAsync(GameBiz gameBiz, string
{
lang = LanguageUtil.FilterLanguage(lang);
GenshinGachaWiki wiki;
if (gameBiz.IsChinaOfficial() && lang is "zh-cn")
if (gameBiz.IsChinaServer() && lang is "zh-cn")
{
const string url = "https://api-takumi.mihoyo.com/event/platsimulator/config?gids=2&game=hk4e";
wiki = await CommonGetAsync<GenshinGachaWiki>(url, cancellationToken);
Expand Down
8 changes: 4 additions & 4 deletions src/Starward.Core/HoYoPlay/HoYoPlayClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,11 @@ public async Task<List<GameBranch>> GetGameBranchAsync(string launcherId, string
public async Task<GameChunkBuild> GetGameChunkBuildAsync(GameBranch gameBranch, GameBranchPackage gameBranchPackage, CancellationToken cancellationToken = default)
{
string? url = null;
if (gameBranch.GameId.GameBiz.IsChinaOfficial())
if (gameBranch.GameId.GameBiz.IsChinaServer())
{
url = "https://api-takumi.mihoyo.com/downloader/sophon_chunk/api/getBuild?plat_app=ddxf5qt290cg";
}
if (gameBranch.GameId.GameBiz.IsGlobalOfficial())
if (gameBranch.GameId.GameBiz.IsGlobalServer())
{
url = "https://sg-public-api.hoyoverse.com/downloader/sophon_chunk/api/getBuild?plat_app=ddxf6vlr1reo";
}
Expand All @@ -496,11 +496,11 @@ public async Task<GameChunkBuild> GetGameChunkBuildAsync(GameBranch gameBranch,
public async Task<GameChunkBuild> GetGameChunkBuildAsync(GameBranch gameBranch, GameBranchPackage gameBranchPackage, string version, CancellationToken cancellationToken = default)
{
string? url = null;
if (gameBranch.GameId.GameBiz.IsChinaOfficial())
if (gameBranch.GameId.GameBiz.IsChinaServer())
{
url = "https://api-takumi.mihoyo.com/downloader/sophon_chunk/api/getBuild?plat_app=ddxf5qt290cg";
}
if (gameBranch.GameId.GameBiz.IsGlobalOfficial())
if (gameBranch.GameId.GameBiz.IsGlobalServer())
{
url = "https://sg-public-api.hoyoverse.com/downloader/sophon_chunk/api/getBuild?plat_app=ddxf6vlr1reo";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Starward.Core/JsonConverter/GameBizJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Starward.Core.JsonConverter;

public class GameBizJsonConverter : JsonConverter<GameBiz>
{
public override GameBiz? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
public override GameBiz Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return new GameBiz(reader.GetString());
}
Expand Down
24 changes: 12 additions & 12 deletions src/Starward/Controls/BBSWebBridge.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private async Task InitializeWebViewAsync()
{
return;
}
if (CurrentGameBiz.IsGlobalOfficial())
if (CurrentGameBiz.IsGlobalServer())
{
_gameRecordClient = AppConfig.GetService<HoyolabClient>();
}
Expand Down Expand Up @@ -151,7 +151,7 @@ public async Task LoadPageAsync(bool force = false)
if (coreWebView2.Source is "about:blank" || force)
{
var manager = coreWebView2.CookieManager;
var cookies = await manager.GetCookiesAsync(CurrentGameBiz.IsGlobalOfficial() ? "https://act.hoyolab.com" : "https://webstatic.mihoyo.com");
var cookies = await manager.GetCookiesAsync(CurrentGameBiz.IsGlobalServer() ? "https://act.hoyolab.com" : "https://webstatic.mihoyo.com");
foreach (var cookie in cookies)
{
manager.DeleteCookie(cookie);
Expand All @@ -161,10 +161,10 @@ public async Task LoadPageAsync(bool force = false)
ParseCookie();
foreach (var cookie in cookieDic)
{
manager.AddOrUpdateCookie(manager.CreateCookie(cookie.Key, cookie.Value, CurrentGameBiz.IsGlobalOfficial() ? ".hoyolab.com" : ".mihoyo.com", "/"));
manager.AddOrUpdateCookie(manager.CreateCookie(cookie.Key, cookie.Value, CurrentGameBiz.IsGlobalServer() ? ".hoyolab.com" : ".mihoyo.com", "/"));
}

string? url = (CurrentGameBiz.IsGlobalOfficial(), CurrentGameBiz.ToGame().Value) switch
string? url = (CurrentGameBiz.IsGlobalServer(), CurrentGameBiz.ToGame().Value) switch
{
(true, GameBiz.hk4e) => "https://act.hoyolab.com/app/community-game-records-sea/m.html?gid=2",
(true, GameBiz.hkrpg) => "https://act.hoyolab.com/app/community-game-records-sea/m.html?gid=6",
Expand Down Expand Up @@ -556,7 +556,7 @@ private void CloseScreenshotGrid()
private JsResult? GetDynamicSecrectV1(JsParam param)
{
string ApiSalt;
if (CurrentGameBiz.IsGlobalOfficial())
if (CurrentGameBiz.IsGlobalServer())
{
ApiSalt = "okr4obncj8bw5a65hbnn5oo6ixjc3l9w";
}
Expand Down Expand Up @@ -600,7 +600,7 @@ private static string GetRandomString(int timestamp)
private JsResult? GetDynamicSecrectV2(JsParam param)
{
string ApiSalt2;
if (CurrentGameBiz.IsGlobalOfficial())
if (CurrentGameBiz.IsGlobalServer())
{
ApiSalt2 = "h4c1d6ywfq5bsbnbhm1bzq7bxzzv6srt";
}
Expand Down Expand Up @@ -645,19 +645,19 @@ private static string GetRandomString(int timestamp)
private class JsParam
{
/// <summary>
/// 方法名称
/// 方法名称
/// </summary>
[JsonPropertyName("method")]
public string Method { get; set; }

/// <summary>
/// 数据 可以为空
/// 数据 可以为空
/// </summary>
[JsonPropertyName("payload")]
public JsonNode? Payload { get; set; }

/// <summary>
/// 回调的名称,调用 JavaScript:mhyWebBridge 时作为首个参数传入
/// 回调的名称,调用 JavaScript:mhyWebBridge 时作为首个参数传入
/// </summary>
[JsonPropertyName("callback")]
public string? Callback { get; set; }
Expand All @@ -668,19 +668,19 @@ private class JsParam
private class JsResult
{
/// <summary>
/// 代码
/// 代码
/// </summary>
[JsonPropertyName("retcode")]
public int Code { get; set; }

/// <summary>
/// 消息
/// 消息
/// </summary>
[JsonPropertyName("message")]
public string Message { get; set; } = string.Empty;

/// <summary>
/// 数据
/// 数据
/// </summary>
[JsonPropertyName("data")]
public Dictionary<string, object> Data { get; set; } = default!;
Expand Down
8 changes: 4 additions & 4 deletions src/Starward/Controls/ColorfulTextBlock.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ partial void OnTextChanged(string value)
int lastIndex = 0;
for (int i = 0; i < desc.Length; i++)
{
// »»ÐÐ
// 换行
if (desc[i] == '\\' && desc[i + 1] == 'n')
{
text.Inlines.Add(new Run { Text = desc[lastIndex..i].ToString() });
text.Inlines.Add(new LineBreak());
i += 1;
lastIndex = i + 1;
}
// ÑÕÉ«
// 颜色
if (desc[i] == '<' && desc[i + 1] == 'c')
{
text.Inlines.Add(new Run { Text = desc[lastIndex..i].ToString() });
Expand Down Expand Up @@ -94,7 +94,7 @@ partial void OnTextChanged(string value)
i += 16 + colorLength + textLength;
lastIndex = i + 1;
}
// ÒýÓÃ
// 引用
if (desc[i] == '<' && desc[i + 1] == 'i')
{
text.Inlines.Add(new Run { Text = desc[lastIndex..i].ToString() });
Expand All @@ -107,7 +107,7 @@ partial void OnTextChanged(string value)
i += length + 6;
lastIndex = i + 1;
}
// ½áβ
// 结尾
if (i == desc.Length - 1)
{
text.Inlines.Add(new Run { Text = desc.Slice(lastIndex).ToString() });
Expand Down
2 changes: 1 addition & 1 deletion src/Starward/Controls/GameBannerAndPost.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private void FlipView_Banner_Loaded(object sender, RoutedEventArgs e)
var child = VisualTreeHelper.GetChild(grid, i);
if (child is Button button)
{
// 隐藏banner中自动出现的翻页按键
// 隐藏banner中自动出现的翻页按键
button.IsHitTestVisible = false;
button.Opacity = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Starward/Features/Background/AppBackground.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private void StartMediaPlayer(string file)

private void MediaPlayer_VideoFrameAvailable(MediaPlayer sender, object args)
{
DispatcherQueue?.TryEnqueue(() =>
DispatcherQueue?.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.High, () =>
{
try
{
Expand Down
6 changes: 3 additions & 3 deletions src/Starward/Features/Database/DapperSqlMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ public override void SetValue(IDbDataParameter parameter, List<string>? value)

public class GameBizHandler : SqlMapper.TypeHandler<GameBiz>
{
public override GameBiz? Parse(object value)
public override GameBiz Parse(object value)
{
return new GameBiz(value as string);
}

public override void SetValue(IDbDataParameter parameter, GameBiz? value)
public override void SetValue(IDbDataParameter parameter, GameBiz value)
{
parameter.Value = value?.ToString() ?? "";
parameter.Value = value.Value;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Starward/Helpers/SystemUIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Starward.Helpers;
/// <summary>
/// 不可用状态,系统设置远比以下内容更复杂
/// </summary>
[Obsolete("不可用状态",true)]
[Obsolete("不可用状态", true)]
public static class SystemUIHelper
{

Expand Down
2 changes: 1 addition & 1 deletion src/Starward/MyWindows/CloudGameGachaWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private void RootGrid_Loaded(object sender, RoutedEventArgs e)
{
try
{
// todo WinAppSDK ������ 1.5 ��Ϊ����Ϸ����ҳ�������õ������ļ���
// todo WinAppSDK 升级到 1.5 后,为云游戏的网页缓存设置单独的文件夹
if (GameBiz.ToGame() == GameBiz.hk4e)
{
webview.Source = new Uri("https://ys.mihoyo.com/cloud/");
Expand Down
2 changes: 1 addition & 1 deletion src/Starward/Pages/GachaLogPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
Button_Export_JSON.IsEnabled = false;
Button_Import.IsEnabled = false;
}
if (biz.IsGlobalOfficial())
if (biz.IsGlobalServer())
{
MenuFlyoutItem_CloudGame.Visibility = Visibility.Collapsed;
}
Expand Down
1 change: 0 additions & 1 deletion src/Starward/Pages/GameResourcePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.Logging;
using Microsoft.UI.Xaml.Controls;
using Starward.Core;
using Starward.Core.HoYoPlay;
using Starward.Helpers;
using Starward.Services.Launcher;
Expand Down
6 changes: 3 additions & 3 deletions src/Starward/Pages/HoyolabToolbox/HoyolabToolboxPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
GameBiz.hkrpg_bilibili => GameBiz.hkrpg_cn,
_ => biz
};
_gameRecordService.IsHoyolab = CurrentGameBiz.IsGlobalOfficial();
if (CurrentGameBiz.IsGlobalOfficial())
_gameRecordService.IsHoyolab = CurrentGameBiz.IsGlobalServer();
if (CurrentGameBiz.IsGlobalServer())
{
NavigationViewItem_UpdateDeviceInfo.Visibility = Visibility.Collapsed;
}
Expand Down Expand Up @@ -260,7 +260,7 @@ private void InitializeNavigationViewItemVisibility()
private List<GameRecordRole> gameRoleList;


public string AvatarUrl => CurrentUser?.AvatarUrl ?? $"ms-appx:///Assets/Image/icon_{(CurrentGameBiz.IsGlobalOfficial() ? "hoyolab" : "hyperion")}.png";
public string AvatarUrl => CurrentUser?.AvatarUrl ?? $"ms-appx:///Assets/Image/icon_{(CurrentGameBiz.IsGlobalServer() ? "hoyolab" : "hyperion")}.png";



Expand Down
2 changes: 1 addition & 1 deletion src/Starward/Pages/HoyolabToolbox/LoginPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public LoginPage()

private string GetGameBizUrl()
{
if (CurrentGameBiz.IsChinaOfficial())
if (CurrentGameBiz.IsChinaServer())
{
return CurrentGameBiz.ToGame().Value switch
{
Expand Down
4 changes: 2 additions & 2 deletions src/Starward/Pages/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -564,12 +564,12 @@ private void UpdateNavigationViewItemsText()
ToolTipService.SetToolTip(NavigationViewItem_GachaLog, Lang.GachaLogService_SignalSearchRecords);
TextBlock_GachaLog.Text = Lang.GachaLogService_SignalSearchRecords;
}
if (CurrentGameBiz.IsChinaOfficial())
if (CurrentGameBiz.IsChinaServer())
{
ToolTipService.SetToolTip(NavigationViewItem_HoyolabToolbox, Lang.HyperionToolbox);
TextBlock_HoyolabToolbox.Text = Lang.HyperionToolbox;
}
if (CurrentGameBiz.IsGlobalOfficial())
if (CurrentGameBiz.IsGlobalServer())
{
ToolTipService.SetToolTip(NavigationViewItem_HoyolabToolbox, Lang.HoYoLABToolbox);
TextBlock_HoyolabToolbox.Text = Lang.HoYoLABToolbox;
Expand Down
6 changes: 3 additions & 3 deletions src/Starward/Pages/Setting/FileSettingPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ private async Task ChangeDataFolderAsync()
var dialog = new ContentDialog
{
Title = Lang.SettingPage_ReselectDataFolder,
// 当前数据文件夹的位置是:
// 想要重新选择吗?(你需要在选择前手动迁移数据文件)
// 当前数据文件夹的位置是:
// 想要重新选择吗?(你需要在选择前手动迁移数据文件)
Content = $"""
{Lang.SettingPage_TheCurrentLocationOfTheDataFolderIs}
Expand Down Expand Up @@ -112,7 +112,7 @@ private async Task DeleteAllSettingAsync()
var dialog = new ContentDialog
{
Title = Lang.SettingPage_DeleteAllSettings,
// 删除完成后,将自动重启软件。
// 删除完成后,将自动重启软件。
Content = Lang.SettingPage_AfterDeletingTheSoftwareWillBeRestartedAutomatically,
PrimaryButtonText = Lang.Common_Delete,
SecondaryButtonText = Lang.Common_Cancel,
Expand Down
6 changes: 3 additions & 3 deletions src/Starward/Services/DatabaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -811,14 +811,14 @@ public override void SetValue(IDbDataParameter parameter, List<string>? value)

public class GameBizHandler : SqlMapper.TypeHandler<GameBiz>
{
public override GameBiz? Parse(object value)
public override GameBiz Parse(object value)
{
return new GameBiz(value as string);
}

public override void SetValue(IDbDataParameter parameter, GameBiz? value)
public override void SetValue(IDbDataParameter parameter, GameBiz value)
{
parameter.Value = value?.ToString() ?? "";
parameter.Value = value.Value;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Starward/Services/Download/GenshinInstallGameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ public override async Task StartHardLinkAsync(GameBiz linkGameBiz, CancellationT
var linkGameFilesItem = await GetPkgVersionsAsync(linkPrefix, "pkg_version");
linkGameFilesItem.AddRange(await GetAudioPkgVersionsAsync(linkPrefix));

if (CurrentGameBiz.IsChinaOfficial() || CurrentGameBiz.IsBilibili())
if (CurrentGameBiz.IsChinaServer() || CurrentGameBiz.IsBilibili())
{
foreach (var item in linkGameFilesItem)
{
item.Path = item.Path.Replace("GenshinImpact_Data", "YuanShen_Data");
}
}
if (CurrentGameBiz.IsGlobalOfficial())
if (CurrentGameBiz.IsGlobalServer())
{
foreach (var item in linkGameFilesItem)
{
Expand All @@ -121,11 +121,11 @@ public override async Task StartHardLinkAsync(GameBiz linkGameBiz, CancellationT
{
item.Type = InstallGameItemType.HardLink;
item.HardLinkSource = Path.Combine(linkInstallPath, Path.GetRelativePath(_installPath, item.Path));
if (linkGameBiz.IsChinaOfficial() || linkGameBiz.IsBilibili())
if (linkGameBiz.IsChinaServer() || linkGameBiz.IsBilibili())
{
item.HardLinkSource = item.HardLinkSource.Replace("GenshinImpact_Data", "YuanShen_Data");
}
if (linkGameBiz.IsGlobalOfficial())
if (linkGameBiz.IsGlobalServer())
{
item.HardLinkSource = item.HardLinkSource.Replace("YuanShen_Data", "GenshinImpact_Data");
}
Expand Down
Loading

0 comments on commit c53a9ba

Please sign in to comment.