Beispiel #1
0
        public static AdDetectionSettings Load()
        {
            if (_settings != null)
            {
                return(_settings);
            }

            try
            {
                if (File.Exists(FileName))
                {
                    var s = new DataContractSerializer(typeof(AdDetectionSettings));
                    using (var fs = File.Open(FileName, FileMode.Open))
                    {
                        using (var reader = XmlReader.Create(fs))
                        {
                            _settings = (AdDetectionSettings)s.ReadObject(reader);
                            return(_settings);
                        }
                    }
                }
            }
            catch
            {
                Console.WriteLine($@"Unable to load {FileName}. Using default config.");
            }

            Save(Default);
            return(_settings);
        }
Beispiel #2
0
        private void RemoveUninstalledModulesFromConfig()
        {
            var removedModules =
                _settings.EnabledModules.Where(enabledModule => !_modules.ContainsKey(enabledModule)).ToList();

            _settings.EnabledModules.RemoveAll(x => removedModules.Contains(x));
            AdDetectionSettings.Save(_settings);
        }
Beispiel #3
0
        private void DisableModule(IAdModule module)
        {
            EnabledModules.Remove(module);
            DisabledModules.Add(module);

            _settings.EnabledModules = EnabledModules.Select(x => x.Title).ToList();
            AdDetectionSettings.Save(_settings);
        }
        private void EnableChanged()
        {
            if (m_settings.IsEnabled != AdDetectingEnabled)
            {
                m_settings.IsEnabled = AdDetectingEnabled;

                AdDetectionSettings.Save(m_settings);
            }
        }
Beispiel #5
0
        private void AdDetectionEngineChanged()
        {
            if (SelectedAdDetectionEngineDescriptor != null &&
                SelectedAdDetectionEngineDescriptor.Type != _settings.EngineType)
            {
                _settings.EngineType = SelectedAdDetectionEngineDescriptor.Type;

                AdDetectionSettings.Save(_settings);
            }
        }
Beispiel #6
0
        private void EnableChanged()
        {
            if (_settings.IsEnabled == AdDetectingEnabled)
            {
                return;
            }

            _settings.IsEnabled = AdDetectingEnabled;

            AdDetectionSettings.Save(_settings);
        }
Beispiel #7
0
        public void LoadConfig()
        {
            _settings = AdDetectionSettings.Load();

            _adDetectingEnabled = _settings.IsEnabled;

            _enabledModules =
                new ObservableCollection <IAdModule>(
                    _modules.Where(x => _settings.EnabledModules.Contains(x.Key)).Select(x => x.Value));
            _disabledModules =
                new ObservableCollection <IAdModule>(
                    _modules.Where(x => !_settings.EnabledModules.Contains(x.Key)).Select(x => x.Value));

            _selectedAdDetectionEngineDescriptor = AdDetectionEngines.FirstOrDefault(x => x.Type == _settings.EngineType);
        }
Beispiel #8
0
 public static void Save(AdDetectionSettings settings)
 {
     try
     {
         var s = new DataContractSerializer(typeof(AdDetectionSettings));
         using (var fs = File.Open(FileName, FileMode.Create))
         {
             s.WriteObject(fs, settings);
             _settings = settings;
         }
     }
     catch
     {
         Console.WriteLine($@"Unable to save {FileName}");
     }
 }