using System; using System.IO; using System.Reflection; using System.Text.Json; using System.Text.Json.Serialization; namespace BetterGenshinImpact.Core.Config; public class Global { public static string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version!.ToString(3); public static string StartUpPath { get; set; } = AppContext.BaseDirectory; public static readonly JsonSerializerOptions ManifestJsonOptions = new() { NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals, Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping, PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower, WriteIndented = true, AllowTrailingCommas = true, ReadCommentHandling = JsonCommentHandling.Skip, }; public static string Absolute(string relativePath) { return Path.Combine(StartUpPath, relativePath); } public static string ScriptPath() { return Absolute("User\\JsScript"); } public static string? ReadAllTextIfExist(string relativePath) { var path = Absolute(relativePath); if (File.Exists(path)) return File.ReadAllText(path); return null; } /// /// 新获取到的版本号与当前版本号比较,判断是否为新版本 /// /// 新获取到的版本 /// public static bool IsNewVersion(string currentVersion) { return IsNewVersion(Version, currentVersion); } /// /// 新获取到的版本号与当前版本号比较,判断是否为新版本 /// /// 老版本 /// 新获取到的版本 /// 是否需要更新 public static bool IsNewVersion(string oldVersion, string currentVersion) { try { Version oldVersionX = new(oldVersion); Version currentVersionX = new(currentVersion); if (currentVersionX > oldVersionX) // 需要更新 return true; } catch { /// } // 不需要更新 return false; } public static void WriteAllText(string relativePath, string blackListJson) { var path = Absolute(relativePath); File.WriteAllText(path, blackListJson); } }