* Добавлены пакеты: Newtonsoft.Json, ILRepack.Lib.MSBuild.Task Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
56 lines
2.0 KiB
C#
56 lines
2.0 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace SaveWizard_rewritten
|
|
{
|
|
static class UpdateHandler
|
|
{
|
|
private static readonly string githubLink = "https://raw.githubusercontent.com/JDM170/SaveWizard/configs/";
|
|
|
|
private static void CheckPath(string path)
|
|
{
|
|
string currentDirectory = Environment.CurrentDirectory;
|
|
foreach (string unit in Regex.Split(path, "/"))
|
|
{
|
|
currentDirectory = Path.Combine(currentDirectory, unit);
|
|
if (!unit.Contains(".json"))
|
|
{
|
|
if (!Directory.Exists(currentDirectory))
|
|
Directory.CreateDirectory(currentDirectory);
|
|
}
|
|
else
|
|
{
|
|
if (!File.Exists(currentDirectory))
|
|
File.WriteAllText(currentDirectory, "");
|
|
}
|
|
}
|
|
}
|
|
|
|
public static void UpdateConfigs()
|
|
{
|
|
using (WebClient wb = new WebClient())
|
|
{
|
|
wb.Encoding = Encoding.UTF8;
|
|
string responseInString = wb.DownloadString($"{githubLink}configs/version.cfg");
|
|
Dictionary<string, string> result = JsonConvert.DeserializeObject<Dictionary<string, string>>(responseInString);
|
|
foreach (KeyValuePair<string, string> unit in result)
|
|
{
|
|
string[] splitted = Regex.Split(unit.Key, "_");
|
|
string path = $"configs/{splitted.GetValue(0)}/{splitted.GetValue(1)}.json";
|
|
CheckPath(path);
|
|
if (Utils.GenerateMD5(path) != unit.Value)
|
|
{
|
|
string newConfigText = wb.DownloadString($"{githubLink}{path}");
|
|
File.WriteAllText(Path.Combine(Environment.CurrentDirectory, path), newConfigText);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|