From 24824799c601117bbb4bb15f87ef49de52eb0f7f Mon Sep 17 00:00:00 2001 From: Lev Rusanov <30170278+JDM170@users.noreply.github.com> Date: Sat, 12 Jul 2025 20:49:20 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Добавлена архитектура сборки x86 * Ссылка на репозиторий с конфигурациями вынесена в конфигурационный файл (update.cfg) * Обновлен механизм создания и взаимодействия с файлом конфигурации (update.cfg) * Добавлена обработка ошибки декодирования файла при попытке его открыть Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com> --- ConfigEditor/ConfigEditor.csproj | 20 ++++++++ SaveWizard/MainForm/MainForm.cs | 76 +++++++++++++++++++++-------- SaveWizard/SaveWizard.csproj | 20 ++++++++ SaveWizard/UpdateForm/UpdateForm.cs | 9 ++-- SaveWizard_rewritten.sln | 10 ++++ 5 files changed, 111 insertions(+), 24 deletions(-) diff --git a/ConfigEditor/ConfigEditor.csproj b/ConfigEditor/ConfigEditor.csproj index a3892a9..940ffdc 100644 --- a/ConfigEditor/ConfigEditor.csproj +++ b/ConfigEditor/ConfigEditor.csproj @@ -32,6 +32,26 @@ prompt 4 + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + 7.3 + prompt + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + 7.3 + prompt + true + diff --git a/SaveWizard/MainForm/MainForm.cs b/SaveWizard/MainForm/MainForm.cs index 75f96e1..5979495 100644 --- a/SaveWizard/MainForm/MainForm.cs +++ b/SaveWizard/MainForm/MainForm.cs @@ -12,9 +12,31 @@ namespace SaveWizard { private readonly string config_file_name = "update.cfg"; + // SIIDEC_RESULT_GENERIC_ERROR = -1; + // SIIDEC_RESULT_SUCCESS = 0; + // SIIDEC_RESULT_FORMAT_PLAINTEXT = 1; + // SIIDEC_RESULT_FORMAT_ENCRYPTED = 2; + // SIIDEC_RESULT_FORMAT_BINARY = 3; + // SIIDEC_RESULT_FORMAT_3NK = 4; + // SIIDEC_RESULT_FORMAT_UNKNOWN = 10; + // SIIDEC_RESULT_TOO_FEW_DATA = 11; + // SIIDEC_RESULT_BUFFER_TOO_SMALL = 12; + + // SIIDEC_RESULT_GENERIC_ERROR - an unhandled exception have occured + // SIIDEC_RESULT_FORMAT_PLAINTEXT - plain-text SII file + // SIIDEC_RESULT_FORMAT_ENCRYPTED - encrypted SII file + // SIIDEC_RESULT_FORMAT_BINARY - binary form of SII file + // SIIDEC_RESULT_FORMAT_3NK - file is an 3nK-encoded SII file + // SIIDEC_RESULT_FORMAT_UNKNOWN - file of an unknown format + // SIIDEC_RESULT_TOO_FEW_DATA - file is too small to contain valid data for its format [DllImport("SII_Decrypt.dll")] public static extern int GetFileFormat(string FileName); + // SIIDEC_RESULT_GENERIC_ERROR - an unhandled exception have occured + // SIIDEC_RESULT_SUCCESS - input file was successfully decrypted and/or decoded and result stored in the output file + // SIIDEC_RESULT_FORMAT_PLAINTEXT - input file contains plain-text SII file (does not need decryption or decoding) + // SIIDEC_RESULT_FORMAT_UNKNOWN - input file is of an uknown format + // SIIDEC_RESULT_TOO_FEW_DATA - input file is too small to contain a valid encrypted or encoded SII file [DllImport("SII_Decrypt.dll")] public static extern int DecryptAndDecodeFile(string InputFile, string OutputFile); @@ -189,31 +211,39 @@ namespace SaveWizard foreach (TextBox txtbox in items.Keys) txtbox.TextChanged += boxTextChanged; txt_adr.TextChanged += boxTextChanged; - Dictionary update_conf = new Dictionary + string config_path = Path.Combine(Environment.CurrentDirectory, config_file_name); + if (File.Exists(config_path)) { - { "update_on_start", false } - }; - string path = Path.Combine(Environment.CurrentDirectory, config_file_name); - if (File.Exists(path)) - update_conf = JsonConvert.DeserializeObject>(File.ReadAllText(path)); - if (update_conf["update_on_start"]) + Dictionary update_conf = JsonConvert.DeserializeObject>(File.ReadAllText(config_path)); + if ((bool)update_conf["update_on_start"]) + { + chk_update_on_start.Checked = true; + UpdateForm window = new UpdateForm((string)update_conf["respository_link"]); + window.ShowDialog(); + window.Focus(); + } + } + else { - chk_update_on_start.Checked = true; - UpdateForm window = new UpdateForm(); - window.ShowDialog(); - window.Focus(); + File.WriteAllText(config_path, + JsonConvert.SerializeObject(new Dictionary + { + { "update_on_start", false }, + { "respository_link", "https://raw.githubusercontent.com/JDM170/SaveWizard_configs/main/" } + } + ) + ); } } private void chk_update_on_start_CheckedChanged(object sender, EventArgs e) { - File.WriteAllText( - Path.Combine(Environment.CurrentDirectory, config_file_name), - JsonConvert.SerializeObject(new Dictionary - { - { "update_on_start", chk_update_on_start.Checked } - }) - ); + string config_path = Path.Combine(Environment.CurrentDirectory, config_file_name); + if (!File.Exists(config_path)) + return; + Dictionary fileData = JsonConvert.DeserializeObject>(File.ReadAllText(config_path)); + fileData["update_on_start"] = chk_update_on_start.Checked; + File.WriteAllText(config_path, JsonConvert.SerializeObject(fileData)); } private void btn_open_save_Click(object sender, EventArgs e) @@ -222,12 +252,18 @@ namespace SaveWizard OpenFileDialog ofd = new OpenFileDialog() { Title = "Выберите файл сохранения", - Filter = "Сохранение в формате SII|game.sii", + Filter = "Файл game.sii|game.sii", Multiselect = false, }; if (ofd.ShowDialog() == DialogResult.OK) { - if (GetFileFormat(ofd.FileName) == 2) + int fileFormat = GetFileFormat(ofd.FileName); + if (fileFormat == -1) + { + Utils.ShowError("The file name cannot contain spaces or special characters."); + return; + } + if (fileFormat >= 2 && fileFormat <= 4) { if (DecryptAndDecodeFile(ofd.FileName, ofd.FileName) != 0) { diff --git a/SaveWizard/SaveWizard.csproj b/SaveWizard/SaveWizard.csproj index 56c609d..a88adca 100644 --- a/SaveWizard/SaveWizard.csproj +++ b/SaveWizard/SaveWizard.csproj @@ -49,6 +49,26 @@ prompt 4 + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + 7.3 + prompt + true + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + 7.3 + prompt + true + $(SolutionDir)\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll diff --git a/SaveWizard/UpdateForm/UpdateForm.cs b/SaveWizard/UpdateForm/UpdateForm.cs index b060ef4..6266486 100644 --- a/SaveWizard/UpdateForm/UpdateForm.cs +++ b/SaveWizard/UpdateForm/UpdateForm.cs @@ -11,11 +11,12 @@ namespace SaveWizard { public partial class UpdateForm: Form { - private static readonly string githubLink = "https://raw.githubusercontent.com/JDM170/SaveWizard_configs/main/"; + private static string repositoryLink = ""; - public UpdateForm() + public UpdateForm(string _repositoryLink) { InitializeComponent(); + repositoryLink = _repositoryLink; } private static void CheckPath(string path) @@ -47,7 +48,7 @@ namespace SaveWizard using (WebClient wb = new WebClient()) { wb.Encoding = Encoding.UTF8; - string responseInString = wb.DownloadString($"{githubLink}version.cfg"); + string responseInString = wb.DownloadString($"{repositoryLink}version.cfg"); Dictionary result = JsonConvert.DeserializeObject>(responseInString); string[] splitted; string path; @@ -58,7 +59,7 @@ namespace SaveWizard CheckPath(path); if (Utils.GenerateMD5(path) != unit.Value) { - string newConfigText = wb.DownloadString($"{githubLink}{path.Replace("configs/", "")}"); + 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); diff --git a/SaveWizard_rewritten.sln b/SaveWizard_rewritten.sln index 920f50c..07da9ba 100644 --- a/SaveWizard_rewritten.sln +++ b/SaveWizard_rewritten.sln @@ -10,17 +10,27 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {0EFCF0E0-4EBC-41A3-9207-0BF27630E397}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {0EFCF0E0-4EBC-41A3-9207-0BF27630E397}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0EFCF0E0-4EBC-41A3-9207-0BF27630E397}.Debug|x86.ActiveCfg = Debug|x86 + {0EFCF0E0-4EBC-41A3-9207-0BF27630E397}.Debug|x86.Build.0 = Debug|x86 {0EFCF0E0-4EBC-41A3-9207-0BF27630E397}.Release|Any CPU.ActiveCfg = Release|Any CPU {0EFCF0E0-4EBC-41A3-9207-0BF27630E397}.Release|Any CPU.Build.0 = Release|Any CPU + {0EFCF0E0-4EBC-41A3-9207-0BF27630E397}.Release|x86.ActiveCfg = Release|x86 + {0EFCF0E0-4EBC-41A3-9207-0BF27630E397}.Release|x86.Build.0 = Release|x86 {A08C24B5-43A9-4E0B-8C5C-0AB019CBAFE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A08C24B5-43A9-4E0B-8C5C-0AB019CBAFE8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A08C24B5-43A9-4E0B-8C5C-0AB019CBAFE8}.Debug|x86.ActiveCfg = Debug|x86 + {A08C24B5-43A9-4E0B-8C5C-0AB019CBAFE8}.Debug|x86.Build.0 = Debug|x86 {A08C24B5-43A9-4E0B-8C5C-0AB019CBAFE8}.Release|Any CPU.ActiveCfg = Release|Any CPU {A08C24B5-43A9-4E0B-8C5C-0AB019CBAFE8}.Release|Any CPU.Build.0 = Release|Any CPU + {A08C24B5-43A9-4E0B-8C5C-0AB019CBAFE8}.Release|x86.ActiveCfg = Release|x86 + {A08C24B5-43A9-4E0B-8C5C-0AB019CBAFE8}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE