修复备份读取顺序问题 Fix #192

This commit is contained in:
ZouJin 2023-09-10 21:52:02 +08:00
parent 1c8420d139
commit 5549edf8b1
4 changed files with 26 additions and 5 deletions

View File

@ -121,9 +121,18 @@ namespace VPet_Simulator.Windows
var name = lps.First().Info;
var p = mw.Pets.FirstOrDefault(x => x.Name == name);
if (p == null)
mw.Pets.Add(new PetLoader(lps, di));
{
p = new PetLoader(lps, di);
if (p.Config.Works.Count > 0)
Tag.Add("work");
mw.Pets.Add(p);
}
else
{
if (lps.FindAllLine("work").Length >= 0)
{
}
p.path.Add(di.FullName + "\\" + lps.First()["path"].Info);
p.Config.Set(lps);
}

View File

@ -7,6 +7,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
@ -180,7 +181,12 @@ namespace VPet_Simulator.Windows
if (Core != null && Core.Save != null)
{
var ds = new List<string>(Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + @"\BackUP"));
var ds = new List<string>(Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + @"\BackUP", "*.lps")).FindAll(x => x.Contains('_')).OrderBy(x =>
{
if (int.TryParse(x.Split('_')[1], out int i))
return i;
return 0;
}).ToList();
while (ds.Count > Set.BackupSaveMaxNum)
{
File.Delete(ds[0]);

View File

@ -235,13 +235,18 @@ namespace VPet_Simulator.Windows
{
if (Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\BackUP"))
{
var latestsave = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + @"\BackUP")
.GetFiles("*.lps").OrderByDescending(x => x.LastWriteTime).FirstOrDefault();
var ds = new List<string>(Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + @"\BackUP", "*.lps")).FindAll(x => x.Contains('_')).OrderBy(x =>
{
if (int.TryParse(x.Split('_')[1], out int i))
return i;
return 0;
}).ToList();
var latestsave = ds.LastOrDefault();
if (latestsave != null)
{
try
{
if (GameLoad(new Line(File.ReadAllText(latestsave.FullName))))
if (GameLoad(new Line(File.ReadAllText(latestsave))))
return;
MessageBoxX.Show("存档损毁,无法加载该存档\n可能是上次储存出错或Steam云同步导致的\n请在设置中加载备份还原存档", "存档损毁".Translate());
}

View File

@ -0,0 +1 @@
D:/Documents/Visual Studio 2022/Projects/VPet.ModMaker/0001_ModMaker