using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Net; using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; namespace SaveWizard { public partial class UpdateForm: Form { private static string repositoryLink = ""; public UpdateForm(string _repositoryLink) { InitializeComponent(); repositoryLink = _repositoryLink; } 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 (!File.Exists(currentDirectory)) File.WriteAllText(currentDirectory, ""); } else { if (!Directory.Exists(currentDirectory)) Directory.CreateDirectory(currentDirectory); } } } private void ProgressWindow_Load(object sender, EventArgs e) { backgroundWorker1.RunWorkerAsync(); } private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { using (WebClient wb = new WebClient()) { wb.Encoding = Encoding.UTF8; string responseInString = wb.DownloadString($"{repositoryLink}version.cfg"); Dictionary result = JsonConvert.DeserializeObject>(responseInString); string[] splitted; string path; foreach (KeyValuePair unit in result) { splitted = Regex.Split(unit.Key, "_"); path = $"configs/{splitted.GetValue(0)}/{splitted.GetValue(1)}.json"; CheckPath(path); if (Utils.GenerateMD5(path) != unit.Value) { string newConfigText = wb.DownloadString($"{repositoryLink}{path.Replace("configs/", "")}"); File.WriteAllText(Path.Combine(Environment.CurrentDirectory, path), newConfigText.Replace("\n", "\r\n")); } backgroundWorker1.ReportProgress(progressBar1.Value + 1); } } } private void backgroundWorker1_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e) { progressBar1.Value = e.ProgressPercentage; lbl_progress.Text = $"{e.ProgressPercentage}/6"; } private void backgroundWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e) { Close(); } } }