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

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