修复老版本vpet(v1.4-)hashcheck失效的错误

This commit is contained in:
ZouJin 2024-02-07 16:46:02 +08:00
parent 8673d05775
commit 22745eb116
3 changed files with 28 additions and 8 deletions

View File

@ -10,7 +10,9 @@ using System.Security.Cryptography;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using VPet_Simulator.Core;
using static System.Net.Mime.MediaTypeNames;
namespace VPet_Simulator.Windows.Interface
{
@ -31,7 +33,7 @@ namespace VPet_Simulator.Windows.Interface
{
if (lps.FindLine("statistics") == null)
{//尝试从老存档加载
Statistics = oldStatistics;
Statistics = oldStatistics ?? new Statistics();
}
else
{
@ -46,8 +48,26 @@ namespace VPet_Simulator.Windows.Interface
hash = vpet.GetInt64("hash");
if (vpet.Remove("hash"))
{
HashCheck = vpet.GetLongHashCode() == hash;
nohashcheck = false;
try
{
using (MD5 md5 = MD5.Create())
{
long hs = BitConverter.ToInt64(md5.ComputeHash(Encoding.UTF8.GetBytes(vpet.Name)), 0)
* 2 + BitConverter.ToInt64(md5.ComputeHash(Encoding.UTF8.GetBytes(vpet.info)), 0)
* 3 + BitConverter.ToInt64(md5.ComputeHash(Encoding.UTF8.GetBytes(vpet.text)), 0) * 4;
foreach (ISub su in vpet.ToList())
{
hs += BitConverter.ToInt64(md5.ComputeHash(Encoding.UTF8.GetBytes(su.Name)), 0) * 2
+ BitConverter.ToInt64(md5.ComputeHash(Encoding.UTF8.GetBytes(su.Info)), 0) * 3;
}
HashCheck = hs == hash;
}
}
catch
{
nohashcheck = true;
}
}
}
else if (oldGameSave != null)

View File

@ -145,7 +145,7 @@ namespace VPet_Simulator.Windows.Interface
/// </summary>
public int BackupSaveMaxNum
{
get => Math.Max(GetInt("bakupsave", 30), 1);
get => Math.Max(GetInt("bakupsave", 50), 1);
set => SetInt("bakupsave", value);
}
/// <summary>

View File

@ -125,10 +125,6 @@
<Resource Include="Res\remixicon.ttf" />
<Resource Include="vpeticon.ico" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VPet-Simulator.Core\VPet-Simulator.Core.csproj" />
<ProjectReference Include="..\VPet-Simulator.Windows.Interface\VPet-Simulator.Windows.Interface.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
@ -242,4 +238,8 @@
<PackageReference Include="Panuon.WPF" Version="1.0.3" />
<PackageReference Include="Panuon.WPF.UI" Version="1.1.16.8" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VPet-Simulator.Core\VPet-Simulator.Core.csproj" />
<ProjectReference Include="..\VPet-Simulator.Windows.Interface\VPet-Simulator.Windows.Interface.csproj" />
</ItemGroup>
</Project>