diff --git a/SaveWizard_rewritten.csproj b/SaveWizard_rewritten.csproj index 4ecc674..831ef36 100644 --- a/SaveWizard_rewritten.csproj +++ b/SaveWizard_rewritten.csproj @@ -12,6 +12,8 @@ 512 true true + + AnyCPU @@ -33,6 +35,9 @@ 4 + + packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll + @@ -46,6 +51,7 @@ + @@ -65,6 +71,7 @@ True Resources.resx + SettingsSingleFileGenerator Settings.Designer.cs @@ -79,4 +86,11 @@ + + + + Данный проект ссылается на пакеты NuGet, отсутствующие на этом компьютере. Используйте восстановление пакетов NuGet, чтобы скачать их. Дополнительную информацию см. по адресу: http://go.microsoft.com/fwlink/?LinkID=322105. Отсутствует следующий файл: {0}. + + + \ No newline at end of file diff --git a/UpdateHandler.cs b/UpdateHandler.cs new file mode 100644 index 0000000..d6af471 --- /dev/null +++ b/UpdateHandler.cs @@ -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 result = JsonConvert.DeserializeObject>(responseInString); + foreach (KeyValuePair 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); + } + } + } + } + } +} diff --git a/packages.config b/packages.config new file mode 100644 index 0000000..e0db844 --- /dev/null +++ b/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file