private void addNewParser_Click(object sender, RoutedEventArgs e) { ParserCreator newParser = new ParserCreator(className.Text, classSelector.Text, baseUrl.Text, prefixStructure.Text); string name = parserName.Text; if (userPrefs.Parsers.ContainsKey(name)) { MessageBox.Show("Name already exists!"); } else { userPrefs.addParser(name, newParser); } }
//Десериализует обьект настроек и создает класс настроек internal UserPrefs loadSettings() { UserPrefs userPrefs = null; if (Directory.Exists(appData + "\\UTMChangerData")) { if (File.Exists(appData + "\\UTMChangerData\\config.dat")) { BinaryFormatter formatter = new BinaryFormatter(); using (FileStream fs = new FileStream(path, FileMode.Open)) { try { userPrefs = (UserPrefs)formatter.Deserialize(fs); } catch (Exception) { //throw; } } } else { userPrefs = new UserPrefs(); if (userPrefs.Parsers.Keys.Count == 0) { userPrefs.addParser("habr", new ParserCreator("post__title_link", "a", "https://habr.com/", "page{CurrentId}")); } } } else { userPrefs = new UserPrefs(); if (userPrefs.Parsers.Keys.Count == 0) { userPrefs.addParser("habr", new ParserCreator("post__title_link", "a", "https://habr.com/", "page{CurrentId}")); } } // Console.WriteLine("Объект десериализован"); return(userPrefs); }