You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ShadowsocksController.cs 24 kB

7 years ago
11 years ago
7 years ago
11 years ago
11 years ago
11 years ago
7 years ago
11 years ago
11 years ago
11 years ago
7 years ago
11 years ago
7 years ago
11 years ago
7 years ago
7 years ago
7 years ago
11 years ago
11 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
11 years ago
11 years ago
7 years ago
11 years ago
7 years ago
11 years ago
7 years ago
7 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Net.Http;
  8. using System.Net.Sockets;
  9. using System.Text;
  10. using System.Threading;
  11. using System.Threading.Tasks;
  12. using System.Web;
  13. using System.Windows.Forms;
  14. using NLog;
  15. using Shadowsocks.Controller.Service;
  16. using Shadowsocks.Controller.Strategy;
  17. using Shadowsocks.Model;
  18. using Shadowsocks.Util;
  19. using WPFLocalizeExtension.Engine;
  20. namespace Shadowsocks.Controller
  21. {
  22. public class ShadowsocksController
  23. {
  24. private readonly Logger logger;
  25. private readonly HttpClient httpClient;
  26. // controller:
  27. // handle user actions
  28. // manipulates UI
  29. // interacts with low level logic
  30. #region Member definition
  31. private Thread _trafficThread;
  32. private TCPListener _tcpListener;
  33. private UDPListener _udpListener;
  34. private PACDaemon _pacDaemon;
  35. private PACServer _pacServer;
  36. private Configuration _config;
  37. private StrategyManager _strategyManager;
  38. private PrivoxyRunner privoxyRunner;
  39. private readonly ConcurrentDictionary<Server, Sip003Plugin> _pluginsByServer;
  40. private long _inboundCounter = 0;
  41. private long _outboundCounter = 0;
  42. public long InboundCounter => Interlocked.Read(ref _inboundCounter);
  43. public long OutboundCounter => Interlocked.Read(ref _outboundCounter);
  44. public Queue<TrafficPerSecond> trafficPerSecondQueue;
  45. private bool stopped = false;
  46. public class PathEventArgs : EventArgs
  47. {
  48. public string Path;
  49. }
  50. public class UpdatedEventArgs : EventArgs
  51. {
  52. public string OldVersion;
  53. public string NewVersion;
  54. }
  55. public class TrafficPerSecond
  56. {
  57. public long inboundCounter;
  58. public long outboundCounter;
  59. public long inboundIncreasement;
  60. public long outboundIncreasement;
  61. }
  62. public event EventHandler ConfigChanged;
  63. public event EventHandler EnableStatusChanged;
  64. public event EventHandler EnableGlobalChanged;
  65. public event EventHandler ShareOverLANStatusChanged;
  66. public event EventHandler VerboseLoggingStatusChanged;
  67. public event EventHandler ShowPluginOutputChanged;
  68. public event EventHandler TrafficChanged;
  69. // when user clicked Edit PAC, and PAC file has already created
  70. public event EventHandler<PathEventArgs> PACFileReadyToOpen;
  71. public event EventHandler<PathEventArgs> UserRuleFileReadyToOpen;
  72. public event EventHandler<GeositeResultEventArgs> UpdatePACFromGeositeCompleted;
  73. public event ErrorEventHandler UpdatePACFromGeositeError;
  74. public event ErrorEventHandler Errored;
  75. // Invoked when controller.Start();
  76. public event EventHandler<UpdatedEventArgs> ProgramUpdated;
  77. #endregion
  78. public ShadowsocksController()
  79. {
  80. logger = LogManager.GetCurrentClassLogger();
  81. httpClient = new HttpClient();
  82. _config = Configuration.Load();
  83. Configuration.Process(ref _config);
  84. _strategyManager = new StrategyManager(this);
  85. _pluginsByServer = new ConcurrentDictionary<Server, Sip003Plugin>();
  86. StartTrafficStatistics(61);
  87. ProgramUpdated += (o, e) =>
  88. {
  89. logger.Info($"Updated from {e.OldVersion} to {e.NewVersion}");
  90. };
  91. }
  92. #region Basic
  93. public void Start(bool systemWakeUp = false)
  94. {
  95. if (_config.firstRunOnNewVersion && !systemWakeUp)
  96. {
  97. ProgramUpdated.Invoke(this, new UpdatedEventArgs()
  98. {
  99. OldVersion = _config.version,
  100. NewVersion = UpdateChecker.Version,
  101. });
  102. // delete pac.txt when regeneratePacOnUpdate is true
  103. if (_config.regeneratePacOnUpdate)
  104. try
  105. {
  106. File.Delete(PACDaemon.PAC_FILE);
  107. logger.Info("Deleted pac.txt from previous version.");
  108. }
  109. catch (Exception e)
  110. {
  111. logger.LogUsefulException(e);
  112. }
  113. // finish up first run of new version
  114. _config.firstRunOnNewVersion = false;
  115. _config.version = UpdateChecker.Version;
  116. Configuration.Save(_config);
  117. }
  118. Reload();
  119. if (!systemWakeUp)
  120. HotkeyReg.RegAllHotkeys();
  121. }
  122. public void Stop()
  123. {
  124. if (stopped)
  125. {
  126. return;
  127. }
  128. stopped = true;
  129. _tcpListener?.Stop();
  130. _udpListener?.Stop();
  131. StopPlugins();
  132. if (privoxyRunner != null)
  133. {
  134. privoxyRunner.Stop();
  135. }
  136. if (_config.enabled)
  137. {
  138. SystemProxy.Update(_config, true, null);
  139. }
  140. }
  141. protected void Reload()
  142. {
  143. Encryption.RNG.Reload();
  144. // some logic in configuration updated the config when saving, we need to read it again
  145. _config = Configuration.Load();
  146. Configuration.Process(ref _config);
  147. NLogConfig.LoadConfiguration();
  148. logger.Info($"WPF Localization Extension|Current culture: {LocalizeDictionary.CurrentCulture}");
  149. // set User-Agent for httpClient
  150. try
  151. {
  152. if (!string.IsNullOrWhiteSpace(_config.userAgentString))
  153. httpClient.DefaultRequestHeaders.Add("User-Agent", _config.userAgentString);
  154. }
  155. catch
  156. {
  157. // reset userAgent to default and reapply
  158. Configuration.ResetUserAgent(_config);
  159. httpClient.DefaultRequestHeaders.Add("User-Agent", _config.userAgentString);
  160. }
  161. privoxyRunner = privoxyRunner ?? new PrivoxyRunner();
  162. _pacDaemon = _pacDaemon ?? new PACDaemon(_config);
  163. _pacDaemon.PACFileChanged += PacDaemon_PACFileChanged;
  164. _pacDaemon.UserRuleFileChanged += PacDaemon_UserRuleFileChanged;
  165. _pacServer = _pacServer ?? new PACServer(_pacDaemon);
  166. _pacServer.UpdatePACURL(_config); // So PACServer works when system proxy disabled.
  167. GeositeUpdater.ResetEvent();
  168. GeositeUpdater.UpdateCompleted += PacServer_PACUpdateCompleted;
  169. GeositeUpdater.Error += PacServer_PACUpdateError;
  170. _tcpListener?.Stop();
  171. _udpListener?.Stop();
  172. StopPlugins();
  173. // don't put PrivoxyRunner.Start() before pacServer.Stop()
  174. // or bind will fail when switching bind address from 0.0.0.0 to 127.0.0.1
  175. // though UseShellExecute is set to true now
  176. // http://stackoverflow.com/questions/10235093/socket-doesnt-close-after-application-exits-if-a-launched-process-is-open
  177. privoxyRunner.Stop();
  178. try
  179. {
  180. var strategy = GetCurrentStrategy();
  181. strategy?.ReloadServers();
  182. StartPlugin();
  183. privoxyRunner.Start(_config);
  184. TCPRelay tcpRelay = new TCPRelay(this, _config);
  185. tcpRelay.OnInbound += UpdateInboundCounter;
  186. tcpRelay.OnOutbound += UpdateOutboundCounter;
  187. tcpRelay.OnFailed += (o, e) => GetCurrentStrategy()?.SetFailure(e.server);
  188. UDPRelay udpRelay = new UDPRelay(this);
  189. _tcpListener = new TCPListener(_config, new List<IStreamService>
  190. {
  191. tcpRelay,
  192. _pacServer,
  193. new PortForwarder(privoxyRunner.RunningPort),
  194. });
  195. _tcpListener.Start();
  196. _udpListener = new UDPListener(_config, new List<IDatagramService>
  197. {
  198. udpRelay,
  199. });
  200. _udpListener.Start();
  201. }
  202. catch (Exception e)
  203. {
  204. // translate Microsoft language into human language
  205. // i.e. An attempt was made to access a socket in a way forbidden by its access permissions => Port already in use
  206. if (e is SocketException se)
  207. {
  208. if (se.SocketErrorCode == SocketError.AddressAlreadyInUse)
  209. {
  210. e = new Exception(I18N.GetString("Port {0} already in use", _config.localPort), e);
  211. }
  212. else if (se.SocketErrorCode == SocketError.AccessDenied)
  213. {
  214. e = new Exception(I18N.GetString("Port {0} is reserved by system", _config.localPort), e);
  215. }
  216. }
  217. logger.LogUsefulException(e);
  218. ReportError(e);
  219. }
  220. ConfigChanged?.Invoke(this, new EventArgs());
  221. UpdateSystemProxy();
  222. }
  223. protected void SaveConfig(Configuration newConfig)
  224. {
  225. Configuration.Save(newConfig);
  226. Reload();
  227. }
  228. protected void ReportError(Exception e)
  229. {
  230. Errored?.Invoke(this, new ErrorEventArgs(e));
  231. }
  232. public HttpClient GetHttpClient() => httpClient;
  233. public Server GetCurrentServer() => _config.GetCurrentServer();
  234. public Configuration GetCurrentConfiguration() => _config;
  235. public Server GetAServer(IStrategyCallerType type, IPEndPoint localIPEndPoint, EndPoint destEndPoint)
  236. {
  237. IStrategy strategy = GetCurrentStrategy();
  238. if (strategy != null)
  239. {
  240. return strategy.GetAServer(type, localIPEndPoint, destEndPoint);
  241. }
  242. if (_config.index < 0)
  243. {
  244. _config.index = 0;
  245. }
  246. return GetCurrentServer();
  247. }
  248. public void SaveServers(List<Server> servers, int localPort, bool portableMode)
  249. {
  250. _config.configs = servers;
  251. _config.localPort = localPort;
  252. _config.portableMode = portableMode;
  253. Configuration.Save(_config);
  254. }
  255. public void SelectServerIndex(int index)
  256. {
  257. _config.index = index;
  258. _config.strategy = null;
  259. SaveConfig(_config);
  260. }
  261. public void ToggleShareOverLAN(bool enabled)
  262. {
  263. _config.shareOverLan = enabled;
  264. SaveConfig(_config);
  265. ShareOverLANStatusChanged?.Invoke(this, new EventArgs());
  266. }
  267. #endregion
  268. #region OS Proxy
  269. public void ToggleEnable(bool enabled)
  270. {
  271. _config.enabled = enabled;
  272. SaveConfig(_config);
  273. EnableStatusChanged?.Invoke(this, new EventArgs());
  274. }
  275. public void ToggleGlobal(bool global)
  276. {
  277. _config.global = global;
  278. SaveConfig(_config);
  279. EnableGlobalChanged?.Invoke(this, new EventArgs());
  280. }
  281. public void SaveProxy(ForwardProxyConfig proxyConfig)
  282. {
  283. _config.proxy = proxyConfig;
  284. SaveConfig(_config);
  285. }
  286. private void UpdateSystemProxy()
  287. {
  288. SystemProxy.Update(_config, false, _pacServer);
  289. }
  290. #endregion
  291. #region PAC
  292. private void PacDaemon_PACFileChanged(object sender, EventArgs e)
  293. {
  294. UpdateSystemProxy();
  295. }
  296. private void PacServer_PACUpdateCompleted(object sender, GeositeResultEventArgs e)
  297. {
  298. UpdatePACFromGeositeCompleted?.Invoke(this, e);
  299. }
  300. private void PacServer_PACUpdateError(object sender, ErrorEventArgs e)
  301. {
  302. UpdatePACFromGeositeError?.Invoke(this, e);
  303. }
  304. private static readonly IEnumerable<char> IgnoredLineBegins = new[] { '!', '[' };
  305. private void PacDaemon_UserRuleFileChanged(object sender, EventArgs e)
  306. {
  307. GeositeUpdater.MergeAndWritePACFile(_config.geositeDirectGroups, _config.geositeProxiedGroups, _config.geositePreferDirect);
  308. UpdateSystemProxy();
  309. }
  310. public void CopyPacUrl()
  311. {
  312. Clipboard.SetDataObject(_pacServer.PacUrl);
  313. }
  314. public void SavePACUrl(string pacUrl)
  315. {
  316. _config.pacUrl = pacUrl;
  317. SaveConfig(_config);
  318. ConfigChanged?.Invoke(this, new EventArgs());
  319. }
  320. public void UseOnlinePAC(bool useOnlinePac)
  321. {
  322. _config.useOnlinePac = useOnlinePac;
  323. SaveConfig(_config);
  324. ConfigChanged?.Invoke(this, new EventArgs());
  325. }
  326. public void TouchPACFile()
  327. {
  328. string pacFilename = _pacDaemon.TouchPACFile();
  329. PACFileReadyToOpen?.Invoke(this, new PathEventArgs() { Path = pacFilename });
  330. }
  331. public void TouchUserRuleFile()
  332. {
  333. string userRuleFilename = _pacDaemon.TouchUserRuleFile();
  334. UserRuleFileReadyToOpen?.Invoke(this, new PathEventArgs() { Path = userRuleFilename });
  335. }
  336. public void ToggleSecureLocalPac(bool enabled)
  337. {
  338. _config.secureLocalPac = enabled;
  339. SaveConfig(_config);
  340. ConfigChanged?.Invoke(this, new EventArgs());
  341. }
  342. public void ToggleRegeneratePacOnUpdate(bool enabled)
  343. {
  344. _config.regeneratePacOnUpdate = enabled;
  345. SaveConfig(_config);
  346. ConfigChanged?.Invoke(this, new EventArgs());
  347. }
  348. #endregion
  349. #region SIP002
  350. public bool AskAddServerBySSURL(string ssURL)
  351. {
  352. var dr = MessageBox.Show(I18N.GetString("Import from URL: {0} ?", ssURL), I18N.GetString("Shadowsocks"), MessageBoxButtons.YesNo);
  353. if (dr == DialogResult.Yes)
  354. {
  355. if (AddServerBySSURL(ssURL))
  356. {
  357. MessageBox.Show(I18N.GetString("Successfully imported from {0}", ssURL));
  358. return true;
  359. }
  360. else
  361. {
  362. MessageBox.Show(I18N.GetString("Failed to import. Please check if the link is valid."));
  363. }
  364. }
  365. return false;
  366. }
  367. public bool AddServerBySSURL(string ssURL)
  368. {
  369. try
  370. {
  371. if (string.IsNullOrWhiteSpace(ssURL))
  372. return false;
  373. var servers = Server.GetServers(ssURL);
  374. if (servers == null || servers.Count == 0)
  375. return false;
  376. foreach (var server in servers)
  377. {
  378. _config.configs.Add(server);
  379. }
  380. _config.index = _config.configs.Count - 1;
  381. SaveConfig(_config);
  382. return true;
  383. }
  384. catch (Exception e)
  385. {
  386. logger.LogUsefulException(e);
  387. return false;
  388. }
  389. }
  390. public string GetServerURLForCurrentServer()
  391. {
  392. return GetCurrentServer().GetURL(_config.generateLegacyUrl);
  393. }
  394. #endregion
  395. #region Misc
  396. public void ToggleVerboseLogging(bool enabled)
  397. {
  398. _config.isVerboseLogging = enabled;
  399. SaveConfig(_config);
  400. NLogConfig.LoadConfiguration(); // reload nlog
  401. VerboseLoggingStatusChanged?.Invoke(this, new EventArgs());
  402. }
  403. public void ToggleCheckingUpdate(bool enabled)
  404. {
  405. _config.autoCheckUpdate = enabled;
  406. Configuration.Save(_config);
  407. ConfigChanged?.Invoke(this, new EventArgs());
  408. }
  409. public void ToggleCheckingPreRelease(bool enabled)
  410. {
  411. _config.checkPreRelease = enabled;
  412. Configuration.Save(_config);
  413. ConfigChanged?.Invoke(this, new EventArgs());
  414. }
  415. public void SaveSkippedUpdateVerion(string version)
  416. {
  417. _config.skippedUpdateVersion = version;
  418. Configuration.Save(_config);
  419. }
  420. public void SaveLogViewerConfig(LogViewerConfig newConfig)
  421. {
  422. _config.logViewer = newConfig;
  423. newConfig.SaveSize();
  424. Configuration.Save(_config);
  425. ConfigChanged?.Invoke(this, new EventArgs());
  426. }
  427. public void SaveHotkeyConfig(HotkeyConfig newConfig)
  428. {
  429. _config.hotkey = newConfig;
  430. SaveConfig(_config);
  431. ConfigChanged?.Invoke(this, new EventArgs());
  432. }
  433. #endregion
  434. #region Strategy
  435. public void SelectStrategy(string strategyID)
  436. {
  437. _config.index = -1;
  438. _config.strategy = strategyID;
  439. SaveConfig(_config);
  440. }
  441. public IList<IStrategy> GetStrategies()
  442. {
  443. return _strategyManager.GetStrategies();
  444. }
  445. public IStrategy GetCurrentStrategy()
  446. {
  447. foreach (var strategy in _strategyManager.GetStrategies())
  448. {
  449. if (strategy.ID == _config.strategy)
  450. {
  451. return strategy;
  452. }
  453. }
  454. return null;
  455. }
  456. public void UpdateInboundCounter(object sender, SSTransmitEventArgs args)
  457. {
  458. GetCurrentStrategy()?.UpdateLastRead(args.server);
  459. Interlocked.Add(ref _inboundCounter, args.length);
  460. }
  461. public void UpdateOutboundCounter(object sender, SSTransmitEventArgs args)
  462. {
  463. GetCurrentStrategy()?.UpdateLastWrite(args.server);
  464. Interlocked.Add(ref _outboundCounter, args.length);
  465. }
  466. #endregion
  467. #region SIP003
  468. private void StartPlugin()
  469. {
  470. var server = _config.GetCurrentServer();
  471. GetPluginLocalEndPointIfConfigured(server);
  472. }
  473. private void StopPlugins()
  474. {
  475. foreach (var serverAndPlugin in _pluginsByServer)
  476. {
  477. serverAndPlugin.Value?.Dispose();
  478. }
  479. _pluginsByServer.Clear();
  480. }
  481. public EndPoint GetPluginLocalEndPointIfConfigured(Server server)
  482. {
  483. var plugin = _pluginsByServer.GetOrAdd(
  484. server,
  485. x => Sip003Plugin.CreateIfConfigured(x, _config.showPluginOutput));
  486. if (plugin == null)
  487. {
  488. return null;
  489. }
  490. try
  491. {
  492. if (plugin.StartIfNeeded())
  493. {
  494. logger.Info(
  495. $"Started SIP003 plugin for {server.Identifier()} on {plugin.LocalEndPoint} - PID: {plugin.ProcessId}");
  496. }
  497. }
  498. catch (Exception ex)
  499. {
  500. logger.Error("Failed to start SIP003 plugin: " + ex.Message);
  501. throw;
  502. }
  503. return plugin.LocalEndPoint;
  504. }
  505. public void ToggleShowPluginOutput(bool enabled)
  506. {
  507. _config.showPluginOutput = enabled;
  508. SaveConfig(_config);
  509. ShowPluginOutputChanged?.Invoke(this, new EventArgs());
  510. }
  511. #endregion
  512. #region Traffic Statistics
  513. private void StartTrafficStatistics(int queueMaxSize)
  514. {
  515. trafficPerSecondQueue = new Queue<TrafficPerSecond>();
  516. for (int i = 0; i < queueMaxSize; i++)
  517. {
  518. trafficPerSecondQueue.Enqueue(new TrafficPerSecond());
  519. }
  520. _trafficThread = new Thread(new ThreadStart(() => TrafficStatistics(queueMaxSize)))
  521. {
  522. IsBackground = true
  523. };
  524. _trafficThread.Start();
  525. }
  526. private void TrafficStatistics(int queueMaxSize)
  527. {
  528. TrafficPerSecond previous, current;
  529. while (true)
  530. {
  531. previous = trafficPerSecondQueue.Last();
  532. current = new TrafficPerSecond
  533. {
  534. inboundCounter = InboundCounter,
  535. outboundCounter = OutboundCounter
  536. };
  537. current.inboundIncreasement = current.inboundCounter - previous.inboundCounter;
  538. current.outboundIncreasement = current.outboundCounter - previous.outboundCounter;
  539. trafficPerSecondQueue.Enqueue(current);
  540. if (trafficPerSecondQueue.Count > queueMaxSize)
  541. trafficPerSecondQueue.Dequeue();
  542. TrafficChanged?.Invoke(this, new EventArgs());
  543. Thread.Sleep(1000);
  544. }
  545. }
  546. #endregion
  547. #region SIP008
  548. public async Task<int> UpdateOnlineConfigInternal(string url)
  549. {
  550. var onlineServer = await OnlineConfigResolver.GetOnline(url);
  551. _config.configs = Configuration.SortByOnlineConfig(
  552. _config.configs
  553. .Where(c => c.group != url)
  554. .Concat(onlineServer)
  555. );
  556. logger.Info($"updated {onlineServer.Count} server from {url}");
  557. return onlineServer.Count;
  558. }
  559. public async Task<bool> UpdateOnlineConfig(string url)
  560. {
  561. var selected = GetCurrentServer();
  562. try
  563. {
  564. int count = await UpdateOnlineConfigInternal(url);
  565. }
  566. catch (Exception e)
  567. {
  568. logger.LogUsefulException(e);
  569. return false;
  570. }
  571. _config.index = _config.configs.IndexOf(selected);
  572. SaveConfig(_config);
  573. return true;
  574. }
  575. public async Task<List<string>> UpdateAllOnlineConfig()
  576. {
  577. var selected = GetCurrentServer();
  578. var failedUrls = new List<string>();
  579. foreach (var url in _config.onlineConfigSource)
  580. {
  581. try
  582. {
  583. await UpdateOnlineConfigInternal(url);
  584. }
  585. catch (Exception e)
  586. {
  587. logger.LogUsefulException(e);
  588. failedUrls.Add(url);
  589. }
  590. }
  591. _config.index = _config.configs.IndexOf(selected);
  592. SaveConfig(_config);
  593. return failedUrls;
  594. }
  595. public void SaveOnlineConfigSource(List<string> sources)
  596. {
  597. _config.onlineConfigSource = sources;
  598. SaveConfig(_config);
  599. }
  600. public void RemoveOnlineConfig(string url)
  601. {
  602. _config.onlineConfigSource.RemoveAll(v => v == url);
  603. _config.configs = Configuration.SortByOnlineConfig(
  604. _config.configs.Where(c => c.group != url)
  605. );
  606. SaveConfig(_config);
  607. }
  608. #endregion
  609. }
  610. }