Skip to content

Commit cf1a859

Browse files
committed
When updating the bin folder, skip the file if it already exists.
#6515
1 parent 171132b commit cf1a859

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

v2rayN/AmazTool/UpgradeApp.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static void Upgrade(string fileName)
1010
{
1111
Console.WriteLine($"{Resx.Resource.StartUnzipping}\n{fileName}");
1212

13-
Waiting(5);
13+
Utils.Waiting(5);
1414

1515
if (!File.Exists(fileName))
1616
{
@@ -42,12 +42,12 @@ public static void Upgrade(string fileName)
4242
StringBuilder sb = new();
4343
try
4444
{
45-
string thisAppOldFile = $"{Utils.GetExePath()}.tmp";
45+
var thisAppOldFile = $"{Utils.GetExePath()}.tmp";
4646
File.Delete(thisAppOldFile);
47-
string splitKey = "/";
47+
var splitKey = "/";
4848

49-
using ZipArchive archive = ZipFile.OpenRead(fileName);
50-
foreach (ZipArchiveEntry entry in archive.Entries)
49+
using var archive = ZipFile.OpenRead(fileName);
50+
foreach (var entry in archive.Entries)
5151
{
5252
try
5353
{
@@ -60,15 +60,20 @@ public static void Upgrade(string fileName)
6060

6161
var lst = entry.FullName.Split(splitKey);
6262
if (lst.Length == 1) continue;
63-
string fullName = string.Join(splitKey, lst[1..lst.Length]);
63+
var fullName = string.Join(splitKey, lst[1..lst.Length]);
6464

6565
if (string.Equals(Utils.GetExePath(), Utils.GetPath(fullName), StringComparison.OrdinalIgnoreCase))
6666
{
6767
File.Move(Utils.GetExePath(), thisAppOldFile);
6868
}
6969

70-
string entryOutputPath = Utils.GetPath(fullName);
70+
var entryOutputPath = Utils.GetPath(fullName);
7171
Directory.CreateDirectory(Path.GetDirectoryName(entryOutputPath)!);
72+
//In the bin folder, if the file already exists, it will be skipped
73+
if (fullName.StartsWith("bin") && File.Exists(entryOutputPath))
74+
{
75+
continue;
76+
}
7277
entry.ExtractToFile(entryOutputPath, true);
7378

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

9398
Console.WriteLine(Resx.Resource.Restartv2rayN);
94-
Waiting(2);
99+
Utils.Waiting(2);
95100

96101
Utils.StartV2RayN();
97102
}
98-
99-
public static void Waiting(int second)
100-
{
101-
for (var i = second; i > 0; i--)
102-
{
103-
Console.WriteLine(i);
104-
Thread.Sleep(1000);
105-
}
106-
}
107103
}
108104
}

v2rayN/AmazTool/Utils.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,14 @@ public static void StartV2RayN()
3939
};
4040
process.Start();
4141
}
42+
43+
public static void Waiting(int second)
44+
{
45+
for (var i = second; i > 0; i--)
46+
{
47+
Console.WriteLine(i);
48+
Thread.Sleep(1000);
49+
}
50+
}
4251
}
4352
}

0 commit comments

Comments
 (0)