Написано обновление конфигов
* Добавлены пакеты: Newtonsoft.Json, ILRepack.Lib.MSBuild.Task Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
55
UpdateHandler.cs
Normal file
55
UpdateHandler.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user