Обновление

* Добавлена архитектура сборки x86
* Ссылка на репозиторий с конфигурациями вынесена в конфигурационный файл (update.cfg)
* Обновлен механизм создания и взаимодействия с файлом конфигурации (update.cfg)
* Добавлена обработка ошибки декодирования файла при попытке его открыть

Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
2025-07-12 20:49:20 +07:00
parent b4e011e377
commit 24824799c6
5 changed files with 111 additions and 24 deletions

View File

@@ -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<string, bool> update_conf = new Dictionary<string, bool>
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<Dictionary<string, bool>>(File.ReadAllText(path));
if (update_conf["update_on_start"])
Dictionary<string, object> update_conf = JsonConvert.DeserializeObject<Dictionary<string, object>>(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<string, object>
{
{ "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<string, bool>
{
{ "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<string, object> fileData = JsonConvert.DeserializeObject<Dictionary<string, object>>(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)
{