mirror of
				https://github.com/2dust/v2rayN.git
				synced 2025-10-27 10:40:08 +00:00 
			
		
		
		
	Compare commits
	
		
			3 commits
		
	
	
		
			859299c712
			...
			78fde575d7
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 78fde575d7 | ||
|   | 6e5af34877 | ||
|   | 8d1853e991 | 
					 5 changed files with 89 additions and 115 deletions
				
			
		|  | @ -7,33 +7,20 @@ namespace AmazTool | ||||||
|         { |         { | ||||||
|             if (args.Length == 0) |             if (args.Length == 0) | ||||||
|             { |             { | ||||||
|                 Utils.WriteLine(Resx.Resource.Guidelines); |                 Console.WriteLine(Resx.Resource.Guidelines); | ||||||
|                 Utils.Waiting(5); |                 Thread.Sleep(5000); | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             var argData = Uri.UnescapeDataString(string.Join(" ", args)); |             var argData = Uri.UnescapeDataString(string.Join(" ", args)); | ||||||
|             if (argData.Equals("rebootas")) |             if (argData.Equals("rebootas")) | ||||||
|             { |             { | ||||||
|                 Utils.Waiting(1); |                 Thread.Sleep(1000); | ||||||
|                 Utils.StartV2RayN(); |                 Utils.StartV2RayN(); | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             var tryTimes = 0; |             UpgradeApp.Upgrade(argData); | ||||||
|             UpgradeApp.Init(); |  | ||||||
|             while (tryTimes++ < 3) |  | ||||||
|             { |  | ||||||
|                 if (!UpgradeApp.Upgrade(argData)) |  | ||||||
|                 { |  | ||||||
|                     continue; |  | ||||||
|                 } |  | ||||||
| 
 |  | ||||||
|                 Utils.WriteLine(Resx.Resource.Restartv2rayN); |  | ||||||
|                 Utils.Waiting(3); |  | ||||||
|                 Utils.StartV2RayN(); |  | ||||||
|                 break; |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -6,99 +6,19 @@ namespace AmazTool | ||||||
| { | { | ||||||
|     internal class UpgradeApp |     internal class UpgradeApp | ||||||
|     { |     { | ||||||
|         public static bool Upgrade(string fileName) |         public static void Upgrade(string fileName) | ||||||
|         { |         { | ||||||
|             Utils.WriteLine($"{Resx.Resource.StartUnzipping}\n{fileName}"); |             Console.WriteLine($"{Resx.Resource.StartUnzipping}\n{fileName}"); | ||||||
| 
 |  | ||||||
|             if (!File.Exists(fileName)) |  | ||||||
|             { |  | ||||||
|                 Utils.WriteLine(Resx.Resource.UpgradeFileNotFound); |  | ||||||
|                 return false; |  | ||||||
|             } |  | ||||||
| 
 | 
 | ||||||
|             Utils.Waiting(5); |             Utils.Waiting(5); | ||||||
| 
 | 
 | ||||||
|             KillV2rayN(); |             if (!File.Exists(fileName)) | ||||||
| 
 |  | ||||||
|             Utils.WriteLine(Resx.Resource.StartUnzipping); |  | ||||||
|             StringBuilder sb = new(); |  | ||||||
|             try |  | ||||||
|             { |             { | ||||||
|                 var splitKey = "/"; |                 Console.WriteLine(Resx.Resource.UpgradeFileNotFound); | ||||||
| 
 |                 return; | ||||||
|                 using var archive = ZipFile.OpenRead(fileName); |  | ||||||
|                 foreach (var entry in archive.Entries) |  | ||||||
|                 { |  | ||||||
|                     try |  | ||||||
|                     { |  | ||||||
|                         if (entry.Length == 0) |  | ||||||
|                         { |  | ||||||
|                             continue; |  | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|                         Utils.WriteLine(entry.FullName); |             Console.WriteLine(Resx.Resource.TryTerminateProcess); | ||||||
| 
 |  | ||||||
|                         var lst = entry.FullName.Split(splitKey); |  | ||||||
|                         if (lst.Length == 1) |  | ||||||
|                         { |  | ||||||
|                             continue; |  | ||||||
|                         } |  | ||||||
| 
 |  | ||||||
|                         var fullName = string.Join(splitKey, lst[1..lst.Length]); |  | ||||||
|                         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); |  | ||||||
| 
 |  | ||||||
|                         Utils.WriteLine(entryOutputPath); |  | ||||||
|                     } |  | ||||||
|                     catch (Exception ex) |  | ||||||
|                     { |  | ||||||
|                         sb.Append(ex.Message); |  | ||||||
|                         sb.Append(ex.StackTrace); |  | ||||||
|                     } |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|             catch (Exception ex) |  | ||||||
|             { |  | ||||||
|                 sb.Append(Resx.Resource.FailedUpgrade + ex.StackTrace); |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             if (sb.Length <= 0) |  | ||||||
|             { |  | ||||||
|                 return true; |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             Utils.WriteLine(sb.ToString()); |  | ||||||
|             Utils.WriteLine(Resx.Resource.FailedUpgrade); |  | ||||||
|             return false; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         public static bool Init() |  | ||||||
|         { |  | ||||||
|             //Process temporary files generated by the last update |  | ||||||
|             var files = Directory.GetFiles(Utils.GetPath(""), "*.tmp"); |  | ||||||
|             foreach (var file in files) |  | ||||||
|             { |  | ||||||
|                 if (file.Contains(Utils.AmazTool)) |  | ||||||
|                 { |  | ||||||
|                     File.Delete(file); |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
| 
 |  | ||||||
|             var destFileName = $"{Utils.GetExePath()}{Guid.NewGuid().ToString("N")[..8]}.tmp"; |  | ||||||
|             File.Move(Utils.GetExePath(), destFileName); |  | ||||||
| 
 |  | ||||||
|             return true; |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         private static bool KillV2rayN() |  | ||||||
|         { |  | ||||||
|             Utils.WriteLine(Resx.Resource.TryTerminateProcess); |  | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
|                 var existing = Process.GetProcessesByName(Utils.V2rayN); |                 var existing = Process.GetProcessesByName(Utils.V2rayN); | ||||||
|  | @ -115,10 +35,83 @@ namespace AmazTool | ||||||
|             catch (Exception ex) |             catch (Exception ex) | ||||||
|             { |             { | ||||||
|                 // Access may be denied without admin right. The user may not be an administrator. |                 // Access may be denied without admin right. The user may not be an administrator. | ||||||
|                 Utils.WriteLine(Resx.Resource.FailedTerminateProcess + ex.StackTrace); |                 Console.WriteLine(Resx.Resource.FailedTerminateProcess + ex.StackTrace); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             return true; |             Console.WriteLine(Resx.Resource.StartUnzipping); | ||||||
|  |             StringBuilder sb = new(); | ||||||
|  |             try | ||||||
|  |             { | ||||||
|  |                 var thisAppOldFile = $"{Utils.GetExePath()}.tmp"; | ||||||
|  |                 File.Delete(thisAppOldFile); | ||||||
|  |                 var splitKey = "/"; | ||||||
|  | 
 | ||||||
|  |                 using var archive = ZipFile.OpenRead(fileName); | ||||||
|  |                 foreach (var entry in archive.Entries) | ||||||
|  |                 { | ||||||
|  |                     try | ||||||
|  |                     { | ||||||
|  |                         if (entry.Length == 0) | ||||||
|  |                         { | ||||||
|  |                             continue; | ||||||
|  |                         } | ||||||
|  | 
 | ||||||
|  |                         Console.WriteLine(entry.FullName); | ||||||
|  | 
 | ||||||
|  |                         var lst = entry.FullName.Split(splitKey); | ||||||
|  |                         if (lst.Length == 1) | ||||||
|  |                         { | ||||||
|  |                             continue; | ||||||
|  |                         } | ||||||
|  | 
 | ||||||
|  |                         var fullName = string.Join(splitKey, lst[1..lst.Length]); | ||||||
|  | 
 | ||||||
|  |                         if (string.Equals(Utils.GetExePath(), Utils.GetPath(fullName), StringComparison.OrdinalIgnoreCase)) | ||||||
|  |                         { | ||||||
|  |                             File.Move(Utils.GetExePath(), thisAppOldFile); | ||||||
|  |                         } | ||||||
|  | 
 | ||||||
|  |                         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; | ||||||
|  |                         } | ||||||
|  | 
 | ||||||
|  |                         try | ||||||
|  |                         { | ||||||
|  |                             entry.ExtractToFile(entryOutputPath, true); | ||||||
|  |                         } | ||||||
|  |                         catch | ||||||
|  |                         { | ||||||
|  |                             Thread.Sleep(1000); | ||||||
|  |                             entry.ExtractToFile(entryOutputPath, true); | ||||||
|  |                         } | ||||||
|  | 
 | ||||||
|  |                         Console.WriteLine(entryOutputPath); | ||||||
|  |                     } | ||||||
|  |                     catch (Exception ex) | ||||||
|  |                     { | ||||||
|  |                         sb.Append(ex.StackTrace); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             catch (Exception ex) | ||||||
|  |             { | ||||||
|  |                 Console.WriteLine(Resx.Resource.FailedUpgrade + ex.StackTrace); | ||||||
|  |                 //return; | ||||||
|  |             } | ||||||
|  |             if (sb.Length > 0) | ||||||
|  |             { | ||||||
|  |                 Console.WriteLine(Resx.Resource.FailedUpgrade + sb.ToString()); | ||||||
|  |                 //return; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             Console.WriteLine(Resx.Resource.Restartv2rayN); | ||||||
|  |             Utils.Waiting(2); | ||||||
|  | 
 | ||||||
|  |             Utils.StartV2RayN(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -14,7 +14,7 @@ namespace AmazTool | ||||||
|             return AppDomain.CurrentDomain.BaseDirectory; |             return AppDomain.CurrentDomain.BaseDirectory; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public static string GetPath(string? fileName) |         public static string GetPath(string fileName) | ||||||
|         { |         { | ||||||
|             var startupPath = StartupPath(); |             var startupPath = StartupPath(); | ||||||
|             if (string.IsNullOrEmpty(fileName)) |             if (string.IsNullOrEmpty(fileName)) | ||||||
|  | @ -25,7 +25,6 @@ namespace AmazTool | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public static string V2rayN => "v2rayN"; |         public static string V2rayN => "v2rayN"; | ||||||
|         public static string AmazTool => "AmazTool"; |  | ||||||
| 
 | 
 | ||||||
|         public static void StartV2RayN() |         public static void StartV2RayN() | ||||||
|         { |         { | ||||||
|  | @ -45,14 +44,9 @@ namespace AmazTool | ||||||
|         { |         { | ||||||
|             for (var i = second; i > 0; i--) |             for (var i = second; i > 0; i--) | ||||||
|             { |             { | ||||||
|                 Utils.WriteLine(i); |                 Console.WriteLine(i); | ||||||
|                 Thread.Sleep(1000); |                 Thread.Sleep(1000); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 |  | ||||||
|         public static void WriteLine(object obj) |  | ||||||
|         { |  | ||||||
|             Console.WriteLine(obj); |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| <Project> | <Project> | ||||||
| 
 | 
 | ||||||
|     <PropertyGroup> |     <PropertyGroup> | ||||||
|         <Version>7.10.1</Version> |         <Version>7.10.3</Version> | ||||||
|     </PropertyGroup> |     </PropertyGroup> | ||||||
| 
 | 
 | ||||||
|     <PropertyGroup> |     <PropertyGroup> | ||||||
|  |  | ||||||
|  | @ -109,7 +109,7 @@ namespace ServiceLib.Handler | ||||||
|             task.Settings.RunOnlyIfIdle = false; |             task.Settings.RunOnlyIfIdle = false; | ||||||
|             task.Settings.IdleSettings.StopOnIdleEnd = false; |             task.Settings.IdleSettings.StopOnIdleEnd = false; | ||||||
|             task.Settings.ExecutionTimeLimit = TimeSpan.Zero; |             task.Settings.ExecutionTimeLimit = TimeSpan.Zero; | ||||||
|             task.Triggers.Add(new Microsoft.Win32.TaskScheduler.LogonTrigger { UserId = logonUser, Delay = TimeSpan.FromSeconds(20) }); |             task.Triggers.Add(new Microsoft.Win32.TaskScheduler.LogonTrigger { UserId = logonUser, Delay = TimeSpan.FromSeconds(30) }); | ||||||
|             task.Principal.RunLevel = Microsoft.Win32.TaskScheduler.TaskRunLevel.Highest; |             task.Principal.RunLevel = Microsoft.Win32.TaskScheduler.TaskRunLevel.Highest; | ||||||
|             task.Actions.Add(new Microsoft.Win32.TaskScheduler.ExecAction(fileName.AppendQuotes(), null, Path.GetDirectoryName(fileName))); |             task.Actions.Add(new Microsoft.Win32.TaskScheduler.ExecAction(fileName.AppendQuotes(), null, Path.GetDirectoryName(fileName))); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue