Remove unused code

This commit is contained in:
HolographicHat
2022-08-15 23:34:47 +08:00
parent 30a0189f5e
commit b596cad02e
6 changed files with 22 additions and 128 deletions

View File

@@ -1,4 +1,4 @@
using System.Diagnostics.CodeAnalysis;

using System.Net;
using System.Text;
using Microsoft.Win32;
@@ -145,10 +145,11 @@ public static class Export {
};
}
[SuppressMessage("Interoperability", "CA1416:验证平台兼容性")]
#pragma warning disable CA1416
private static bool CheckSnapScheme() {
return (string?)Registry.ClassesRoot.OpenSubKey("snapgenshin")?.GetValue("") == "URL:snapgenshin";
}
#pragma warning restore CA1416
private static string JoinToString(this IEnumerable<object> list, string separator) {
return string.Join(separator, list);

View File

@@ -1,40 +1,28 @@
using System.Collections.Specialized;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Security.Cryptography;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using Newtonsoft.Json;
namespace YaeAchievement;
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
// ReSharper disable MemberCanBePrivate.Global
public static class Extensions {
// ReSharper disable once InconsistentNaming
private static readonly Lazy<Aes> aes = new (Aes.Create);
// ReSharper disable once InconsistentNaming
private static readonly Lazy<MD5> md5 = new (MD5.Create);
// ReSharper disable once InconsistentNaming
private static readonly Lazy<SHA1> sha1 = new (SHA1.Create);
// ReSharper disable once InconsistentNaming
private static readonly Lazy<HttpClient> defaultClient = new (() => new HttpClient(new HttpClientHandler {
Proxy = GlobalVars.DebugProxy ? new WebProxy("http://127.0.0.1:8888") : null
}) {
DefaultRequestHeaders = {{ "User-Agent", "UnityPlayer/2017.4.30f1 (UnityWebRequest/1.0, libcurl/7.51.0-DEV)" }}
});
public static byte[] ToBytes(this string text) {
return Encoding.UTF8.GetBytes(text);
}
public static string DecodeToString(this byte[] bytes) {
return Encoding.UTF8.GetString(bytes);
// ReSharper disable once InconsistentNaming
public static string MD5Hash(this string text) {
return text.ToBytes().MD5Hash();
}
// ReSharper disable once InconsistentNaming
public static string MD5Hash(this string text) {
return md5.Value.ComputeHash(text.ToBytes()).ToHex();
public static string MD5Hash(this byte[] data) {
return md5.Value.ComputeHash(data).ToHex().ToLower();
}
// ReSharper disable once InconsistentNaming
@@ -43,55 +31,6 @@ public static class Extensions {
return base64 ? bytes.ToBase64() : bytes.ToHex();
}
public static HttpResponseMessage Send(this HttpRequestMessage message, HttpClient? client = null) {
Logger.Trace($"{message.Method} {message.RequestUri?.GetFullPath()}");
return (client ?? defaultClient.Value).Send(message); // dispose message?
}
public static T? Send<T>(this HttpRequestMessage message, HttpClient? client = null, Func<string, string>? onPreDeserialize = null) {
Logger.Trace($"{message.Method} {message.RequestUri?.GetFullPath()}");
using var response = (client ?? defaultClient.Value).Send(message);
var text = response.Content.ReadAsStringAsync().Result;
if (onPreDeserialize != null) {
text = onPreDeserialize.Invoke(text);
}
return JsonConvert.DeserializeObject<T>(text);
}
public static string ToQueryString(this NameValueCollection collection, bool escape = true) {
var items = collection.AllKeys
.Select(key => escape ?
$"{HttpUtility.UrlEncode(key)}={HttpUtility.UrlEncode(collection[key])}" :
$"{key}={collection[key]}");
return string.Join("&", items);
}
public static string ToQueryString(this IEnumerable<KeyValuePair<string, object>> dict, bool escape = true) {
var items = dict
.Select(pair => escape ?
$"{HttpUtility.UrlEncode(pair.Key)}={HttpUtility.UrlEncode(pair.Value.ToString())}" :
$"{pair.Key}={pair.Value}");
return string.Join("&", items);
}
public static string ToJsonString<TKey, TValue>(this Dictionary<TKey, TValue> data) where TKey : notnull {
return JsonConvert.SerializeObject(data);
}
public static string GetFullPath(this Uri uri) {
return $"{uri.Scheme}://{uri.Host}{uri.AbsolutePath}";
}
public static IEnumerable<KeyValuePair<string, string>> ToKeyValuePairs(this NameValueCollection collection) {
return collection.AllKeys
.Select(key => new KeyValuePair<string, string>(key!, collection[key] ?? string.Empty))
.ToArray();
}
public static string UrlEncode(this string text) {
return HttpUtility.UrlEncode(text);
}
public static string ToHex(this byte[] bytes) {
return Convert.ToHexString(bytes);
}
@@ -99,8 +38,4 @@ public static class Extensions {
public static string ToBase64(this byte[] bytes) {
return Convert.ToBase64String(bytes);
}
public static byte[] FromBase64(this string text) {
return Convert.FromBase64String(text);
}
}

View File

@@ -1,20 +1,20 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Reflection;
namespace YaeAchievement;
[SuppressMessage("ReSharper", "ConvertToConstant.Global")]
[SuppressMessage("ReSharper", "FieldCanBeMadeReadOnly.Global")]
// ReSharper disable InconsistentNaming
// ReSharper disable ConvertToConstant.Global
// ReSharper disable FieldCanBeMadeReadOnly.Global
#pragma warning disable CA2211
public static class GlobalVars {
public static bool DebugProxy = false;
public static bool CheckGamePath = true;
public static bool UnexpectedExit = true;
public static string GamePath = null!;
public static Logger.Level LogLevel = Logger.Level.Info;
public static Version AppVersion = Assembly.GetEntryAssembly()!.GetName().Version!;
public static readonly string AppPath = AppDomain.CurrentDomain.BaseDirectory;
public const uint AppVersionCode = 28;
public const string AppVersionName = "2.0";
@@ -24,4 +24,3 @@ public static class GlobalVars {
public const string ConfigFileName = "YaeAchievement.runtimeconfig.json";
}
#pragma warning restore CA2211

View File

@@ -1,40 +0,0 @@
namespace YaeAchievement;
public static class Logger {
public enum Level {
Trace, Debug, Info, Warn, Error
}
public static void Error(string msg) {
Log(msg, Level.Error);
}
public static void Warn(string msg) {
Log(msg, Level.Warn);
}
public static void Info(string msg) {
Log(msg, Level.Info);
}
public static void Debug(string msg) {
Log(msg, Level.Debug);
}
public static void Trace(string msg) {
Log(msg, Level.Trace);
}
private static void Log(string msg, Level level) {
if (level >= GlobalVars.LogLevel) {
Console.WriteLine(msg);
}
}
public static void WriteLog(string msg, Level level = Level.Info) {
if (level >= GlobalVars.LogLevel) {
Console.Write($"{DateTime.Now:MM/dd HH:mm:ss} {level.ToString().ToUpper().PadLeft(5)} : {msg}");
}
}
}

View File

@@ -6,7 +6,7 @@ namespace YaeAchievement.Win32;
public static class Extensions {
public static int PrintMsgAndReturnErrCode(this Win32Exception ex, string msg) {
Logger.Error($"{msg}: {ex.Message}");
Console.WriteLine($"{msg}: {ex.Message}");
AppCenter.TrackCrash(ex, false);
return ex.NativeErrorCode;
}

View File

@@ -1,13 +1,13 @@
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using System.Security;
namespace YaeAchievement.Win32;
[SuppressMessage("Interoperability", "CA1401:P/Invokes 应该是不可见的")]
#pragma warning disable CA1401, CA2101
public static class Native {
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool CreateProcess(
string lpApplicationName,
string? lpCommandLine,
@@ -38,7 +38,6 @@ public static class Native {
public static extern IntPtr GetModuleHandle(string lpModuleName);
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
[SuppressMessage("Globalization", "CA2101:指定对 P/Invoke 字符串参数进行封送处理")]
public static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]