/// <summary> /// Saves the UserPrefs to the specified file /// </summary> /// <param name="prefs">UserPrefs object to save</param> /// <param name="file">File to save to</param> public static void SavePrefs(UserPrefs prefs, string file) { try { using (FileStream fStream = new FileStream(file, FileMode.Create)) { List <Type> types = SavePluginSettings(prefs); XmlSerializer xs = new XmlSerializer(typeof(UserPrefs), types.ToArray()); xs.Serialize(fStream, prefs); } } catch (Exception ex) { // https://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Bugs#InvalidOperationException_in_UserPrefs.SavePrefs // Saving settings will fail if permissions problems, so handle this if (ex is InvalidOperationException && ex.Message.Contains("CS0016")) { MessageBox.Show("Saving settings failed due to insufficient permissions.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { ErrorHandler.HandleException(ex); } } }
/// <summary> /// Saves the UserPrefs to the specified file /// </summary> /// <param name="prefs">UserPrefs object to save</param> /// <param name="file">File to save to</param> public static void SavePrefs(UserPrefs prefs, string file) { try { using (FileStream fStream = new FileStream(file, FileMode.Create)) { List <Type> types = SavePluginSettings(prefs); XmlSerializer xs = new XmlSerializer(typeof(UserPrefs), types.ToArray()); xs.Serialize(fStream, prefs); } } catch (Exception ex) { ErrorHandler.Handle(ex); } }
/// <summary> /// Saves the plugin Settings /// </summary> /// <param name="prefs">UserPrefs object</param> /// <returns>A list of the plugin types</returns> public static List <Type> SavePluginSettings(UserPrefs prefs) { List <Type> types = new List <Type>(); /* Find out what types the plugins are using for their settings so we can * add them to the Serializer. The plugin author must ensure s(he) is using * serializable types.*/ foreach (PluginPrefs pl in prefs.Plugin) { if ((pl.PluginSettings != null) && (pl.PluginSettings.Length >= 1)) { foreach (object pl2 in pl.PluginSettings) { types.Add(pl2.GetType()); } } } return(types); }
/// <summary> /// Saves the plugin Settings /// </summary> /// <param name="prefs">UserPrefs object</param> /// <returns>A list of the plugin types</returns> public static List<Type> SavePluginSettings(UserPrefs prefs) { List<Type> types = new List<Type>(); /* Find out what types the plugins are using for their settings so we can add them to the Serializer. The plugin author must ensure s(he) is using serializable types.*/ foreach (PluginPrefs pl in prefs.Plugin) { if ((pl.PluginSettings != null) && (pl.PluginSettings.Length >= 1)) { foreach (object pl2 in pl.PluginSettings) { types.Add(pl2.GetType()); } } } return types; }
/// <summary> /// Saves the UserPrefs to the specified file /// </summary> /// <param name="prefs">UserPrefs object to save</param> /// <param name="file">File to save to</param> public static void SavePrefs(UserPrefs prefs, string file) { try { using (FileStream fStream = new FileStream(file, FileMode.Create)) { List<Type> types = SavePluginSettings(prefs); XmlSerializer xs = new XmlSerializer(typeof(UserPrefs), types.ToArray()); xs.Serialize(fStream, prefs); } } catch (Exception ex) { ErrorHandler.Handle(ex); } }
/// <summary> /// Load preferences object /// </summary> private void LoadPrefs(UserPrefs p) { SetProject(p.LanguageCode, p.Project, p.CustomProject); findAndReplace.Clear(); chkFindandReplace.Checked = p.FindAndReplace.Enabled; findAndReplace.ignoreLinks = p.FindAndReplace.IgnoreSomeText; findAndReplace.ignoreMore = p.FindAndReplace.IgnoreMoreText; findAndReplace.AppendToSummary = p.FindAndReplace.AppendSummary; findAndReplace.AfterOtherFixes = p.FindAndReplace.AfterOtherFixes; findAndReplace.AddNew(p.FindAndReplace.Replacements); replaceSpecial.Clear(); replaceSpecial.AddNewRule(p.FindAndReplace.AdvancedReps); substTemplates.Clear(); substTemplates.TemplateList = p.FindAndReplace.SubstTemplates; substTemplates.ExpandRecursively = p.FindAndReplace.ExpandRecursively; substTemplates.IgnoreUnformatted = p.FindAndReplace.IgnoreUnformatted; substTemplates.IncludeComments = p.FindAndReplace.IncludeComments; findAndReplace.MakeList(); listMaker.SourceText = p.List.ListSource; listMaker.SelectedSource = p.List.SourceIndex; SaveArticleList = p.General.SaveArticleList; IgnoreNoBots = p.General.IgnoreNoBots; listMaker.Add(p.List.ArticleList); chkGeneralFixes.Checked = p.Editprefs.GeneralFixes; chkAutoTagger.Checked = p.Editprefs.Tagger; chkUnicodifyWhole.Checked = p.Editprefs.Unicodify; cmboCategorise.SelectedIndex = p.Editprefs.Recategorisation; txtNewCategory.Text = p.Editprefs.NewCategory; txtNewCategory2.Text = p.Editprefs.NewCategory2; cmboImages.SelectedIndex = p.Editprefs.ReImage; txtImageReplace.Text = p.Editprefs.ImageFind; txtImageWith.Text = p.Editprefs.Replace; chkSkipNoCatChange.Checked = p.Editprefs.SkipIfNoCatChange; chkSkipNoImgChange.Checked = p.Editprefs.SkipIfNoImgChange; chkAppend.Checked = p.Editprefs.AppendText; rdoAppend.Checked = p.Editprefs.Append; rdoPrepend.Checked = !p.Editprefs.Append; txtAppendMessage.Text = p.Editprefs.Text; udNewlineChars.Value = p.Editprefs.Newlines; nudBotSpeed.Value = p.Editprefs.AutoDelay; chkSuppressTag.Checked = p.Editprefs.SupressTag; chkRegExTypo.Checked = p.Editprefs.RegexTypoFix; radSkipNonExistent.Checked = p.SkipOptions.SkipNonexistent; radSkipExistent.Checked = p.SkipOptions.Skipexistent; chkSkipNoChanges.Checked = p.SkipOptions.SkipWhenNoChanges; chkSkipSpamFilter.Checked = p.SkipOptions.SkipSpamFilterBlocked; chkSkipIfInuse.Checked = p.SkipOptions.SkipInuse; chkSkipWhitespace.Checked = p.SkipOptions.SkipWhenOnlyWhitespaceChanged; chkSkipCasing.Checked = p.SkipOptions.SkipOnlyCasingChanged; chkSkipGeneralFixes.Checked = p.SkipOptions.SkipOnlyGeneralFixChanges; chkSkipMinorGeneralFixes.Checked = p.SkipOptions.SkipOnlyMinorGeneralFixChanges; chkSkipIfRedirect.Checked = p.SkipOptions.SkipIfRedirect; chkSkipIfContains.Checked = p.SkipOptions.SkipDoes; chkSkipIfNotContains.Checked = p.SkipOptions.SkipDoesNot; txtSkipIfContains.Text = p.SkipOptions.SkipDoesText; txtSkipIfNotContains.Text = p.SkipOptions.SkipDoesNotText; chkSkipIsRegex.Checked = p.SkipOptions.Regex; chkSkipCaseSensitive.Checked = p.SkipOptions.CaseSensitive; chkSkipWhenNoFAR.Checked = p.SkipOptions.SkipNoFindAndReplace; chkSkipIfNoRegexTypo.Checked = p.SkipOptions.SkipNoRegexTypoFix; Skip.SelectedItems = p.SkipOptions.GeneralSkipList; chkSkipNoDab.Checked = p.SkipOptions.SkipNoDisambiguation; chkSkipNoPageLinks.Checked = p.SkipOptions.SkipNoLinksOnPage; cmboEditSummary.Items.Clear(); if (p.General.Summaries.Count == 0) LoadDefaultEditSummaries(); else foreach (string s in p.General.Summaries) cmboEditSummary.Items.Add(s); chkLock.Checked = p.General.LockSummary; EditToolBarVisible = p.General.EditToolbarEnabled; cmboEditSummary.Text = p.General.SelectedSummary; if (chkLock.Checked) lblSummary.Text = p.General.SelectedSummary; PasteMore1.Text = p.General.PasteMore[0]; PasteMore2.Text = p.General.PasteMore[1]; PasteMore3.Text = p.General.PasteMore[2]; PasteMore4.Text = p.General.PasteMore[3]; PasteMore5.Text = p.General.PasteMore[4]; PasteMore6.Text = p.General.PasteMore[5]; PasteMore7.Text = p.General.PasteMore[6]; PasteMore8.Text = p.General.PasteMore[7]; PasteMore9.Text = p.General.PasteMore[8]; PasteMore10.Text = p.General.PasteMore[9]; txtFind.Text = p.General.FindText; chkFindRegex.Checked = p.General.FindRegex; chkFindCaseSensitive.Checked = p.General.FindCaseSensitive; wordWrapToolStripMenuItem1.Checked = p.General.WordWrap; EnableToolBar = p.General.ToolBarEnabled; bypassRedirectsToolStripMenuItem.Checked = p.General.BypassRedirect; autoSaveSettingsToolStripMenuItem.Checked = p.General.AutoSaveSettings; preParseModeToolStripMenuItem.Checked = p.General.PreParseMode; automaticallyDoAnythingToolStripMenuItem.Checked = !p.General.NoAutoChanges; toolStripComboOnLoad.SelectedIndex = p.General.OnLoadAction; chkMinor.Checked = p.General.Minor; addAllToWatchlistToolStripMenuItem.Checked = p.General.Watch; dontAddToWatchlistToolStripMenuItem.Checked = p.General.DoNotWatch; ShowMovingAverageTimer = p.General.TimerEnabled; sortAlphabeticallyToolStripMenuItem.Checked = p.General.SortListAlphabetically; displayfalsePositivesButtonToolStripMenuItem.Checked = p.General.AddIgnoredToLog; AutoSaveEditBoxEnabled = p.General.AutoSaveEdit.Enabled; AutoSaveEditBoxPeriod = p.General.AutoSaveEdit.SavePeriod; AutoSaveEditBoxFile = p.General.AutoSaveEdit.SaveFile; SuppressUsingAWB = p.General.SuppressUsingAWB; AddUsingAWBOnArticleAction = p.General.AddUsingAWBToActionSummaries; filterOutNonMainSpaceToolStripMenuItem.Checked = p.General.filterNonMainSpace; removeDuplicatesToolStripMenuItem.Checked = p.General.AutoFilterDuplicates; alphaSortInterwikiLinksToolStripMenuItem.Checked = p.General.SortInterWikiOrder; replaceReferenceTagsToolStripMenuItem.Checked = p.General.ReplaceReferenceTags; focusAtEndOfEditTextBoxToolStripMenuItem.Checked = p.General.FocusAtEndOfEditBox; txtEdit.Font = new System.Drawing.Font(p.General.TextBoxFont, p.General.TextBoxSize); LowThreadPriority = p.General.LowThreadPriority; Flash = p.General.Flash; Beep = p.General.Beep; Minimize = p.General.Minimize; TimeOut = p.General.TimeOutLimit; webBrowserEdit.TimeoutLimit = int.Parse(TimeOut.ToString()); chkEnableDab.Checked = p.Disambiguation.Enabled; txtDabLink.Text = p.Disambiguation.Link; txtDabVariants.Lines = p.Disambiguation.Variants; udContextChars.Value = p.Disambiguation.ContextChars; listMaker.SpecialFilterSettings = p.Special; loggingSettings1.SerialisableSettings = p.Logging; cModule.ModuleEnabled = p.Module.Enabled; cModule.Language = p.Module.Language; cModule.Code = p.Module.Code.Replace("\n", "\r\n"); if (cModule.ModuleEnabled) cModule.MakeModule(); else cModule.SetModuleNotBuilt(); externalProgram.Settings = p.ExternalProgram; foreach (PluginPrefs pp in p.Plugin) { if (Plugin.Items.ContainsKey(pp.Name)) Plugin.Items[pp.Name].LoadSettings(pp.PluginSettings); } }
/// <summary> /// Saves the UserPrefs to the specified file /// </summary> /// <param name="prefs">UserPrefs object to save</param> /// <param name="file">File to save to</param> public static void SavePrefs(UserPrefs prefs, string file) { try { using (FileStream fStream = new FileStream(file, FileMode.Create)) { List<Type> types = SavePluginSettings(prefs); XmlSerializer xs = new XmlSerializer(typeof(UserPrefs), types.ToArray()); xs.Serialize(fStream, prefs); } } catch (Exception ex) { // https://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Bugs#InvalidOperationException_in_UserPrefs.SavePrefs // Saving settings will fail if permissions problems, so handle this if (ex is InvalidOperationException && ex.Message.Contains("CS0016")) { MessageBox.Show("Saving settings failed due to insufficient permissions.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else ErrorHandler.Handle(ex); } }
public ListSplitter(UserPrefs Prefs, List<Type> type, List<Article> list) : this(Prefs, type) { listMaker1.Add(list); }
/// <summary> /// /// </summary> /// <param name="prefs"></param> /// <param name="list"></param> public ListSplitter(UserPrefs prefs, List<Article> list) : this(prefs) { listMaker1.Add(list); }
public ListSplitter(UserPrefs Prefs, List<Type> type) { InitializeComponent(); P = Prefs; Types = type; }
/// <summary> /// /// </summary> /// <param name="prefs"></param> public ListSplitter(UserPrefs prefs) { InitializeComponent(); _p = prefs; }
/// <summary> /// Load preferences object /// </summary> private void LoadPrefs(UserPrefs p) { SetProject(p.LanguageCode, p.Project, p.CustomProject, p.Protocol); Variables.LoginDomain = p.LoginDomain; FindAndReplace.Clear(); chkFindandReplace.Checked = p.FindAndReplace.Enabled; FindAndReplace.IgnoreLinks = p.FindAndReplace.IgnoreSomeText; FindAndReplace.IgnoreMore = p.FindAndReplace.IgnoreMoreText; FindAndReplace.AppendToSummary = p.FindAndReplace.AppendSummary; FindAndReplace.AddNew(p.FindAndReplace.Replacements); RplcSpecial.Clear(); RplcSpecial.AddNewRule(p.FindAndReplace.AdvancedReps); SubstTemplates.Clear(); SubstTemplates.TemplateList = p.FindAndReplace.SubstTemplates; SubstTemplates.ExpandRecursively = p.FindAndReplace.ExpandRecursively; SubstTemplates.IgnoreUnformatted = p.FindAndReplace.IgnoreUnformatted; SubstTemplates.IncludeComments = p.FindAndReplace.IncludeComments; FindAndReplace.MakeList(); listMaker.SourceText = p.List.ListSource; listMaker.SelectedProvider = p.List.SelectedProvider; _saveArticleList = p.General.SaveArticleList; IgnoreNoBots = p.General.IgnoreNoBots; ClearPageListOnProjectChange = p.General.ClearPageListOnProjectChange; chkGeneralFixes.Checked = p.Editprefs.GeneralFixes; chkAutoTagger.Checked = p.Editprefs.Tagger; chkUnicodifyWhole.Checked = p.Editprefs.Unicodify; cmboCategorise.SelectedIndex = p.Editprefs.Recategorisation; txtNewCategory.Text = p.Editprefs.NewCategory; txtNewCategory2.Text = p.Editprefs.NewCategory2; cmboImages.SelectedIndex = p.Editprefs.ReImage; txtImageReplace.Text = p.Editprefs.ImageFind; txtImageWith.Text = p.Editprefs.Replace; chkSkipNoCatChange.Checked = p.Editprefs.SkipIfNoCatChange; chkRemoveSortKey.Checked = p.Editprefs.RemoveSortKey; chkSkipNoImgChange.Checked = p.Editprefs.SkipIfNoImgChange; chkAppend.Checked = p.Editprefs.AppendText; chkAppendMetaDataSort.Checked = p.Editprefs.AppendTextMetaDataSort; rdoAppend.Checked = p.Editprefs.Append; rdoPrepend.Checked = !p.Editprefs.Append; txtAppendMessage.Text = p.Editprefs.Text; udNewlineChars.Value = p.Editprefs.Newlines; nudBotSpeed.Value = p.Editprefs.AutoDelay; botEditsStop.Value = p.Editprefs.BotMaxEdits; chkSuppressTag.Checked = p.Editprefs.SupressTag; chkRegExTypo.Checked = p.Editprefs.RegexTypoFix; radSkipNonExistent.Checked = p.SkipOptions.SkipNonexistent; radSkipExistent.Checked = p.SkipOptions.Skipexistent; chkSkipNoChanges.Checked = p.SkipOptions.SkipWhenNoChanges; chkSkipSpamFilter.Checked = p.SkipOptions.SkipSpamFilterBlocked; chkSkipIfInuse.Checked = p.SkipOptions.SkipInuse; chkSkipWhitespace.Checked = p.SkipOptions.SkipWhenOnlyWhitespaceChanged; chkSkipCasing.Checked = p.SkipOptions.SkipOnlyCasingChanged; chkSkipGeneralFixes.Checked = p.SkipOptions.SkipOnlyGeneralFixChanges; chkSkipMinorGeneralFixes.Checked = p.SkipOptions.SkipOnlyMinorGeneralFixChanges; chkSkipCosmetic.Checked = p.SkipOptions.SkipOnlyCosmetic; chkSkipIfRedirect.Checked = p.SkipOptions.SkipIfRedirect; chkSkipIfNoAlerts.Checked = p.SkipOptions.SkipIfNoAlerts; chkSkipIfContains.Checked = p.SkipOptions.SkipDoes; chkSkipIfNotContains.Checked = p.SkipOptions.SkipDoesNot; txtSkipIfContains.Text = p.SkipOptions.SkipDoesText; txtSkipIfNotContains.Text = p.SkipOptions.SkipDoesNotText; chkSkipIsRegex.Checked = p.SkipOptions.Regex; chkSkipCaseSensitive.Checked = p.SkipOptions.CaseSensitive; chkSkipAfterProcessing.Checked = p.SkipOptions.AfterProcessing; chkSkipWhenNoFAR.Checked = p.SkipOptions.SkipNoFindAndReplace; chkSkipOnlyMinorFaR.Checked = p.SkipOptions.SkipMinorFindAndReplace; chkSkipIfNoRegexTypo.Checked = p.SkipOptions.SkipNoRegexTypoFix; Skip.SelectedItems = p.SkipOptions.GeneralSkipList; chkSkipNoDab.Checked = p.SkipOptions.SkipNoDisambiguation; chkSkipNoPageLinks.Checked = p.SkipOptions.SkipNoLinksOnPage; cmboEditSummary.Items.Clear(); if (p.General.Summaries.Count == 0) LoadDefaultEditSummaries(); else foreach (string s in p.General.Summaries) cmboEditSummary.Items.Add(s); chkLock.Checked = p.General.LockSummary; EditToolBarVisible = p.General.EditToolbarEnabled; cmboEditSummary.Text = p.General.SelectedSummary; if (chkLock.Checked) lblSummary.Text = p.General.SelectedSummary; for (int i = 0; i < 10; ++i) SetPasteMoreText(i, p.General.PasteMore[i]); txtFind.Text = p.General.FindText; chkFindRegex.Checked = p.General.FindRegex; chkFindCaseSensitive.Checked = p.General.FindCaseSensitive; wordWrapToolStripMenuItem1.Checked = p.General.WordWrap; EnableToolBar = p.General.ToolBarEnabled; followRedirectsToolStripMenuItem.Checked = p.General.BypassRedirect; autoSaveSettingsToolStripMenuItem.Checked = p.General.AutoSaveSettings; preParseModeToolStripMenuItem.Checked = p.General.PreParseMode; noSectionEditSummaryToolStripMenuItem.Checked = p.General.noSectionEditSummary; restrictDefaultsortChangesToolStripMenuItem.Checked = p.General.restrictDefaultsortAddition; restrictOrphanTaggingToolStripMenuItem.Checked = p.General.restrictOrphanTagging; noMOSComplianceFixesToolStripMenuItem.Checked = p.General.noMOSComplianceFixes; syntaxHighlightEditBoxToolStripMenuItem.Checked = p.General.syntaxHighlightEditBox; highlightAllFindToolStripMenuItem.Checked = p.General.highlightAllFind; automaticallyDoAnythingToolStripMenuItem.Checked = !p.General.NoAutoChanges; actionOnLoad = p.General.OnLoadAction; doDiffInBotMode = p.General.DiffInBotMode; chkMinor.Checked = p.General.Minor; addToWatchList.SelectedIndex = p.General.AddToWatchlist; ShowMovingAverageTimer = p.General.TimerEnabled; alertPreferences = p.General.AlertPreferences; sortAlphabeticallyToolStripMenuItem.Checked = listMaker.AutoAlpha = p.General.SortListAlphabetically; displayfalsePositivesButtonToolStripMenuItem.Checked = p.General.AddIgnoredToLog; _autoSaveEditBoxEnabled = p.General.AutoSaveEdit.Enabled; AutoSaveEditBoxPeriod = p.General.AutoSaveEdit.SavePeriod; _autoSaveEditBoxFile = p.General.AutoSaveEdit.SaveFile; _suppressUsingAWB = p.General.SuppressUsingAWB; Article.AddUsingAWBOnArticleAction = p.General.AddUsingAWBToActionSummaries; filterOutNonMainSpaceToolStripMenuItem.Checked = p.General.filterNonMainSpace; removeDuplicatesToolStripMenuItem.Checked = listMaker.FilterDuplicates = p.General.AutoFilterDuplicates; alphaSortInterwikiLinksToolStripMenuItem.Checked = p.General.SortInterWikiOrder; replaceReferenceTagsToolStripMenuItem.Checked = p.General.ReplaceReferenceTags; focusAtEndOfEditTextBoxToolStripMenuItem.Checked = p.General.FocusAtEndOfEditBox; scrollToAlertsToolStripMenuItem.Checked = p.General.scrollToUnbalancedBrackets; txtEdit.Font = new System.Drawing.Font(p.General.TextBoxFont, p.General.TextBoxSize); loggingEnabled = p.General.LoggingEnabled; LowThreadPriority = p.General.LowThreadPriority; _flash = p.General.Flash; _beep = p.General.Beep; _minimize = p.General.Minimize; chkEnableDab.Checked = p.Disambiguation.Enabled; txtDabLink.Text = p.Disambiguation.Link; txtDabVariants.Lines = p.Disambiguation.Variants; udContextChars.Value = p.Disambiguation.ContextChars; listMaker.SpecialFilterSettings = p.Special; // ensure listmaker is only populated once listmaker filter settings (remove non-mainpace etc.) have been loaded listMaker.Add(p.List.ArticleList); CModule.Language = p.Module.Language; CModule.Code = p.Module.Code.Replace("\n", "\r\n"); //Don't enable custom module until code loaded, prevents phantom compile error CModule.ModuleEnabled = p.Module.Enabled; if (!CModule.ModuleEnabled) CModule.SetModuleNotBuilt(); ExtProgram.Settings = p.ExternalProgram; _listComparerUseCurrentArticleList = p.Tool.ListComparerUseCurrentArticleList; _listSplitterUseCurrentArticleList = p.Tool.ListSplitterUseCurrentArticleList; _dbScannerUseCurrentArticleList = p.Tool.DatabaseScannerUseCurrentArticleList; foreach (PluginPrefs pp in p.Plugin) { IAWBPlugin plugin; if (Plugin.AWBPlugins.TryGetValue(pp.Name, out plugin)) plugin.LoadSettings(pp.PluginSettings); } }
public ListSplitter(UserPrefs Prefs, List<System.Type> Type, List<Article> list) : this(Prefs, Type) { listMaker1.Add(list); }
public ListSplitter(UserPrefs Prefs, List<System.Type> Type) { InitializeComponent(); P = Prefs; Types = Type; }
/// <summary> /// /// </summary> /// <param name="prefs"></param> public ListSplitter(UserPrefs prefs) { InitializeComponent(); _p = prefs; listMaker1.NoOfArticlesChanged += UpdateButtons; }