bump version to 1.0.4.0, add WeModConfig model for backward compatibility, add feature to enable/disable automatic patch updates

This commit is contained in:
kitbyte
2025-11-06 00:48:35 +02:00
parent 8f14ee2939
commit 54fe538ed9
14 changed files with 281 additions and 105 deletions
+102 -3
View File
@@ -1,4 +1,8 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using WeModPatcher.Utils;
namespace WeModPatcher.Models
{
@@ -16,11 +20,106 @@ namespace WeModPatcher.Models
Runtime = 1,
Static = 2
}
public sealed class PatchConfig
/*public sealed class PatchConfigOld
{
public HashSet<EPatchType> PatchTypes { get; set; }
public EPatchProcessMethod PatchMethod { get; set; }
public string Path { get; set; }
}*/
public sealed class PatchConfig
{
private string _path;
public HashSet<EPatchType> PatchTypes { get; set; }
public EPatchProcessMethod PatchMethod { get; set; }
[JsonProperty("u")]
public bool AutoApplyPatches { get; set; }
[JsonIgnore]
public WeModConfig AppProps { get; private set; }
public string Path
{
get => _path;
set
{
_path = value;
AppProps = Extensions.CheckWeModPath(_path) ?? throw new Exception("Invalid WeMod path");
}
}
/*public static void PushConfig(PatchConfig config)
{
var hash = GetConfigHash(config);
var registry = _getRegistry();
registry[hash] = config;
_stashRegistry(registry);
}
public static void ActualizeRegistry()
{
var registry = _getRegistry();
foreach (var entry in registry)
{
if(Extensions.CheckWeModPath(entry.Value.AppProps.RootDirectory) == null)
{
registry.Remove(entry.Key);
break;
}
}
_stashRegistry(registry);
}
public static PatchConfig GetConfig(string hash)
{
var registry = _getRegistry();
return registry.TryGetValue(hash, out var config) ? config : null;
}
public static string GetConfigHash(PatchConfig config)
{
return Common.ComputeSha256Hash(config.AppProps.ExecutablePath);
}
private static Dictionary<string, PatchConfig> _getRegistry()
{
var currentDir = Common.GetCurrentDir();
var registryPath = Path.Combine(currentDir, Constants.PatchRegistryName);
try
{
return JsonConvert.DeserializeObject<Dictionary<string, PatchConfig>>(
File.ReadAllText(registryPath)
);
}
catch
{
// ignored
}
return new Dictionary<string, PatchConfig>();
}
private static void _stashRegistry(Dictionary<string, PatchConfig> registry)
{
var currentDir = Common.GetCurrentDir();
var registryPath = Path.Combine(currentDir, Constants.PatchRegistryName);
if(registry.Count == 0)
{
if(File.Exists(registryPath))
{
File.Delete(registryPath);
}
return;
}
var json = JsonConvert.SerializeObject(registry, Formatting.Indented);
File.WriteAllText(registryPath, json);
}*/
}
}
+19
View File
@@ -0,0 +1,19 @@
using Newtonsoft.Json;
namespace WeModPatcher.Models
{
public class WeModConfig
{
public string BrandName { get; set; }
public string ExecutableName { get; set; }
public string RootDirectory { get; set; }
[JsonIgnore]
public string ExecutablePath => System.IO.Path.Combine(RootDirectory, ExecutableName);
public override string ToString()
{
return RootDirectory;
}
}
}