Exemple #1
0
        void StartFileWatcher(Model.Data.PacServerSettings pacSetting)
        {
            StopCustomPacFileWatcher();
            if (!pacSetting.isUseCustomPac)
            {
                return;
            }

            var filename = pacSetting.customPacFilePath;

            if (!File.Exists(filename))
            {
                return;
            }

            var path = Path.GetDirectoryName(filename);

            customPacFileWatcher = new FileSystemWatcher
            {
                Path   = (string.IsNullOrEmpty(path) ? Lib.Utils.GetAppDir() : path),
                Filter = Path.GetFileName(filename),
            };

            customPacFileWatcher.Changed += (s, a) => LazyCustomPacFileCacheUpdate();
            customPacFileWatcher.Created += (s, a) => LazyCustomPacFileCacheUpdate();
            customPacFileWatcher.Deleted += (s, a) => LazyCustomPacFileCacheUpdate();

            customPacFileWatcher.EnableRaisingEvents = true;
        }
Exemple #2
0
        public override bool SaveOptions()
        {
            if (!IsOptionsChanged())
            {
                return(false);
            }

            var pacSetting = new Model.Data.PacServerSettings
            {
                port              = Lib.Utils.Str2Int(tboxPort.Text),
                isAutorun         = chkIsAutorun.Checked,
                customBlackList   = rtboxCustomBlackList.Text,
                customWhiteList   = rtboxCustomWhiteList.Text,
                customPacFilePath = tboxCustomPacFilePath.Text,
                isUseCustomPac    = chkCustomPacFile.Checked,
            };

            setting.SavePacServerSettings(pacSetting);
            if (pacServer.isWebServRunning)
            {
                pacServer.RestartPacServer();
            }
            UpdateSystemProxy();
            return(true);
        }
Exemple #3
0
 public void SavePacServerSettings(
     Model.Data.PacServerSettings pacSetting)
 {
     userSettings.PacServerSettings =
         JsonConvert.SerializeObject(pacSetting);
     LazySaveUserSettings();
 }
Exemple #4
0
        public Model.Data.PacServerSettings GetPacServerSettings()
        {
            Model.Data.PacServerSettings result = null;

            var empty = new Model.Data.PacServerSettings();

            try
            {
                result = JsonConvert.DeserializeObject <Model.Data.PacServerSettings>(
                    Properties.Settings.Default.PacServerSettings);
            }
            catch
            {
                return(empty);
            }

            return(result ?? empty);
        }
Exemple #5
0
        StringBuilder GenCustomPacFile(
            Model.Data.PacUrlParams urlParam,
            Model.Data.PacServerSettings pacSetting)
        {
            var header = new Model.Data.PacCustomHeader(
                urlParam,
                pacSetting.customWhiteList,
                pacSetting.customBlackList);

            if (string.IsNullOrEmpty(customPacCache))
            {
                // 抢救一下,还不行就算了
                UpdateCustomPacCache();
            }

            return(new StringBuilder("var customSettings = ")
                   .Append(JsonConvert.SerializeObject(header))
                   .Append(";")
                   .Append(customPacCache));
        }
Exemple #6
0
 public void SavePacServerSettings(Model.Data.PacServerSettings pacSetting)
 {
     Properties.Settings.Default.PacServerSettings =
         JsonConvert.SerializeObject(pacSetting);
     Properties.Settings.Default.Save();
 }