From f64c29972d2220493a09f5d42a0327e80cfdf906 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 14 Nov 2026 16:47:48 +0800 Subject: [PATCH] Split configuration management by storage type Move file-backed settings to ConfigTextManager and database operations to ConfigDbManager. Update desktop, Web API, and test references, and add Web API development launch settings. --- v2rayN/ServiceLib.Tests/GlobalUsings.cs | 1 + .../ConfigHandlerCustomSubscriptionTests.cs | 5 +- v2rayN/ServiceLib/GlobalUsings.cs | 1 + .../Builder/CoreConfigContextBuilder.cs | 4 +- .../ServiceLib/Handler/ConnectionHandler.cs | 4 +- .../ServiceLib/Handler/CoreConfigHandler.cs | 2 +- .../ServiceLib/Handler/SubscriptionHandler.cs | 4 +- .../Handler/SysProxy/ProxySettingLinux.cs | 2 +- .../Handler/SysProxy/ProxySettingOSX.cs | 2 +- v2rayN/ServiceLib/Manager/AppManager.cs | 5 +- v2rayN/ServiceLib/Manager/ClashApiManager.cs | 4 +- .../Data/ConfigDbManager.cs} | 301 +----------------- .../Manager/Data/ConfigTextManager.cs | 299 +++++++++++++++++ .../Manager/{ => Data}/ProfileExManager.cs | 2 +- v2rayN/ServiceLib/Manager/PacManager.cs | 2 +- v2rayN/ServiceLib/Manager/TaskManager.cs | 6 +- v2rayN/ServiceLib/Manager/WebDavManager.cs | 2 +- .../CoreConfig/V2ray/V2rayBalancerService.cs | 4 +- .../ViewModels/AddGroupServerViewModel.cs | 4 +- .../ViewModels/AddServer2ViewModel.cs | 8 +- .../ViewModels/AddServerViewModel.cs | 6 +- .../ViewModels/BackupAndRestoreViewModel.cs | 6 +- .../ViewModels/CheckUpdateViewModel.cs | 6 +- .../ViewModels/ClashConnectionsViewModel.cs | 2 +- .../ViewModels/ClashProxiesViewModel.cs | 2 +- .../ViewModels/DNSSettingViewModel.cs | 12 +- .../ViewModels/FullConfigTemplateViewModel.cs | 8 +- .../GlobalHotkeySettingViewModel.cs | 6 +- .../ViewModels/MainWindowViewModel.cs | 20 +- v2rayN/ServiceLib/ViewModels/MsgViewModel.cs | 2 +- .../ViewModels/OptionSettingViewModel.cs | 6 +- .../ViewModels/ProfilesSelectViewModel.cs | 2 +- .../ViewModels/ProfilesViewModel.cs | 32 +- .../ViewModels/RoutingRuleDetailsViewModel.cs | 2 +- .../ViewModels/RoutingRuleSettingViewModel.cs | 8 +- .../ViewModels/RoutingSettingViewModel.cs | 14 +- .../ViewModels/StatusBarViewModel.cs | 16 +- .../ServiceLib/ViewModels/SubEditViewModel.cs | 6 +- .../ViewModels/SubSettingViewModel.cs | 6 +- v2rayN/v2rayN.Desktop/App.axaml.cs | 6 +- v2rayN/v2rayN.Desktop/Base/WindowBase.cs | 4 +- v2rayN/v2rayN.Desktop/GlobalUsings.cs | 1 + v2rayN/v2rayN.Desktop/Program.cs | 2 +- .../ViewModels/ThemeSettingViewModel.cs | 9 +- .../Views/ClashConnectionsView.axaml.cs | 2 +- .../Views/DNSSettingWindow.axaml.cs | 2 +- .../Views/FullConfigTemplateWindow.axaml.cs | 2 +- .../v2rayN.Desktop/Views/MainWindow.axaml.cs | 8 +- .../Views/OptionSettingWindow.axaml.cs | 2 +- .../Views/ProfilesView.axaml.cs | 2 +- .../Views/StatusBarView.axaml.cs | 2 +- v2rayN/v2rayN.WebAPI/GlobalUsings.cs | 12 + .../Properties/launchSettings.json | 12 + .../Services/RegionalPresetStager.cs | 6 +- .../Services/V2rayRuntime.Backup.cs | 9 +- .../Services/V2rayRuntime.CoreUpdate.cs | 4 +- .../Services/V2rayRuntime.Profiles.cs | 39 +-- .../Services/V2rayRuntime.Scheduling.cs | 4 +- .../Services/V2rayRuntime.Settings.cs | 60 ++-- v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.cs | 44 +-- v2rayN/v2rayN.WebAPI/Tests/GlobalUsings.cs | 9 + .../Tests/ParityValidationTests.cs | 8 +- .../Tests/RegionalPresetStagingTests.cs | 8 +- .../Tests/SniffingSettingsIntegrationTests.cs | 3 +- v2rayN/v2rayN/Base/WindowBase.cs | 4 +- .../v2rayN/Converters/MaterialDesignFonts.cs | 2 +- v2rayN/v2rayN/GlobalUsings.cs | 1 + v2rayN/v2rayN/Manager/HotkeyManager.cs | 2 +- v2rayN/v2rayN/Manager/WindowsManager.cs | 3 +- .../ViewModels/ThemeSettingViewModel.cs | 11 +- .../v2rayN/Views/AddGroupServerWindow.xaml.cs | 2 +- v2rayN/v2rayN/Views/AddServer2Window.xaml.cs | 2 +- v2rayN/v2rayN/Views/AddServerWindow.xaml.cs | 2 +- .../v2rayN/Views/ClashConnectionsView.xaml.cs | 2 +- v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs | 4 +- .../Views/FullConfigTemplateWindow.xaml.cs | 4 +- .../Views/GlobalHotkeySettingWindow.xaml.cs | 2 +- v2rayN/v2rayN/Views/MainWindow.xaml.cs | 8 +- .../v2rayN/Views/OptionSettingWindow.xaml.cs | 4 +- .../v2rayN/Views/ProfilesSelectWindow.xaml.cs | 2 +- v2rayN/v2rayN/Views/ProfilesView.xaml.cs | 2 +- .../Views/RoutingRuleDetailsWindow.xaml.cs | 2 +- .../Views/RoutingRuleSettingWindow.xaml.cs | 2 +- .../v2rayN/Views/RoutingSettingWindow.xaml.cs | 2 +- v2rayN/v2rayN/Views/StatusBarView.xaml.cs | 2 +- v2rayN/v2rayN/Views/SubEditWindow.xaml.cs | 2 +- v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs | 2 +- 87 files changed, 622 insertions(+), 531 deletions(-) rename v2rayN/ServiceLib/{Handler/ConfigHandler.cs => Manager/Data/ConfigDbManager.cs} (91%) create mode 100644 v2rayN/ServiceLib/Manager/Data/ConfigTextManager.cs rename v2rayN/ServiceLib/Manager/{ => Data}/ProfileExManager.cs (99%) create mode 100644 v2rayN/v2rayN.WebAPI/GlobalUsings.cs create mode 100644 v2rayN/v2rayN.WebAPI/Properties/launchSettings.json create mode 100644 v2rayN/v2rayN.WebAPI/Tests/GlobalUsings.cs diff --git a/v2rayN/ServiceLib.Tests/GlobalUsings.cs b/v2rayN/ServiceLib.Tests/GlobalUsings.cs index 52bc6321..1e4d98a0 100644 --- a/v2rayN/ServiceLib.Tests/GlobalUsings.cs +++ b/v2rayN/ServiceLib.Tests/GlobalUsings.cs @@ -23,6 +23,7 @@ global using ServiceLib.Handler.Fmt; global using ServiceLib.Handler.SysProxy; global using ServiceLib.Helper; global using ServiceLib.Manager; +global using ServiceLib.Manager.Data; global using ServiceLib.Models.CoreConfigs; global using ServiceLib.Models.Configs; global using ServiceLib.Models.Dto; diff --git a/v2rayN/ServiceLib.Tests/Handler/ConfigHandlerCustomSubscriptionTests.cs b/v2rayN/ServiceLib.Tests/Handler/ConfigHandlerCustomSubscriptionTests.cs index 45d42812..e3d52fd7 100644 --- a/v2rayN/ServiceLib.Tests/Handler/ConfigHandlerCustomSubscriptionTests.cs +++ b/v2rayN/ServiceLib.Tests/Handler/ConfigHandlerCustomSubscriptionTests.cs @@ -1,3 +1,4 @@ + using ServiceLib.Tests.CoreConfig; namespace ServiceLib.Tests.Handler; @@ -31,7 +32,7 @@ public class ConfigHandlerCustomSubscriptionTests oldProfile.IsSub = true; await SQLiteHelper.Instance.InsertAsync(oldProfile); - var count = await ConfigHandler.AddBatchServers(config, FullXrayConfigs, subId, true); + var count = await ConfigDbManager.AddBatchServers(config, FullXrayConfigs, subId, true); var profiles = await AppManager.Instance.ProfileItems(subId) ?? []; await count.Should().BeEqualTo(2); @@ -65,7 +66,7 @@ public class ConfigHandlerCustomSubscriptionTests await SQLiteHelper.Instance.InsertAsync(existing); var invalidSubscription = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("not a valid profile")); - var count = await ConfigHandler.AddBatchServers(config, invalidSubscription, subId, true); + var count = await ConfigDbManager.AddBatchServers(config, invalidSubscription, subId, true); var profiles = await AppManager.Instance.ProfileItems(subId) ?? []; await (count < 1).Should().BeTrue(); diff --git a/v2rayN/ServiceLib/GlobalUsings.cs b/v2rayN/ServiceLib/GlobalUsings.cs index 9ebc2cfc..cbd350b2 100644 --- a/v2rayN/ServiceLib/GlobalUsings.cs +++ b/v2rayN/ServiceLib/GlobalUsings.cs @@ -33,6 +33,7 @@ global using ServiceLib.Handler.Fmt; global using ServiceLib.Handler.SysProxy; global using ServiceLib.Helper; global using ServiceLib.Manager; +global using ServiceLib.Manager.Data; global using ServiceLib.Models.Configs; global using ServiceLib.Models.CoreConfigs; global using ServiceLib.Models.Dto; diff --git a/v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs b/v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs index 5d4e8a5c..d0b8fe32 100644 --- a/v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs +++ b/v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs @@ -46,7 +46,7 @@ public class CoreConfigContextBuilder SimpleDnsItem = config.SimpleDNSItem, ProtectDomainList = [], RawDnsItem = await AppManager.Instance.GetDNSItem(coreType), - RoutingItem = await ConfigHandler.GetDefaultRouting(config), + RoutingItem = await ConfigDbManager.GetDefaultRouting(config), IsWindows = Utils.IsWindows(), IsMacOS = Utils.IsMacOS(), IsLinux = Utils.IsLinux(), @@ -204,7 +204,7 @@ public class CoreConfigContextBuilder var node = nodeContext.Node; var coreType = AppManager.Instance.GetCoreType(node, node.ConfigType); - var preSocksItem = ConfigHandler.GetPreSocksItem(config, node, coreType); + var preSocksItem = ConfigDbManager.GetPreSocksItem(config, node, coreType); if (preSocksItem != null) { var preSocksResult = await Build(nodeContext.AppConfig, preSocksItem); diff --git a/v2rayN/ServiceLib/Handler/ConnectionHandler.cs b/v2rayN/ServiceLib/Handler/ConnectionHandler.cs index b0d90fff..7bd18209 100644 --- a/v2rayN/ServiceLib/Handler/ConnectionHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConnectionHandler.cs @@ -79,7 +79,7 @@ public static class ConnectionHandler public static async Task GetRealPingTime(HttpClient client, CancellationToken cancellationToken = default) { - var url = AppManager.Instance.Config.SpeedTestItem.SpeedPingTestUrl; + var url = ConfigTextManager.Instance.Config.SpeedTestItem.SpeedPingTestUrl; var responseTime = -1; try { @@ -114,7 +114,7 @@ public static class ConnectionHandler { try { - var url = AppManager.Instance.Config.SpeedTestItem.IPAPIUrl; + var url = ConfigTextManager.Instance.Config.SpeedTestItem.IPAPIUrl; if (url.IsNullOrEmpty()) { return null; diff --git a/v2rayN/ServiceLib/Handler/CoreConfigHandler.cs b/v2rayN/ServiceLib/Handler/CoreConfigHandler.cs index a68a9552..6793a2eb 100644 --- a/v2rayN/ServiceLib/Handler/CoreConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreConfigHandler.cs @@ -9,7 +9,7 @@ public static class CoreConfigHandler public static async Task GenerateClientConfig(CoreConfigContext context, string? fileName) { - var config = AppManager.Instance.Config; + var config = ConfigTextManager.Instance.Config; var result = new RetResult(); var node = context.Node; diff --git a/v2rayN/ServiceLib/Handler/SubscriptionHandler.cs b/v2rayN/ServiceLib/Handler/SubscriptionHandler.cs index 1a837ee5..c55c187b 100644 --- a/v2rayN/ServiceLib/Handler/SubscriptionHandler.cs +++ b/v2rayN/ServiceLib/Handler/SubscriptionHandler.cs @@ -1,3 +1,5 @@ + + namespace ServiceLib.Handler; public class SubscriptionHandler( @@ -104,7 +106,7 @@ public class SubscriptionHandler( await updateFunc?.Invoke(false, $"{hashCode}{ResUI.MsgStartParsingSubscription}"); // Add servers to configuration - var ret = await ConfigHandler.AddBatchServers(_config, result, id, true); + var ret = await ConfigDbManager.AddBatchServers(_config, result, id, true); if (ret <= 0) { Logging.SaveLog("FailedImportSubscription"); diff --git a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingLinux.cs b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingLinux.cs index 14d61d9c..135a5feb 100644 --- a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingLinux.cs +++ b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingLinux.cs @@ -19,7 +19,7 @@ public static class ProxySettingLinux private static async Task ExecCmd(List args) { - var customSystemProxyScriptPath = AppManager.Instance.Config.SystemProxyItem?.CustomSystemProxyScriptPath; + var customSystemProxyScriptPath = ConfigTextManager.Instance.Config.SystemProxyItem?.CustomSystemProxyScriptPath; var fileName = (customSystemProxyScriptPath.IsNotEmpty() && File.Exists(customSystemProxyScriptPath)) ? customSystemProxyScriptPath : await FileUtils.CreateLinuxShellFile(_proxySetFileName, EmbedUtils.GetEmbedText(Global.ProxySetLinuxShellFileName), false); diff --git a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs index b598a06c..7a3a4fc6 100644 --- a/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs +++ b/v2rayN/ServiceLib/Handler/SysProxy/ProxySettingOSX.cs @@ -24,7 +24,7 @@ public static class ProxySettingOSX private static async Task ExecCmd(List args) { - var customSystemProxyScriptPath = AppManager.Instance.Config.SystemProxyItem?.CustomSystemProxyScriptPath; + var customSystemProxyScriptPath = ConfigTextManager.Instance.Config.SystemProxyItem?.CustomSystemProxyScriptPath; var fileName = (customSystemProxyScriptPath.IsNotEmpty() && File.Exists(customSystemProxyScriptPath)) ? customSystemProxyScriptPath : await FileUtils.CreateLinuxShellFile(_proxySetFileName, EmbedUtils.GetEmbedText(Global.ProxySetOSXShellFileName), false); diff --git a/v2rayN/ServiceLib/Manager/AppManager.cs b/v2rayN/ServiceLib/Manager/AppManager.cs index 72d29305..3bb4bd2a 100644 --- a/v2rayN/ServiceLib/Manager/AppManager.cs +++ b/v2rayN/ServiceLib/Manager/AppManager.cs @@ -9,7 +9,6 @@ public sealed class AppManager private int? _statePort; private int? _statePort2; public static AppManager Instance => _instance.Value; - public Config Config => _config; public IWindowDialog WindowDialog { get; set; } = null!; public int StatePort @@ -68,7 +67,7 @@ public sealed class AppManager } Logging.Setup(); - var config = ConfigHandler.LoadConfig(); + var config = ConfigTextManager.Instance.Init(); if (config == null) { return false; @@ -129,7 +128,7 @@ public sealed class AppManager AppEvents.AppExitRequested.Publish(); await Task.Delay(50); //Wait for AppExitRequested to be processed - await ConfigHandler.SaveConfig(_config); + await ConfigTextManager.Instance.SaveConfig(); await ProfileExManager.Instance.SaveTo(); await StatisticsManager.Instance.SaveTo(); await CoreManager.Instance.CoreStop(); diff --git a/v2rayN/ServiceLib/Manager/ClashApiManager.cs b/v2rayN/ServiceLib/Manager/ClashApiManager.cs index 0b50814b..cfc88499 100644 --- a/v2rayN/ServiceLib/Manager/ClashApiManager.cs +++ b/v2rayN/ServiceLib/Manager/ClashApiManager.cs @@ -82,7 +82,7 @@ public sealed class ClashApiManager private async Task TestProxyDelay(string name) { var url = $"{ApiUrl}/proxies/{Utils.UrlEncode(name)}/delay?timeout=10000&url=" + - Utils.UrlEncode(AppManager.Instance.Config.SpeedTestItem.SpeedPingTestUrl); + Utils.UrlEncode(ConfigTextManager.Instance.Config.SpeedTestItem.SpeedPingTestUrl); return await SendTestRequest(url); } @@ -90,7 +90,7 @@ public sealed class ClashApiManager { var url = $"{ApiUrl}/providers/proxies/{Utils.UrlEncode(providerName)}/{Utils.UrlEncode(name)}/healthcheck?timeout=10000&url=" + - Utils.UrlEncode(AppManager.Instance.Config.SpeedTestItem.SpeedPingTestUrl); + Utils.UrlEncode(ConfigTextManager.Instance.Config.SpeedTestItem.SpeedPingTestUrl); return await SendTestRequest(url); } diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Manager/Data/ConfigDbManager.cs similarity index 91% rename from v2rayN/ServiceLib/Handler/ConfigHandler.cs rename to v2rayN/ServiceLib/Manager/Data/ConfigDbManager.cs index b6c9ac2f..40d28ddf 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Manager/Data/ConfigDbManager.cs @@ -1,251 +1,14 @@ -namespace ServiceLib.Handler; +namespace ServiceLib.Manager.Data; -public static class ConfigHandler +public static class ConfigDbManager { - private static readonly string _configRes = Global.ConfigFileName; - private static readonly string _tag = "ConfigHandler"; + private static readonly string _tag = "ConfigDbManager"; - #region ConfigHandler - - /// - /// Load the application configuration file - /// If the file exists, deserialize it from JSON - /// If not found, create a new Config object with default settings - /// Initialize default values for missing configuration sections - /// - /// Config object containing application settings or null if there's an error - public static Config? LoadConfig() + private static async Task SaveConfig() { - Config? config = null; - var result = EmbedUtils.LoadResource(Utils.GetConfigPath(_configRes)); - if (result.IsNotEmpty()) - { - config = JsonUtils.Deserialize(result); - } - else - { - if (File.Exists(Utils.GetConfigPath(_configRes))) - { - Logging.SaveLog("LoadConfig Exception"); - return null; - } - } - - config ??= new Config(); - - config.CoreBasicItem ??= new() - { - LogEnabled = false, - Loglevel = "warning", - }; - - if (config.Inbound == null) - { - config.Inbound = []; - InItem inItem = new() - { - Protocol = nameof(EInboundProtocol.socks), - LocalPort = 10808, - UdpEnabled = true, - SniffingEnabled = true, - RouteOnly = false, - }; - - config.Inbound.Add(inItem); - } - else - { - if (config.Inbound.Count > 0) - { - config.Inbound.First().Protocol = nameof(EInboundProtocol.socks); - } - } - - config.RoutingBasicItem ??= new(); - if (config.RoutingBasicItem.DomainStrategy.IsNullOrEmpty()) - { - config.RoutingBasicItem.DomainStrategy = Global.DomainStrategies.First(); - } - - config.KcpItem ??= new KcpItem - { - Mtu = 1350, - Tti = 50, - UplinkCapacity = 12, - DownlinkCapacity = 100, - CwndMultiplier = 1, - MaxSendingWindow = 2 * 1024 * 1024, - }; - config.KcpItem.CwndMultiplier = config.KcpItem.CwndMultiplier <= 0 ? 1 : config.KcpItem.CwndMultiplier; - config.KcpItem.MaxSendingWindow = config.KcpItem.MaxSendingWindow <= 0 ? (2 * 1024 * 1024) : config.KcpItem.MaxSendingWindow; - config.GrpcItem ??= new GrpcItem - { - IdleTimeout = 60, - HealthCheckTimeout = 20, - PermitWithoutStream = false, - InitialWindowsSize = 0, - }; - config.TunModeItem ??= new TunModeItem - { - EnableTun = false, - Mtu = 9000, - IcmpRouting = Global.TunIcmpRoutingPolicies.First(), - EnableLegacyProtect = true, - }; - config.GuiItem ??= new(); - if (!Global.RootCertProviders.Contains(config.GuiItem.RootCertProvider)) - { - config.GuiItem.RootCertProvider = Global.RootCertProviders.First(); - } - config.MsgUIItem ??= new(); - - config.UiItem ??= new(); - config.UiItem.MainColumnItem ??= []; - config.UiItem.WindowSizeItem ??= []; - if (config.UiItem.FrozenColumnCount == null) - { - var lvColumnItem = config.UiItem.MainColumnItem.OrderBy(t => t.Index).ToList(); - if (lvColumnItem.Count == 0 - || (lvColumnItem.Count >= 2 - && lvColumnItem[0].Name.Equals("ConfigType") - && lvColumnItem[1].Name.Equals("Remarks"))) - { - config.UiItem.FrozenColumnCount = 2; - } - else - { - config.UiItem.FrozenColumnCount = 0; - } - } - - if (config.UiItem.CurrentLanguage.IsNullOrEmpty()) - { - config.UiItem.CurrentLanguage = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName.Equals("zh", StringComparison.CurrentCultureIgnoreCase) - ? Global.Languages.First() - : Global.Languages[2]; - } - - config.ConstItem ??= new ConstItem(); - - config.SimpleDNSItem ??= InitBuiltinSimpleDNS(); - config.SimpleDNSItem.BlockAAAAQuery ??= false; - config.SimpleDNSItem.FakeIPRange ??= Global.FakeIPRanges.FirstOrDefault(); - config.SimpleDNSItem.FakeIPv6 ??= false; - config.SimpleDNSItem.FakeIPv6Range ??= Global.FakeIPv6Ranges.First(); - config.SimpleDNSItem.GlobalFakeIp ??= true; - config.SimpleDNSItem.BootstrapDNS ??= Global.DomainPureIPDNSAddress.FirstOrDefault(); - config.SimpleDNSItem.ServeStale ??= false; - config.SimpleDNSItem.ParallelQuery ??= false; - config.SimpleDNSItem.EnableHappyEyeballs ??= false; - - config.SpeedTestItem ??= new(); - if (config.SpeedTestItem.SpeedTestTimeout < 10) - { - config.SpeedTestItem.SpeedTestTimeout = 10; - } - if (config.SpeedTestItem.SpeedTestUrl.IsNullOrEmpty()) - { - config.SpeedTestItem.SpeedTestUrl = Global.SpeedTestUrls.First(); - } - if (config.SpeedTestItem.SpeedPingTestUrl.IsNullOrEmpty()) - { - config.SpeedTestItem.SpeedPingTestUrl = Global.SpeedPingTestUrls.First(); - } - config.SpeedTestItem.MixedConcurrencyCount = Math.Max(config.SpeedTestItem.MixedConcurrencyCount, Global.SpeedTestConcurrencyCountMin); - if (config.SpeedTestItem.UdpTestTarget.IsNullOrEmpty()) - { - config.SpeedTestItem.UdpTestTarget = Global.UdpTestTargets.First(); - } - - config.Mux4RayItem ??= new() - { - Concurrency = 8, - XudpConcurrency = 16, - XudpProxyUDP443 = "reject" - }; - - config.Mux4SboxItem ??= new() - { - Protocol = Global.SingboxMuxs.First(), - MaxConnections = 8 - }; - - config.HysteriaItem ??= new() - { - UpMbps = 100, - DownMbps = 100 - }; - config.ClashUIItem ??= new(); - config.ClashUIItem.ConnectionsColumnItem ??= []; - config.SystemProxyItem ??= new(); - config.WebDavItem ??= new(); - config.CheckUpdateItem ??= new(); - config.Fragment4RayItem ??= new() - { - Packets = "tlshello", - }; - config.Fragment4RayItem.MaxSplit ??= "0"; - - config.HappyEyeballs4RayItem ??= new() - { - TryDelayMs = 250, - PrioritizeIPv6 = false, - Interleave = 1, - MaxConcurrentTry = 4, - }; - if ((config.Fragment4RayItem.Lengths ?? []).Count == 0) - { - config.Fragment4RayItem.Lengths = [config.Fragment4RayItem.Length ?? "50-100"]; - } - if ((config.Fragment4RayItem.Delays ?? []).Count == 0) - { - config.Fragment4RayItem.Delays = [config.Fragment4RayItem.Interval ?? "10-20"]; - } - config.GlobalHotkeys ??= []; - - if (config.SystemProxyItem.SystemProxyExceptions.IsNullOrEmpty()) - { - config.SystemProxyItem.SystemProxyExceptions = Utils.IsWindows() ? Global.SystemProxyExceptionsWindows : Global.SystemProxyExceptionsLinux; - } - - return config; + return await ConfigTextManager.Instance.SaveConfig(); } - /// - /// Save the configuration to a file - /// First writes to a temporary file, then replaces the original file - /// - /// Configuration object to be saved - /// 0 if successful, -1 if failed - public static async Task SaveConfig(Config config) - { - try - { - //save temp file - var resPath = Utils.GetConfigPath(_configRes); - var tempPath = $"{resPath}_temp"; - - var content = JsonUtils.Serialize(config, true, true); - if (content.IsNullOrEmpty()) - { - return -1; - } - await File.WriteAllTextAsync(tempPath, content); - - //rename - File.Move(tempPath, resPath, true); - } - catch (Exception ex) - { - Logging.SaveLog(_tag, ex); - return -1; - } - - return 0; - } - - #endregion ConfigHandler - #region Server /// @@ -428,7 +191,7 @@ public static class ConfigHandler config.IndexId = indexId; - await SaveConfig(config); + await SaveConfig(); return 0; } @@ -1816,7 +1579,7 @@ public static class ConfigHandler await SQLiteHelper.Instance.InsertAllAsync(lstAdd); } - await SaveConfig(config); + await SaveConfig(); return countServers; } @@ -2056,7 +1819,7 @@ public static class ConfigHandler counter++; } } - await SaveConfig(config); + await SaveConfig(); return counter; } @@ -2087,7 +1850,7 @@ public static class ConfigHandler counter++; } } - await SaveConfig(config); + await SaveConfig(); return counter; } return -1; @@ -2137,7 +1900,7 @@ public static class ConfigHandler { await SQLiteHelper.Instance.InsertAllAsync(lstAdd); } - await SaveConfig(config); + await SaveConfig(); return counter; } @@ -2236,7 +1999,7 @@ public static class ConfigHandler var existItem = FindMatchedProfileItem(lstSub, activeProfile); if (existItem != null) { - await ConfigHandler.SetDefaultServerIndex(config, existItem.IndexId); + await ConfigDbManager.SetDefaultServerIndex(config, existItem.IndexId); } } @@ -2729,7 +2492,7 @@ public static class ConfigHandler var lockItem = items?.FirstOrDefault(t => t.Locked == true); if (lockItem != null) { - await ConfigHandler.RemoveRoutingItem(lockItem); + await ConfigDbManager.RemoveRoutingItem(lockItem); items = await AppManager.Instance.RoutingItems(); } @@ -3077,44 +2840,4 @@ public static class ConfigHandler } #endregion Regional Presets - - #region UIItem - - public static WindowSizeItem? GetWindowSizeItem(Config config, string typeName) - { - var sizeItem = config?.UiItem?.WindowSizeItem?.FirstOrDefault(t => t.TypeName == typeName); - if (sizeItem == null || sizeItem.Width <= 0 || sizeItem.Height <= 0) - { - return null; - } - - return sizeItem; - } - - public static int SaveWindowSizeItem(Config config, string typeName, double width, double height) - { - var sizeItem = config?.UiItem?.WindowSizeItem?.FirstOrDefault(t => t.TypeName == typeName); - if (sizeItem == null) - { - sizeItem = new WindowSizeItem { TypeName = typeName }; - config.UiItem.WindowSizeItem.Add(sizeItem); - } - - sizeItem.Width = (int)width; - sizeItem.Height = (int)height; - - return 0; - } - - public static int SaveMainGirdHeight(Config config, double height1, double height2) - { - var uiItem = config.UiItem ?? new(); - - uiItem.MainGirdHeight1 = (int)(height1 + 0.1); - uiItem.MainGirdHeight2 = (int)(height2 + 0.1); - - return 0; - } - - #endregion UIItem } diff --git a/v2rayN/ServiceLib/Manager/Data/ConfigTextManager.cs b/v2rayN/ServiceLib/Manager/Data/ConfigTextManager.cs new file mode 100644 index 00000000..95eda405 --- /dev/null +++ b/v2rayN/ServiceLib/Manager/Data/ConfigTextManager.cs @@ -0,0 +1,299 @@ +namespace ServiceLib.Manager.Data; + +public class ConfigTextManager +{ + private static readonly Lazy _instance = new(() => new()); + public static ConfigTextManager Instance => _instance.Value; + + private static readonly string _configRes = Global.ConfigFileName; + private static readonly string _tag = "ConfigTextManager"; + + public Config Config { get; private set; } + + #region Init + + public Config? Init() + { + Config = LoadConfig(); + return Config; + } + + /// + /// Load the application configuration file + /// If the file exists, deserialize it from JSON + /// If not found, create a new Config object with default settings + /// Initialize default values for missing configuration sections + /// + /// Config object containing application settings or null if there's an error + private Config? LoadConfig() + { + Config? config = null; + var result = EmbedUtils.LoadResource(Utils.GetConfigPath(_configRes)); + if (result.IsNotEmpty()) + { + config = JsonUtils.Deserialize(result); + } + else + { + if (File.Exists(Utils.GetConfigPath(_configRes))) + { + Logging.SaveLog("LoadConfig Exception"); + return null; + } + } + + config ??= new Config(); + + config.CoreBasicItem ??= new() + { + LogEnabled = false, + Loglevel = "warning", + }; + + if (config.Inbound == null) + { + config.Inbound = []; + InItem inItem = new() + { + Protocol = nameof(EInboundProtocol.socks), + LocalPort = 10808, + UdpEnabled = true, + SniffingEnabled = true, + RouteOnly = false, + }; + + config.Inbound.Add(inItem); + } + else + { + if (config.Inbound.Count > 0) + { + config.Inbound.First().Protocol = nameof(EInboundProtocol.socks); + } + } + + config.RoutingBasicItem ??= new(); + if (config.RoutingBasicItem.DomainStrategy.IsNullOrEmpty()) + { + config.RoutingBasicItem.DomainStrategy = Global.DomainStrategies.First(); + } + + config.KcpItem ??= new KcpItem + { + Mtu = 1350, + Tti = 50, + UplinkCapacity = 12, + DownlinkCapacity = 100, + CwndMultiplier = 1, + MaxSendingWindow = 2 * 1024 * 1024, + }; + config.KcpItem.CwndMultiplier = config.KcpItem.CwndMultiplier <= 0 ? 1 : config.KcpItem.CwndMultiplier; + config.KcpItem.MaxSendingWindow = config.KcpItem.MaxSendingWindow <= 0 ? (2 * 1024 * 1024) : config.KcpItem.MaxSendingWindow; + config.GrpcItem ??= new GrpcItem + { + IdleTimeout = 60, + HealthCheckTimeout = 20, + PermitWithoutStream = false, + InitialWindowsSize = 0, + }; + config.TunModeItem ??= new TunModeItem + { + EnableTun = false, + Mtu = 9000, + IcmpRouting = Global.TunIcmpRoutingPolicies.First(), + EnableLegacyProtect = true, + }; + config.GuiItem ??= new(); + if (!Global.RootCertProviders.Contains(config.GuiItem.RootCertProvider)) + { + config.GuiItem.RootCertProvider = Global.RootCertProviders.First(); + } + config.MsgUIItem ??= new(); + + config.UiItem ??= new(); + config.UiItem.MainColumnItem ??= []; + config.UiItem.WindowSizeItem ??= []; + if (config.UiItem.FrozenColumnCount == null) + { + var lvColumnItem = config.UiItem.MainColumnItem.OrderBy(t => t.Index).ToList(); + if (lvColumnItem.Count == 0 + || (lvColumnItem.Count >= 2 + && lvColumnItem[0].Name.Equals("ConfigType") + && lvColumnItem[1].Name.Equals("Remarks"))) + { + config.UiItem.FrozenColumnCount = 2; + } + else + { + config.UiItem.FrozenColumnCount = 0; + } + } + + if (config.UiItem.CurrentLanguage.IsNullOrEmpty()) + { + config.UiItem.CurrentLanguage = Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName.Equals("zh", StringComparison.CurrentCultureIgnoreCase) + ? Global.Languages.First() + : Global.Languages[2]; + } + + config.ConstItem ??= new ConstItem(); + + config.SimpleDNSItem ??= ConfigDbManager.InitBuiltinSimpleDNS(); + config.SimpleDNSItem.BlockAAAAQuery ??= false; + config.SimpleDNSItem.FakeIPRange ??= Global.FakeIPRanges.FirstOrDefault(); + config.SimpleDNSItem.FakeIPv6 ??= false; + config.SimpleDNSItem.FakeIPv6Range ??= Global.FakeIPv6Ranges.First(); + config.SimpleDNSItem.GlobalFakeIp ??= true; + config.SimpleDNSItem.BootstrapDNS ??= Global.DomainPureIPDNSAddress.FirstOrDefault(); + config.SimpleDNSItem.ServeStale ??= false; + config.SimpleDNSItem.ParallelQuery ??= false; + config.SimpleDNSItem.EnableHappyEyeballs ??= false; + + config.SpeedTestItem ??= new(); + if (config.SpeedTestItem.SpeedTestTimeout < 10) + { + config.SpeedTestItem.SpeedTestTimeout = 10; + } + if (config.SpeedTestItem.SpeedTestUrl.IsNullOrEmpty()) + { + config.SpeedTestItem.SpeedTestUrl = Global.SpeedTestUrls.First(); + } + if (config.SpeedTestItem.SpeedPingTestUrl.IsNullOrEmpty()) + { + config.SpeedTestItem.SpeedPingTestUrl = Global.SpeedPingTestUrls.First(); + } + config.SpeedTestItem.MixedConcurrencyCount = Math.Max(config.SpeedTestItem.MixedConcurrencyCount, Global.SpeedTestConcurrencyCountMin); + if (config.SpeedTestItem.UdpTestTarget.IsNullOrEmpty()) + { + config.SpeedTestItem.UdpTestTarget = Global.UdpTestTargets.First(); + } + + config.Mux4RayItem ??= new() + { + Concurrency = 8, + XudpConcurrency = 16, + XudpProxyUDP443 = "reject" + }; + + config.Mux4SboxItem ??= new() + { + Protocol = Global.SingboxMuxs.First(), + MaxConnections = 8 + }; + + config.HysteriaItem ??= new() + { + UpMbps = 100, + DownMbps = 100 + }; + config.ClashUIItem ??= new(); + config.ClashUIItem.ConnectionsColumnItem ??= []; + config.SystemProxyItem ??= new(); + config.WebDavItem ??= new(); + config.CheckUpdateItem ??= new(); + config.Fragment4RayItem ??= new() + { + Packets = "tlshello", + }; + config.Fragment4RayItem.MaxSplit ??= "0"; + + config.HappyEyeballs4RayItem ??= new() + { + TryDelayMs = 250, + PrioritizeIPv6 = false, + Interleave = 1, + MaxConcurrentTry = 4, + }; + if ((config.Fragment4RayItem.Lengths ?? []).Count == 0) + { + config.Fragment4RayItem.Lengths = [config.Fragment4RayItem.Length ?? "50-100"]; + } + if ((config.Fragment4RayItem.Delays ?? []).Count == 0) + { + config.Fragment4RayItem.Delays = [config.Fragment4RayItem.Interval ?? "10-20"]; + } + config.GlobalHotkeys ??= []; + + if (config.SystemProxyItem.SystemProxyExceptions.IsNullOrEmpty()) + { + config.SystemProxyItem.SystemProxyExceptions = Utils.IsWindows() ? Global.SystemProxyExceptionsWindows : Global.SystemProxyExceptionsLinux; + } + + return config; + } + + /// + /// Save the configuration to a file + /// First writes to a temporary file, then replaces the original file + /// + /// Configuration object to be saved + /// 0 if successful, -1 if failed + public async Task SaveConfig() + { + try + { + //save temp file + var resPath = Utils.GetConfigPath(_configRes); + var tempPath = $"{resPath}_temp"; + + var content = JsonUtils.Serialize(Config, true, true); + if (content.IsNullOrEmpty()) + { + return -1; + } + await File.WriteAllTextAsync(tempPath, content); + + //rename + File.Move(tempPath, resPath, true); + } + catch (Exception ex) + { + Logging.SaveLog(_tag, ex); + return -1; + } + + return 0; + } + + #endregion Init + + #region UIItem + + public static WindowSizeItem? GetWindowSizeItem(Config config, string typeName) + { + var sizeItem = config?.UiItem?.WindowSizeItem?.FirstOrDefault(t => t.TypeName == typeName); + if (sizeItem == null || sizeItem.Width <= 0 || sizeItem.Height <= 0) + { + return null; + } + + return sizeItem; + } + + public static int SaveWindowSizeItem(Config config, string typeName, double width, double height) + { + var sizeItem = config?.UiItem?.WindowSizeItem?.FirstOrDefault(t => t.TypeName == typeName); + if (sizeItem == null) + { + sizeItem = new WindowSizeItem { TypeName = typeName }; + config.UiItem.WindowSizeItem.Add(sizeItem); + } + + sizeItem.Width = (int)width; + sizeItem.Height = (int)height; + + return 0; + } + + public static int SaveMainGirdHeight(Config config, double height1, double height2) + { + var uiItem = config.UiItem ?? new(); + + uiItem.MainGirdHeight1 = (int)(height1 + 0.1); + uiItem.MainGirdHeight2 = (int)(height2 + 0.1); + + return 0; + } + + #endregion UIItem +} diff --git a/v2rayN/ServiceLib/Manager/ProfileExManager.cs b/v2rayN/ServiceLib/Manager/Data/ProfileExManager.cs similarity index 99% rename from v2rayN/ServiceLib/Manager/ProfileExManager.cs rename to v2rayN/ServiceLib/Manager/Data/ProfileExManager.cs index 1c361716..beed2734 100644 --- a/v2rayN/ServiceLib/Manager/ProfileExManager.cs +++ b/v2rayN/ServiceLib/Manager/Data/ProfileExManager.cs @@ -1,4 +1,4 @@ -namespace ServiceLib.Manager; +namespace ServiceLib.Manager.Data; public class ProfileExManager { diff --git a/v2rayN/ServiceLib/Manager/PacManager.cs b/v2rayN/ServiceLib/Manager/PacManager.cs index 37386a13..e4b1b5d3 100644 --- a/v2rayN/ServiceLib/Manager/PacManager.cs +++ b/v2rayN/ServiceLib/Manager/PacManager.cs @@ -31,7 +31,7 @@ public class PacManager private async Task InitText(int httpPort) { - var customSystemProxyPacPath = AppManager.Instance.Config.SystemProxyItem.CustomSystemProxyPacPath; + var customSystemProxyPacPath = ConfigTextManager.Instance.Config.SystemProxyItem.CustomSystemProxyPacPath; var fileName = customSystemProxyPacPath.IsNotEmpty() && File.Exists(customSystemProxyPacPath) ? customSystemProxyPacPath : Path.Combine(Utils.GetConfigPath(), "pac.txt"); diff --git a/v2rayN/ServiceLib/Manager/TaskManager.cs b/v2rayN/ServiceLib/Manager/TaskManager.cs index 18121c49..a548e1bc 100644 --- a/v2rayN/ServiceLib/Manager/TaskManager.cs +++ b/v2rayN/ServiceLib/Manager/TaskManager.cs @@ -1,3 +1,5 @@ + + namespace ServiceLib.Manager; public class TaskManager @@ -40,7 +42,7 @@ public class TaskManager try { - await ConfigHandler.SaveConfig(_config); + await ConfigTextManager.Instance.SaveConfig(); await ProfileExManager.Instance.SaveTo(); } catch (Exception ex) @@ -111,7 +113,7 @@ public class TaskManager }); await handler.UpdateProcess(item.Id); item.UpdateTime = updateTime; - await ConfigHandler.AddSubItem(_config, item); + await ConfigDbManager.AddSubItem(_config, item); await Task.Delay(1000); } } diff --git a/v2rayN/ServiceLib/Manager/WebDavManager.cs b/v2rayN/ServiceLib/Manager/WebDavManager.cs index 54c31a1b..403139bb 100644 --- a/v2rayN/ServiceLib/Manager/WebDavManager.cs +++ b/v2rayN/ServiceLib/Manager/WebDavManager.cs @@ -16,7 +16,7 @@ public sealed class WebDavManager public WebDavManager() { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; } private async Task GetClient() diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayBalancerService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayBalancerService.cs index 2fb2025d..36eaa48a 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayBalancerService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayBalancerService.cs @@ -47,7 +47,7 @@ public partial class CoreConfigV2rayService subjectSelector = [baseTagName], pingConfig = new() { - destination = AppManager.Instance.Config.SpeedTestItem.SpeedPingTestUrl, + destination = ConfigTextManager.Instance.Config.SpeedTestItem.SpeedPingTestUrl, interval = "5m", timeout = "30s", sampling = 2, @@ -68,7 +68,7 @@ public partial class CoreConfigV2rayService _coreConfig.observatory = new Observatory4Ray { subjectSelector = [baseTagName], - probeUrl = AppManager.Instance.Config.SpeedTestItem.SpeedPingTestUrl, + probeUrl = ConfigTextManager.Instance.Config.SpeedTestItem.SpeedPingTestUrl, probeInterval = "3m", enableConcurrency = true, }; diff --git a/v2rayN/ServiceLib/ViewModels/AddGroupServerViewModel.cs b/v2rayN/ServiceLib/ViewModels/AddGroupServerViewModel.cs index 970bd8cc..af63204f 100644 --- a/v2rayN/ServiceLib/ViewModels/AddGroupServerViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/AddGroupServerViewModel.cs @@ -43,7 +43,7 @@ public partial class AddGroupServerViewModel : MyReactiveObject, ICloseable public AddGroupServerViewModel(ProfileItem profileItem) { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; var canEditRemove = this.WhenAnyValue( x => x.SelectedChild, @@ -245,7 +245,7 @@ public partial class AddGroupServerViewModel : MyReactiveObject, ICloseable SelectedSource.SetProtocolExtra(protocolExtra); - if (await ConfigHandler.AddServerCommon(_config, SelectedSource) == 0) + if (await ConfigDbManager.AddServerCommon(_config, SelectedSource) == 0) { NoticeManager.Instance.Enqueue(ResUI.OperationSuccess); RequestClose?.Invoke(this, EventArgs.Empty); diff --git a/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs b/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs index 6d08dbab..09c8e2e1 100644 --- a/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/AddServer2ViewModel.cs @@ -1,3 +1,5 @@ + + namespace ServiceLib.ViewModels; public partial class AddServer2ViewModel : MyReactiveObject, ICloseable @@ -22,7 +24,7 @@ public partial class AddServer2ViewModel : MyReactiveObject, ICloseable public AddServer2ViewModel(ProfileItem profileItem) { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; BrowseServerCmd = ReactiveCommand.CreateFromTask(async () => { @@ -69,7 +71,7 @@ public partial class AddServer2ViewModel : MyReactiveObject, ICloseable IsSingboxEndpoint = IsSingboxEndpoint ? true : null, }); - if (await ConfigHandler.EditCustomServer(_config, SelectedSource) == 0) + if (await ConfigDbManager.EditCustomServer(_config, SelectedSource) == 0) { NoticeManager.Instance.Enqueue(ResUI.OperationSuccess); RequestClose?.Invoke(this, EventArgs.Empty); @@ -90,7 +92,7 @@ public partial class AddServer2ViewModel : MyReactiveObject, ICloseable var item = await AppManager.Instance.GetProfileItem(SelectedSource.IndexId); item ??= SelectedSource; item.Address = fileName; - var result = item.ConfigType == EConfigType.Outbound ? await ConfigHandler.AddCustomOutboundServer(_config, item, false) : await ConfigHandler.AddCustomServer(_config, item, false); + var result = item.ConfigType == EConfigType.Outbound ? await ConfigDbManager.AddCustomOutboundServer(_config, item, false) : await ConfigDbManager.AddCustomServer(_config, item, false); if (result == 0) { NoticeManager.Instance.Enqueue(ResUI.SuccessfullyImportedCustomServer); diff --git a/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs b/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs index 76965f5a..2fa7fabd 100644 --- a/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/AddServerViewModel.cs @@ -1,3 +1,5 @@ + + namespace ServiceLib.ViewModels; public partial class AddServerViewModel : MyReactiveObject, ICloseable @@ -317,7 +319,7 @@ public partial class AddServerViewModel : MyReactiveObject, ICloseable public AddServerViewModel(ProfileItem profileItem) { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; FetchCertCmd = ReactiveCommand.CreateFromTask(async () => { @@ -592,7 +594,7 @@ public partial class AddServerViewModel : MyReactiveObject, ICloseable }); SelectedSource.SetTransportExtra(transport); - if (await ConfigHandler.AddServer(_config, SelectedSource) == 0) + if (await ConfigDbManager.AddServer(_config, SelectedSource) == 0) { NoticeManager.Instance.Enqueue(ResUI.OperationSuccess); RequestClose?.Invoke(this, EventArgs.Empty); diff --git a/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs b/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs index f0cc0f5d..a90d8a2a 100644 --- a/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs @@ -1,3 +1,5 @@ + + namespace ServiceLib.ViewModels; public partial class BackupAndRestoreViewModel : MyReactiveObject @@ -17,7 +19,7 @@ public partial class BackupAndRestoreViewModel : MyReactiveObject public BackupAndRestoreViewModel() { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; WebDavCheckCmd = ReactiveCommand.CreateFromTask(async () => { @@ -44,7 +46,7 @@ public partial class BackupAndRestoreViewModel : MyReactiveObject { DisplayOperationMsg(); _config.WebDavItem = SelectedSource; - _ = await ConfigHandler.SaveConfig(_config); + _ = await ConfigTextManager.Instance.SaveConfig(); var result = await WebDavManager.Instance.CheckConnection(); if (result) diff --git a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs index f8b04b72..c6dbb091 100644 --- a/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/CheckUpdateViewModel.cs @@ -1,3 +1,5 @@ + + namespace ServiceLib.ViewModels; public partial class CheckUpdateViewModel : MyReactiveObject @@ -17,7 +19,7 @@ public partial class CheckUpdateViewModel : MyReactiveObject public CheckUpdateViewModel() { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; CheckUpdateCmd = ReactiveCommand.CreateFromTask(CheckUpdate); CheckUpdateCmd.ThrownExceptions.Subscribe(ex => @@ -124,7 +126,7 @@ public partial class CheckUpdateViewModel : MyReactiveObject .Select(t => t.CoreTypeForStorage) .ToList(); - await ConfigHandler.SaveConfig(_config); + await ConfigTextManager.Instance.SaveConfig(); } private async Task CheckOnly() diff --git a/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs index 98299fc9..d90e494d 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashConnectionsViewModel.cs @@ -4,7 +4,7 @@ public partial class ClashConnectionsViewModel : MyReactiveObject { public ClashConnectionsViewModel() { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; AutoRefresh = _config.ClashUIItem.ConnectionsAutoRefresh; var canEditRemove = this.WhenAnyValue( diff --git a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs index d3fe3cd2..4ab3eb88 100644 --- a/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ClashProxiesViewModel.cs @@ -7,7 +7,7 @@ public partial class ClashProxiesViewModel : MyReactiveObject public ClashProxiesViewModel() { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; ProxiesReloadCmd = ReactiveCommand.CreateFromTask(async () => { diff --git a/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs index c4a63db4..459be253 100644 --- a/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs @@ -1,3 +1,5 @@ + + namespace ServiceLib.ViewModels; public partial class DNSSettingViewModel : MyReactiveObject, ICloseable @@ -46,7 +48,7 @@ public partial class DNSSettingViewModel : MyReactiveObject, ICloseable public DNSSettingViewModel() { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; SaveCmd = ReactiveCommand.CreateFromTask(SaveSettingAsync); ImportDefConfig4V2rayCompatibleCmd = ReactiveCommand.CreateFromTask(async () => @@ -80,7 +82,7 @@ public partial class DNSSettingViewModel : MyReactiveObject, ICloseable private async Task Init() { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; var item = _config.SimpleDNSItem; UseSystemHosts = item.UseSystemHosts ?? false; AddCommonHosts = item.AddCommonHosts ?? false; @@ -205,7 +207,7 @@ public partial class DNSSettingViewModel : MyReactiveObject, ICloseable item1.UseSystemHosts = UseSystemHostsCompatible; item1.NormalDNS = NormalDNSCompatible; item1.TunDNS = TunDNSCompatible; - await ConfigHandler.SaveDNSItems(_config, item1); + await ConfigDbManager.SaveDNSItems(_config, item1); var item2 = await AppManager.Instance.GetDNSItem(ECoreType.sing_box); item2.Enabled = SBCustomDNSEnableCompatible; @@ -213,9 +215,9 @@ public partial class DNSSettingViewModel : MyReactiveObject, ICloseable item2.DomainDNSAddress = DomainDNSAddress2Compatible; item2.NormalDNS = JsonUtils.Serialize(JsonUtils.Deserialize(NormalDNS2Compatible)); item2.TunDNS = JsonUtils.Serialize(JsonUtils.Deserialize(TunDNS2Compatible)); - await ConfigHandler.SaveDNSItems(_config, item2); + await ConfigDbManager.SaveDNSItems(_config, item2); - await ConfigHandler.SaveConfig(_config); + await ConfigTextManager.Instance.SaveConfig(); RequestClose?.Invoke(this, EventArgs.Empty); } } diff --git a/v2rayN/ServiceLib/ViewModels/FullConfigTemplateViewModel.cs b/v2rayN/ServiceLib/ViewModels/FullConfigTemplateViewModel.cs index b10c2cf6..5a21eba3 100644 --- a/v2rayN/ServiceLib/ViewModels/FullConfigTemplateViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/FullConfigTemplateViewModel.cs @@ -1,3 +1,5 @@ + + namespace ServiceLib.ViewModels; public partial class FullConfigTemplateViewModel : MyReactiveObject, ICloseable @@ -42,7 +44,7 @@ public partial class FullConfigTemplateViewModel : MyReactiveObject, ICloseable public FullConfigTemplateViewModel() { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; SaveCmd = ReactiveCommand.CreateFromTask(async () => { await SaveSettingAsync(); @@ -102,7 +104,7 @@ public partial class FullConfigTemplateViewModel : MyReactiveObject, ICloseable item.AddProxyOnly = AddProxyOnly4Ray; item.ProxyDetour = ProxyDetour4Ray; - await ConfigHandler.SaveFullConfigTemplate(_config, item); + await ConfigDbManager.SaveFullConfigTemplate(_config, item); return true; } @@ -120,7 +122,7 @@ public partial class FullConfigTemplateViewModel : MyReactiveObject, ICloseable item.AddProxyOnly = AddProxyOnly4Singbox; item.ProxyDetour = ProxyDetour4Singbox; - await ConfigHandler.SaveFullConfigTemplate(_config, item); + await ConfigDbManager.SaveFullConfigTemplate(_config, item); return true; } } diff --git a/v2rayN/ServiceLib/ViewModels/GlobalHotkeySettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/GlobalHotkeySettingViewModel.cs index b630457a..7f9ea362 100644 --- a/v2rayN/ServiceLib/ViewModels/GlobalHotkeySettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/GlobalHotkeySettingViewModel.cs @@ -1,3 +1,5 @@ + + namespace ServiceLib.ViewModels; public class GlobalHotkeySettingViewModel : MyReactiveObject, ICloseable @@ -10,7 +12,7 @@ public class GlobalHotkeySettingViewModel : MyReactiveObject, ICloseable public GlobalHotkeySettingViewModel() { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; _globalHotkeys = JsonUtils.DeepCopy(_config.GlobalHotkeys); @@ -50,7 +52,7 @@ public class GlobalHotkeySettingViewModel : MyReactiveObject, ICloseable { _config.GlobalHotkeys = _globalHotkeys; - if (await ConfigHandler.SaveConfig(_config) == 0) + if (await ConfigTextManager.Instance.SaveConfig() == 0) { RequestClose?.Invoke(this, EventArgs.Empty); } diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index 547f859c..b4edb324 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -90,7 +90,7 @@ public partial class MainWindowViewModel : MyReactiveObject public MainWindowViewModel() { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; BlIsWindows = Utils.IsWindows(); MainGirdOrientation = _config.UiItem.MainGirdOrientation; @@ -331,8 +331,8 @@ public partial class MainWindowViewModel : MyReactiveObject } //await ConfigHandler.InitBuiltinRouting(_config); - await ConfigHandler.InitBuiltinDNS(_config); - await ConfigHandler.InitBuiltinFullConfigTemplate(_config); + await ConfigDbManager.InitBuiltinDNS(_config); + await ConfigDbManager.InitBuiltinFullConfigTemplate(_config); await ProfileExManager.Instance.Init(); await CoreManager.Instance.Init(_config, UpdateHandler); await CertPemManager.Instance.Init(_config); @@ -499,7 +499,7 @@ public partial class MainWindowViewModel : MyReactiveObject } stringData = result; } - var ret = await ConfigHandler.AddBatchServers(_config, stringData, _config.SubIndexId, false); + var ret = await ConfigDbManager.AddBatchServers(_config, stringData, _config.SubIndexId, false); if (ret > 0) { await RefreshSubscriptions(); @@ -549,7 +549,7 @@ public partial class MainWindowViewModel : MyReactiveObject } else { - var ret = await ConfigHandler.AddBatchServers(_config, result, _config.SubIndexId, false); + var ret = await ConfigDbManager.AddBatchServers(_config, result, _config.SubIndexId, false); if (ret > 0) { await RefreshSubscriptions(); @@ -610,7 +610,7 @@ public partial class MainWindowViewModel : MyReactiveObject var ret = await AppManager.Instance.WindowDialog.ShowDialogAsync(routingSettingViewModel); if (ret == true) { - await ConfigHandler.InitBuiltinRouting(_config); + await ConfigDbManager.InitBuiltinRouting(_config); RxSchedulers.MainThreadScheduler.Schedule(async () => { await StatusBarViewModel.RefreshRoutingsMenu(); @@ -696,7 +696,7 @@ public partial class MainWindowViewModel : MyReactiveObject TabMainSelectedIndex = 0; } }); - var profileItem = await ConfigHandler.GetDefaultServer(_config); + var profileItem = await ConfigDbManager.GetDefaultServer(_config); if (profileItem == null) { NoticeManager.Instance.Enqueue(ResUI.CheckServerSettings); @@ -788,14 +788,14 @@ public partial class MainWindowViewModel : MyReactiveObject public async Task ApplyRegionalPreset(EPresetType type) { - await ConfigHandler.ApplyRegionalPreset(_config, type); - await ConfigHandler.InitRouting(_config); + await ConfigDbManager.ApplyRegionalPreset(_config, type); + await ConfigDbManager.InitRouting(_config); RxSchedulers.MainThreadScheduler.Schedule(async () => { await StatusBarViewModel.RefreshRoutingsMenu(); }); - await ConfigHandler.SaveConfig(_config); + await ConfigTextManager.Instance.SaveConfig(); using var downloadService = await DownloadService.CreateDownloadServiceWithCheck(); await new UpdateService(downloadService, _config, UpdateTaskHandler).UpdateGeoFileAll(); await Reload(); diff --git a/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs b/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs index 2a1b2fea..3ccf635e 100644 --- a/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MsgViewModel.cs @@ -16,7 +16,7 @@ public partial class MsgViewModel : MyReactiveObject public MsgViewModel() { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; MsgFilter = _config.MsgUIItem.MainMsgFilter ?? string.Empty; AutoRefresh = _config.MsgUIItem.AutoRefresh ?? true; diff --git a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs index 5c81d1de..db55b24a 100644 --- a/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs @@ -1,3 +1,5 @@ + + namespace ServiceLib.ViewModels; public partial class OptionSettingViewModel : MyReactiveObject, ICloseable @@ -122,7 +124,7 @@ public partial class OptionSettingViewModel : MyReactiveObject, ICloseable public OptionSettingViewModel() { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; BlIsWindows = Utils.IsWindows(); BlIsLinux = Utils.IsLinux(); BlIsIsMacOS = Utils.IsMacOS(); @@ -405,7 +407,7 @@ public partial class OptionSettingViewModel : MyReactiveObject, ICloseable //coreType await SaveCoreType(); - if (await ConfigHandler.SaveConfig(_config) == 0) + if (await ConfigTextManager.Instance.SaveConfig() == 0) { await AutoStartupHandler.UpdateTask(_config); AppManager.Instance.Reset(); diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs index 32bb5f45..c733ad92 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesSelectViewModel.cs @@ -51,7 +51,7 @@ public partial class ProfilesSelectViewModel : MyReactiveObject, ICloseable public ProfilesSelectViewModel() { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; _subIndexId = _config.SubIndexId ?? string.Empty; #region WhenAnyValue && ReactiveCommand diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs index 0f6c859d..34d84205 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs @@ -1,3 +1,5 @@ + + namespace ServiceLib.ViewModels; public partial class ProfilesViewModel : MyReactiveObject @@ -94,7 +96,7 @@ public partial class ProfilesViewModel : MyReactiveObject public ProfilesViewModel() { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; #region WhenAnyValue && ReactiveCommand @@ -399,7 +401,7 @@ public partial class ProfilesViewModel : MyReactiveObject { var lstModel = await AppManager.Instance.ProfileModels(_config.SubIndexId, filter); - await ConfigHandler.SetDefaultServer(_config, lstModel); + await ConfigDbManager.SetDefaultServer(_config, lstModel); var lstServerStat = (_config.GuiItem.EnableStatistics ? StatisticsManager.Instance.ServerStat : null) ?? []; var lstProfileExs = await ProfileExManager.Instance.GetProfileExs(); @@ -514,7 +516,7 @@ public partial class ProfilesViewModel : MyReactiveObject } var exists = lstSelected.Exists(t => t.IndexId == _config.IndexId); - await ConfigHandler.RemoveServers(_config, lstSelected); + await ConfigDbManager.RemoveServers(_config, lstSelected); NoticeManager.Instance.Enqueue(ResUI.OperationSuccess); if (lstSelected.Count == ProfileItems.Count) { @@ -534,7 +536,7 @@ public partial class ProfilesViewModel : MyReactiveObject return; } - var tuple = await ConfigHandler.DedupServerList(_config, _config.SubIndexId); + var tuple = await ConfigDbManager.DedupServerList(_config, _config.SubIndexId); if (tuple.Item1 > 0 || tuple.Item2 > 0) { await RefreshServers(); @@ -550,7 +552,7 @@ public partial class ProfilesViewModel : MyReactiveObject { return; } - if (await ConfigHandler.CopyServer(_config, lstSelected) == 0) + if (await ConfigDbManager.CopyServer(_config, lstSelected) == 0) { await RefreshServers(); NoticeManager.Instance.Enqueue(ResUI.OperationSuccess); @@ -583,7 +585,7 @@ public partial class ProfilesViewModel : MyReactiveObject return; } - if (await ConfigHandler.SetDefaultServerIndex(_config, indexId) == 0) + if (await ConfigDbManager.SetDefaultServerIndex(_config, indexId) == 0) { await RefreshServers(); Reload(); @@ -609,7 +611,7 @@ public partial class ProfilesViewModel : MyReactiveObject private async Task GenGroupAllServer() { - var ret = await ConfigHandler.AddGroupAllServer(_config, SelectedSub); + var ret = await ConfigDbManager.AddGroupAllServer(_config, SelectedSub); if (ret.Success != true) { NoticeManager.Instance.Enqueue(ResUI.OperationFailed); @@ -621,7 +623,7 @@ public partial class ProfilesViewModel : MyReactiveObject private async Task GenGroupRegionServer() { - var ret = await ConfigHandler.AddGroupRegionServer(_config, SelectedSub); + var ret = await ConfigDbManager.AddGroupRegionServer(_config, SelectedSub); if (ret.Success != true) { NoticeManager.Instance.Enqueue(ResUI.OperationFailed); @@ -641,7 +643,7 @@ public partial class ProfilesViewModel : MyReactiveObject _dicHeaderSort.TryAdd(colName, true); _dicHeaderSort.TryGetValue(colName, out var asc); - if (await ConfigHandler.SortServers(_config, _config.SubIndexId, colName, asc) != 0) + if (await ConfigDbManager.SortServers(_config, _config.SubIndexId, colName, asc) != 0) { return; } @@ -651,7 +653,7 @@ public partial class ProfilesViewModel : MyReactiveObject public async Task RemoveInvalidServerResult() { - var count = await ConfigHandler.RemoveInvalidServerResult(_config, _config.SubIndexId); + var count = await ConfigDbManager.RemoveInvalidServerResult(_config, _config.SubIndexId); await RefreshServers(); NoticeManager.Instance.Enqueue(string.Format(ResUI.RemoveInvalidServerResultTip, count)); } @@ -665,7 +667,7 @@ public partial class ProfilesViewModel : MyReactiveObject return; } - await ConfigHandler.MoveToGroup(_config, lstSelected, SelectedMoveToGroup.Id); + await ConfigDbManager.MoveToGroup(_config, lstSelected, SelectedMoveToGroup.Id); NoticeManager.Instance.Enqueue(ResUI.OperationSuccess); await RefreshServers(); @@ -683,7 +685,7 @@ public partial class ProfilesViewModel : MyReactiveObject return; } - if (await ConfigHandler.MoveServer(_config, lstProfile, index, eMove) == 0) + if (await ConfigDbManager.MoveServer(_config, lstProfile, index, eMove) == 0) { await RefreshServers(); } @@ -695,7 +697,7 @@ public partial class ProfilesViewModel : MyReactiveObject if (startIndex >= 0 && targetIndex >= 0 && startIndex != targetIndex) { var lstProfile = ProfileItems?.Select(t => t.IndexId).ToList() ?? []; - if (await ConfigHandler.MoveServer(_config, lstProfile, startIndex, EMove.Position, targetIndex) == 0) + if (await ConfigDbManager.MoveServer(_config, lstProfile, startIndex, EMove.Position, targetIndex) == 0) { await RefreshServers(); } @@ -717,7 +719,7 @@ public partial class ProfilesViewModel : MyReactiveObject .Select(item => item.IndexId) .ToList(); - var result = await ConfigHandler.MoveServersTo( + var result = await ConfigDbManager.MoveServersTo( _config, orderedProfileIds, sourceIndices, @@ -921,7 +923,7 @@ public partial class ProfilesViewModel : MyReactiveObject { return; } - await ConfigHandler.DeleteSubItem(_config, item.Id); + await ConfigDbManager.DeleteSubItem(_config, item.Id); await RefreshSubscriptions(); await SubSelectedChangedAsync(); diff --git a/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs b/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs index ee6826bc..aba722c5 100644 --- a/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/RoutingRuleDetailsViewModel.cs @@ -45,7 +45,7 @@ public partial class RoutingRuleDetailsViewModel : MyReactiveObject, ICloseable public RoutingRuleDetailsViewModel(RulesItem rulesItem) { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; SelectProfileCmd = ReactiveCommand.CreateFromTask(async () => { diff --git a/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs index d95fddfd..6f1c6e8f 100644 --- a/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/RoutingRuleSettingViewModel.cs @@ -1,3 +1,5 @@ + + namespace ServiceLib.ViewModels; public partial class RoutingRuleSettingViewModel : MyReactiveObject, ICloseable @@ -36,7 +38,7 @@ public partial class RoutingRuleSettingViewModel : MyReactiveObject, ICloseable public RoutingRuleSettingViewModel(RoutingItem routingItem) { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; var canEditRemove = this.WhenAnyValue( x => x.SelectedSource, @@ -209,7 +211,7 @@ public partial class RoutingRuleSettingViewModel : MyReactiveObject, ICloseable return; } var index = _rules.IndexOf(item); - if (await ConfigHandler.MoveRoutingRule(_rules, index, eMove) == 0) + if (await ConfigDbManager.MoveRoutingRule(_rules, index, eMove) == 0) { RefreshRulesItems(); } @@ -231,7 +233,7 @@ public partial class RoutingRuleSettingViewModel : MyReactiveObject, ICloseable item.RuleNum = _rules.Count; item.RuleSet = JsonUtils.Serialize(_rules, false); - if (await ConfigHandler.SaveRoutingItem(_config, item) == 0) + if (await ConfigDbManager.SaveRoutingItem(_config, item) == 0) { NoticeManager.Instance.Enqueue(ResUI.OperationSuccess); RequestClose?.Invoke(this, EventArgs.Empty); diff --git a/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs index 709e3cb6..98eb3306 100644 --- a/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/RoutingSettingViewModel.cs @@ -1,3 +1,5 @@ + + namespace ServiceLib.ViewModels; public partial class RoutingSettingViewModel : MyReactiveObject @@ -30,7 +32,7 @@ public partial class RoutingSettingViewModel : MyReactiveObject public RoutingSettingViewModel() { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; var canEditRemove = this.WhenAnyValue( x => x.SelectedSource, @@ -75,7 +77,7 @@ public partial class RoutingSettingViewModel : MyReactiveObject DomainStrategy = _config.RoutingBasicItem.DomainStrategy; DomainStrategy4Singbox = _config.RoutingBasicItem.DomainStrategy4Singbox; - await ConfigHandler.InitBuiltinRouting(_config); + await ConfigDbManager.InitBuiltinRouting(_config); await RefreshRoutingItems(); } @@ -111,7 +113,7 @@ public partial class RoutingSettingViewModel : MyReactiveObject { _config.RoutingBasicItem.DomainStrategy = DomainStrategy; _config.RoutingBasicItem.DomainStrategy4Singbox = DomainStrategy4Singbox; - await ConfigHandler.SaveConfig(_config); + await ConfigTextManager.Instance.SaveConfig(); } #endregion Refresh Save @@ -155,7 +157,7 @@ public partial class RoutingSettingViewModel : MyReactiveObject var item = await AppManager.Instance.GetRoutingItem(it?.Id); if (item != null) { - await ConfigHandler.RemoveRoutingItem(item); + await ConfigDbManager.RemoveRoutingItem(item); } } @@ -172,7 +174,7 @@ public partial class RoutingSettingViewModel : MyReactiveObject return; } - if (await ConfigHandler.SetDefaultRouting(_config, item) == 0) + if (await ConfigDbManager.SetDefaultRouting(_config, item) == 0) { await RefreshRoutingItems(); IsModified = true; @@ -181,7 +183,7 @@ public partial class RoutingSettingViewModel : MyReactiveObject private async Task RoutingAdvancedImportRules() { - if (await ConfigHandler.InitRouting(_config, true) == 0) + if (await ConfigDbManager.InitRouting(_config, true) == 0) { await RefreshRoutingItems(); IsModified = true; diff --git a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs index 91895e3f..a403e822 100644 --- a/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/StatusBarViewModel.cs @@ -1,3 +1,5 @@ + + namespace ServiceLib.ViewModels; public partial class StatusBarViewModel : MyReactiveObject @@ -105,7 +107,7 @@ public partial class StatusBarViewModel : MyReactiveObject public StatusBarViewModel() { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; SelectedRouting = new(); SelectedServer = new(); RunningServerToolTipText = GetRunningServerToolTipText("-"); @@ -216,7 +218,7 @@ public partial class StatusBarViewModel : MyReactiveObject private async Task Init() { - await ConfigHandler.InitBuiltinRouting(_config); + await ConfigDbManager.InitBuiltinRouting(_config); await RefreshRoutingsMenu(); await InboundDisplayStatus(); // The view refreshes its icon on initialization; interaction handlers are not registered yet. @@ -265,7 +267,7 @@ public partial class StatusBarViewModel : MyReactiveObject await RefreshServersMenu(); //display running server - var running = await ConfigHandler.GetDefaultServer(_config); + var running = await ConfigDbManager.GetDefaultServer(_config); if (running != null) { RunningServerDisplay = running.GetSummary(); @@ -317,7 +319,7 @@ public partial class StatusBarViewModel : MyReactiveObject public async Task TestServerAvailability() { - var item = await ConfigHandler.GetDefaultServer(_config); + var item = await ConfigDbManager.GetDefaultServer(_config); if (item == null) { return null; @@ -371,7 +373,7 @@ public partial class StatusBarViewModel : MyReactiveObject NoticeManager.Instance.SendMessageEx($"{ResUI.TipChangeSystemProxy} - {_config.SystemProxyItem.SysProxyType}"); SystemProxySelected = (int)_config.SystemProxyItem.SysProxyType; - await ConfigHandler.SaveConfig(_config); + await ConfigTextManager.Instance.SaveConfig(); } public async Task ChangeSystemProxyAsync(ESysProxyType type, bool blChange) @@ -411,7 +413,7 @@ public partial class StatusBarViewModel : MyReactiveObject return; } - if (await ConfigHandler.SetDefaultRouting(_config, item) == 0) + if (await ConfigDbManager.SetDefaultRouting(_config, item) == 0) { NoticeManager.Instance.SendMessageEx(ResUI.TipChangeRouting); ReloadRequested.Publish(); @@ -457,7 +459,7 @@ public partial class StatusBarViewModel : MyReactiveObject } } - await ConfigHandler.SaveConfig(_config); + await ConfigTextManager.Instance.SaveConfig(); ReloadRequested.Publish(); } diff --git a/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs b/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs index efc64858..71a66c1c 100644 --- a/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/SubEditViewModel.cs @@ -1,3 +1,5 @@ + + namespace ServiceLib.ViewModels; public partial class SubEditViewModel : MyReactiveObject, ICloseable @@ -22,7 +24,7 @@ public partial class SubEditViewModel : MyReactiveObject, ICloseable public SubEditViewModel(SubItem subItem) { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; SelectPrevProfileCmd = ReactiveCommand.CreateFromTask(async () => { @@ -87,7 +89,7 @@ public partial class SubEditViewModel : MyReactiveObject, ICloseable SelectedSource.PrevProfile = PrevProfile; SelectedSource.NextProfile = NextProfile; - if (await ConfigHandler.AddSubItem(_config, SelectedSource) == 0) + if (await ConfigDbManager.AddSubItem(_config, SelectedSource) == 0) { NoticeManager.Instance.Enqueue(ResUI.OperationSuccess); RequestClose?.Invoke(this, EventArgs.Empty); diff --git a/v2rayN/ServiceLib/ViewModels/SubSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/SubSettingViewModel.cs index d3a75a34..e01d3e9e 100644 --- a/v2rayN/ServiceLib/ViewModels/SubSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/SubSettingViewModel.cs @@ -1,3 +1,5 @@ + + namespace ServiceLib.ViewModels; public partial class SubSettingViewModel : MyReactiveObject @@ -20,7 +22,7 @@ public partial class SubSettingViewModel : MyReactiveObject public SubSettingViewModel() { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; var canEditRemove = this.WhenAnyValue( x => x.SelectedSource, @@ -90,7 +92,7 @@ public partial class SubSettingViewModel : MyReactiveObject foreach (var it in SelectedSources ?? [SelectedSource]) { - await ConfigHandler.DeleteSubItem(_config, it.Id); + await ConfigDbManager.DeleteSubItem(_config, it.Id); } await RefreshSubItems(); NoticeManager.Instance.Enqueue(ResUI.OperationSuccess); diff --git a/v2rayN/v2rayN.Desktop/App.axaml.cs b/v2rayN/v2rayN.Desktop/App.axaml.cs index b53b4959..74191475 100644 --- a/v2rayN/v2rayN.Desktop/App.axaml.cs +++ b/v2rayN/v2rayN.Desktop/App.axaml.cs @@ -65,7 +65,7 @@ public partial class App : Application return; } - if (!AppManager.Instance.Config.UiItem.MacOSShowInDock) + if (!ConfigTextManager.Instance.Config.UiItem.MacOSShowInDock) { MacAppUtils.SetActivationPolicyAccessory(); } @@ -76,7 +76,7 @@ public partial class App : Application private static void RestoreMacOSAccessoryPolicyAfterMiniaturize(MainWindow mainWindow) { - if (AppManager.Instance.Config.UiItem.MacOSShowInDock) + if (ConfigTextManager.Instance.Config.UiItem.MacOSShowInDock) { return; } @@ -98,7 +98,7 @@ public partial class App : Application private static void RestoreMacOSAccessoryPolicy(MainWindow mainWindow) { - if (AppManager.Instance.Config.UiItem.MacOSShowInDock || MacAppUtils.IsWindowMiniaturized(mainWindow)) + if (ConfigTextManager.Instance.Config.UiItem.MacOSShowInDock || MacAppUtils.IsWindowMiniaturized(mainWindow)) { return; } diff --git a/v2rayN/v2rayN.Desktop/Base/WindowBase.cs b/v2rayN/v2rayN.Desktop/Base/WindowBase.cs index fda48831..70a7c7c7 100644 --- a/v2rayN/v2rayN.Desktop/Base/WindowBase.cs +++ b/v2rayN/v2rayN.Desktop/Base/WindowBase.cs @@ -23,7 +23,7 @@ public class WindowBase : ReactiveWindow where TViewMode { try { - var sizeItem = ConfigHandler.GetWindowSizeItem(AppManager.Instance.Config, GetType().Name); + var sizeItem = ConfigTextManager.GetWindowSizeItem(ConfigTextManager.Instance.Config, GetType().Name); if (sizeItem is null) { return; @@ -55,7 +55,7 @@ public class WindowBase : ReactiveWindow where TViewMode base.OnClosed(e); try { - ConfigHandler.SaveWindowSizeItem(AppManager.Instance.Config, GetType().Name, Width, Height); + ConfigTextManager.SaveWindowSizeItem(ConfigTextManager.Instance.Config, GetType().Name, Width, Height); } catch { } } diff --git a/v2rayN/v2rayN.Desktop/GlobalUsings.cs b/v2rayN/v2rayN.Desktop/GlobalUsings.cs index f15be259..e498e66f 100644 --- a/v2rayN/v2rayN.Desktop/GlobalUsings.cs +++ b/v2rayN/v2rayN.Desktop/GlobalUsings.cs @@ -31,6 +31,7 @@ global using ServiceLib.Enums; global using ServiceLib.Events; global using ServiceLib.Handler; global using ServiceLib.Manager; +global using ServiceLib.Manager.Data; global using ServiceLib.Models.CoreConfigs; global using ServiceLib.Models.Configs; global using ServiceLib.Models.Dto; diff --git a/v2rayN/v2rayN.Desktop/Program.cs b/v2rayN/v2rayN.Desktop/Program.cs index b7e76b1c..c961ab26 100644 --- a/v2rayN/v2rayN.Desktop/Program.cs +++ b/v2rayN/v2rayN.Desktop/Program.cs @@ -69,7 +69,7 @@ internal class Program if (OperatingSystem.IsMacOS()) { - var showInDock = Design.IsDesignMode || AppManager.Instance.Config.UiItem.MacOSShowInDock; + var showInDock = Design.IsDesignMode || ConfigTextManager.Instance.Config.UiItem.MacOSShowInDock; builder = builder.With(new MacOSPlatformOptions { ShowInDock = showInDock }); } diff --git a/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs b/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs index d18f873e..d502ebee 100644 --- a/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs +++ b/v2rayN/v2rayN.Desktop/ViewModels/ThemeSettingViewModel.cs @@ -1,5 +1,6 @@ using Semi.Avalonia; + namespace v2rayN.Desktop.ViewModels; public partial class ThemeSettingViewModel : MyReactiveObject @@ -12,7 +13,7 @@ public partial class ThemeSettingViewModel : MyReactiveObject public ThemeSettingViewModel() { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; BindingUI(); RestoreUI(); @@ -42,7 +43,7 @@ public partial class ThemeSettingViewModel : MyReactiveObject { _config.UiItem.CurrentTheme = CurrentTheme; ModifyTheme(); - await ConfigHandler.SaveConfig(_config); + await ConfigTextManager.Instance.SaveConfig(); } }); @@ -54,7 +55,7 @@ public partial class ThemeSettingViewModel : MyReactiveObject { _config.UiItem.CurrentFontSize = CurrentFontSize; ModifyFontSize(); - await ConfigHandler.SaveConfig(_config); + await ConfigTextManager.Instance.SaveConfig(); } }); @@ -66,7 +67,7 @@ public partial class ThemeSettingViewModel : MyReactiveObject { _config.UiItem.CurrentLanguage = CurrentLanguage; Thread.CurrentThread.CurrentUICulture = new(CurrentLanguage); - await ConfigHandler.SaveConfig(_config); + await ConfigTextManager.Instance.SaveConfig(); NoticeManager.Instance.Enqueue(ResUI.NeedRebootTips); } }); diff --git a/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml.cs index 938bbe84..a7afd819 100644 --- a/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/ClashConnectionsView.axaml.cs @@ -9,7 +9,7 @@ public partial class ClashConnectionsView : ReactiveUserControl { InitializeComponent(); - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; Loaded += Window_Loaded; btnCancel.Click += (s, e) => Close(); diff --git a/v2rayN/v2rayN.Desktop/Views/FullConfigTemplateWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/FullConfigTemplateWindow.axaml.cs index 8f7e6f6c..16a6993a 100644 --- a/v2rayN/v2rayN.Desktop/Views/FullConfigTemplateWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/FullConfigTemplateWindow.axaml.cs @@ -10,7 +10,7 @@ public partial class FullConfigTemplateWindow : WindowBase Close(); diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index 650917b5..db3a56a1 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -25,7 +25,7 @@ public partial class MainWindow : WindowBase { InitializeComponent(); - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; _manager = new WindowNotificationManager(TopLevel.GetTopLevel(this)) { MaxItems = 3, Position = NotificationPosition.TopRight }; KeyDown += MainWindow_KeyDown; @@ -396,15 +396,15 @@ public partial class MainWindow : WindowBase private void StorageUI() { - ConfigHandler.SaveWindowSizeItem(_config, GetType().Name, Width, Height); + ConfigTextManager.SaveWindowSizeItem(_config, GetType().Name, Width, Height); if (_config.UiItem.MainGirdOrientation == EGirdOrientation.Horizontal) { - ConfigHandler.SaveMainGirdHeight(_config, gridMain.ColumnDefinitions[0].ActualWidth, gridMain.ColumnDefinitions[2].ActualWidth); + ConfigTextManager.SaveMainGirdHeight(_config, gridMain.ColumnDefinitions[0].ActualWidth, gridMain.ColumnDefinitions[2].ActualWidth); } else if (_config.UiItem.MainGirdOrientation == EGirdOrientation.Vertical) { - ConfigHandler.SaveMainGirdHeight(_config, gridMain.RowDefinitions[0].ActualHeight, gridMain.RowDefinitions[2].ActualHeight); + ConfigTextManager.SaveMainGirdHeight(_config, gridMain.RowDefinitions[0].ActualHeight, gridMain.RowDefinitions[2].ActualHeight); } } diff --git a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs index 8c016813..dae8ad67 100644 --- a/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs @@ -13,7 +13,7 @@ public partial class OptionSettingWindow : WindowBase Loaded += Window_Loaded; btnCancel.Click += (s, e) => Close(); - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; clbdestOverride.SelectionChanged += ClbdestOverride_SelectionChanged; btnBrowseCustomSystemProxyPacPath.Click += BtnBrowseCustomSystemProxyPacPath_Click; diff --git a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs index 89812e6e..691eed93 100644 --- a/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/ProfilesView.axaml.cs @@ -15,7 +15,7 @@ public partial class ProfilesView : ReactiveUserControl { InitializeComponent(); - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; menuSelectAll.Click += menuSelectAll_Click; btnAutofitColumnWidth.Click += BtnAutofitColumnWidth_Click; diff --git a/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs b/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs index 67ad4cfc..51865038 100644 --- a/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/StatusBarView.axaml.cs @@ -11,7 +11,7 @@ public partial class StatusBarView : ReactiveUserControl { InitializeComponent(); - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; txtRunningServerDisplay.Tapped += TxtRunningServerDisplay_Tapped; txtRunningInfoDisplay.Tapped += TxtRunningServerDisplay_Tapped; diff --git a/v2rayN/v2rayN.WebAPI/GlobalUsings.cs b/v2rayN/v2rayN.WebAPI/GlobalUsings.cs new file mode 100644 index 00000000..41833d22 --- /dev/null +++ b/v2rayN/v2rayN.WebAPI/GlobalUsings.cs @@ -0,0 +1,12 @@ +global using ServiceLib; +global using ServiceLib.Base; +global using ServiceLib.Common; +global using ServiceLib.Enums; +global using ServiceLib.Handler; +global using ServiceLib.Manager; +global using ServiceLib.Manager.Data; +global using ServiceLib.Models.Configs; +global using ServiceLib.Models.CoreConfigs; +global using ServiceLib.Models.Dto; +global using ServiceLib.Models.Entities; +global using ServiceLib.Resx; diff --git a/v2rayN/v2rayN.WebAPI/Properties/launchSettings.json b/v2rayN/v2rayN.WebAPI/Properties/launchSettings.json new file mode 100644 index 00000000..af315529 --- /dev/null +++ b/v2rayN/v2rayN.WebAPI/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "profiles": { + "v2rayN.WebAPI": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:4939;http://localhost:4940" + } + } +} \ No newline at end of file diff --git a/v2rayN/v2rayN.WebAPI/Services/RegionalPresetStager.cs b/v2rayN/v2rayN.WebAPI/Services/RegionalPresetStager.cs index 73c152ca..829ff9d3 100644 --- a/v2rayN/v2rayN.WebAPI/Services/RegionalPresetStager.cs +++ b/v2rayN/v2rayN.WebAPI/Services/RegionalPresetStager.cs @@ -2,7 +2,7 @@ using System.Net; using ServiceLib; using ServiceLib.Common; using ServiceLib.Enums; -using ServiceLib.Handler; + using ServiceLib.Models.Configs; using ServiceLib.Models.Dto; using ServiceLib.Models.Entities; @@ -49,7 +49,7 @@ internal sealed class RegionalPresetStager( string.Empty, string.Empty, string.Empty, - ConfigHandler.InitBuiltinSimpleDNS(), + ConfigDbManager.InitBuiltinSimpleDNS(), [CreateDefaultDns(ECoreType.Xray, "V2ray"), CreateDefaultDns(ECoreType.sing_box, "sing-box")], new(null, [])); } @@ -143,7 +143,7 @@ internal sealed class RegionalPresetStager( var content = await TryDownloadAsync(url, proxy, cancellationToken); var template = content is null ? null : JsonUtils.Deserialize(content); return template is null - ? (ConfigHandler.InitBuiltinSimpleDNS(), true) + ? (ConfigDbManager.InitBuiltinSimpleDNS(), true) : (template, false); } diff --git a/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Backup.cs b/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Backup.cs index e117e82e..d2a330e8 100644 --- a/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Backup.cs +++ b/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Backup.cs @@ -3,13 +3,12 @@ using System.Text.Json; using SQLite; using ServiceLib; using ServiceLib.Common; -using ServiceLib.Handler; using ServiceLib.Helper; -using ServiceLib.Manager; using ServiceLib.Models.Configs; using v2rayN.WebAPI.Contracts; using v2rayN.WebAPI.Launcher; + namespace v2rayN.WebAPI.Services; public sealed partial class V2rayRuntime @@ -42,7 +41,7 @@ public sealed partial class V2rayRuntime Config.WebDavItem.Password = input.Password; } Config.WebDavItem.DirName = input.DirName?.Trim(); - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); }); return OperationView.Ok(ApiMessageKeys.WebDavSettingsSaved); } @@ -63,7 +62,7 @@ public sealed partial class V2rayRuntime { await _mutations.RunAsync(async () => { - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); await ProfileExManager.Instance.SaveTo(); await StatisticsManager.Instance.SaveTo(); }); @@ -217,7 +216,7 @@ public sealed partial class V2rayRuntime await ProfileExManager.Instance.SaveTo(); await StatisticsManager.Instance.SaveTo(); StatisticsManager.Instance.Close(); - await _mutations.RunAsync(() => EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)), cancellationToken); + await _mutations.RunAsync(() => EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()), cancellationToken); await SQLiteHelper.Instance.DisposeDbConnectionAsync(); databaseClosed = true; diff --git a/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.CoreUpdate.cs b/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.CoreUpdate.cs index f7f2a59e..ef25759f 100644 --- a/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.CoreUpdate.cs +++ b/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.CoreUpdate.cs @@ -4,8 +4,8 @@ using System.Text.RegularExpressions; using ServiceLib; using ServiceLib.Common; using ServiceLib.Enums; -using ServiceLib.Handler; using ServiceLib.Manager; + using ServiceLib.Models.CoreConfigs; using ServiceLib.Models.Dto; using ServiceLib.Models.Entities; @@ -120,7 +120,7 @@ public sealed partial class V2rayRuntime .Distinct(StringComparer.Ordinal) .ToList(); Config.CheckUpdateItem.UpdateViaProxy = input.UseProxy; - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); }); return OperationView.Ok(ApiMessageKeys.CoreUpdateSettingsSaved); diff --git a/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Profiles.cs b/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Profiles.cs index 8440b1a3..511a59dd 100644 --- a/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Profiles.cs +++ b/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Profiles.cs @@ -5,6 +5,7 @@ using ServiceLib.Handler; using ServiceLib.Handler.Builder; using ServiceLib.Handler.Fmt; using ServiceLib.Manager; + using ServiceLib.Models.Dto; using ServiceLib.Models.Entities; using ServiceLib.Services; @@ -46,7 +47,7 @@ public sealed partial class V2rayRuntime await _mutations.RunAsync(async () => { Config.SubIndexId = subscriptionId ?? string.Empty; - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); }); _events.Publish("profiles-changed", new { subscriptionId = Config.SubIndexId }); return OperationView.Ok(ApiMessageKeys.CommonCompleted, new { subscriptionId = Config.SubIndexId }); @@ -67,10 +68,10 @@ public sealed partial class V2rayRuntime var count = await _mutations.RunAsync(async () => { - var imported = await ConfigHandler.AddBatchServers(Config, request.Content, groupId, request.IsSubscription); + var imported = await ConfigDbManager.AddBatchServers(Config, request.Content, groupId, request.IsSubscription); if (imported > 0) { - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); } return imported; }); @@ -167,13 +168,13 @@ public sealed partial class V2rayRuntime try { result = await _mutations.RunAsync(() => profile.ConfigType.IsGroupType() - ? ConfigHandler.AddServerCommon(Config, profile) + ? ConfigDbManager.AddServerCommon(Config, profile) : profile.ConfigType switch { - EConfigType.Custom when isNew => ConfigHandler.AddCustomServer(Config, profile, blDelete: false), - EConfigType.Outbound when isNew => ConfigHandler.AddCustomOutboundServer(Config, profile, blDelete: false, toFile: true), - EConfigType.Custom or EConfigType.Outbound => ConfigHandler.EditCustomServer(Config, profile), - _ => ConfigHandler.AddServer(Config, profile), + EConfigType.Custom when isNew => ConfigDbManager.AddCustomServer(Config, profile, blDelete: false), + EConfigType.Outbound when isNew => ConfigDbManager.AddCustomOutboundServer(Config, profile, blDelete: false, toFile: true), + EConfigType.Custom or EConfigType.Outbound => ConfigDbManager.EditCustomServer(Config, profile), + _ => ConfigDbManager.AddServer(Config, profile), }); } catch (Exception exception) @@ -270,14 +271,14 @@ public sealed partial class V2rayRuntime await _mutations.RunAsync(async () => { - if (await ConfigHandler.RemoveServers(Config, selected) != 0) + if (await ConfigDbManager.RemoveServers(Config, selected) != 0) { throw new IOException("ServiceLib could not remove the selected profiles."); } if (removesCurrent) { - _ = await ConfigHandler.GetDefaultServer(Config); - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + _ = await ConfigDbManager.GetDefaultServer(Config); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); } }); @@ -304,7 +305,7 @@ public sealed partial class V2rayRuntime return OperationView.Fail("profile_not_found", ApiMessageKeys.ProfileNotFound); } - if (await _mutations.RunAsync(() => ConfigHandler.CopyServer(Config, items)) != 0) + if (await _mutations.RunAsync(() => ConfigDbManager.CopyServer(Config, items)) != 0) { return OperationView.Fail("profile_copy_failed", ApiMessageKeys.CommonInvalidInput); } @@ -326,7 +327,7 @@ public sealed partial class V2rayRuntime return OperationView.Fail("profile_not_found", ApiMessageKeys.ProfileNotFound); } - if (await _mutations.RunAsync(() => ConfigHandler.MoveToGroup(Config, items, request.SubscriptionId ?? string.Empty)) != 0) + if (await _mutations.RunAsync(() => ConfigDbManager.MoveToGroup(Config, items, request.SubscriptionId ?? string.Empty)) != 0) { return OperationView.Fail("profile_move_failed", ApiMessageKeys.CommonInvalidInput); } @@ -345,7 +346,7 @@ public sealed partial class V2rayRuntime return OperationView.Fail("profile_not_in_group", ApiMessageKeys.ProfileNotInGroup); } - var result = await _mutations.RunAsync(() => ConfigHandler.MoveServer(Config, orderedIds, index, request.Direction, request.Position)); + var result = await _mutations.RunAsync(() => ConfigDbManager.MoveServer(Config, orderedIds, index, request.Direction, request.Position)); _events.Publish("profiles-changed", new { subscriptionId = groupId }); return result == 0 ? OperationView.Ok(ApiMessageKeys.ProfileOrderSaved) @@ -360,7 +361,7 @@ public sealed partial class V2rayRuntime return OperationView.Fail("profile_sort_column_invalid", ApiMessageKeys.CommonInvalidInput); } - var result = await _mutations.RunAsync(() => ConfigHandler.SortServers(Config, groupId, request.Column, request.Ascending)); + var result = await _mutations.RunAsync(() => ConfigDbManager.SortServers(Config, groupId, request.Column, request.Ascending)); _events.Publish("profiles-changed", new { subscriptionId = groupId }); return result == 0 ? OperationView.Ok(ApiMessageKeys.ProfileOrderSaved) @@ -369,14 +370,14 @@ public sealed partial class V2rayRuntime public async Task RemoveDuplicateProfilesAsync(string? subscriptionId) { - var result = await _mutations.RunAsync(() => ConfigHandler.DedupServerList(Config, subscriptionId ?? Config.SubIndexId ?? string.Empty)); + var result = await _mutations.RunAsync(() => ConfigDbManager.DedupServerList(Config, subscriptionId ?? Config.SubIndexId ?? string.Empty)); _events.Publish("profiles-changed", new { subscriptionId = subscriptionId ?? Config.SubIndexId }); return OperationView.Ok(ApiMessageKeys.ProfileDeduplicated, new { removed = result.Item1 - result.Item2 }); } public async Task RemoveInvalidProfilesAsync(string? subscriptionId) { - var count = await _mutations.RunAsync(() => ConfigHandler.RemoveInvalidServerResult(Config, subscriptionId ?? Config.SubIndexId ?? string.Empty)); + var count = await _mutations.RunAsync(() => ConfigDbManager.RemoveInvalidServerResult(Config, subscriptionId ?? Config.SubIndexId ?? string.Empty)); _events.Publish("profiles-changed", new { subscriptionId = subscriptionId ?? Config.SubIndexId }); return count < 0 ? OperationView.Ok(ApiMessageKeys.CommonCompleted, new { removed = 0 }) @@ -396,8 +397,8 @@ public sealed partial class V2rayRuntime } var result = await _mutations.RunAsync(() => byRegion - ? ConfigHandler.AddGroupRegionServer(Config, subscription) - : ConfigHandler.AddGroupAllServer(Config, subscription)); + ? ConfigDbManager.AddGroupRegionServer(Config, subscription) + : ConfigDbManager.AddGroupAllServer(Config, subscription)); if (!result.Success) { return OperationView.Fail("profile_group_empty", ApiMessageKeys.ProfileGrouped, result.Data); diff --git a/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Scheduling.cs b/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Scheduling.cs index 8faf1b5c..7d3cee5c 100644 --- a/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Scheduling.cs +++ b/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Scheduling.cs @@ -1,6 +1,4 @@ using ServiceLib.Common; -using ServiceLib.Handler; -using ServiceLib.Manager; using ServiceLib.Models.Entities; using ServiceLib.Services; using v2rayN.WebAPI.Contracts; @@ -65,7 +63,7 @@ public sealed partial class V2rayRuntime await using var operation = await _operations.EnterOperationAsync(token); await _mutations.RunAsync(async () => { - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); await ProfileExManager.Instance.SaveTo(); }, operation.Token); }, cancellationToken); diff --git a/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Settings.cs b/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Settings.cs index 9185dee5..468102bf 100644 --- a/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Settings.cs +++ b/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.Settings.cs @@ -256,7 +256,7 @@ public sealed partial class V2rayRuntime } Config.RoutingBasicItem.DomainStrategy = input.DomainStrategy!; Config.RoutingBasicItem.DomainStrategy4Singbox = input.DomainStrategy4Singbox!; - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); }); } catch (Exception exception) @@ -264,7 +264,7 @@ public sealed partial class V2rayRuntime RestoreConfigValues(Config, oldConfig); try { - await _mutations.RunAsync(() => EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config))); + await _mutations.RunAsync(() => EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig())); } catch (Exception rollbackException) { @@ -314,7 +314,7 @@ public sealed partial class V2rayRuntime await _mutations.RunAsync(async () => { ApplyInboundSettings(Config.Inbound[0], input); - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); }); return await CompleteCoreAffectingChangeAsync("inbound", fingerprint != GetCoreConfigurationFingerprint(), applyContext); @@ -371,7 +371,7 @@ public sealed partial class V2rayRuntime Config.Fragment4RayItem.Lengths = fragmentLengths.ToList(); Config.Fragment4RayItem.Delays = fragmentDelays.ToList(); Config.Fragment4RayItem.MaxSplit = input.FragmentMaxSplit; - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); }); return await CompleteCoreAffectingChangeAsync("core", fingerprint != GetCoreConfigurationFingerprint(), applyContext); @@ -398,7 +398,7 @@ public sealed partial class V2rayRuntime Config.ConstItem.SrsSourceUrl = input.SrsSourceUrl; Config.ConstItem.RouteRulesTemplateSourceUrl = input.RouteRulesTemplateSourceUrl; Config.ConstItem.SubConvertUrl = input.SubConvertUrl; - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); }); if (statisticsChanged) @@ -431,7 +431,7 @@ public sealed partial class V2rayRuntime Config.SpeedTestItem.MixedConcurrencyCount = Math.Max(input.MixedConcurrencyCount, Global.SpeedTestConcurrencyCountMin); Config.SpeedTestItem.IPAPIUrl = input.IPAPIUrl; Config.SpeedTestItem.UdpTestTarget = input.UdpTestTarget; - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); }); _events.Publish("settings-changed", new { section = "speedtest", restartRequired = false }); return OperationView.Ok(ApiMessageKeys.SpeedTestSettingsSaved); @@ -459,7 +459,7 @@ public sealed partial class V2rayRuntime item.CoreType = mapping.CoreType; } } - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); }); return await CompleteCoreAffectingChangeAsync("core-types", fingerprint != GetCoreConfigurationFingerprint(), applyContext); } @@ -491,7 +491,7 @@ public sealed partial class V2rayRuntime { Config.RoutingBasicItem.DomainStrategy = input.DomainStrategy!; Config.RoutingBasicItem.DomainStrategy4Singbox = input.DomainStrategy4Singbox!; - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); }); return await CompleteCoreAffectingChangeAsync("routing", fingerprint != GetCoreConfigurationFingerprint(), applyContext); } @@ -506,7 +506,7 @@ public sealed partial class V2rayRuntime await _mutations.RunAsync(async () => { Config.SimpleDNSItem = input; - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); }); return await CompleteCoreAffectingChangeAsync("dns", fingerprint != GetCoreConfigurationFingerprint(), applyContext); } @@ -543,7 +543,7 @@ public sealed partial class V2rayRuntime || current.DomainDNSAddress != input.DomainDNSAddress || current.Remarks != (input.Remarks ?? current.Remarks); var item = ApplyDnsProfileInput(current, coreType, input); - return (Result: await ConfigHandler.SaveDNSItems(Config, item), Changed: changed); + return (Result: await ConfigDbManager.SaveDNSItems(Config, item), Changed: changed); }); if (result.Result == -2) { @@ -668,8 +668,8 @@ public sealed partial class V2rayRuntime item.RuleNum = parsedRules.Count; } var result = parsedRules.Count == 0 - ? await ConfigHandler.SaveRoutingItem(Config, item) - : await ConfigHandler.AddBatchRoutingRules(item, JsonUtils.Serialize(parsedRules, false)); + ? await ConfigDbManager.SaveRoutingItem(Config, item) + : await ConfigDbManager.AddBatchRoutingRules(item, JsonUtils.Serialize(parsedRules, false)); return (Result: result, Item: (RoutingItem?)item, Changed: changed); }); if (save.Result == -2) @@ -696,14 +696,14 @@ public sealed partial class V2rayRuntime { return (Removed: false, AffectsCore: false); } - await ConfigHandler.RemoveRoutingItem(item); + await ConfigDbManager.RemoveRoutingItem(item); if (item.IsActive) { var remaining = await AppManager.Instance.RoutingItems() ?? []; var fallback = remaining.FirstOrDefault(); if (fallback is not null) { - if (await ConfigHandler.SetDefaultRouting(Config, fallback) != 0) + if (await ConfigDbManager.SetDefaultRouting(Config, fallback) != 0) { throw new IOException("ServiceLib could not select the fallback routing profile."); } @@ -711,7 +711,7 @@ public sealed partial class V2rayRuntime else { Config.RoutingBasicItem.RoutingIndexId = string.Empty; - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); } } return (Removed: true, AffectsCore: item.IsActive); @@ -736,7 +736,7 @@ public sealed partial class V2rayRuntime return (Result: -2, Changed: false); } var changed = !item.IsActive; - return (Result: changed ? await ConfigHandler.SetDefaultRouting(Config, item) : 0, Changed: changed); + return (Result: changed ? await ConfigDbManager.SetDefaultRouting(Config, item) : 0, Changed: changed); }); if (result.Result == -2) { @@ -783,7 +783,7 @@ public sealed partial class V2rayRuntime { return -2; } - return await ConfigHandler.AddBatchRoutingRules(item, JsonUtils.Serialize(rules, false)); + return await ConfigDbManager.AddBatchRoutingRules(item, JsonUtils.Serialize(rules, false)); } private async Task GetActiveRoutingSignatureAsync() @@ -882,7 +882,7 @@ public sealed partial class V2rayRuntime { return -3; } - if (await ConfigHandler.MoveRoutingRule(rules, index, direction, position) != 0) + if (await ConfigDbManager.MoveRoutingRule(rules, index, direction, position) != 0) { return -4; } @@ -937,7 +937,7 @@ public sealed partial class V2rayRuntime await using var applyContext = await BeginCoreSettingsApplyAsync(); if (applyContext.Failure is { } applyFailure) return applyFailure; var before = await GetActiveRoutingSignatureAsync(); - var result = await _mutations.RunAsync(() => ConfigHandler.InitRouting(Config, true)); + var result = await _mutations.RunAsync(() => ConfigDbManager.InitRouting(Config, true)); if (result != 0) { return OperationView.Fail("routing_import_failed", ApiMessageKeys.RoutingSaveFailed); @@ -988,7 +988,7 @@ public sealed partial class V2rayRuntime return -2; } var item = ApplyCoreConfigTemplateInput(current, coreType, input); - return await ConfigHandler.SaveFullConfigTemplate(Config, item); + return await ConfigDbManager.SaveFullConfigTemplate(Config, item); }); if (result == -2) { @@ -1097,7 +1097,7 @@ public sealed partial class V2rayRuntime await SQLiteHelper.Instance.DeleteAllAsync(); foreach (var item in stage.DnsItems) { - if (await ConfigHandler.SaveDNSItems(Config, item) != 0) + if (await ConfigDbManager.SaveDNSItems(Config, item) != 0) { throw new IOException($"The {item.CoreType} DNS profile could not be saved."); } @@ -1105,7 +1105,7 @@ public sealed partial class V2rayRuntime // Default routing uses embedded data only; this call performs no network I/O // because the route template source was cleared in the staged plan. - if (await ConfigHandler.InitRouting(Config, false) != 0) + if (await ConfigDbManager.InitRouting(Config, false) != 0) { throw new IOException("The built-in routing profiles could not be initialized."); } @@ -1114,7 +1114,7 @@ public sealed partial class V2rayRuntime { foreach (var item in stage.DnsItems) { - if (await ConfigHandler.SaveDNSItems(Config, item) != 0) + if (await ConfigDbManager.SaveDNSItems(Config, item) != 0) { throw new IOException($"The {item.CoreType} DNS profile could not be saved."); } @@ -1125,7 +1125,7 @@ public sealed partial class V2rayRuntime var item = await AppManager.Instance.GetRoutingItem(itemId); if (item is not null) { - await ConfigHandler.RemoveRoutingItem(item); + await ConfigDbManager.RemoveRoutingItem(item); } } @@ -1144,7 +1144,7 @@ public sealed partial class V2rayRuntime foreach (var item in stage.Routing.Items) { item.Sort = ++nextSort; - if (await ConfigHandler.AddBatchRoutingRules(item, item.RuleSet ?? "[]") != 0) + if (await ConfigDbManager.AddBatchRoutingRules(item, item.RuleSet ?? "[]") != 0) { throw new IOException($"The routing profile '{item.Remarks}' could not be saved."); } @@ -1153,7 +1153,7 @@ public sealed partial class V2rayRuntime var defaultItem = stage.Routing.DefaultRemarks is { } remarks ? stage.Routing.Items.FirstOrDefault(item => item.Remarks == remarks) : null; - if (defaultItem is not null && await ConfigHandler.SetDefaultRouting(Config, defaultItem) != 0) + if (defaultItem is not null && await ConfigDbManager.SetDefaultRouting(Config, defaultItem) != 0) { throw new IOException("The first staged routing profile could not be activated."); } @@ -1163,7 +1163,7 @@ public sealed partial class V2rayRuntime { var existingDefault = currentRoutes.FirstOrDefault(item => item.Id == existingDefaultId); if (existingDefault is not null && !existingDefault.IsActive - && await ConfigHandler.SetDefaultRouting(Config, existingDefault) != 0) + && await ConfigDbManager.SetDefaultRouting(Config, existingDefault) != 0) { throw new IOException("The migrated default routing profile could not be activated."); } @@ -1171,7 +1171,7 @@ public sealed partial class V2rayRuntime } token.ThrowIfCancellationRequested(); - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); token.ThrowIfCancellationRequested(); }, token), () => RestoreRegionalPresetSnapshotAsync(applyContext)); @@ -1287,7 +1287,7 @@ public sealed partial class V2rayRuntime await _mutations.RunAsync(async () => { RestoreConfigValues(Config, context.OldConfig); - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); await SQLiteHelper.Instance.DeleteAllAsync(); if (context.OldRoutingItems.Length > 0 @@ -1563,7 +1563,7 @@ public sealed partial class V2rayRuntime try { RestoreConfigValues(Config, context.OldConfig); - await _mutations.RunAsync(() => EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config))); + await _mutations.RunAsync(() => EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig())); configRestored = true; await _mutations.RunAsync(async () => { diff --git a/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.cs b/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.cs index 17071ff3..1ee5f886 100644 --- a/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.cs +++ b/v2rayN/v2rayN.WebAPI/Services/V2rayRuntime.cs @@ -7,7 +7,6 @@ using ServiceLib.Enums; using ServiceLib.Handler; using ServiceLib.Handler.Builder; using ServiceLib.Helper; -using ServiceLib.Manager; using ServiceLib.Models.Configs; using ServiceLib.Models.Dto; using ServiceLib.Models.Entities; @@ -18,6 +17,7 @@ using NLog.Targets; using v2rayN.WebAPI.Adapters; using v2rayN.WebAPI.Contracts; + namespace v2rayN.WebAPI.Services; public sealed partial class V2rayRuntime( @@ -52,7 +52,7 @@ public sealed partial class V2rayRuntime( private bool _restoring; private int _restoreAndRestartRequested; - private Config Config => AppManager.Instance.Config; + private Config Config => ConfigTextManager.Instance.Config; private CoreRuntimeSnapshot CurrentCoreRuntime => Volatile.Read(ref _coreRuntime); public bool RestoreAndRestartRequested => Volatile.Read(ref _restoreAndRestartRequested) != 0; @@ -248,19 +248,19 @@ public sealed partial class V2rayRuntime( { Config.Inbound[0].AllowLANConn = allowProxyFromLan; } - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); }); - await ConfigHandler.InitBuiltinDNS(Config); + await ConfigDbManager.InitBuiltinDNS(Config); await BuiltinDnsProfileBootstrap.EnsureAsync( Config, async () => await AppManager.Instance.DNSItems() ?? [], - ConfigHandler.SaveDNSItems); - await ConfigHandler.InitBuiltinFullConfigTemplate(Config); + ConfigDbManager.SaveDNSItems); + await ConfigDbManager.InitBuiltinFullConfigTemplate(Config); // Keep startup aligned with Desktop's StatusBarViewModel. In particular, // InitBuiltinRouting owns the RoutingIndexId -> IsActive migration and must // run even when a restored Desktop database already has routing rows. - await ConfigHandler.InitBuiltinRouting(Config); - _ = await ConfigHandler.GetDefaultRouting(Config); + await ConfigDbManager.InitBuiltinRouting(Config); + _ = await ConfigDbManager.GetDefaultRouting(Config); var restoredSubscriptions = await AppManager.Instance.SubItems() ?? []; var normalizedSubIndexId = NormalizeSelectedSubscriptionId( Config.SubIndexId, @@ -271,8 +271,8 @@ public sealed partial class V2rayRuntime( Config.SubIndexId = normalizedSubIndexId; } var selectedProfileId = Config.IndexId; - var defaultProfile = await ConfigHandler.GetDefaultServer(Config); - await _mutations.RunAsync(() => EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config))); + var defaultProfile = await ConfigDbManager.GetDefaultServer(Config); + await _mutations.RunAsync(() => EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig())); await ProfileExManager.Instance.Init(); await CertPemManager.Instance.Init(Config); // The Web frontend owns its runtime and rejects generated launch contexts that enable TUN. @@ -395,7 +395,7 @@ public sealed partial class V2rayRuntime( steps.Add(new("configuration save", async deadline => { await _mutations.RunAsync( - () => EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)), + () => EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()), deadline.Token); return true; })); @@ -440,7 +440,7 @@ public sealed partial class V2rayRuntime( } var item = ToSubItem(input, null); - var result = await _mutations.RunAsync(() => ConfigHandler.AddSubItem(Config, item)); + var result = await _mutations.RunAsync(() => ConfigDbManager.AddSubItem(Config, item)); if (result != 0) { return new(false, "subscription_save_failed", ApiMessageKeys.SubscriptionSaveFailed, null); @@ -469,7 +469,7 @@ public sealed partial class V2rayRuntime( var item = ToSubItem(input, existing); item.Id = id; - var result = await ConfigHandler.AddSubItem(Config, item); + var result = await ConfigDbManager.AddSubItem(Config, item); if (result != 0) { return new SubscriptionMutationResult(false, "subscription_save_failed", ApiMessageKeys.SubscriptionSaveFailed, null); @@ -499,14 +499,14 @@ public sealed partial class V2rayRuntime( await _mutations.RunAsync(async () => { - if (await ConfigHandler.DeleteSubItem(Config, id) != 0) + if (await ConfigDbManager.DeleteSubItem(Config, id) != 0) { throw new IOException("ServiceLib could not delete the subscription."); } if (removesCurrentProfile) { - _ = await ConfigHandler.GetDefaultServer(Config); - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + _ = await ConfigDbManager.GetDefaultServer(Config); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); } }); @@ -555,7 +555,7 @@ public sealed partial class V2rayRuntime( await handler.UpdateProcess(id); operation.Token.ThrowIfCancellationRequested(); - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); await UpdateSubscriptionTimestampLockedAsync(id); }, operation.Token); _events.Publish("profiles-changed", new { subscriptionId = id }); @@ -784,7 +784,7 @@ public sealed partial class V2rayRuntime( await _mutations.RunAsync(async () => { Config.IndexId = profile.IndexId; - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); }); } @@ -793,10 +793,10 @@ public sealed partial class V2rayRuntime( private async Task GetDefaultProfileAsync() => await _mutations.RunAsync(async () => { - var selected = await ConfigHandler.GetDefaultServer(Config); + var selected = await ConfigDbManager.GetDefaultServer(Config); if (selected is not null) { - await EnsureConfigSaveSucceededAsync(() => ConfigHandler.SaveConfig(Config)); + await EnsureConfigSaveSucceededAsync(() => ConfigTextManager.Instance.SaveConfig()); } return selected; }); @@ -1182,7 +1182,7 @@ public sealed partial class V2rayRuntime( if (item is not null) { item.UpdateTime = updateTime; - if (await ConfigHandler.AddSubItem(Config, item) != 0) + if (await ConfigDbManager.AddSubItem(Config, item) != 0) { throw new IOException("ServiceLib could not save the subscription timestamp."); } @@ -1195,7 +1195,7 @@ public sealed partial class V2rayRuntime( if (item.Enabled) { item.UpdateTime = updateTime; - if (await ConfigHandler.AddSubItem(Config, item) != 0) + if (await ConfigDbManager.AddSubItem(Config, item) != 0) { throw new IOException("ServiceLib could not save the subscription timestamp."); } diff --git a/v2rayN/v2rayN.WebAPI/Tests/GlobalUsings.cs b/v2rayN/v2rayN.WebAPI/Tests/GlobalUsings.cs new file mode 100644 index 00000000..1da312df --- /dev/null +++ b/v2rayN/v2rayN.WebAPI/Tests/GlobalUsings.cs @@ -0,0 +1,9 @@ +global using ServiceLib; +global using ServiceLib.Common; +global using ServiceLib.Enums; +global using ServiceLib.Manager; +global using ServiceLib.Manager.Data; +global using ServiceLib.Models.Configs; +global using ServiceLib.Models.CoreConfigs; +global using ServiceLib.Models.Dto; +global using ServiceLib.Models.Entities; diff --git a/v2rayN/v2rayN.WebAPI/Tests/ParityValidationTests.cs b/v2rayN/v2rayN.WebAPI/Tests/ParityValidationTests.cs index 63e5e701..fe99734e 100644 --- a/v2rayN/v2rayN.WebAPI/Tests/ParityValidationTests.cs +++ b/v2rayN/v2rayN.WebAPI/Tests/ParityValidationTests.cs @@ -1,6 +1,6 @@ using ServiceLib; using ServiceLib.Enums; -using ServiceLib.Handler; + using ServiceLib.Models.Configs; using ServiceLib.Models.Entities; using v2rayN.WebAPI.Contracts; @@ -29,7 +29,7 @@ public class ParityValidationTests await code.Should().BeEqualTo("ok"); await profile.IsValid().Should().BeFalse(); - var result = await ConfigHandler.AddShadowsocksServer(new Config(), profile, toFile: false); + var result = await ConfigDbManager.AddShadowsocksServer(new Config(), profile, toFile: false); await result.Should().BeEqualTo(0); await profile.ConfigVersion.Should().BeEqualTo(4); @@ -46,7 +46,7 @@ public class ParityValidationTests await code.Should().BeEqualTo("ok"); await profile.IsValid().Should().BeTrue(); - var result = await ConfigHandler.AddShadowsocksServer(new Config(), profile, toFile: false); + var result = await ConfigDbManager.AddShadowsocksServer(new Config(), profile, toFile: false); await result.Should().BeEqualTo(0); } @@ -59,7 +59,7 @@ public class ParityValidationTests var valid = V2rayRuntime.TryValidateProfile(profile, out _, out _); await valid.Should().BeTrue(); - var result = await ConfigHandler.AddShadowsocksServer(new Config(), profile, toFile: false); + var result = await ConfigDbManager.AddShadowsocksServer(new Config(), profile, toFile: false); await result.Should().BeEqualTo(-1); } diff --git a/v2rayN/v2rayN.WebAPI/Tests/RegionalPresetStagingTests.cs b/v2rayN/v2rayN.WebAPI/Tests/RegionalPresetStagingTests.cs index e7c76f2d..63f008a0 100644 --- a/v2rayN/v2rayN.WebAPI/Tests/RegionalPresetStagingTests.cs +++ b/v2rayN/v2rayN.WebAPI/Tests/RegionalPresetStagingTests.cs @@ -3,7 +3,7 @@ using System.Net; using ServiceLib; using ServiceLib.Common; using ServiceLib.Enums; -using ServiceLib.Handler; + using ServiceLib.Models.Configs; using ServiceLib.Models.Dto; using ServiceLib.Models.Entities; @@ -112,7 +112,7 @@ public class RegionalPresetStagingTests await applyCalled.Should().BeTrue(); await capturedStage.Should().NotBeNull(); await capturedStage!.DnsItems[0].NormalDNS.Should().BeEqualTo("existing-xray-data"); - await capturedStage.SimpleDnsItem.RemoteDNS.Should().BeEqualTo(ConfigHandler.InitBuiltinSimpleDNS().RemoteDNS); + await capturedStage.SimpleDnsItem.RemoteDNS.Should().BeEqualTo(ConfigDbManager.InitBuiltinSimpleDNS().RemoteDNS); await capturedStage.Routing.IsBuiltinFallback.Should().BeTrue(); await capturedStage.Routing.Items.Count.Should().BeEqualTo(3); await config.ConstItem.GeoSourceUrl.Should().BeEqualTo("original-geo-source"); @@ -566,7 +566,7 @@ public class RegionalPresetStagingTests var staged = await stager.StageAsync(EPresetType.Russia, CreateDnsRows(), [], null, CancellationToken.None); - var builtin = ConfigHandler.InitBuiltinSimpleDNS(); + var builtin = ConfigDbManager.InitBuiltinSimpleDNS(); await staged.SimpleDnsItem.RemoteDNS.Should().BeEqualTo(builtin.RemoteDNS); await staged.SimpleDnsItem.DirectDNS.Should().BeEqualTo(builtin.DirectDNS); await staged.DnsItems.All(item => item.Enabled).Should().BeTrue(); @@ -671,7 +671,7 @@ public class RegionalPresetStagingTests var staged = await stager.StageAsync(EPresetType.Russia, CreateDnsRows(), [], null, CancellationToken.None); await staged.DnsItems[0].NormalDNS.Should().BeEqualTo("existing-xray-data"); - await staged.SimpleDnsItem.RemoteDNS.Should().BeEqualTo(ConfigHandler.InitBuiltinSimpleDNS().RemoteDNS); + await staged.SimpleDnsItem.RemoteDNS.Should().BeEqualTo(ConfigDbManager.InitBuiltinSimpleDNS().RemoteDNS); await staged.Routing.IsBuiltinFallback.Should().BeTrue(); await staged.Routing.Items.Count.Should().BeEqualTo(3); } diff --git a/v2rayN/v2rayN.WebAPI/Tests/SniffingSettingsIntegrationTests.cs b/v2rayN/v2rayN.WebAPI/Tests/SniffingSettingsIntegrationTests.cs index 83005c05..be87bc3a 100644 --- a/v2rayN/v2rayN.WebAPI/Tests/SniffingSettingsIntegrationTests.cs +++ b/v2rayN/v2rayN.WebAPI/Tests/SniffingSettingsIntegrationTests.cs @@ -2,7 +2,6 @@ using System.Reflection; using System.Text.Json.Nodes; using ServiceLib; using ServiceLib.Enums; -using ServiceLib.Handler; using ServiceLib.Models; using ServiceLib.Models.Configs; using ServiceLib.Models.CoreConfigs; @@ -229,7 +228,7 @@ public class SniffingSettingsIntegrationTests ], GlobalHotkeys = [], CoreTypeItem = [new CoreTypeItem { ConfigType = EConfigType.VMess, CoreType = ECoreType.Xray }], - SimpleDNSItem = ConfigHandler.InitBuiltinSimpleDNS(), + SimpleDNSItem = ConfigDbManager.InitBuiltinSimpleDNS(), HappyEyeballs4RayItem = new HappyEyeballs4RayItem(), IndexId = string.Empty, SubIndexId = string.Empty, diff --git a/v2rayN/v2rayN/Base/WindowBase.cs b/v2rayN/v2rayN/Base/WindowBase.cs index aa6401e5..4e58b90f 100644 --- a/v2rayN/v2rayN/Base/WindowBase.cs +++ b/v2rayN/v2rayN/Base/WindowBase.cs @@ -11,7 +11,7 @@ public class WindowBase : ReactiveWindow where TViewMode { try { - var sizeItem = ConfigHandler.GetWindowSizeItem(AppManager.Instance.Config, GetType().Name); + var sizeItem = ConfigTextManager.GetWindowSizeItem(ConfigTextManager.Instance.Config, GetType().Name); if (sizeItem == null) { return; @@ -32,7 +32,7 @@ public class WindowBase : ReactiveWindow where TViewMode try { - ConfigHandler.SaveWindowSizeItem(AppManager.Instance.Config, GetType().Name, Width, Height); + ConfigTextManager.SaveWindowSizeItem(ConfigTextManager.Instance.Config, GetType().Name, Width, Height); } catch { } } diff --git a/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs b/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs index 37b2e925..e6d3daad 100644 --- a/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs +++ b/v2rayN/v2rayN/Converters/MaterialDesignFonts.cs @@ -10,7 +10,7 @@ public class MaterialDesignFonts { try { - var fontFamily = AppManager.Instance.Config.UiItem.CurrentFontFamily; + var fontFamily = ConfigTextManager.Instance.Config.UiItem.CurrentFontFamily; if (fontFamily.IsNotEmpty()) { var fontPath = Utils.GetFontsPath(); diff --git a/v2rayN/v2rayN/GlobalUsings.cs b/v2rayN/v2rayN/GlobalUsings.cs index 14823ad3..8cfb88e4 100644 --- a/v2rayN/v2rayN/GlobalUsings.cs +++ b/v2rayN/v2rayN/GlobalUsings.cs @@ -28,6 +28,7 @@ global using ServiceLib.Enums; global using ServiceLib.Events; global using ServiceLib.Handler; global using ServiceLib.Manager; +global using ServiceLib.Manager.Data; global using ServiceLib.Models.CoreConfigs; global using ServiceLib.Models.Configs; global using ServiceLib.Models.Dto; diff --git a/v2rayN/v2rayN/Manager/HotkeyManager.cs b/v2rayN/v2rayN/Manager/HotkeyManager.cs index 2d588a3b..7cea8dbe 100644 --- a/v2rayN/v2rayN/Manager/HotkeyManager.cs +++ b/v2rayN/v2rayN/Manager/HotkeyManager.cs @@ -22,7 +22,7 @@ public sealed partial class HotkeyManager private void Init() { _hotkeyTriggerDic.Clear(); - foreach (var item in AppManager.Instance.Config.GlobalHotkeys) + foreach (var item in ConfigTextManager.Instance.Config.GlobalHotkeys) { if (item.KeyCode != null && (Key)item.KeyCode != Key.None) { diff --git a/v2rayN/v2rayN/Manager/WindowsManager.cs b/v2rayN/v2rayN/Manager/WindowsManager.cs index 0b91f2fb..b76d44f1 100644 --- a/v2rayN/v2rayN/Manager/WindowsManager.cs +++ b/v2rayN/v2rayN/Manager/WindowsManager.cs @@ -1,6 +1,7 @@ using System.Drawing; using System.Windows.Media.Imaging; + namespace v2rayN.Manager; public sealed class WindowsManager @@ -54,7 +55,7 @@ public sealed class WindowsManager { try { - var item = await ConfigHandler.GetDefaultRouting(config); + var item = await ConfigDbManager.GetDefaultRouting(config); if (item == null || item.CustomIcon.IsNullOrEmpty() || !File.Exists(item.CustomIcon)) { return null; diff --git a/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs index 42fda62c..1518e926 100644 --- a/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/ThemeSettingViewModel.cs @@ -3,6 +3,7 @@ using MaterialDesignColors.ColorManipulation; using MaterialDesignThemes.Wpf; using Microsoft.Win32; + namespace v2rayN.ViewModels; public partial class ThemeSettingViewModel : MyReactiveObject @@ -22,7 +23,7 @@ public partial class ThemeSettingViewModel : MyReactiveObject public ThemeSettingViewModel() { - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; RegisterSystemColorSet(_config, ModifyTheme); @@ -63,7 +64,7 @@ public partial class ThemeSettingViewModel : MyReactiveObject { _config.UiItem.CurrentTheme = CurrentTheme; ModifyTheme(); - await ConfigHandler.SaveConfig(_config); + await ConfigTextManager.Instance.SaveConfig(); } }); @@ -82,7 +83,7 @@ public partial class ThemeSettingViewModel : MyReactiveObject { _config.UiItem.ColorPrimaryName = SelectedSwatch?.Name; ChangePrimaryColor(SelectedSwatch.ExemplarHue.Color); - await ConfigHandler.SaveConfig(_config); + await ConfigTextManager.Instance.SaveConfig(); } }); @@ -94,7 +95,7 @@ public partial class ThemeSettingViewModel : MyReactiveObject { _config.UiItem.CurrentFontSize = CurrentFontSize; ModifyFontSize(); - await ConfigHandler.SaveConfig(_config); + await ConfigTextManager.Instance.SaveConfig(); } }); @@ -106,7 +107,7 @@ public partial class ThemeSettingViewModel : MyReactiveObject { _config.UiItem.CurrentLanguage = CurrentLanguage; Thread.CurrentThread.CurrentUICulture = new(CurrentLanguage); - await ConfigHandler.SaveConfig(_config); + await ConfigTextManager.Instance.SaveConfig(); NoticeManager.Instance.Enqueue(ResUI.NeedRebootTips); } }); diff --git a/v2rayN/v2rayN/Views/AddGroupServerWindow.xaml.cs b/v2rayN/v2rayN/Views/AddGroupServerWindow.xaml.cs index 02cdab03..adcc7d96 100644 --- a/v2rayN/v2rayN/Views/AddGroupServerWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/AddGroupServerWindow.xaml.cs @@ -51,7 +51,7 @@ public partial class AddGroupServerWindow this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); }); - WindowsUtils.SetDarkBorder(this, AppManager.Instance.Config.UiItem.CurrentTheme); + WindowsUtils.SetDarkBorder(this, ConfigTextManager.Instance.Config.UiItem.CurrentTheme); } private void InitializeData(ProfileItem profileItem) diff --git a/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs b/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs index 4c132b86..9b1788ab 100644 --- a/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs +++ b/v2rayN/v2rayN/Views/AddServer2Window.xaml.cs @@ -38,7 +38,7 @@ public partial class AddServer2Window interaction.SetOutput(fileName); }).DisposeWith(disposables); }); - WindowsUtils.SetDarkBorder(this, AppManager.Instance.Config.UiItem.CurrentTheme); + WindowsUtils.SetDarkBorder(this, ConfigTextManager.Instance.Config.UiItem.CurrentTheme); } private void InitializeData(ProfileItem profileItem) diff --git a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs index ee900d1b..87d7b77f 100644 --- a/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/AddServerWindow.xaml.cs @@ -204,7 +204,7 @@ public partial class AddServerWindow this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); }); - WindowsUtils.SetDarkBorder(this, AppManager.Instance.Config.UiItem.CurrentTheme); + WindowsUtils.SetDarkBorder(this, ConfigTextManager.Instance.Config.UiItem.CurrentTheme); } private void InitializeData(ProfileItem profileItem) diff --git a/v2rayN/v2rayN/Views/ClashConnectionsView.xaml.cs b/v2rayN/v2rayN/Views/ClashConnectionsView.xaml.cs index 227f3ab4..1d6aa8b7 100644 --- a/v2rayN/v2rayN/Views/ClashConnectionsView.xaml.cs +++ b/v2rayN/v2rayN/Views/ClashConnectionsView.xaml.cs @@ -14,7 +14,7 @@ public partial class ClashConnectionsView public ClashConnectionsView() { InitializeComponent(); - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; btnAutofitColumnWidth.Click += BtnAutofitColumnWidth_Click; diff --git a/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs index f2cd8874..ee633ab7 100644 --- a/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/DNSSettingWindow.xaml.cs @@ -8,7 +8,7 @@ public partial class DNSSettingWindow { InitializeComponent(); - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; cmbDirectDNSStrategy.ItemsSource = Global.DomainStrategy; cmbRemoteDNSStrategy.ItemsSource = Global.DomainStrategy; @@ -72,7 +72,7 @@ public partial class DNSSettingWindow this.OneWayBind(ViewModel, vm => vm.IsSimpleDNSEnabled, v => v.gridBasicDNSSettings.IsEnabled).DisposeWith(disposables); this.OneWayBind(ViewModel, vm => vm.IsSimpleDNSEnabled, v => v.gridAdvancedDNSSettings.IsEnabled).DisposeWith(disposables); }); - WindowsUtils.SetDarkBorder(this, AppManager.Instance.Config.UiItem.CurrentTheme); + WindowsUtils.SetDarkBorder(this, ConfigTextManager.Instance.Config.UiItem.CurrentTheme); } private void linkDnsObjectDoc_Click(object sender, RoutedEventArgs e) diff --git a/v2rayN/v2rayN/Views/FullConfigTemplateWindow.xaml.cs b/v2rayN/v2rayN/Views/FullConfigTemplateWindow.xaml.cs index 78d4e719..48fa4dcf 100644 --- a/v2rayN/v2rayN/Views/FullConfigTemplateWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/FullConfigTemplateWindow.xaml.cs @@ -8,7 +8,7 @@ public partial class FullConfigTemplateWindow { InitializeComponent(); - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; this.WhenActivated(disposables => { @@ -25,7 +25,7 @@ public partial class FullConfigTemplateWindow this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); }); - WindowsUtils.SetDarkBorder(this, AppManager.Instance.Config.UiItem.CurrentTheme); + WindowsUtils.SetDarkBorder(this, ConfigTextManager.Instance.Config.UiItem.CurrentTheme); } private void linkFullConfigTemplateDoc_Click(object sender, RoutedEventArgs e) diff --git a/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs b/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs index 4f93d7b1..3f6723e1 100644 --- a/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs @@ -21,7 +21,7 @@ public partial class GlobalHotkeySettingWindow this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); BindingData(); }); - WindowsUtils.SetDarkBorder(this, AppManager.Instance.Config.UiItem.CurrentTheme); + WindowsUtils.SetDarkBorder(this, ConfigTextManager.Instance.Config.UiItem.CurrentTheme); Init(); } diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index 6c9052ae..7237ce3f 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -17,7 +17,7 @@ public partial class MainWindow { InitializeComponent(); - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; ThreadPool.RegisterWaitForSingleObject(App.ProgramStarted, OnProgramStarted, null, -1, false); App.Current.SessionEnding += Current_SessionEnding; @@ -345,15 +345,15 @@ public partial class MainWindow private void StorageUI() { - ConfigHandler.SaveWindowSizeItem(_config, GetType().Name, Width, Height); + ConfigTextManager.SaveWindowSizeItem(_config, GetType().Name, Width, Height); if (_config.UiItem.MainGirdOrientation == EGirdOrientation.Horizontal) { - ConfigHandler.SaveMainGirdHeight(_config, gridMain.ColumnDefinitions[0].ActualWidth, gridMain.ColumnDefinitions[2].ActualWidth); + ConfigTextManager.SaveMainGirdHeight(_config, gridMain.ColumnDefinitions[0].ActualWidth, gridMain.ColumnDefinitions[2].ActualWidth); } else if (_config.UiItem.MainGirdOrientation == EGirdOrientation.Vertical) { - ConfigHandler.SaveMainGirdHeight(_config, gridMain1.RowDefinitions[0].ActualHeight, gridMain1.RowDefinitions[2].ActualHeight); + ConfigTextManager.SaveMainGirdHeight(_config, gridMain1.RowDefinitions[0].ActualHeight, gridMain1.RowDefinitions[2].ActualHeight); } } diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs index b8d05abb..dc3bb64b 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs @@ -10,7 +10,7 @@ public partial class OptionSettingWindow { InitializeComponent(); - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; clbdestOverride.SelectionChanged += ClbdestOverride_SelectionChanged; btnBrowseCustomSystemProxyPacPath.Click += BtnBrowseCustomSystemProxyPacPath_Click; @@ -149,7 +149,7 @@ public partial class OptionSettingWindow this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); }); - WindowsUtils.SetDarkBorder(this, AppManager.Instance.Config.UiItem.CurrentTheme); + WindowsUtils.SetDarkBorder(this, ConfigTextManager.Instance.Config.UiItem.CurrentTheme); } private async Task InitSettingFont() diff --git a/v2rayN/v2rayN/Views/ProfilesSelectWindow.xaml.cs b/v2rayN/v2rayN/Views/ProfilesSelectWindow.xaml.cs index d5ce1a39..eafea9c4 100644 --- a/v2rayN/v2rayN/Views/ProfilesSelectWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/ProfilesSelectWindow.xaml.cs @@ -39,7 +39,7 @@ public partial class ProfilesSelectWindow }).DisposeWith(disposables); }); - WindowsUtils.SetDarkBorder(this, AppManager.Instance.Config.UiItem.CurrentTheme); + WindowsUtils.SetDarkBorder(this, ConfigTextManager.Instance.Config.UiItem.CurrentTheme); } private void AllowMultiSelect(bool allow) diff --git a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs index 47683b31..f2be343a 100644 --- a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs +++ b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs @@ -17,7 +17,7 @@ public partial class ProfilesView InitializeComponent(); lstGroup.MaxHeight = Math.Floor(SystemParameters.WorkArea.Height * 0.20 / 40) * 40; - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; btnAutofitColumnWidth.Click += BtnAutofitColumnWidth_Click; txtServerFilter.PreviewKeyDown += TxtServerFilter_PreviewKeyDown; diff --git a/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs index 6118045b..c4fa6610 100644 --- a/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml.cs @@ -37,7 +37,7 @@ public partial class RoutingRuleDetailsWindow this.BindCommand(ViewModel, vm => vm.SelectProfileCmd, v => v.btnSelectProfile).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); }); - WindowsUtils.SetDarkBorder(this, AppManager.Instance.Config.UiItem.CurrentTheme); + WindowsUtils.SetDarkBorder(this, ConfigTextManager.Instance.Config.UiItem.CurrentTheme); } private void InitializeData(RulesItem rulesItem) diff --git a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs index e82e11e8..e741d3e6 100644 --- a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml.cs @@ -76,7 +76,7 @@ public partial class RoutingRuleSettingWindow interaction.SetOutput(fileName); }).DisposeWith(disposables); }); - WindowsUtils.SetDarkBorder(this, AppManager.Instance.Config.UiItem.CurrentTheme); + WindowsUtils.SetDarkBorder(this, ConfigTextManager.Instance.Config.UiItem.CurrentTheme); } private void Window_Loaded(object sender, RoutedEventArgs e) diff --git a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs index fac80f1c..f8a5018b 100644 --- a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml.cs @@ -37,7 +37,7 @@ public partial class RoutingSettingWindow interaction.SetOutput(result); }).DisposeWith(disposables); }); - WindowsUtils.SetDarkBorder(this, AppManager.Instance.Config.UiItem.CurrentTheme); + WindowsUtils.SetDarkBorder(this, ConfigTextManager.Instance.Config.UiItem.CurrentTheme); } private void RoutingSettingWindow_Closing(object? sender, System.ComponentModel.CancelEventArgs e) diff --git a/v2rayN/v2rayN/Views/StatusBarView.xaml.cs b/v2rayN/v2rayN/Views/StatusBarView.xaml.cs index aeadc0c9..fc19ad2b 100644 --- a/v2rayN/v2rayN/Views/StatusBarView.xaml.cs +++ b/v2rayN/v2rayN/Views/StatusBarView.xaml.cs @@ -9,7 +9,7 @@ public partial class StatusBarView public StatusBarView() { InitializeComponent(); - _config = AppManager.Instance.Config; + _config = ConfigTextManager.Instance.Config; menuExit.Click += menuExit_Click; txtRunningServerDisplay.PreviewMouseDown += txtRunningInfoDisplay_MouseDoubleClick; diff --git a/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs b/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs index a725f1d4..4aefe796 100644 --- a/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/SubEditWindow.xaml.cs @@ -35,7 +35,7 @@ public partial class SubEditWindow this.BindCommand(ViewModel, vm => vm.SelectNextProfileCmd, v => v.btnSelectNextProfile).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); }); - WindowsUtils.SetDarkBorder(this, AppManager.Instance.Config.UiItem.CurrentTheme); + WindowsUtils.SetDarkBorder(this, ConfigTextManager.Instance.Config.UiItem.CurrentTheme); } private void Window_Loaded(object sender, RoutedEventArgs e) diff --git a/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs index ed8ec027..2d5575af 100644 --- a/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs @@ -47,7 +47,7 @@ public partial class SubSettingWindow interaction.SetOutput(RxVoid.Default); }).DisposeWith(disposables); }); - WindowsUtils.SetDarkBorder(this, AppManager.Instance.Config.UiItem.CurrentTheme); + WindowsUtils.SetDarkBorder(this, ConfigTextManager.Instance.Config.UiItem.CurrentTheme); } private async Task ShareSub(string url)