diff --git a/v2rayN/ServiceLib/Enums/EPresetType.cs b/v2rayN/ServiceLib/Enums/EPresetType.cs new file mode 100644 index 00000000..57a1984f --- /dev/null +++ b/v2rayN/ServiceLib/Enums/EPresetType.cs @@ -0,0 +1,8 @@ +namespace ServiceLib.Enums +{ + public enum EPresetType + { + Default = 0, + Russia = 1, + } +} diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index bed7bd7a..937061d4 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -1788,5 +1788,31 @@ namespace ServiceLib.Handler } #endregion DNS + + #region Presets + + public static bool ApplyPreset(Config config, EPresetType type) + { + switch (type) + { + case EPresetType.Default: + config.constItem.geoSourceUrl = ""; + config.constItem.srsSourceUrl = ""; + config.constItem.routeRulesTemplateSourceUrl = ""; + + return true; + + case EPresetType.Russia: + config.constItem.geoSourceUrl = Global.GeoFilesSources[1]; + config.constItem.srsSourceUrl = Global.SingboxRulesetSources[1]; + config.constItem.routeRulesTemplateSourceUrl = Global.RoutingRulesSources[1]; + + return true; + } + + return false; + } + + #endregion } } \ No newline at end of file diff --git a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs index 75a4af32..0c92385c 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.Designer.cs +++ b/v2rayN/ServiceLib/Resx/ResUI.Designer.cs @@ -1113,6 +1113,33 @@ namespace ServiceLib.Resx { } } + /// + /// 查找类似 Regional presets 的本地化字符串。 + /// + public static string menuPresets { + get { + return ResourceManager.GetString("menuPresets", resourceCulture); + } + } + + /// + /// 查找类似 Default 的本地化字符串。 + /// + public static string menuPresetsDefault { + get { + return ResourceManager.GetString("menuPresetsDefault", resourceCulture); + } + } + + /// + /// 查找类似 Russia 的本地化字符串。 + /// + public static string menuPresetsRussia { + get { + return ResourceManager.GetString("menuPresetsRussia", resourceCulture); + } + } + /// /// 查找类似 Auto column width adjustment 的本地化字符串。 /// diff --git a/v2rayN/ServiceLib/Resx/ResUI.resx b/v2rayN/ServiceLib/Resx/ResUI.resx index afd1a699..cfc597e6 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.resx @@ -1339,4 +1339,13 @@ Routing rules source (optional) + + Regional presets + + + Default + + + Russia + \ No newline at end of file diff --git a/v2rayN/ServiceLib/Services/UpdateService.cs b/v2rayN/ServiceLib/Services/UpdateService.cs index 006a96f0..f25548ce 100644 --- a/v2rayN/ServiceLib/Services/UpdateService.cs +++ b/v2rayN/ServiceLib/Services/UpdateService.cs @@ -253,23 +253,6 @@ namespace ServiceLib.Services }); } - public async Task VerifyGeoFilesRepo(Config config, Action updateFunc) - { - var repoPath = Utils.GetBinPath("geo.repo"); - var repo = File.Exists(repoPath) ? File.ReadAllText(repoPath) : ""; - - if (repo != (config.constItem.geoSourceUrl ?? "")) - { - await UpdateGeoFileAll(config, updateFunc); - - File.WriteAllText(repoPath, repo); - - return false; - } - - return true; - } - public async Task UpdateGeoFileAll(Config config, Action updateFunc) { await UpdateGeoFile("geosite", config, updateFunc); diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index c122c53f..450a73a1 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -44,6 +44,10 @@ namespace ServiceLib.ViewModels public ReactiveCommand ClearServerStatisticsCmd { get; } public ReactiveCommand OpenTheFileLocationCmd { get; } + //Presets + public ReactiveCommand PresetDefaultCmd { get; } + public ReactiveCommand PresetRussiaCmd { get; } + public ReactiveCommand ReloadCmd { get; } [Reactive] @@ -181,6 +185,16 @@ namespace ServiceLib.ViewModels await Reload(); }); + PresetDefaultCmd = ReactiveCommand.CreateFromTask(async () => + { + await ApplyPreset(EPresetType.Default); + }); + + PresetRussiaCmd = ReactiveCommand.CreateFromTask(async () => + { + await ApplyPreset(EPresetType.Russia); + }); + #endregion WhenAnyValue && ReactiveCommand AutoHideStartup(); @@ -191,7 +205,6 @@ namespace ServiceLib.ViewModels ConfigHandler.InitRouting(_config); ConfigHandler.InitBuiltinDNS(_config); CoreHandler.Instance.Init(_config, UpdateHandler); - Task.Run(() => VerifyGeoFiles(true)); TaskHandler.Instance.RegUpdateTask(_config, UpdateTaskHandler); if (_config.guiItem.enableStatistics) @@ -422,7 +435,6 @@ namespace ServiceLib.ViewModels var ret = await _updateView?.Invoke(EViewAction.OptionSettingWindow, null); if (ret == true) { - await VerifyGeoFiles(); Locator.Current.GetService()?.InboundDisplayStatus(); Reload(); } @@ -543,14 +555,23 @@ namespace ServiceLib.ViewModels } } - public async Task VerifyGeoFiles(bool needReload = false) - { - var result = await new UpdateService().VerifyGeoFilesRepo(_config, UpdateHandler); + #endregion core job - if (needReload && !result) - Reload(); + #region Presets + + public async Task ApplyPreset(EPresetType type) + { + ConfigHandler.ApplyPreset(_config, type); + + await new UpdateService().UpdateGeoFileAll(_config, UpdateHandler); + + ConfigHandler.InitRouting(_config); + Locator.Current.GetService()?.RefreshRoutingsMenu(); + + ConfigHandler.SaveConfig(_config, false); + Reload(); } - #endregion core job + #endregion } } \ No newline at end of file diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml index e86bd461..159de1d8 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml @@ -74,6 +74,10 @@ + + + + diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index f4fd21c5..a417a876 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -76,6 +76,8 @@ namespace v2rayN.Desktop.Views 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.OpenTheFileLocationCmd, v => v.menuOpenTheFileLocation).DisposeWith(disposables); + this.BindCommand(ViewModel, vm => vm.PresetDefaultCmd, v => v.menuPresetsDefault).DisposeWith(disposables); + this.BindCommand(ViewModel, vm => vm.PresetRussiaCmd, v => v.menuPresetsRussia).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ReloadCmd, v => v.menuReload).DisposeWith(disposables); this.OneWayBind(ViewModel, vm => vm.BlReloadEnabled, v => v.menuReload.IsEnabled).DisposeWith(disposables); diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml b/v2rayN/v2rayN/Views/MainWindow.xaml index 7757911b..c2143cf0 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml +++ b/v2rayN/v2rayN/Views/MainWindow.xaml @@ -171,6 +171,16 @@ x:Name="menuGlobalHotkeySetting" Height="{StaticResource MenuItemHeight}" Header="{x:Static resx:ResUI.menuGlobalHotkeySetting}" /> + + + + vm.RebootAsAdminCmd, v => v.menuRebootAsAdmin).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ClearServerStatisticsCmd, v => v.menuClearServerStatistics).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.OpenTheFileLocationCmd, v => v.menuOpenTheFileLocation).DisposeWith(disposables); + this.BindCommand(ViewModel, vm => vm.PresetDefaultCmd, v => v.menuPresetsDefault).DisposeWith(disposables); + this.BindCommand(ViewModel, vm => vm.PresetRussiaCmd, v => v.menuPresetsRussia).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.ReloadCmd, v => v.menuReload).DisposeWith(disposables); this.OneWayBind(ViewModel, vm => vm.BlReloadEnabled, v => v.menuReload.IsEnabled).DisposeWith(disposables);