Обновление

* Добавлена архитектура сборки 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

@@ -32,6 +32,26 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />

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)
{

View File

@@ -49,6 +49,26 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>$(SolutionDir)\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>

View File

@@ -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<string, string> result = JsonConvert.DeserializeObject<Dictionary<string, string>>(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);

View File

@@ -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