mirror of https://github.com/2dust/v2rayN
				
				
				
			Improve the code
							parent
							
								
									61e9101851
								
							
						
					
					
						commit
						a1c8bc0e61
					
				|  | @ -145,7 +145,7 @@ namespace ServiceLib.Handler | |||
| 
 | ||||
|         private string CoreFindExe(CoreInfo coreInfo) | ||||
|         { | ||||
|             string fileName = string.Empty; | ||||
|             var fileName = string.Empty; | ||||
|             foreach (var name in coreInfo.CoreExes) | ||||
|             { | ||||
|                 var vName = Utils.GetBinPath(Utils.GetExeName(name), coreInfo.CoreType.ToString()); | ||||
|  | @ -157,7 +157,7 @@ namespace ServiceLib.Handler | |||
|             } | ||||
|             if (Utils.IsNullOrEmpty(fileName)) | ||||
|             { | ||||
|                 string msg = string.Format(ResUI.NotFoundCore, Utils.GetBinPath("", coreInfo.CoreType.ToString()), string.Join(", ", coreInfo.CoreExes.ToArray()), coreInfo.Url); | ||||
|                 var msg = string.Format(ResUI.NotFoundCore, Utils.GetBinPath("", coreInfo.CoreType.ToString()), string.Join(", ", coreInfo.CoreExes.ToArray()), coreInfo.Url); | ||||
|                 Logging.SaveLog(msg); | ||||
|                 ShowMsg(false, msg); | ||||
|             } | ||||
|  | @ -183,7 +183,7 @@ namespace ServiceLib.Handler | |||
|             var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(coreType); | ||||
| 
 | ||||
|             var displayLog = node.ConfigType != EConfigType.Custom || node.DisplayLog; | ||||
|             var proc = await RunProcess(node, coreInfo, "", displayLog); | ||||
|             var proc = await RunProcess(coreInfo, Global.CoreConfigFileName, displayLog); | ||||
|             if (proc is null) | ||||
|             { | ||||
|                 return; | ||||
|  | @ -220,12 +220,12 @@ namespace ServiceLib.Handler | |||
|                 } | ||||
|                 if (itemSocks != null) | ||||
|                 { | ||||
|                     string fileName2 = Utils.GetConfigPath(Global.CorePreConfigFileName); | ||||
|                     var fileName2 = Utils.GetConfigPath(Global.CorePreConfigFileName); | ||||
|                     var result = await CoreConfigHandler.GenerateClientConfig(itemSocks, fileName2); | ||||
|                     if (result.Success) | ||||
|                     { | ||||
|                         var coreInfo2 = CoreInfoHandler.Instance.GetCoreInfo(preCoreType); | ||||
|                         var proc2 = await RunProcess(node, coreInfo2, $" -c {Global.CorePreConfigFileName}", true); | ||||
|                         var proc2 = await RunProcess(coreInfo2, Global.CorePreConfigFileName, true); | ||||
|                         if (proc2 is not null) | ||||
|                         { | ||||
|                             _processPre = proc2; | ||||
|  | @ -243,7 +243,7 @@ namespace ServiceLib.Handler | |||
|             try | ||||
|             { | ||||
|                 var coreInfo = CoreInfoHandler.Instance.GetCoreInfo(coreType); | ||||
|                 var proc = await RunProcess(new(), coreInfo, $" -c {Global.CoreSpeedtestConfigFileName}", true); | ||||
|                 var proc = await RunProcess(coreInfo, Global.CoreSpeedtestConfigFileName, true); | ||||
|                 if (proc is null) | ||||
|                 { | ||||
|                     return -1; | ||||
|  | @ -254,8 +254,7 @@ namespace ServiceLib.Handler | |||
|             catch (Exception ex) | ||||
|             { | ||||
|                 Logging.SaveLog(ex.Message, ex); | ||||
|                 string msg = ex.Message; | ||||
|                 ShowMsg(false, msg); | ||||
|                 ShowMsg(false, ex.Message); | ||||
|                 return -1; | ||||
|             } | ||||
|         } | ||||
|  | @ -269,15 +268,15 @@ namespace ServiceLib.Handler | |||
| 
 | ||||
|         #region Process | ||||
| 
 | ||||
|         private async Task<Process?> RunProcess(ProfileItem node, CoreInfo coreInfo, string configPath, bool displayLog) | ||||
|         private async Task<Process?> RunProcess(CoreInfo coreInfo, string configPath, bool displayLog) | ||||
|         { | ||||
|             try | ||||
|             { | ||||
|                 string fileName = CoreFindExe(coreInfo); | ||||
|             var fileName = CoreFindExe(coreInfo); | ||||
|             if (Utils.IsNullOrEmpty(fileName)) | ||||
|             { | ||||
|                 return null; | ||||
|             } | ||||
|             try | ||||
|             { | ||||
|                 Process proc = new() | ||||
|                 { | ||||
|                     StartInfo = new() | ||||
|  | @ -299,23 +298,17 @@ namespace ServiceLib.Handler | |||
|                 { | ||||
|                     proc.OutputDataReceived += (sender, e) => | ||||
|                     { | ||||
|                         if (Utils.IsNotEmpty(e.Data)) | ||||
|                         { | ||||
|                             string msg = e.Data + Environment.NewLine; | ||||
|                             ShowMsg(false, msg); | ||||
|                         } | ||||
|                         if (Utils.IsNullOrEmpty(e.Data)) return; | ||||
|                         ShowMsg(false, e.Data + Environment.NewLine); | ||||
|                     }; | ||||
|                     proc.ErrorDataReceived += (sender, e) => | ||||
|                     { | ||||
|                         if (Utils.IsNotEmpty(e.Data)) | ||||
|                         { | ||||
|                             string msg = e.Data + Environment.NewLine; | ||||
|                             ShowMsg(false, msg); | ||||
|                         if (Utils.IsNullOrEmpty(e.Data)) return; | ||||
|                         ShowMsg(false, e.Data + Environment.NewLine); | ||||
| 
 | ||||
|                         if (!startUpSuccessful) | ||||
|                         { | ||||
|                                 startUpErrorMessage.Append(msg); | ||||
|                             } | ||||
|                             startUpErrorMessage.Append(e.Data + Environment.NewLine); | ||||
|                         } | ||||
|                     }; | ||||
|                 } | ||||
|  | @ -342,8 +335,7 @@ namespace ServiceLib.Handler | |||
|             catch (Exception ex) | ||||
|             { | ||||
|                 Logging.SaveLog(ex.Message, ex); | ||||
|                 string msg = ex.Message; | ||||
|                 ShowMsg(true, msg); | ||||
|                 ShowMsg(true, ex.Message); | ||||
|                 return null; | ||||
|             } | ||||
|         } | ||||
|  | @ -354,19 +346,25 @@ namespace ServiceLib.Handler | |||
|             { | ||||
|                 return; | ||||
|             } | ||||
|             var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(1)); | ||||
|             try | ||||
|             { | ||||
|                 await proc.WaitForExitAsync(timeout.Token); | ||||
|             } | ||||
|             catch (OperationCanceledException) | ||||
|             { | ||||
|                 proc.Kill(); | ||||
|                 proc.WaitForExit(100); | ||||
|             } | ||||
|             if (!proc.HasExited) | ||||
|             { | ||||
|                     proc.Kill(); | ||||
|                     proc.WaitForExit(100); | ||||
|                 } | ||||
|             } | ||||
|             catch (Exception ex) | ||||
|                 try | ||||
|                 { | ||||
|                 Logging.SaveLog(ex.Message, ex); | ||||
|                     await proc.WaitForExitAsync(timeout.Token); | ||||
|                 } | ||||
|                 catch (Exception) | ||||
|                 { | ||||
|                     proc.Kill(); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|  |  | |||
|  | @ -72,7 +72,7 @@ | |||
|             { | ||||
|                 CoreType = ECoreType.Xray, | ||||
|                 CoreExes = new List<string> { "xray", "wxray" }, | ||||
|                 Arguments = "run {0}", | ||||
|                 Arguments = "run -c {0}", | ||||
|                 Url = Global.XrayCoreUrl, | ||||
|                 ReleaseApiUrl = Global.XrayCoreUrl.Replace(Global.GithubUrl, Global.GithubApiUrl), | ||||
|                 DownloadUrlWin64 = Global.XrayCoreUrl + "/download/{0}/Xray-windows-64.zip", | ||||
|  | @ -132,7 +132,7 @@ | |||
|             { | ||||
|                 CoreType = ECoreType.sing_box, | ||||
|                 CoreExes = new List<string> { "sing-box-client", "sing-box" }, | ||||
|                 Arguments = "run {0} --disable-color", | ||||
|                 Arguments = "run -c {0} --disable-color", | ||||
|                 Url = Global.SingboxCoreUrl, | ||||
|                 RedirectInfo = true, | ||||
|                 ReleaseApiUrl = Global.SingboxCoreUrl.Replace(Global.GithubUrl, Global.GithubApiUrl), | ||||
|  |  | |||
|  | @ -1271,7 +1271,7 @@ | |||
|     <value>显示或隐藏主界面</value> | ||||
|   </data> | ||||
|   <data name="UpdateStandalonePackageTip" xml:space="preserve"> | ||||
|     <value>您当前运行的是独立包,请手动下载 SelfContained.7z文件解压覆盖</value> | ||||
|     <value>您当前运行的是独立包,请手动下载 SelfContained.7z文件解压覆盖!</value> | ||||
|   </data> | ||||
|   <data name="TbPreSocksPort4Sub" xml:space="preserve"> | ||||
|     <value>自定义配置的Socks端口</value> | ||||
|  |  | |||
|  | @ -1151,7 +1151,7 @@ | |||
|     <value>顯示或隱藏主介面</value> | ||||
|   </data> | ||||
|   <data name="UpdateStandalonePackageTip" xml:space="preserve"> | ||||
|     <value>您目前運行的是獨立包,請手動下載 SelfContained.7z檔案解壓縮覆蓋</value> | ||||
|     <value>您目前運行的是獨立包,請手動下載 SelfContained.7z檔案解壓縮覆蓋!</value> | ||||
|   </data> | ||||
|   <data name="TbPreSocksPort4Sub" xml:space="preserve"> | ||||
|     <value>自訂設定的Socks端口</value> | ||||
|  |  | |||
|  | @ -86,7 +86,7 @@ namespace ServiceLib.ViewModels | |||
|                 return; | ||||
|             } | ||||
|             //NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess); | ||||
|             _updateView?.Invoke(EViewAction.CloseWindow, null); | ||||
|             await _updateView?.Invoke(EViewAction.CloseWindow, null); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | @ -43,11 +43,11 @@ namespace v2rayN.Desktop.Views | |||
|             { | ||||
|                 rulesItem.Protocol?.ForEach(it => | ||||
|                 { | ||||
|                     clbProtocol.SelectedItems.Add(it); | ||||
|                     clbProtocol?.SelectedItems?.Add(it); | ||||
|                 }); | ||||
|                 rulesItem.InboundTag?.ForEach(it => | ||||
|                 { | ||||
|                     clbInboundTag.SelectedItems.Add(it); | ||||
|                     clbInboundTag?.SelectedItems?.Add(it); | ||||
|                 }); | ||||
|             } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 2dust
						2dust