Esempio n. 1
0
 public static void ReSetPACProxy(Config config)
 {
     if (config.listenerType == 2)
     {
         SysProxyHandle.SetIEProxy(false, false, null, null);
         PACServerHandle.Stop();
     }
     Update(config, false);
 }
Esempio n. 2
0
        public static bool Update(Config config, bool forceDisable)
        {
            int type = config.listenerType;

            if (forceDisable)
            {
                type = 0;
            }

            try
            {
                if (type != 0)
                {
                    var port = Utils.GetHttpPortNum(config);
                    if (port == -1)
                    {
                        return(false);
                    }
                    if (type == 1)
                    {
                        PACServerHandle.Stop();
                        PACFileWatcherHandle.StopWatch();
                        SysProxyHandle.SetIEProxy(true, true, "127.0.0.1:" + port, null);
                    }
                    else
                    {
                        string pacUrl = string.Format("http://127.0.0.1:{0}/pac/?t={1}", config.pacPort,
                                                      GetTimestamp(DateTime.Now));
                        SysProxyHandle.SetIEProxy(true, false, null, pacUrl);
                        PACServerHandle.Init(config);
                        PACFileWatcherHandle.StartWatch(config);
                    }
                }
                else
                {
                    SysProxyHandle.SetIEProxy(false, false, null, null);
                    PACServerHandle.Stop();
                    PACFileWatcherHandle.StopWatch();
                }
            }
            catch (Exception ex)
            {
                //Logging.LogUsefulException(ex);
            }
            return(true);
        }
Esempio n. 3
0
        public void UpdateSubscriptionProcess(Config config, string groupId, bool blProxy, Action <bool, string> update)
        {
            _config     = config;
            _updateFunc = update;

            _updateFunc(false, ResUI.MsgUpdateSubscriptionStart);

            if (config.subItem == null || config.subItem.Count <= 0)
            {
                _updateFunc(false, ResUI.MsgNoValidSubscription);
                return;
            }

            Task.Run(async() =>
            {
                //Turn off system proxy
                bool bSysProxyType = false;
                if (!blProxy && config.sysProxyType == ESysProxyType.ForcedChange)
                {
                    bSysProxyType       = true;
                    config.sysProxyType = ESysProxyType.ForcedClear;
                    SysProxyHandle.UpdateSysProxy(config, false);
                    Thread.Sleep(3000);
                }

                foreach (var item in config.subItem)
                {
                    if (item.enabled == false)
                    {
                        continue;
                    }
                    if (!Utils.IsNullOrEmpty(groupId) && item.groupId != groupId)
                    {
                        continue;
                    }

                    string id        = item.id.TrimEx();
                    string url       = item.url.TrimEx();
                    string userAgent = item.userAgent.TrimEx();
                    //string groupId = item.groupId.TrimEx();
                    string hashCode = $"{item.remarks}->";
                    if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url))
                    {
                        //_updateFunc(false, $"{hashCode}{ResUI.MsgNoValidSubscription}");
                        continue;
                    }

                    var downloadHandle    = new DownloadHandle();
                    downloadHandle.Error += (sender2, args) =>
                    {
                        _updateFunc(false, $"{hashCode}{args.GetException().Message}");
                    };

                    _updateFunc(false, $"{hashCode}{ResUI.MsgStartGettingSubscriptions}");
                    var result = await downloadHandle.DownloadStringAsync(url, blProxy, userAgent);
                    if (blProxy && Utils.IsNullOrEmpty(result))
                    {
                        result = await downloadHandle.DownloadStringAsync(url, false, userAgent);
                    }

                    if (Utils.IsNullOrEmpty(result))
                    {
                        _updateFunc(false, $"{hashCode}{ResUI.MsgSubscriptionDecodingFailed}");
                    }
                    else
                    {
                        _updateFunc(false, $"{hashCode}{ResUI.MsgGetSubscriptionSuccessfully}");
                        if (result.Length < 99)
                        {
                            _updateFunc(false, $"{hashCode}{result}");
                        }

                        int ret = ConfigHandler.AddBatchServers(ref config, result, id, item.groupId.TrimEx());
                        _updateFunc(false,
                                    ret > 0
                                ? $"{hashCode}{ResUI.MsgUpdateSubscriptionEnd}"
                                : $"{hashCode}{ResUI.MsgFailedImportSubscription}");
                    }
                    _updateFunc(false, "-------------------------------------------------------");
                }
                //restore system proxy
                if (bSysProxyType)
                {
                    config.sysProxyType = ESysProxyType.ForcedChange;
                    SysProxyHandle.UpdateSysProxy(config, false);
                }
                _updateFunc(true, $"{ResUI.MsgUpdateSubscriptionEnd}");
            });
        }