Добавлена форма обновления конфигов

Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
2025-02-23 18:57:13 +07:00
parent b33ea983bb
commit 704103721f
4 changed files with 262 additions and 5 deletions

View File

@@ -51,7 +51,12 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="UpdateHandler.cs" /> <Compile Include="UpdateForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UpdateForm.Designer.cs">
<DependentUpon>UpdateForm.cs</DependentUpon>
</Compile>
<Compile Include="Utils.cs" /> <Compile Include="Utils.cs" />
<Compile Include="RegexHandler.cs" /> <Compile Include="RegexHandler.cs" />
<Compile Include="MainForm.cs"> <Compile Include="MainForm.cs">
@@ -62,6 +67,12 @@
</Compile> </Compile>
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UpdateForm.resx">
<DependentUpon>UpdateForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>

98
UpdateForm.Designer.cs generated Normal file
View File

@@ -0,0 +1,98 @@
namespace SaveWizard_rewritten
{
partial class UpdateForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@@ -5,12 +5,18 @@ using System.IO;
using System.Net; using System.Net;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace SaveWizard_rewritten namespace SaveWizard_rewritten
{ {
static class UpdateHandler public partial class UpdateForm: Form
{ {
private static readonly string githubLink = "https://raw.githubusercontent.com/JDM170/SaveWizard/configs/"; private static readonly string githubLink = "https://raw.githubusercontent.com/JDM170/SaveWizard/configs/";
public UpdateForm()
{
InitializeComponent();
}
private static void CheckPath(string path) 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()) using (WebClient wb = new WebClient())
{ {
wb.Encoding = Encoding.UTF8; wb.Encoding = Encoding.UTF8;
string responseInString = wb.DownloadString($"{githubLink}configs/version.cfg"); string responseInString = wb.DownloadString($"{githubLink}configs/version.cfg");
Dictionary<string, string> result = JsonConvert.DeserializeObject<Dictionary<string, string>>(responseInString); Dictionary<string, string> result = JsonConvert.DeserializeObject<Dictionary<string, string>>(responseInString);
string[] splitted;
string path;
foreach (KeyValuePair<string, string> unit in result) foreach (KeyValuePair<string, string> unit in result)
{ {
string[] splitted = Regex.Split(unit.Key, "_"); splitted = Regex.Split(unit.Key, "_");
string path = $"configs/{splitted.GetValue(0)}/{splitted.GetValue(1)}.json"; path = $"configs/{splitted.GetValue(0)}/{splitted.GetValue(1)}.json";
CheckPath(path); CheckPath(path);
if (Utils.GenerateMD5(path) != unit.Value) if (Utils.GenerateMD5(path) != unit.Value)
{ {
string newConfigText = wb.DownloadString($"{githubLink}{path}"); string newConfigText = wb.DownloadString($"{githubLink}{path}");
File.WriteAllText(Path.Combine(Environment.CurrentDirectory, path), newConfigText); 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();
}
} }
} }

123
UpdateForm.resx Normal file
View File

@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="backgroundWorker1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>