Skip to content

Commit e4e6953

Browse files
authored
Mirror酱集成 (#1666)
* 更多更新渠道的UI改造 * CDK存储逻辑 * feat: enhance CDK input dialog with left button and update check logic for Alpha channel * 支持修改cdk * 支持删除cdk
1 parent 468a54e commit e4e6953

File tree

14 files changed

+701
-80
lines changed

14 files changed

+701
-80
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2-
<s:Boolean x:Key="/Default/UserDictionary/Words/=enkanomiya/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
2+
<s:Boolean x:Key="/Default/UserDictionary/Words/=chyan/@EntryIndexedValue">True</s:Boolean>
3+
<s:Boolean x:Key="/Default/UserDictionary/Words/=enkanomiya/@EntryIndexedValue">True</s:Boolean>
4+
<s:Boolean x:Key="/Default/UserDictionary/Words/=mirrorchan/@EntryIndexedValue">True</s:Boolean>
5+
<s:Boolean x:Key="/Default/UserDictionary/Words/=steambird/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

BetterGenshinImpact/Assets/Strings/md2html.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@
1818
::-webkit-scrollbar-thumb:hover {
1919
background: #555;
2020
}
21-
.body {
22-
background-color: #202020;
23-
color: #e6edf3;
24-
}
2521
.markdown-body {
2622
margin: 0;
2723
padding: 8px;
28-
background-color: #202020;
24+
background-color: #202020 !important;
2925
height: 100%
3026
}
3127
* {

BetterGenshinImpact/BetterGenshinImpact.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<PackageReference Include="DeviceId.Windows" Version="6.9.0" />
4949
<PackageReference Include="DeviceId.Windows.Wmi" Version="6.9.0" />
5050
<PackageReference Include="Emoji.Wpf" Version="0.3.4" />
51+
<PackageReference Include="Meziantou.Framework.Win32.CredentialManager" Version="1.7.4" />
5152
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.4" />
5253
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.4" />
5354
<PackageReference Include="Microsoft.Extensions.Localization" Version="9.0.4" />
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using Meziantou.Framework.Win32;
3+
4+
namespace BetterGenshinImpact.Helpers.Win32;
5+
6+
public static class CredentialManagerHelper
7+
{
8+
public static void SaveCredential(string applicationName, string userName, string secret, string comment,
9+
CredentialPersistence persistence)
10+
{
11+
CredentialManager.WriteCredential(
12+
applicationName: applicationName,
13+
userName: userName,
14+
secret: secret,
15+
comment: comment,
16+
persistence: persistence);
17+
}
18+
19+
public static Credential? ReadCredential(string applicationName)
20+
{
21+
var credential = CredentialManager.ReadCredential(applicationName);
22+
if (credential == null)
23+
{
24+
Console.WriteLine("No credential found.");
25+
return null;
26+
}
27+
28+
Console.WriteLine($"UserName: {credential.UserName}");
29+
Console.WriteLine($"Secret: {credential.Password}");
30+
Console.WriteLine($"Comment: {credential.Comment}");
31+
32+
return credential;
33+
}
34+
35+
public static void UpdateCredential(string applicationName, string newUserName, string newSecret, string newComment)
36+
{
37+
SaveCredential(applicationName, newUserName, newSecret, newComment, CredentialPersistence.LocalMachine);
38+
}
39+
40+
public static void DeleteCredential(string applicationName)
41+
{
42+
try
43+
{
44+
CredentialManager.DeleteCredential(applicationName);
45+
Console.WriteLine("Credential deleted successfully.");
46+
}
47+
catch (Exception ex)
48+
{
49+
Console.WriteLine($"Error deleting credential: {ex.Message}");
50+
}
51+
}
52+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using System;
2+
using Windows.System;
3+
using BetterGenshinImpact.View.Windows;
4+
using Meziantou.Framework.Win32;
5+
using Wpf.Ui.Violeta.Controls;
6+
7+
namespace BetterGenshinImpact.Helpers.Win32;
8+
9+
public static class MirrorChyanHelper
10+
{
11+
public static readonly string MirrorChyanCdkAppName = "KachinaInstaller_MirrorChyanCDK_BetterGI";
12+
13+
14+
public static string? GetCdk()
15+
{
16+
var credential = CredentialManagerHelper.ReadCredential(MirrorChyanCdkAppName);
17+
return credential?.Password;
18+
}
19+
20+
public static string? GetAndPromptCdk()
21+
{
22+
var credential = CredentialManagerHelper.ReadCredential(MirrorChyanCdkAppName);
23+
if (credential == null || credential.Password == null)
24+
{
25+
var cdk = PromptDialog.Prompt("Mirror酱是独立的第三方软件下载平台,提供付费的软件下载加速服务。\n如果你有 Mirror酱的 CDK,可以在这里输入。",
26+
"请输入Mirror酱CDK",
27+
string.Empty,
28+
new PromptDialogConfig
29+
{
30+
ShowLeftButton = true,
31+
LeftButtonText = "获取CDK",
32+
LeftButtonClick = (sender, args) =>
33+
{
34+
Launcher.LaunchUriAsync(new Uri("https://mirrorchyan.com/zh/get-start"));
35+
}
36+
}
37+
);
38+
if (string.IsNullOrEmpty(cdk))
39+
{
40+
Toast.Warning("输入CDK为空,无法继续操作");
41+
return null;
42+
}
43+
44+
CredentialManagerHelper.SaveCredential(
45+
MirrorChyanCdkAppName,
46+
string.Empty,
47+
cdk,
48+
string.Empty,
49+
CredentialPersistence.LocalMachine);
50+
return cdk;
51+
}
52+
else
53+
{
54+
return credential.Password;
55+
}
56+
}
57+
58+
public static void EditCdk()
59+
{
60+
var credential = CredentialManagerHelper.ReadCredential(MirrorChyanCdkAppName);
61+
var cdk = PromptDialog.Prompt("Mirror酱是独立的第三方软件下载平台,提供付费的软件下载加速服务。\n如果你有 Mirror酱的 CDK,可以在这里输入。",
62+
"修改Mirror酱CDK",
63+
credential?.Password!,
64+
new PromptDialogConfig
65+
{
66+
ShowLeftButton = true,
67+
LeftButtonText = "获取CDK",
68+
LeftButtonClick = (sender, args) =>
69+
{
70+
Launcher.LaunchUriAsync(new Uri("https://mirrorchyan.com/zh/get-start"));
71+
}
72+
}
73+
);
74+
if (string.IsNullOrEmpty(cdk))
75+
{
76+
DeleteCdk();
77+
}
78+
else
79+
{
80+
CredentialManagerHelper.SaveCredential(
81+
MirrorChyanCdkAppName,
82+
string.Empty,
83+
cdk,
84+
string.Empty,
85+
CredentialPersistence.LocalMachine);
86+
}
87+
}
88+
89+
public static void DeleteCdk()
90+
{
91+
CredentialManagerHelper.DeleteCredential(MirrorChyanCdkAppName);
92+
}
93+
}

BetterGenshinImpact/Model/UpdateOption.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@
33
public sealed class UpdateOption
44
{
55
public UpdateTrigger Trigger { get; set; } = default;
6+
7+
public UpdateChannel Channel { get; set; } = UpdateChannel.Stable;
68
}
79

810
public enum UpdateTrigger
911
{
1012
Auto,
1113
Manual,
1214
}
15+
16+
17+
public enum UpdateChannel
18+
{
19+
Stable,
20+
Alpha,
21+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace BetterGenshinImpact.Service.Model.MirrorChyan;
4+
5+
#nullable enable
6+
#pragma warning disable CS8618
7+
#pragma warning disable CS8601
8+
#pragma warning disable CS8603
9+
public partial class LatestResponse
10+
{
11+
/// <summary>
12+
/// 响应代码,https://github.com/MirrorChyan/docs/blob/main/ErrorCode.md
13+
/// </summary>
14+
[JsonPropertyName("code")]
15+
public long Code { get; set; }
16+
17+
/// <summary>
18+
/// 响应数据
19+
/// </summary>
20+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
21+
[JsonPropertyName("data")]
22+
public Data Data { get; set; }
23+
24+
/// <summary>
25+
/// 响应信息
26+
/// </summary>
27+
[JsonPropertyName("msg")]
28+
public string Msg { get; set; }
29+
}
30+
31+
/// <summary>
32+
/// 响应数据
33+
/// </summary>
34+
public partial class Data
35+
{
36+
/// <summary>
37+
/// 更新包架构
38+
/// </summary>
39+
[JsonPropertyName("arch")]
40+
public string Arch { get; set; }
41+
42+
/// <summary>
43+
/// CDK过期时间戳
44+
/// </summary>
45+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
46+
[JsonPropertyName("cdk_expired_time")]
47+
public double? CdkExpiredTime { get; set; }
48+
49+
/// <summary>
50+
/// 更新频道,stable | beta | alpha
51+
/// </summary>
52+
[JsonPropertyName("channel")]
53+
public string Channel { get; set; }
54+
55+
/// <summary>
56+
/// 自定义数据
57+
/// </summary>
58+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
59+
[JsonPropertyName("custom_data")]
60+
public string CustomData { get; set; }
61+
62+
/// <summary>
63+
/// 文件大小
64+
/// </summary>
65+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
66+
[JsonPropertyName("filesize")]
67+
public long? Filesize { get; set; }
68+
69+
/// <summary>
70+
/// 更新包系统
71+
/// </summary>
72+
[JsonPropertyName("os")]
73+
public string Os { get; set; }
74+
75+
/// <summary>
76+
/// 发版日志
77+
/// </summary>
78+
[JsonPropertyName("release_note")]
79+
public string ReleaseNote { get; set; }
80+
81+
/// <summary>
82+
/// sha256
83+
/// </summary>
84+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
85+
[JsonPropertyName("sha256")]
86+
public string Sha256 { get; set; }
87+
88+
/// <summary>
89+
/// 更新包类型,incremental | full
90+
/// </summary>
91+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
92+
[JsonPropertyName("update_type")]
93+
public string UpdateType { get; set; }
94+
95+
/// <summary>
96+
/// 下载地址
97+
/// </summary>
98+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
99+
[JsonPropertyName("url")]
100+
public string Url { get; set; }
101+
102+
/// <summary>
103+
/// 资源版本名称
104+
/// </summary>
105+
[JsonPropertyName("version_name")]
106+
public string VersionName { get; set; }
107+
108+
/// <summary>
109+
/// 资源版本号仅内部使用
110+
/// </summary>
111+
[JsonPropertyName("version_number")]
112+
public long VersionNumber { get; set; }
113+
}
114+
115+
#pragma warning restore CS8618
116+
#pragma warning restore CS8601
117+
#pragma warning restore CS8603

0 commit comments

Comments
 (0)