Написано обновление конфигов

* Добавлены пакеты: Newtonsoft.Json, ILRepack.Lib.MSBuild.Task

Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
2025-02-20 22:45:01 +07:00
parent 527aae7b40
commit b759ba4a97
3 changed files with 74 additions and 0 deletions

View File

@@ -12,6 +12,8 @@
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
@@ -33,6 +35,9 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
@@ -46,6 +51,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="UpdateHandler.cs" />
<Compile Include="Utils.cs" /> <Compile Include="Utils.cs" />
<Compile Include="RegexHandler.cs" /> <Compile Include="RegexHandler.cs" />
<Compile Include="MainForm.cs"> <Compile Include="MainForm.cs">
@@ -65,6 +71,7 @@
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -79,4 +86,11 @@
<None Include="App.config" /> <None Include="App.config" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="packages\ILRepack.Lib.MSBuild.Task.2.0.37\build\ILRepack.Lib.MSBuild.Task.targets" Condition="Exists('packages\ILRepack.Lib.MSBuild.Task.2.0.37\build\ILRepack.Lib.MSBuild.Task.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>Данный проект ссылается на пакеты NuGet, отсутствующие на этом компьютере. Используйте восстановление пакетов NuGet, чтобы скачать их. Дополнительную информацию см. по адресу: http://go.microsoft.com/fwlink/?LinkID=322105. Отсутствует следующий файл: {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\ILRepack.Lib.MSBuild.Task.2.0.37\build\ILRepack.Lib.MSBuild.Task.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\ILRepack.Lib.MSBuild.Task.2.0.37\build\ILRepack.Lib.MSBuild.Task.targets'))" />
</Target>
</Project> </Project>

55
UpdateHandler.cs Normal file
View File

@@ -0,0 +1,55 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
namespace SaveWizard_rewritten
{
static class UpdateHandler
{
private static readonly string githubLink = "https://raw.githubusercontent.com/JDM170/SaveWizard/configs/";
private static void CheckPath(string path)
{
string currentDirectory = Environment.CurrentDirectory;
foreach (string unit in Regex.Split(path, "/"))
{
currentDirectory = Path.Combine(currentDirectory, unit);
if (!unit.Contains(".json"))
{
if (!Directory.Exists(currentDirectory))
Directory.CreateDirectory(currentDirectory);
}
else
{
if (!File.Exists(currentDirectory))
File.WriteAllText(currentDirectory, "");
}
}
}
public static void UpdateConfigs()
{
using (WebClient wb = new WebClient())
{
wb.Encoding = Encoding.UTF8;
string responseInString = wb.DownloadString($"{githubLink}configs/version.cfg");
Dictionary<string, string> result = JsonConvert.DeserializeObject<Dictionary<string, string>>(responseInString);
foreach (KeyValuePair<string, string> unit in result)
{
string[] splitted = Regex.Split(unit.Key, "_");
string path = $"configs/{splitted.GetValue(0)}/{splitted.GetValue(1)}.json";
CheckPath(path);
if (Utils.GenerateMD5(path) != unit.Value)
{
string newConfigText = wb.DownloadString($"{githubLink}{path}");
File.WriteAllText(Path.Combine(Environment.CurrentDirectory, path), newConfigText);
}
}
}
}
}
}

5
packages.config Normal file
View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ILRepack.Lib.MSBuild.Task" version="2.0.37" targetFramework="net48" developmentDependency="true" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
</packages>