Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This is open-source software licensed under the terms of the MIT License.
- *
- * Copyright (c) 2009-2022 Petr Červinka - FortSoft <[email protected]>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- **
- * Version 1.0.0.0
- */
- using FortSoft.Tools;
- using System;
- using System.Diagnostics;
- using System.IO;
- namespace ExampleApplication {
- /// <summary>
- /// This is an example of using the PersistentSettings class.
- /// </summary>
- public class Settings {
- /// <summary>
- /// Fields
- /// </summary>
- private PersistentSettings persistentSettings;
- /// <summary>
- /// Initializes a new instance of the <see cref="Settings"/> class.
- /// </summary>
- public Settings() {
- persistentSettings = new PersistentSettings();
- try {
- string externalImageViewer = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), Properties.Resources.DefaultExternalImageViewerRelativePath);
- if (File.Exists(externalImageViewer)) {
- ExternalImageViewer = externalImageViewer;
- } else {
- externalImageViewer = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), Properties.Resources.DefaultExternalImageViewerRelativePath);
- if (File.Exists(externalImageViewer)) {
- ExternalImageViewer = externalImageViewer;
- }
- }
- } catch (Exception exception) {
- Debug.WriteLine(exception);
- ErrorLog.WriteLine(exception);
- }
- PrintSoftMargins = true;
- CheckForUpdates = true;
- EscapeFunction = 1;
- Load();
- }
- /// <summary>
- /// An example of software application setting that will be stored in the
- /// Windows registry.
- /// </summary>
- public int ActivePanel { get; set; }
- /// <summary>
- /// An example of software application setting that will be stored in the
- /// Windows registry.
- /// </summary>
- public int ActivePreferencesPanel { get; set; }
- /// <summary>
- /// An example of software application setting that will be stored in the
- /// Windows registry.
- /// </summary>
- public string ArchiveDirectory { get; set; }
- /// <summary>
- /// An example of software application setting that will be stored in the
- /// Windows registry.
- /// </summary>
- public string ExternalImageViewer { get; set; }
- /// <summary>
- /// An example of software application setting that will be stored in the
- /// Windows registry.
- /// </summary>
- public bool PrintSoftMargins { get; set; }
- /// <summary>
- /// An example of software application setting that will be stored in the
- /// Windows registry.
- /// </summary>
- public int EscapeFunction { get; set; }
- /// <summary>
- /// An example of software application setting that will be stored in the
- /// Windows registry.
- /// </summary>
- public bool DisableThemes { get; set; }
- /// <summary>
- /// An example of software application setting that will be stored in the
- /// Windows registry.
- /// </summary>
- public string LastExportDirectory { get; set; }
- /// <summary>
- /// An example of software application setting that will be stored in the
- /// Windows registry.
- /// </summary>
- public int ExtensionImageFilterIndex { get; set; }
- /// <summary>
- /// An example of software application setting that will be stored in the
- /// Windows registry.
- /// </summary>
- public int ExtensionTableFilterIndex { get; set; }
- /// <summary>
- /// An example of software application setting that will be stored in the
- /// Windows registry.
- /// </summary>
- public bool CheckForUpdates { get; set; }
- /// <summary>
- /// An example of software application setting that will be stored in the
- /// Windows registry.
- /// </summary>
- public bool StatusBarNotifOnly { get; set; }
- /// <summary>
- /// Loads the software application settings from the Windows registry.
- /// </summary>
- private void Load() {
- ActivePanel = persistentSettings.Load("ActivePanel", ActivePanel);
- ActivePreferencesPanel = persistentSettings.Load("ActivePrefsPanel", ActivePreferencesPanel);
- ArchiveDirectory = persistentSettings.Load("ArchiveDir", ArchiveDirectory);
- ExternalImageViewer = persistentSettings.Load("ExternalImgViewer", ExternalImageViewer);
- PrintSoftMargins = persistentSettings.Load("PrintSoftMargins", PrintSoftMargins);
- EscapeFunction = persistentSettings.Load("EscapeFunction", EscapeFunction);
- DisableThemes = persistentSettings.Load("DisableThemes", DisableThemes);
- LastExportDirectory = persistentSettings.Load("LastExportDir", LastExportDirectory);
- ExtensionImageFilterIndex = persistentSettings.Load("ExtImageFilterIndex", ExtensionImageFilterIndex);
- ExtensionTableFilterIndex = persistentSettings.Load("ExtTableFilterIndex", ExtensionTableFilterIndex);
- CheckForUpdates = persistentSettings.Load("CheckForUpdates", CheckForUpdates);
- StatusBarNotifOnly = persistentSettings.Load("StatusBarNotifOnly", StatusBarNotifOnly);
- }
- /// <summary>
- /// Saves the software application settings into the Windows registry.
- /// </summary>
- public void Save() {
- persistentSettings.Save("ActivePanel", ActivePanel);
- persistentSettings.Save("ActivePrefsPanel", ActivePreferencesPanel);
- persistentSettings.Save("ArchiveDir", ArchiveDirectory);
- persistentSettings.Save("ExternalImgViewer", ExternalImageViewer);
- persistentSettings.Save("PrintSoftMargins", PrintSoftMargins);
- persistentSettings.Save("EscapeFunction", EscapeFunction);
- persistentSettings.Save("DisableThemes", DisableThemes);
- persistentSettings.Save("LastExportDir", LastExportDirectory);
- persistentSettings.Save("ExtImageFilterIndex", ExtensionImageFilterIndex);
- persistentSettings.Save("ExtTableFilterIndex", ExtensionTableFilterIndex);
- persistentSettings.Save("CheckForUpdates", CheckForUpdates);
- persistentSettings.Save("StatusBarNotifOnly", StatusBarNotifOnly);
- }
- /// <summary>
- /// An example of software application setting that will not be stored in
- /// the Windows registry.
- /// </summary>
- public bool RenderWithVisualStyles { get; set; }
- /// <summary>
- /// Clears the software application values from the Windows Registry.
- /// </summary>
- public void Clear() {
- persistentSettings.Clear();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement