mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-17 10:00:44 +08:00
fix: 修复更新报错无法访问.old
This commit is contained in:
@@ -223,6 +223,28 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
return false;
|
||||
}
|
||||
|
||||
static void DeleteFileWithBackup(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(filePath);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
int index = 0;
|
||||
string currentDate = DateTime.Now.ToString("yyyyMMddHHmm");
|
||||
string backupFilePath = $"{filePath}.{currentDate}.{index}";
|
||||
|
||||
while (File.Exists(backupFilePath))
|
||||
{
|
||||
index++;
|
||||
backupFilePath = $"{filePath}.{currentDate}.{index}";
|
||||
}
|
||||
|
||||
File.Move(filePath, backupFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
string removeListFile = Path.Combine(extractDir, "removelist.txt");
|
||||
if (File.Exists(removeListFile))
|
||||
{
|
||||
@@ -235,7 +257,7 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
string moveTo = Path.Combine(oldFileDir, file);
|
||||
if (File.Exists(moveTo))
|
||||
{
|
||||
File.Delete(moveTo);
|
||||
DeleteFileWithBackup(moveTo);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -258,7 +280,7 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
foreach (var file in Directory.GetFiles(extractDir, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
var fileName = Path.GetFileName(file);
|
||||
if (fileName == "removelist.txt" || fileName == "filelist.txt")
|
||||
if (fileName == "removelist.txt")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -269,7 +291,7 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
string moveTo = file.Replace(extractDir, oldFileDir);
|
||||
if (File.Exists(moveTo))
|
||||
{
|
||||
File.Delete(moveTo);
|
||||
DeleteFileWithBackup(moveTo);
|
||||
}
|
||||
|
||||
File.Move(curFileName, moveTo);
|
||||
@@ -278,18 +300,6 @@ namespace MaaWpfGui.ViewModels.UI
|
||||
File.Move(file, curFileName);
|
||||
}
|
||||
|
||||
foreach (var oldFile in Directory.GetFiles(curDir, "*.old"))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(oldFile);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
File.Move(oldFile, oldFile + ".old");
|
||||
}
|
||||
}
|
||||
|
||||
// 操作完了,把解压的文件删了
|
||||
Directory.Delete(extractDir, true);
|
||||
File.Delete(UpdatePackageName);
|
||||
|
||||
Reference in New Issue
Block a user