Skip to content

Commit

Permalink
When updating the bin folder, skip the file if it already exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Jan 17, 2025
1 parent 171132b commit cf1a859
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
30 changes: 13 additions & 17 deletions v2rayN/AmazTool/UpgradeApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static void Upgrade(string fileName)
{
Console.WriteLine($"{Resx.Resource.StartUnzipping}\n{fileName}");

Waiting(5);
Utils.Waiting(5);

if (!File.Exists(fileName))
{
Expand Down Expand Up @@ -42,12 +42,12 @@ public static void Upgrade(string fileName)
StringBuilder sb = new();
try
{
string thisAppOldFile = $"{Utils.GetExePath()}.tmp";
var thisAppOldFile = $"{Utils.GetExePath()}.tmp";
File.Delete(thisAppOldFile);
string splitKey = "/";
var splitKey = "/";

using ZipArchive archive = ZipFile.OpenRead(fileName);
foreach (ZipArchiveEntry entry in archive.Entries)
using var archive = ZipFile.OpenRead(fileName);
foreach (var entry in archive.Entries)
{
try
{
Expand All @@ -60,15 +60,20 @@ public static void Upgrade(string fileName)

var lst = entry.FullName.Split(splitKey);
if (lst.Length == 1) continue;
string fullName = string.Join(splitKey, lst[1..lst.Length]);
var fullName = string.Join(splitKey, lst[1..lst.Length]);

if (string.Equals(Utils.GetExePath(), Utils.GetPath(fullName), StringComparison.OrdinalIgnoreCase))
{
File.Move(Utils.GetExePath(), thisAppOldFile);
}

string entryOutputPath = Utils.GetPath(fullName);
var entryOutputPath = Utils.GetPath(fullName);
Directory.CreateDirectory(Path.GetDirectoryName(entryOutputPath)!);
//In the bin folder, if the file already exists, it will be skipped
if (fullName.StartsWith("bin") && File.Exists(entryOutputPath))
{
continue;
}
entry.ExtractToFile(entryOutputPath, true);

Console.WriteLine(entryOutputPath);
Expand All @@ -91,18 +96,9 @@ public static void Upgrade(string fileName)
}

Console.WriteLine(Resx.Resource.Restartv2rayN);
Waiting(2);
Utils.Waiting(2);

Utils.StartV2RayN();
}

public static void Waiting(int second)
{
for (var i = second; i > 0; i--)
{
Console.WriteLine(i);
Thread.Sleep(1000);
}
}
}
}
9 changes: 9 additions & 0 deletions v2rayN/AmazTool/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,14 @@ public static void StartV2RayN()
};
process.Start();
}

public static void Waiting(int second)
{
for (var i = second; i > 0; i--)
{
Console.WriteLine(i);
Thread.Sleep(1000);
}
}
}
}

0 comments on commit cf1a859

Please sign in to comment.