From 28e41dc621927b7368f67186c82df758eff4fb26 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Wed, 8 May 2024 11:43:03 +0800 Subject: [PATCH] Add open the file location --- v2rayN/v2rayN/Common/Utils.cs | 4 +- v2rayN/v2rayN/Handler/ConfigHandler.cs | 172 +++++++++--------- v2rayN/v2rayN/Resx/ResUI.Designer.cs | 9 + v2rayN/v2rayN/Resx/ResUI.resx | 3 + v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx | 3 + v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx | 3 + .../v2rayN/ViewModels/MainWindowViewModel.cs | 61 ++++--- v2rayN/v2rayN/Views/MainWindow.xaml | 6 +- v2rayN/v2rayN/Views/MainWindow.xaml.cs | 3 +- v2rayN/v2rayN/v2rayN.csproj | 2 +- 10 files changed, 147 insertions(+), 119 deletions(-) diff --git a/v2rayN/v2rayN/Common/Utils.cs b/v2rayN/v2rayN/Common/Utils.cs index 6a2a0bb3..53f3511d 100644 --- a/v2rayN/v2rayN/Common/Utils.cs +++ b/v2rayN/v2rayN/Common/Utils.cs @@ -744,11 +744,11 @@ namespace v2rayN return Guid.TryParse(strSrc, out Guid g); } - public static void ProcessStart(string fileName) + public static void ProcessStart(string fileName, string arguments = "") { try { - Process.Start(new ProcessStartInfo(fileName) { UseShellExecute = true }); + Process.Start(new ProcessStartInfo(fileName, arguments) { UseShellExecute = true }); } catch (Exception ex) { diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs index 5253857f..cd1819e0 100644 --- a/v2rayN/v2rayN/Handler/ConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs @@ -240,103 +240,103 @@ namespace v2rayN.Handler } } - public static int ImportOldGuiConfig(Config config, string fileName) - { - var result = Utils.LoadResource(fileName); - if (Utils.IsNullOrEmpty(result)) - { - return -1; - } + //public static int ImportOldGuiConfig(Config config, string fileName) + //{ + // var result = Utils.LoadResource(fileName); + // if (Utils.IsNullOrEmpty(result)) + // { + // return -1; + // } - var configOld = JsonUtils.Deserialize(result); - if (configOld == null) - { - return -1; - } + // var configOld = JsonUtils.Deserialize(result); + // if (configOld == null) + // { + // return -1; + // } - var subItem = JsonUtils.Deserialize>(JsonUtils.Serialize(configOld.subItem)); - foreach (var it in subItem) - { - if (Utils.IsNullOrEmpty(it.id)) - { - it.id = Utils.GetGUID(false); - } - SQLiteHelper.Instance.Replace(it); - } + // var subItem = JsonUtils.Deserialize>(JsonUtils.Serialize(configOld.subItem)); + // foreach (var it in subItem) + // { + // if (Utils.IsNullOrEmpty(it.id)) + // { + // it.id = Utils.GetGUID(false); + // } + // SQLiteHelper.Instance.Replace(it); + // } - var profileItems = JsonUtils.Deserialize>(JsonUtils.Serialize(configOld.vmess)); - foreach (var it in profileItems) - { - if (Utils.IsNullOrEmpty(it.indexId)) - { - it.indexId = Utils.GetGUID(false); - } - SQLiteHelper.Instance.Replace(it); - } + // var profileItems = JsonUtils.Deserialize>(JsonUtils.Serialize(configOld.vmess)); + // foreach (var it in profileItems) + // { + // if (Utils.IsNullOrEmpty(it.indexId)) + // { + // it.indexId = Utils.GetGUID(false); + // } + // SQLiteHelper.Instance.Replace(it); + // } - foreach (var it in configOld.routings) - { - if (it.locked) - { - continue; - } - var routing = JsonUtils.Deserialize(JsonUtils.Serialize(it)); - foreach (var it2 in it.rules) - { - it2.id = Utils.GetGUID(false); - } - routing.ruleNum = it.rules.Count; - routing.ruleSet = JsonUtils.Serialize(it.rules, false); + // foreach (var it in configOld.routings) + // { + // if (it.locked) + // { + // continue; + // } + // var routing = JsonUtils.Deserialize(JsonUtils.Serialize(it)); + // foreach (var it2 in it.rules) + // { + // it2.id = Utils.GetGUID(false); + // } + // routing.ruleNum = it.rules.Count; + // routing.ruleSet = JsonUtils.Serialize(it.rules, false); - if (Utils.IsNullOrEmpty(routing.id)) - { - routing.id = Utils.GetGUID(false); - } - SQLiteHelper.Instance.Replace(routing); - } + // if (Utils.IsNullOrEmpty(routing.id)) + // { + // routing.id = Utils.GetGUID(false); + // } + // SQLiteHelper.Instance.Replace(routing); + // } - config = JsonUtils.Deserialize(JsonUtils.Serialize(configOld)); + // config = JsonUtils.Deserialize(JsonUtils.Serialize(configOld)); - if (config.coreBasicItem == null) - { - config.coreBasicItem = new() - { - logEnabled = configOld.logEnabled, - loglevel = configOld.loglevel, - muxEnabled = configOld.muxEnabled, - }; - } + // if (config.coreBasicItem == null) + // { + // config.coreBasicItem = new() + // { + // logEnabled = configOld.logEnabled, + // loglevel = configOld.loglevel, + // muxEnabled = configOld.muxEnabled, + // }; + // } - if (config.routingBasicItem == null) - { - config.routingBasicItem = new() - { - enableRoutingAdvanced = configOld.enableRoutingAdvanced, - domainStrategy = configOld.domainStrategy - }; - } + // if (config.routingBasicItem == null) + // { + // config.routingBasicItem = new() + // { + // enableRoutingAdvanced = configOld.enableRoutingAdvanced, + // domainStrategy = configOld.domainStrategy + // }; + // } - if (config.guiItem == null) - { - config.guiItem = new() - { - enableStatistics = configOld.enableStatistics, - keepOlderDedupl = configOld.keepOlderDedupl, - ignoreGeoUpdateCore = configOld.ignoreGeoUpdateCore, - autoUpdateInterval = configOld.autoUpdateInterval, - checkPreReleaseUpdate = configOld.checkPreReleaseUpdate, - enableSecurityProtocolTls13 = configOld.enableSecurityProtocolTls13, - trayMenuServersLimit = configOld.trayMenuServersLimit, - }; - } + // if (config.guiItem == null) + // { + // config.guiItem = new() + // { + // enableStatistics = configOld.enableStatistics, + // keepOlderDedupl = configOld.keepOlderDedupl, + // ignoreGeoUpdateCore = configOld.ignoreGeoUpdateCore, + // autoUpdateInterval = configOld.autoUpdateInterval, + // checkPreReleaseUpdate = configOld.checkPreReleaseUpdate, + // enableSecurityProtocolTls13 = configOld.enableSecurityProtocolTls13, + // trayMenuServersLimit = configOld.trayMenuServersLimit, + // }; + // } - GetDefaultServer(config); - GetDefaultRouting(config); - SaveConfig(config); - LoadConfig(ref config); + // GetDefaultServer(config); + // GetDefaultRouting(config); + // SaveConfig(config); + // LoadConfig(ref config); - return 0; - } + // return 0; + //} #endregion ConfigHandler diff --git a/v2rayN/v2rayN/Resx/ResUI.Designer.cs b/v2rayN/v2rayN/Resx/ResUI.Designer.cs index 5fe8cabb..45c7d3c3 100644 --- a/v2rayN/v2rayN/Resx/ResUI.Designer.cs +++ b/v2rayN/v2rayN/Resx/ResUI.Designer.cs @@ -978,6 +978,15 @@ namespace v2rayN.Resx { } } + /// + /// 查找类似 Open the storage location 的本地化字符串。 + /// + public static string menuOpenTheFileLocation { + get { + return ResourceManager.GetString("menuOpenTheFileLocation", resourceCulture); + } + } + /// /// 查找类似 Option Setting 的本地化字符串。 /// diff --git a/v2rayN/v2rayN/Resx/ResUI.resx b/v2rayN/v2rayN/Resx/ResUI.resx index edff8e36..d3b17f9a 100644 --- a/v2rayN/v2rayN/Resx/ResUI.resx +++ b/v2rayN/v2rayN/Resx/ResUI.resx @@ -1216,4 +1216,7 @@ Successful operation. Click the settings menu to reboot the app. + + Open the storage location + \ No newline at end of file diff --git a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx index 73390893..56b28678 100644 --- a/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx +++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hans.resx @@ -1213,4 +1213,7 @@ 操作成功。请点击设置菜单重启应用。 + + 打开存储所在的位置 + \ No newline at end of file diff --git a/v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx b/v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx index 295b4311..7367329e 100644 --- a/v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/v2rayN/Resx/ResUI.zh-Hant.resx @@ -1186,4 +1186,7 @@ 操作成功。 請點選設定選單重啟應用程式。 + + 打開儲存所在的位置 + \ No newline at end of file diff --git a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs index 89b8f441..c8b9dadc 100644 --- a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs @@ -143,7 +143,8 @@ namespace v2rayN.ViewModels public ReactiveCommand GlobalHotkeySettingCmd { get; } public ReactiveCommand RebootAsAdminCmd { get; } public ReactiveCommand ClearServerStatisticsCmd { get; } - public ReactiveCommand ImportOldGuiConfigCmd { get; } + public ReactiveCommand OpenTheFileLocationCmd { get; } + //public ReactiveCommand ImportOldGuiConfigCmd { get; } //CheckUpdate public ReactiveCommand CheckUpdateNCmd { get; } @@ -503,10 +504,14 @@ namespace v2rayN.ViewModels _statistics?.ClearAllServerStatistics(); RefreshServers(); }); - ImportOldGuiConfigCmd = ReactiveCommand.Create(() => + OpenTheFileLocationCmd = ReactiveCommand.Create(() => { - ImportOldGuiConfig(); + Utils.ProcessStart("Explorer", $"/select,{Utils.GetConfigPath()}"); }); + //ImportOldGuiConfigCmd = ReactiveCommand.Create(() => + //{ + // ImportOldGuiConfig(); + //}); //CheckUpdate CheckUpdateNCmd = ReactiveCommand.Create(() => @@ -1422,32 +1427,32 @@ namespace v2rayN.ViewModels catch { } } - private void ImportOldGuiConfig() - { - if (UI.OpenFileDialog(out string fileName, - "guiNConfig|*.json|All|*.*") != true) - { - return; - } - if (Utils.IsNullOrEmpty(fileName)) - { - return; - } + //private void ImportOldGuiConfig() + //{ + // if (UI.OpenFileDialog(out string fileName, + // "guiNConfig|*.json|All|*.*") != true) + // { + // return; + // } + // if (Utils.IsNullOrEmpty(fileName)) + // { + // return; + // } - var ret = ConfigHandler.ImportOldGuiConfig(_config, fileName); - if (ret == 0) - { - RefreshRoutingsMenu(); - InitSubscriptionView(); - RefreshServers(); - Reload(); - _noticeHandler?.Enqueue(ResUI.OperationSuccess); - } - else - { - _noticeHandler?.Enqueue(ResUI.OperationFailed); - } - } + // var ret = ConfigHandler.ImportOldGuiConfig(_config, fileName); + // if (ret == 0) + // { + // RefreshRoutingsMenu(); + // InitSubscriptionView(); + // RefreshServers(); + // Reload(); + // _noticeHandler?.Enqueue(ResUI.OperationSuccess); + // } + // else + // { + // _noticeHandler?.Enqueue(ResUI.OperationFailed); + // } + //} #endregion Setting diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml b/v2rayN/v2rayN/Views/MainWindow.xaml index b8162795..ce09c1df 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml +++ b/v2rayN/v2rayN/Views/MainWindow.xaml @@ -191,9 +191,13 @@ Header="{x:Static resx:ResUI.menuClearServerStatistics}" /> + diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index 84da87f2..b16972cb 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -138,7 +138,8 @@ namespace v2rayN.Views this.BindCommand(ViewModel, vm => vm.GlobalHotkeySettingCmd, v => v.menuGlobalHotkeySetting).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.RebootAsAdminCmd, v => v.menuRebootAsAdmin).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ClearServerStatisticsCmd, v => v.menuClearServerStatistics).DisposeWith(disposables); - this.BindCommand(ViewModel, vm => vm.ImportOldGuiConfigCmd, v => v.menuImportOldGuiConfig).DisposeWith(disposables); + this.BindCommand(ViewModel, vm => vm.OpenTheFileLocationCmd, v => v.menuOpenTheFileLocation).DisposeWith(disposables); + //this.BindCommand(ViewModel, vm => vm.ImportOldGuiConfigCmd, v => v.menuImportOldGuiConfig).DisposeWith(disposables); //check update this.BindCommand(ViewModel, vm => vm.CheckUpdateNCmd, v => v.menuCheckUpdateN).DisposeWith(disposables); diff --git a/v2rayN/v2rayN/v2rayN.csproj b/v2rayN/v2rayN/v2rayN.csproj index 88ddc373..f777a200 100644 --- a/v2rayN/v2rayN/v2rayN.csproj +++ b/v2rayN/v2rayN/v2rayN.csproj @@ -23,7 +23,7 @@ - +