diff --git a/SaveWizard_rewritten.csproj b/SaveWizard_rewritten.csproj index 831ef36..4c4e56a 100644 --- a/SaveWizard_rewritten.csproj +++ b/SaveWizard_rewritten.csproj @@ -51,7 +51,12 @@ - + + Form + + + UpdateForm.cs + @@ -62,6 +67,12 @@ + + MainForm.cs + + + UpdateForm.cs + ResXFileCodeGenerator Resources.Designer.cs diff --git a/UpdateForm.Designer.cs b/UpdateForm.Designer.cs new file mode 100644 index 0000000..0224ffd --- /dev/null +++ b/UpdateForm.Designer.cs @@ -0,0 +1,98 @@ +namespace SaveWizard_rewritten +{ + partial class UpdateForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.lbl_downloading = new System.Windows.Forms.Label(); + this.lbl_progress = new System.Windows.Forms.Label(); + this.progressBar1 = new System.Windows.Forms.ProgressBar(); + this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); + this.SuspendLayout(); + // + // lbl_downloading + // + this.lbl_downloading.AutoSize = true; + this.lbl_downloading.Font = new System.Drawing.Font("Calibri", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.lbl_downloading.Location = new System.Drawing.Point(12, 9); + this.lbl_downloading.Name = "lbl_downloading"; + this.lbl_downloading.Size = new System.Drawing.Size(148, 18); + this.lbl_downloading.TabIndex = 0; + this.lbl_downloading.Text = "Downloading configs..."; + // + // lbl_progress + // + this.lbl_progress.AutoSize = true; + this.lbl_progress.Font = new System.Drawing.Font("Calibri", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); + this.lbl_progress.Location = new System.Drawing.Point(166, 9); + this.lbl_progress.Name = "lbl_progress"; + this.lbl_progress.Size = new System.Drawing.Size(28, 18); + this.lbl_progress.TabIndex = 1; + this.lbl_progress.Text = "0/6"; + // + // progressBar1 + // + this.progressBar1.Location = new System.Drawing.Point(12, 34); + this.progressBar1.Maximum = 6; + this.progressBar1.Name = "progressBar1"; + this.progressBar1.Size = new System.Drawing.Size(182, 23); + this.progressBar1.TabIndex = 2; + // + // backgroundWorker1 + // + this.backgroundWorker1.WorkerReportsProgress = true; + this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork); + this.backgroundWorker1.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.backgroundWorker1_ProgressChanged); + this.backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted); + // + // ProgressWindow + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(204, 66); + this.Controls.Add(this.progressBar1); + this.Controls.Add(this.lbl_progress); + this.Controls.Add(this.lbl_downloading); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "ProgressWindow"; + this.Text = "Updating..."; + this.Load += new System.EventHandler(this.ProgressWindow_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label lbl_downloading; + private System.Windows.Forms.Label lbl_progress; + private System.Windows.Forms.ProgressBar progressBar1; + private System.ComponentModel.BackgroundWorker backgroundWorker1; + } +} \ No newline at end of file diff --git a/UpdateHandler.cs b/UpdateForm.cs similarity index 62% rename from UpdateHandler.cs rename to UpdateForm.cs index d6af471..41274a6 100644 --- a/UpdateHandler.cs +++ b/UpdateForm.cs @@ -5,12 +5,18 @@ using System.IO; using System.Net; using System.Text; using System.Text.RegularExpressions; +using System.Windows.Forms; namespace SaveWizard_rewritten { - static class UpdateHandler + public partial class UpdateForm: Form { private static readonly string githubLink = "https://raw.githubusercontent.com/JDM170/SaveWizard/configs/"; + + public UpdateForm() + { + InitializeComponent(); + } private static void CheckPath(string path) { @@ -31,25 +37,44 @@ namespace SaveWizard_rewritten } } - public static void UpdateConfigs() + 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($"{githubLink}configs/version.cfg"); Dictionary result = JsonConvert.DeserializeObject>(responseInString); + string[] splitted; + string path; foreach (KeyValuePair unit in result) { - string[] splitted = Regex.Split(unit.Key, "_"); - string path = $"configs/{splitted.GetValue(0)}/{splitted.GetValue(1)}.json"; + 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($"{githubLink}{path}"); File.WriteAllText(Path.Combine(Environment.CurrentDirectory, path), newConfigText); } + 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) + { + this.Close(); + } } } diff --git a/UpdateForm.resx b/UpdateForm.resx new file mode 100644 index 0000000..59099f2 --- /dev/null +++ b/UpdateForm.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file