Advertisement
fortsoft

Settings

Oct 26th, 2022 (edited)
919
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.18 KB | Source Code | 0 0
  1. /**
  2.  * This is open-source software licensed under the terms of the MIT License.
  3.  *
  4.  * Copyright (c) 2009-2022 Petr Červinka - FortSoft <[email protected]>
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a copy
  7.  * of this software and associated documentation files (the "Software"), to deal
  8.  * in the Software without restriction, including without limitation the rights
  9.  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10.  * copies of the Software, and to permit persons to whom the Software is
  11.  * furnished to do so, subject to the following conditions:
  12.  *
  13.  * The above copyright notice and this permission notice shall be included in all
  14.  * copies or substantial portions of the Software.
  15.  *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19.  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20.  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21.  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22.  * SOFTWARE.
  23.  **
  24.  * Version 1.0.0.0
  25.  */
  26.  
  27. using FortSoft.Tools;
  28. using System;
  29. using System.Diagnostics;
  30. using System.IO;
  31.  
  32. namespace ExampleApplication {
  33.  
  34.     /// <summary>
  35.     /// This is an example of using the PersistentSettings class.
  36.     /// </summary>
  37.     public class Settings {
  38.  
  39.         /// <summary>
  40.         /// Fields
  41.         /// </summary>
  42.         private PersistentSettings persistentSettings;
  43.  
  44.         /// <summary>
  45.         /// Initializes a new instance of the <see cref="Settings"/> class.
  46.         /// </summary>
  47.         public Settings() {
  48.             persistentSettings = new PersistentSettings();
  49.             try {
  50.                 string externalImageViewer = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), Properties.Resources.DefaultExternalImageViewerRelativePath);
  51.                 if (File.Exists(externalImageViewer)) {
  52.                     ExternalImageViewer = externalImageViewer;
  53.                 } else {
  54.                     externalImageViewer = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), Properties.Resources.DefaultExternalImageViewerRelativePath);
  55.                     if (File.Exists(externalImageViewer)) {
  56.                         ExternalImageViewer = externalImageViewer;
  57.                     }
  58.                 }
  59.             } catch (Exception exception) {
  60.                 Debug.WriteLine(exception);
  61.                 ErrorLog.WriteLine(exception);
  62.             }
  63.             PrintSoftMargins = true;
  64.             CheckForUpdates = true;
  65.             EscapeFunction = 1;
  66.             Load();
  67.         }
  68.  
  69.         /// <summary>
  70.         /// An example of software application setting that will be stored in the
  71.         /// Windows registry.
  72.         /// </summary>
  73.         public int ActivePanel { get; set; }
  74.  
  75.         /// <summary>
  76.         /// An example of software application setting that will be stored in the
  77.         /// Windows registry.
  78.         /// </summary>
  79.         public int ActivePreferencesPanel { get; set; }
  80.  
  81.         /// <summary>
  82.         /// An example of software application setting that will be stored in the
  83.         /// Windows registry.
  84.         /// </summary>
  85.         public string ArchiveDirectory { get; set; }
  86.  
  87.         /// <summary>
  88.         /// An example of software application setting that will be stored in the
  89.         /// Windows registry.
  90.         /// </summary>
  91.         public string ExternalImageViewer { get; set; }
  92.  
  93.         /// <summary>
  94.         /// An example of software application setting that will be stored in the
  95.         /// Windows registry.
  96.         /// </summary>
  97.         public bool PrintSoftMargins { get; set; }
  98.  
  99.         /// <summary>
  100.         /// An example of software application setting that will be stored in the
  101.         /// Windows registry.
  102.         /// </summary>
  103.         public int EscapeFunction { get; set; }
  104.  
  105.         /// <summary>
  106.         /// An example of software application setting that will be stored in the
  107.         /// Windows registry.
  108.         /// </summary>
  109.         public bool DisableThemes { get; set; }
  110.  
  111.         /// <summary>
  112.         /// An example of software application setting that will be stored in the
  113.         /// Windows registry.
  114.         /// </summary>
  115.         public string LastExportDirectory { get; set; }
  116.  
  117.         /// <summary>
  118.         /// An example of software application setting that will be stored in the
  119.         /// Windows registry.
  120.         /// </summary>
  121.         public int ExtensionImageFilterIndex { get; set; }
  122.  
  123.         /// <summary>
  124.         /// An example of software application setting that will be stored in the
  125.         /// Windows registry.
  126.         /// </summary>
  127.         public int ExtensionTableFilterIndex { get; set; }
  128.  
  129.         /// <summary>
  130.         /// An example of software application setting that will be stored in the
  131.         /// Windows registry.
  132.         /// </summary>
  133.         public bool CheckForUpdates { get; set; }
  134.  
  135.         /// <summary>
  136.         /// An example of software application setting that will be stored in the
  137.         /// Windows registry.
  138.         /// </summary>
  139.         public bool StatusBarNotifOnly { get; set; }
  140.  
  141.         /// <summary>
  142.         /// Loads the software application settings from the Windows registry.
  143.         /// </summary>
  144.         private void Load() {
  145.             ActivePanel = persistentSettings.Load("ActivePanel", ActivePanel);
  146.             ActivePreferencesPanel = persistentSettings.Load("ActivePrefsPanel", ActivePreferencesPanel);
  147.             ArchiveDirectory = persistentSettings.Load("ArchiveDir", ArchiveDirectory);
  148.             ExternalImageViewer = persistentSettings.Load("ExternalImgViewer", ExternalImageViewer);
  149.             PrintSoftMargins = persistentSettings.Load("PrintSoftMargins", PrintSoftMargins);
  150.             EscapeFunction = persistentSettings.Load("EscapeFunction", EscapeFunction);
  151.             DisableThemes = persistentSettings.Load("DisableThemes", DisableThemes);
  152.             LastExportDirectory = persistentSettings.Load("LastExportDir", LastExportDirectory);
  153.             ExtensionImageFilterIndex = persistentSettings.Load("ExtImageFilterIndex", ExtensionImageFilterIndex);
  154.             ExtensionTableFilterIndex = persistentSettings.Load("ExtTableFilterIndex", ExtensionTableFilterIndex);
  155.             CheckForUpdates = persistentSettings.Load("CheckForUpdates", CheckForUpdates);
  156.             StatusBarNotifOnly = persistentSettings.Load("StatusBarNotifOnly", StatusBarNotifOnly);
  157.         }
  158.  
  159.         /// <summary>
  160.         /// Saves the software application settings into the Windows registry.
  161.         /// </summary>
  162.         public void Save() {
  163.             persistentSettings.Save("ActivePanel", ActivePanel);
  164.             persistentSettings.Save("ActivePrefsPanel", ActivePreferencesPanel);
  165.             persistentSettings.Save("ArchiveDir", ArchiveDirectory);
  166.             persistentSettings.Save("ExternalImgViewer", ExternalImageViewer);
  167.             persistentSettings.Save("PrintSoftMargins", PrintSoftMargins);
  168.             persistentSettings.Save("EscapeFunction", EscapeFunction);
  169.             persistentSettings.Save("DisableThemes", DisableThemes);
  170.             persistentSettings.Save("LastExportDir", LastExportDirectory);
  171.             persistentSettings.Save("ExtImageFilterIndex", ExtensionImageFilterIndex);
  172.             persistentSettings.Save("ExtTableFilterIndex", ExtensionTableFilterIndex);
  173.             persistentSettings.Save("CheckForUpdates", CheckForUpdates);
  174.             persistentSettings.Save("StatusBarNotifOnly", StatusBarNotifOnly);
  175.         }
  176.  
  177.         /// <summary>
  178.         /// An example of software application setting that will not be stored in
  179.         /// the Windows registry.
  180.         /// </summary>
  181.         public bool RenderWithVisualStyles { get; set; }
  182.  
  183.         /// <summary>
  184.         /// Clears the software application values from the Windows Registry.
  185.         /// </summary>
  186.         public void Clear() {
  187.             persistentSettings.Clear();
  188.         }
  189.     }
  190. }
  191.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement