/// <summary> /// Imports all or some of the settings/prefs stored in the inpute stream. /// This will overwrite appropriate parts of the current (own) settings with the imported ones. /// </summary> /// <param name="fs"></param> /// <param name="flags">Flags to indicate which parts shall be imported</param> private Settings Import(Settings currentSettings, Stream fs, ExportImportFlags flags) { Settings importSettings = LoadOrCreateNew(fs); Settings ownSettings = ObjectClone.Clone<Settings>(currentSettings); Settings newSettings; // at first check for 'Other' as this are the most options. if ((flags & ExportImportFlags.Other) == ExportImportFlags.Other) { newSettings = ownSettings; newSettings.preferences = ObjectClone.Clone<Preferences>(importSettings.preferences); newSettings.preferences.columnizerMaskList = ownSettings.preferences.columnizerMaskList; newSettings.preferences.highlightMaskList = ownSettings.preferences.highlightMaskList; newSettings.hilightGroupList = ownSettings.hilightGroupList; newSettings.preferences.toolEntries = ownSettings.preferences.toolEntries; } else { newSettings = ownSettings; } if ((flags & ExportImportFlags.ColumnizerMasks) == ExportImportFlags.ColumnizerMasks) { newSettings.preferences.columnizerMaskList = importSettings.preferences.columnizerMaskList; } if ((flags & ExportImportFlags.HighlightMasks) == ExportImportFlags.HighlightMasks) { newSettings.preferences.highlightMaskList = importSettings.preferences.highlightMaskList; } if ((flags & ExportImportFlags.HighlightSettings) == ExportImportFlags.HighlightSettings) { newSettings.hilightGroupList = importSettings.hilightGroupList; } if ((flags & ExportImportFlags.ToolEntries) == ExportImportFlags.ToolEntries) { newSettings.preferences.toolEntries = importSettings.preferences.toolEntries; } return newSettings; }
/// <summary> /// Convert settings loaded from previous versions. /// </summary> /// <param name="settings"></param> /// <param name="currentBuildNumber"></param> private void ConvertSettings(Settings settings, int currentBuildNumber) { int oldBuildNumber = settings.versionBuild; // All Versions before 3583 if (oldBuildNumber < 3584) { // External tools List<ToolEntry> newList = new List<ToolEntry>(); foreach (ToolEntry tool in settings.preferences.toolEntries) { // set favourite to true only when name is empty, because there are always version released without this conversion fx // remove empty tool entries (there were always 3 entries before, which can be empty if not used) if (string.IsNullOrEmpty(tool.name)) { if (!string.IsNullOrEmpty(tool.cmd)) { tool.name = tool.cmd; tool.isFavourite = true; newList.Add(tool); } } else { newList.Add(tool); } if (string.IsNullOrEmpty(tool.iconFile)) { tool.iconFile = tool.cmd; tool.iconIndex = 0; } } settings.preferences.toolEntries = newList; } if (oldBuildNumber < 3584) { // Set the color for the FilterList entries to default (black) foreach (FilterParams filterParam in settings.filterList) { filterParam.color = Color.FromKnownColor(KnownColor.Black); } } }
private void Save(Stream fs, Settings settings, SettingsFlags flags) { settings.versionBuild = Assembly.GetExecutingAssembly().GetName().Version.Build; BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(fs, settings); }
private void Save(Settings settings, SettingsFlags flags) { lock (this.loadSaveLock) { Logger.logInfo("Saving settings"); lock (this) { string dir = ConfigDir; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } Stream fs = new FileStream(dir + "\\settings.dat", FileMode.Create, FileAccess.Write); Save(fs, settings, flags); fs.Close(); } OnConfigChanged(flags); } }
private Settings LoadOrCreateNew(Stream fs) { lock (this.loadSaveLock) { Settings settings; if (fs == null) { settings = new Settings(); } else { BinaryFormatter formatter = new BinaryFormatter(); try { settings = (Settings)formatter.Deserialize(fs); } catch (SerializationException) { //Logger.logError("Error while deserializing config data: " + e.Message); settings = new Settings(); } } if (settings.preferences == null) { settings.preferences = new Preferences(); } if (settings.preferences.toolEntries == null) { settings.preferences.toolEntries = new List<ToolEntry>(); } if (settings.preferences.columnizerMaskList == null) { settings.preferences.columnizerMaskList = new List<ColumnizerMaskEntry>(); } if (settings.fileHistoryList == null) { settings.fileHistoryList = new List<string>(); } if (settings.lastOpenFilesList == null) { settings.lastOpenFilesList = new List<string>(); } if (settings.fileColors == null) { settings.fileColors = new List<ColorEntry>(); } if (settings.preferences.showTailColor == Color.Empty) { settings.preferences.showTailColor = Color.FromKnownColor(KnownColor.Blue); } if (settings.preferences.timeSpreadColor == Color.Empty) { settings.preferences.timeSpreadColor = Color.Gray; } if (settings.preferences.bufferCount < 10) { settings.preferences.bufferCount = 100; } if (settings.preferences.linesPerBuffer < 1) { settings.preferences.linesPerBuffer = 500; } if (settings.filterList == null) { settings.filterList = new List<FilterParams>(); } if (settings.searchHistoryList == null) { settings.searchHistoryList = new List<string>(); } if (settings.filterHistoryList == null) { settings.filterHistoryList = new List<string>(); } if (settings.filterRangeHistoryList == null) { settings.filterRangeHistoryList = new List<string>(); } foreach (FilterParams filterParams in settings.filterList) { filterParams.Init(); } if (settings.hilightGroupList == null) { settings.hilightGroupList = new List<HilightGroup>(); // migrate old non-grouped entries HilightGroup defaultGroup = new HilightGroup(); defaultGroup.GroupName = "[Default]"; defaultGroup.HilightEntryList = settings.hilightEntryList; settings.hilightGroupList.Add(defaultGroup); } if (settings.preferences.highlightMaskList == null) { settings.preferences.highlightMaskList = new List<HighlightMaskEntry>(); } if (settings.preferences.pollingInterval < 20) { settings.preferences.pollingInterval = 250; } if (settings.preferences.multifileOptions == null) { settings.preferences.multifileOptions = new MultifileOptions(); } if (settings.preferences.defaultEncoding == null) { settings.preferences.defaultEncoding = Encoding.Default.HeaderName; } ConvertSettings(settings, Assembly.GetExecutingAssembly().GetName().Version.Build); return settings; } }
private ConfigManager() { this.settings = this.Load(); }