Обновление

* Реализовано сохранение и восстановление бекапа
* Обновлен RegexHandler

Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
2025-02-27 22:18:41 +07:00
parent ec5f1f6e46
commit e633408665
3 changed files with 51 additions and 16 deletions

12
MainForm.Designer.cs generated
View File

@@ -487,7 +487,7 @@
this.btn_unlock_garages.Font = new System.Drawing.Font("Calibri", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.btn_unlock_garages.Font = new System.Drawing.Font("Calibri", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.btn_unlock_garages.Location = new System.Drawing.Point(12, 458); this.btn_unlock_garages.Location = new System.Drawing.Point(12, 458);
this.btn_unlock_garages.Name = "btn_unlock_garages"; this.btn_unlock_garages.Name = "btn_unlock_garages";
this.btn_unlock_garages.Size = new System.Drawing.Size(115, 34); this.btn_unlock_garages.Size = new System.Drawing.Size(105, 34);
this.btn_unlock_garages.TabIndex = 20; this.btn_unlock_garages.TabIndex = 20;
this.btn_unlock_garages.Text = "Unlock garages"; this.btn_unlock_garages.Text = "Unlock garages";
this.btn_unlock_garages.UseVisualStyleBackColor = true; this.btn_unlock_garages.UseVisualStyleBackColor = true;
@@ -496,23 +496,25 @@
// //
this.btn_recover_backup.Enabled = false; this.btn_recover_backup.Enabled = false;
this.btn_recover_backup.Font = new System.Drawing.Font("Calibri", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.btn_recover_backup.Font = new System.Drawing.Font("Calibri", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.btn_recover_backup.Location = new System.Drawing.Point(133, 458); this.btn_recover_backup.Location = new System.Drawing.Point(131, 458);
this.btn_recover_backup.Name = "btn_recover_backup"; this.btn_recover_backup.Name = "btn_recover_backup";
this.btn_recover_backup.Size = new System.Drawing.Size(116, 34); this.btn_recover_backup.Size = new System.Drawing.Size(105, 34);
this.btn_recover_backup.TabIndex = 21; this.btn_recover_backup.TabIndex = 21;
this.btn_recover_backup.Text = "Recover backup"; this.btn_recover_backup.Text = "Recover backup";
this.btn_recover_backup.UseVisualStyleBackColor = true; this.btn_recover_backup.UseVisualStyleBackColor = true;
this.btn_recover_backup.Click += new System.EventHandler(this.btn_recover_backup_Click);
// //
// btn_apply_changes // btn_apply_changes
// //
this.btn_apply_changes.Enabled = false; this.btn_apply_changes.Enabled = false;
this.btn_apply_changes.Font = new System.Drawing.Font("Calibri", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); this.btn_apply_changes.Font = new System.Drawing.Font("Calibri", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.btn_apply_changes.Location = new System.Drawing.Point(254, 458); this.btn_apply_changes.Location = new System.Drawing.Point(250, 458);
this.btn_apply_changes.Name = "btn_apply_changes"; this.btn_apply_changes.Name = "btn_apply_changes";
this.btn_apply_changes.Size = new System.Drawing.Size(101, 34); this.btn_apply_changes.Size = new System.Drawing.Size(105, 34);
this.btn_apply_changes.TabIndex = 22; this.btn_apply_changes.TabIndex = 22;
this.btn_apply_changes.Text = "Apply changes"; this.btn_apply_changes.Text = "Apply changes";
this.btn_apply_changes.UseVisualStyleBackColor = true; this.btn_apply_changes.UseVisualStyleBackColor = true;
this.btn_apply_changes.Click += new System.EventHandler(this.btn_apply_changes_Click);
// //
// MainForm // MainForm
// //

View File

@@ -4,7 +4,6 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Windows.Forms; using System.Windows.Forms;
namespace SaveWizard_rewritten namespace SaveWizard_rewritten
@@ -40,8 +39,8 @@ namespace SaveWizard_rewritten
private class WindowText private class WindowText
{ {
private CheckBox Check { get; set; } private readonly CheckBox Check;
private string Str { get; set; } private readonly string Str;
public WindowText(CheckBox _check, string _str) public WindowText(CheckBox _check, string _str)
{ {
@@ -80,11 +79,13 @@ namespace SaveWizard_rewritten
private void GetFileData(string filename) private void GetFileData(string filename)
{ {
string file_data = File.ReadAllText(filename); RegexHandler.FillLines(File.ReadAllLines(filename).ToList());
RegexHandler.FillLines(Regex.Split(file_data, "\n").ToList());
foreach (KeyValuePair<TextBox, WindowText> item in items) foreach (KeyValuePair<TextBox, WindowText> item in items)
{
item.Key.Text = RegexHandler.GetValue(RegexHandler.SearchLine(item.Value.GetString())); item.Key.Text = RegexHandler.GetValue(RegexHandler.SearchLine(item.Value.GetString()));
item.Value.GetCheck().Checked = true;
}
if (RegexHandler.SearchLine("company.volatile.stokes.calais") != 0) if (RegexHandler.SearchLine("company.volatile.stokes.calais") != 0)
selected_game = "ets2"; selected_game = "ets2";
@@ -216,5 +217,30 @@ namespace SaveWizard_rewritten
opened_file_path = ofd.FileName; opened_file_path = ofd.FileName;
} }
} }
private void btn_recover_backup_Click(object sender, EventArgs e)
{
string backup_path = opened_file_path + ".swbak";
if (!File.Exists(backup_path))
{
MessageBox.Show("Backup not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
File.WriteAllLines(opened_file_path, File.ReadAllLines(backup_path));
File.Delete(backup_path);
MessageBox.Show("Backup successfully recovered.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
GetFileData(opened_file_path);
}
private void btn_apply_changes_Click(object sender, EventArgs e)
{
foreach (KeyValuePair<TextBox, WindowText> item in items)
if (!item.Value.GetCheck().Checked)
RegexHandler.SetValue(RegexHandler.SearchLine(item.Value.GetString()), item.Key.Text);
File.WriteAllLines(opened_file_path + ".swbak", RegexHandler.GetBackup());
File.WriteAllLines(opened_file_path, RegexHandler.GetAllLines());
MessageBox.Show("Changes successfully applied.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
GetFileData(opened_file_path);
}
} }
} }

View File

@@ -7,10 +7,16 @@ namespace SaveWizard_rewritten
static class RegexHandler static class RegexHandler
{ {
private static List<string> lines; private static List<string> lines;
private static List<string> backup;
public static void FillLines(List<string> _lines) public static void FillLines(List<string> _lines)
{ {
lines = _lines; if (_lines == null)
return;
lines = new List<string>();
lines.AddRange(_lines);
backup = new List<string>();
backup.AddRange(_lines);
} }
public static string GetLine(int index) public static string GetLine(int index)
@@ -23,6 +29,11 @@ namespace SaveWizard_rewritten
return lines; return lines;
} }
public static List<string> GetBackup()
{
return backup;
}
public static int SearchLine(string term, int start = 0, string cancel = "this_string_must_not_exist") public static int SearchLine(string term, int start = 0, string cancel = "this_string_must_not_exist")
{ {
if (lines[start].Contains(term)) if (lines[start].Contains(term))
@@ -64,7 +75,6 @@ namespace SaveWizard_rewritten
public static void SetValue(int line, string value) public static void SetValue(int line, string value)
{ {
//string name = Regex.Match(lines[line], "(.+):").Value;
string name = Regex.Match(lines[line], "(.+):").Groups[1].ToString(); string name = Regex.Match(lines[line], "(.+):").Groups[1].ToString();
lines[line] = $"{name}: {value}"; lines[line] = $"{name}: {value}";
} }
@@ -76,7 +86,6 @@ namespace SaveWizard_rewritten
public static int GetArrayLength(int line) public static int GetArrayLength(int line)
{ {
//return Convert.ToInt32(Regex.Match(lines[line], ": ([0-9]+)$").Value);
return Convert.ToInt32(GetValue(line)); return Convert.ToInt32(GetValue(line));
} }
@@ -101,7 +110,6 @@ namespace SaveWizard_rewritten
{ {
List<string> items = new List<string>(); List<string> items = new List<string>();
for (int i = 0; i < GetArrayLength(line); i++) for (int i = 0; i < GetArrayLength(line); i++)
//items.Add(Regex.Match(lines[line + i + 1], ": (.+)$").Value);
items.Add(Regex.Match(lines[line + i + 1], ": (.+)$").Groups[1].ToString()); items.Add(Regex.Match(lines[line + i + 1], ": (.+)$").Groups[1].ToString());
if (items.Count == 0) if (items.Count == 0)
return null; return null;
@@ -110,7 +118,6 @@ namespace SaveWizard_rewritten
public static void AddArrayValue(int line, string value) public static void AddArrayValue(int line, string value)
{ {
//string name = Regex.Match(lines[line], "(.+):").Value;
string name = Regex.Match(lines[line], "(.+):").Groups[1].ToString(); string name = Regex.Match(lines[line], "(.+):").Groups[1].ToString();
int length = GetArrayLength(line); int length = GetArrayLength(line);
lines[line] = $"{name}: {length + 1}"; lines[line] = $"{name}: {length + 1}";