mirror of
https://github.com/babalae/better-genshin-impact.git
synced 2026-05-07 00:15:53 +08:00
87 lines
2.6 KiB
C#
87 lines
2.6 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
using Semver;
|
|
|
|
namespace BetterGenshinImpact.Core.Config;
|
|
|
|
public class Global
|
|
{
|
|
public static string Version { get; } = Assembly.GetEntryAssembly()?.
|
|
GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.
|
|
InformationalVersion!;
|
|
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新获取到的版本号与当前版本号比较,判断是否为新版本
|
|
/// </summary>
|
|
/// <param name="currentVersion">新获取到的版本</param>
|
|
/// <returns></returns>
|
|
public static bool IsNewVersion(string currentVersion)
|
|
{
|
|
return IsNewVersion(Version, currentVersion);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 新获取到的版本号与当前版本号比较,判断是否为新版本
|
|
/// </summary>
|
|
/// <param name="oldVersion">老版本</param>
|
|
/// <param name="currentVersion">新获取到的版本</param>
|
|
/// <returns>是否需要更新</returns>
|
|
public static bool IsNewVersion(string oldVersion, string currentVersion)
|
|
{
|
|
try
|
|
{
|
|
var oldVersionX = SemVersion.Parse(oldVersion);
|
|
var currentVersionX = SemVersion.Parse(currentVersion);
|
|
|
|
if (currentVersionX.CompareSortOrderTo(oldVersionX) > 0)
|
|
// 需要更新
|
|
return true;
|
|
}
|
|
catch
|
|
{
|
|
///
|
|
}
|
|
|
|
// 不需要更新
|
|
return false;
|
|
}
|
|
|
|
public static void WriteAllText(string relativePath, string blackListJson)
|
|
{
|
|
var path = Absolute(relativePath);
|
|
File.WriteAllText(path, blackListJson);
|
|
}
|
|
}
|