diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs index 1367ebcd..af7fbc19 100644 --- a/v2rayN/v2rayN/Handler/ConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs @@ -44,10 +44,7 @@ namespace v2rayN.Handler { config = new Config { - enableStatistics = false, - - statisticsFreshRate = 1, - + enableRoutingAdvanced = true }; } @@ -134,6 +131,14 @@ namespace v2rayN.Handler mtu = 9000, }; } + if (config.guiItem == null) + { + config.guiItem = new() + { + enableStatistics = false, + statisticsFreshRate = 1, + }; + } if (config.uiItem == null) { config.uiItem = new UIItem() @@ -180,9 +185,9 @@ namespace v2rayN.Handler config.speedTestItem.speedPingTestUrl = Global.SpeedPingTestUrl; } - if (config.statisticsFreshRate > 100 || config.statisticsFreshRate < 1) + if (config.guiItem.statisticsFreshRate > 100 || config.guiItem.statisticsFreshRate < 1) { - config.statisticsFreshRate = 1; + config.guiItem.statisticsFreshRate = 1; } if (config == null) @@ -758,7 +763,7 @@ namespace v2rayN.Handler public static int DedupServerList(ref Config config, ref List lstProfile) { List source = lstProfile; - bool keepOlder = config.keepOlderDedupl; + bool keepOlder = config.guiItem.keepOlderDedupl; List list = new List(); if (!keepOlder) source.Reverse(); // Remove the early items first diff --git a/v2rayN/v2rayN/Handler/CoreConfigHandler.cs b/v2rayN/v2rayN/Handler/CoreConfigHandler.cs index c1d7e05c..b6be7fab 100644 --- a/v2rayN/v2rayN/Handler/CoreConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/CoreConfigHandler.cs @@ -825,7 +825,7 @@ namespace v2rayN.Handler private static int statistic(Config config, ref V2rayConfig v2rayConfig) { - if (config.enableStatistics) + if (config.guiItem.enableStatistics) { string tag = Global.InboundAPITagName; API apiObj = new API(); diff --git a/v2rayN/v2rayN/Handler/DownloadHandle.cs b/v2rayN/v2rayN/Handler/DownloadHandle.cs index 29e2b10d..07f3fb9c 100644 --- a/v2rayN/v2rayN/Handler/DownloadHandle.cs +++ b/v2rayN/v2rayN/Handler/DownloadHandle.cs @@ -35,7 +35,7 @@ namespace v2rayN.Handler { try { - Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13); + Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().guiItem.enableSecurityProtocolTls13); var progress = new Progress(); progress.ProgressChanged += (sender, value) => @@ -67,7 +67,7 @@ namespace v2rayN.Handler { try { - Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13); + Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().guiItem.enableSecurityProtocolTls13); UpdateCompleted?.Invoke(this, new ResultEventArgs(false, ResUI.Downloading)); var progress = new Progress(); @@ -101,7 +101,7 @@ namespace v2rayN.Handler public async Task UrlRedirectAsync(string url, bool blProxy) { - Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13); + Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().guiItem.enableSecurityProtocolTls13); var webRequestHandler = new SocketsHttpHandler { AllowAutoRedirect = false, @@ -129,7 +129,7 @@ namespace v2rayN.Handler { try { - Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13); + Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().guiItem.enableSecurityProtocolTls13); var webProxy = GetWebProxy(blProxy); var result = await DownloaderHelper.Instance.DownloadStringAsync(webProxy, url, userAgent, 30); @@ -155,7 +155,7 @@ namespace v2rayN.Handler { try { - Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13); + Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().guiItem.enableSecurityProtocolTls13); var client = new HttpClient(new SocketsHttpHandler() { Proxy = GetWebProxy(blProxy) diff --git a/v2rayN/v2rayN/Handler/MainFormHandler.cs b/v2rayN/v2rayN/Handler/MainFormHandler.cs index 7d42c448..72b99f77 100644 --- a/v2rayN/v2rayN/Handler/MainFormHandler.cs +++ b/v2rayN/v2rayN/Handler/MainFormHandler.cs @@ -309,9 +309,9 @@ namespace v2rayN.Handler { var dtNow = DateTime.Now; - if (config.autoUpdateSubInterval > 0) + if (config.guiItem.autoUpdateSubInterval > 0) { - if ((dtNow - autoUpdateSubTime).Hours % config.autoUpdateSubInterval == 0) + if ((dtNow - autoUpdateSubTime).Hours % config.guiItem.autoUpdateSubInterval == 0) { updateHandle.UpdateSubscriptionProcess(config, "", true, (bool success, string msg) => { @@ -324,9 +324,9 @@ namespace v2rayN.Handler Thread.Sleep(60000); } - if (config.autoUpdateInterval > 0) + if (config.guiItem.autoUpdateInterval > 0) { - if ((dtNow - autoUpdateGeoTime).Hours % config.autoUpdateInterval == 0) + if ((dtNow - autoUpdateGeoTime).Hours % config.guiItem.autoUpdateInterval == 0) { updateHandle.UpdateGeoFile("geosite", config, (bool success, string msg) => { diff --git a/v2rayN/v2rayN/Handler/StatisticsHandler.cs b/v2rayN/v2rayN/Handler/StatisticsHandler.cs index 3928aa3d..cb747f46 100644 --- a/v2rayN/v2rayN/Handler/StatisticsHandler.cs +++ b/v2rayN/v2rayN/Handler/StatisticsHandler.cs @@ -27,7 +27,7 @@ namespace v2rayN.Handler public StatisticsHandler(Mode.Config config, Action update) { config_ = config; - Enable = config.enableStatistics; + Enable = config.guiItem.enableStatistics; updateFunc_ = update; exitFlag_ = false; @@ -103,7 +103,7 @@ namespace v2rayN.Handler } } } - var sleep = config_.statisticsFreshRate < 1 ? 1 : config_.statisticsFreshRate; + var sleep = config_.guiItem.statisticsFreshRate < 1 ? 1 : config_.guiItem.statisticsFreshRate; Thread.Sleep(1000 * sleep); channel_.ConnectAsync(); } diff --git a/v2rayN/v2rayN/Mode/Config.cs b/v2rayN/v2rayN/Mode/Config.cs index 2ba09b71..a6341523 100644 --- a/v2rayN/v2rayN/Mode/Config.cs +++ b/v2rayN/v2rayN/Mode/Config.cs @@ -7,15 +7,11 @@ public class Config { #region property - - - + public string indexId { get; set; - } - - + } /// /// @@ -23,33 +19,7 @@ public ESysProxyType sysProxyType { get; set; - } - - public bool autoRun { get; set; } - - /// - /// 启用实时网速和流量统计 - /// - public bool enableStatistics - { - get; set; - } - - /// - /// 去重时优先保留较旧(顶部)节点 - /// - public bool keepOlderDedupl - { - get; set; - } - - /// - /// 视图刷新率 - /// - public int statisticsFreshRate - { - get; set; - } + } /// /// 自定义远程DNS @@ -65,9 +35,7 @@ public string domainStrategy4Freedom { get; set; - } - - + } /// /// 域名解析策略 @@ -84,9 +52,7 @@ public bool enableRoutingAdvanced { get; set; - } - - public bool ignoreGeoUpdateCore { get; set; } = true; + } /// /// systemProxyExceptions @@ -97,19 +63,6 @@ } public string systemProxyAdvancedProtocol { get; set; } - public int autoUpdateInterval { get; set; } = 10; - - public int autoUpdateSubInterval { get; set; } = 10; - - public bool checkPreReleaseUpdate { get; set; } = false; - - public bool enableSecurityProtocolTls13 - { - get; set; - } - - public int trayMenuServersLimit { get; set; } = 20; - #endregion #region other entities @@ -118,6 +71,7 @@ public TunModeItem tunModeItem { get; set; } public KcpItem kcpItem { get; set; } public GrpcItem grpcItem { get; set; } + public GUIItem guiItem { get; set; } public UIItem uiItem { get; set; } public ConstItem constItem { get; set; } public SpeedTestItem speedTestItem { get; set; } diff --git a/v2rayN/v2rayN/Mode/ConfigItems.cs b/v2rayN/v2rayN/Mode/ConfigItems.cs index 95444036..1aa90eb4 100644 --- a/v2rayN/v2rayN/Mode/ConfigItems.cs +++ b/v2rayN/v2rayN/Mode/ConfigItems.cs @@ -2,6 +2,7 @@ namespace v2rayN.Mode { + [Serializable] public class CoreBasicItem { /// @@ -32,7 +33,6 @@ namespace v2rayN.Mode public string defUserAgent { get; set; } } - [Serializable] public class InItem { @@ -82,6 +82,30 @@ namespace v2rayN.Mode public int initial_windows_size { get; set; } } + [Serializable] + public class GUIItem + { + public bool autoRun { get; set; } + + public bool enableStatistics { get; set; } + + public int statisticsFreshRate { get; set; } + + public bool keepOlderDedupl { get; set; } + + public bool ignoreGeoUpdateCore { get; set; } = true; + + public int autoUpdateInterval { get; set; } = 10; + + public int autoUpdateSubInterval { get; set; } = 10; + + public bool checkPreReleaseUpdate { get; set; } = false; + + public bool enableSecurityProtocolTls13 { get; set; } + + public int trayMenuServersLimit { get; set; } = 20; + } + [Serializable] public class UIItem { diff --git a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs index 5d2cee28..d9c8927c 100644 --- a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs @@ -506,7 +506,7 @@ namespace v2rayN.ViewModels //MainFormHandler.Instance.BackupGuiNConfig(_config, true); _coreHandler = new CoreHandler(UpdateHandler); - if (_config.enableStatistics) + if (_config.guiItem.enableStatistics) { _statistics = new StatisticsHandler(_config, UpdateStatisticsHandler); } @@ -773,7 +773,7 @@ namespace v2rayN.ViewModels private void RefreshServersMenu() { _servers.Clear(); - if (_lstProfile.Count > _config.trayMenuServersLimit) + if (_lstProfile.Count > _config.guiItem.trayMenuServersLimit) { return; } @@ -1301,7 +1301,7 @@ namespace v2rayN.ViewModels MyAppExit(false); } }; - (new UpdateHandle()).CheckUpdateGuiN(_config, _updateUI, _config.checkPreReleaseUpdate); + (new UpdateHandle()).CheckUpdateGuiN(_config, _updateUI, _config.guiItem.checkPreReleaseUpdate); } private void CheckUpdateCore(ECoreType type) @@ -1316,7 +1316,7 @@ namespace v2rayN.ViewModels string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(msg)); string toPath = Utils.GetBinPath("", type); - FileManager.ZipExtractToFile(fileName, toPath, _config.ignoreGeoUpdateCore ? "geo" : ""); + FileManager.ZipExtractToFile(fileName, toPath, _config.guiItem.ignoreGeoUpdateCore ? "geo" : ""); _noticeHandler?.SendMessage(ResUI.MsgUpdateV2rayCoreSuccessfullyMore); @@ -1330,7 +1330,7 @@ namespace v2rayN.ViewModels } } }; - (new UpdateHandle()).CheckUpdateCore(type, _config, _updateUI, _config.checkPreReleaseUpdate); + (new UpdateHandle()).CheckUpdateCore(type, _config, _updateUI, _config.guiItem.checkPreReleaseUpdate); } private void CheckUpdateGeo() diff --git a/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs index ba387c37..34ec6053 100644 --- a/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/OptionSettingViewModel.cs @@ -140,20 +140,20 @@ namespace v2rayN.ViewModels #endregion #region UI - AutoRun = _config.autoRun; - EnableStatistics = _config.enableStatistics; - StatisticsFreshRate = _config.statisticsFreshRate; - KeepOlderDedupl = _config.keepOlderDedupl; - IgnoreGeoUpdateCore = _config.ignoreGeoUpdateCore; + AutoRun = _config.guiItem.autoRun; + EnableStatistics = _config.guiItem.enableStatistics; + StatisticsFreshRate = _config.guiItem.statisticsFreshRate; + KeepOlderDedupl = _config.guiItem.keepOlderDedupl; + IgnoreGeoUpdateCore = _config.guiItem.ignoreGeoUpdateCore; EnableAutoAdjustMainLvColWidth = _config.uiItem.enableAutoAdjustMainLvColWidth; - EnableSecurityProtocolTls13 = _config.enableSecurityProtocolTls13; + EnableSecurityProtocolTls13 = _config.guiItem.enableSecurityProtocolTls13; AutoHideStartup = _config.uiItem.autoHideStartup; - EnableCheckPreReleaseUpdate = _config.checkPreReleaseUpdate; + EnableCheckPreReleaseUpdate = _config.guiItem.checkPreReleaseUpdate; EnableDragDropSort = _config.uiItem.enableDragDropSort; DoubleClick2Activate = _config.uiItem.doubleClick2Activate; - autoUpdateInterval = _config.autoUpdateInterval; - autoUpdateSubInterval = _config.autoUpdateSubInterval; - trayMenuServersLimit = _config.trayMenuServersLimit; + autoUpdateInterval = _config.guiItem.autoUpdateInterval; + autoUpdateSubInterval = _config.guiItem.autoUpdateSubInterval; + trayMenuServersLimit = _config.guiItem.trayMenuServersLimit; currentFontFamily = _config.uiItem.currentFontFamily; SpeedTestTimeout = _config.speedTestItem.speedTestTimeout; SpeedTestUrl = _config.speedTestItem.speedTestUrl; @@ -312,24 +312,24 @@ namespace v2rayN.ViewModels //UI Utils.SetAutoRun(AutoRun); - _config.autoRun = AutoRun; - _config.enableStatistics = EnableStatistics; - _config.statisticsFreshRate = StatisticsFreshRate; - if (_config.statisticsFreshRate > 100 || _config.statisticsFreshRate < 1) + _config.guiItem.autoRun = AutoRun; + _config.guiItem.enableStatistics = EnableStatistics; + _config.guiItem.statisticsFreshRate = StatisticsFreshRate; + if (_config.guiItem.statisticsFreshRate > 100 || _config.guiItem.statisticsFreshRate < 1) { - _config.statisticsFreshRate = 1; + _config.guiItem.statisticsFreshRate = 1; } - _config.keepOlderDedupl = KeepOlderDedupl; - _config.ignoreGeoUpdateCore = IgnoreGeoUpdateCore; + _config.guiItem.keepOlderDedupl = KeepOlderDedupl; + _config.guiItem.ignoreGeoUpdateCore = IgnoreGeoUpdateCore; _config.uiItem.enableAutoAdjustMainLvColWidth = EnableAutoAdjustMainLvColWidth; - _config.enableSecurityProtocolTls13 = EnableSecurityProtocolTls13; + _config.guiItem.enableSecurityProtocolTls13 = EnableSecurityProtocolTls13; _config.uiItem.autoHideStartup = AutoHideStartup; - _config.autoUpdateInterval = autoUpdateInterval; - _config.autoUpdateSubInterval = autoUpdateSubInterval; - _config.checkPreReleaseUpdate = EnableCheckPreReleaseUpdate; + _config.guiItem.autoUpdateInterval = autoUpdateInterval; + _config.guiItem.autoUpdateSubInterval = autoUpdateSubInterval; + _config.guiItem.checkPreReleaseUpdate = EnableCheckPreReleaseUpdate; _config.uiItem.enableDragDropSort = EnableDragDropSort; _config.uiItem.doubleClick2Activate = DoubleClick2Activate; - _config.trayMenuServersLimit = trayMenuServersLimit; + _config.guiItem.trayMenuServersLimit = trayMenuServersLimit; _config.uiItem.currentFontFamily = currentFontFamily; _config.speedTestItem.speedTestTimeout = SpeedTestTimeout; _config.speedTestItem.speedTestUrl = SpeedTestUrl; diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index f84eac79..b6a75966 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -434,7 +434,7 @@ namespace v2rayN.Views var width = ConfigHandler.GetformMainLvColWidth(ref _config, ((EServerColName)k).ToString(), Convert.ToInt32(lstProfiles.Columns[k].Width.Value)); lstProfiles.Columns[k].Width = width; } - if (!_config.enableStatistics) + if (!_config.guiItem.enableStatistics) { colTodayUp.Visibility = Visibility.Hidden; colTodayDown.Visibility = Visibility.Hidden;