mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-19 09:35:48 +08:00
取消兑换码使用后不再弹出此剪切板内容的兑换码
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using BetterGenshinImpact.Helpers.Security;
|
||||
using BetterGenshinImpact.View.Windows;
|
||||
using TextBox = Wpf.Ui.Controls.TextBox;
|
||||
|
||||
@@ -11,8 +12,16 @@ namespace BetterGenshinImpact.GameTask.UseRedeemCode;
|
||||
|
||||
public class RedeemCodeManager
|
||||
{
|
||||
public static HashSet<string> CancelClipboardHash { get; } = [];
|
||||
|
||||
public static async Task ImportFromClipboard(string clipboardText)
|
||||
{
|
||||
var md5Hash = MD5Helper.ComputeMD5(clipboardText);
|
||||
if (CancelClipboardHash.Contains(md5Hash))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var codes = ExtractAllCodes(clipboardText);
|
||||
if (codes.Count == 0)
|
||||
{
|
||||
@@ -36,6 +45,11 @@ public class RedeemCodeManager
|
||||
|
||||
if (p.DialogResult != true)
|
||||
{
|
||||
if (CancelClipboardHash.Count > 10)
|
||||
{
|
||||
CancelClipboardHash.Clear();
|
||||
}
|
||||
CancelClipboardHash.Add(md5Hash);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
35
BetterGenshinImpact/Helpers/Security/MD5Helper.cs
Normal file
35
BetterGenshinImpact/Helpers/Security/MD5Helper.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace BetterGenshinImpact.Helpers.Security;
|
||||
|
||||
public static class MD5Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// 计算字符串的MD5哈希值
|
||||
/// </summary>
|
||||
/// <param name="input">输入字符串</param>
|
||||
/// <param name="encoding">字符编码,默认为UTF-8</param>
|
||||
/// <returns>32位小写MD5哈希值</returns>
|
||||
public static string ComputeMD5(string input, Encoding encoding = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input))
|
||||
return string.Empty;
|
||||
|
||||
encoding = encoding ?? Encoding.UTF8;
|
||||
|
||||
using (var md5 = MD5.Create())
|
||||
{
|
||||
byte[] inputBytes = encoding.GetBytes(input);
|
||||
byte[] hashBytes = md5.ComputeHash(inputBytes);
|
||||
|
||||
// 将字节数组转换为十六进制字符串
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < hashBytes.Length; i++)
|
||||
{
|
||||
sb.Append(hashBytes[i].ToString("x2"));
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user