📄 settings.cs
字号:
using System;
using TXML;
namespace VirtualPhotoOrganizer.Util
{
/// <summary>
/// Handles access to the program's settings
/// </summary>
internal class Settings
{
#region MasterNode names
const string GENERAL = "General";
const string PHOTO = "Photo";
#endregion
#region Settings Vars
// General
private bool _FirstStart;
private int _MainWidth; // the width of our main Form
private int _MainHeight; // the height of our main Form
private bool _MainMaximized; // is the main form maximized or not
private int _PhotoEditorWidth; // the width of the photo editor
private int _PhotoEditorHeight; // the hieght of the photo editor
private bool _PhotoEditorMax; // is the photo editor maximized
private string _DefaultAlbumFolder; // the default album folder
private bool _AssocVPOA; // shall we associate vpo with vpoa albums?
private int _APSplitPos; // the position of the Album-Photo pane splitter
private bool _ShowQuickPhotoInfo; // does the user want to see the quick photo info?
private bool _ShowQuickAlbumInfo; // does the user want to see the quick album info?
// Photo
private int _SlideShowInterval;
private int _ThumbWidth;
private int _ThumbHeight;
private bool _ShowImgRes;
#endregion
/// <summary>
/// Reads all settings from disk into the vars
/// </summary>
public Settings() {
TXmlReader reader = XmlHandler.OpenSettingsReader();
// read the settings from disk
ReadGeneralSettings(reader);
ReadPhotoSettings(reader);
reader.Close();
}
/// <summary>
/// Saves the settings to disk
/// </summary>
public void SaveSettings() {
TXmlWriter writer = XmlHandler.OpenSettingsWriter();
// Write settings to disk
SaveGeneralSettings(writer);
SavePhotoSettings(writer);
writer.Close();
}
/// <summary>
/// Registers vpo as the main program for opening *.vpoa files
/// </summary>
public void RegisterVPOA() {
const string VPO = "VirtuaPhotoOrganizer";
// create the vpo subkey and its contents
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.ClassesRoot;
key.CreateSubKey(VPO);
key = key.OpenSubKey(VPO, true);
key.SetValue("", "Virtual Photo Organizer Album");
key.CreateSubKey("DefaultIcon");
key = key.OpenSubKey("DefaultIcon", true);
key.SetValue("", System.Windows.Forms.Application.ExecutablePath + ",0");
key.Close();
key = Microsoft.Win32.Registry.ClassesRoot;
key = key.OpenSubKey(VPO, true);
key.CreateSubKey("shell");
key = key.OpenSubKey("shell", true);
key.CreateSubKey("open");
key = key.OpenSubKey("open", true);
key.CreateSubKey("command");
key = key.OpenSubKey("command", true);
key.SetValue("", '\"' + System.Windows.Forms.Application.ExecutablePath + "\" \"%1\"");
key.Close();
// register the extension to our newly created VPO class
key = Microsoft.Win32.Registry.ClassesRoot;
key.CreateSubKey(".vpoa");
key = key.OpenSubKey(".vpoa", true);
key.SetValue("", VPO);
key.Close();
}
#region ReadSettings
/// <summary>
/// Reads the settings specified under the node "General"
/// </summary>
private void ReadGeneralSettings(TXmlReader reader) {
_FirstStart = reader.GetBoolean(GENERAL, "FirstStart", true);
XmlHandler.LangFile = reader.GetString(GENERAL, "Lang", "English.xml"); // LanguageFile
_MainWidth = reader.GetInt32(GENERAL, "MainWidth", 760);
_MainHeight = reader.GetInt32(GENERAL, "MainHeight", 642);
_MainMaximized = reader.GetBoolean(GENERAL, "MainMax", false);
_PhotoEditorWidth = reader.GetInt32(GENERAL, "PEWidth", 776);
_PhotoEditorHeight = reader.GetInt32(GENERAL, "PEHeight", 640);
_PhotoEditorMax = reader.GetBoolean(GENERAL, "PEMax", false);
_DefaultAlbumFolder = reader.GetString(GENERAL, "DefaultAlbumFolder", Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "\\My Photo Albums");
_AssocVPOA = reader.GetBoolean(GENERAL, "AssocVPOA", true);
_APSplitPos = reader.GetInt32(GENERAL, "APSplitPos", 208);
_ShowQuickAlbumInfo = reader.GetBoolean(GENERAL, "ShowQuickAlbumInfo", true);
_ShowQuickPhotoInfo = reader.GetBoolean(GENERAL, "ShowQuickPhotoInfo", true);
}
private void ReadPhotoSettings(TXmlReader reader) {
_SlideShowInterval = reader.GetInt32(PHOTO, "SlideShowInterval", 1);
_ThumbWidth = reader.GetInt32(PHOTO, "ThumbWidth", 150);
_ThumbHeight = reader.GetInt32(PHOTO, "ThumbHeight", 113);
_ShowImgRes = reader.GetBoolean(PHOTO, "ShowImgRes", true);
}
#endregion
#region SaveSettings
private void SaveGeneralSettings(TXmlWriter writer) {
writer.WriteBoolean(GENERAL, "FirstStart", _FirstStart);
writer.WriteString(GENERAL, "Lang", XmlHandler.LangFile);
writer.WriteInt32(GENERAL, "MainWidth", _MainWidth);
writer.WriteInt32(GENERAL, "MainHeight", _MainHeight);
writer.WriteBoolean(GENERAL, "MainMax", _MainMaximized);
writer.WriteInt32(GENERAL, "PEWidth", _PhotoEditorWidth);
writer.WriteInt32(GENERAL, "PEHeight", _PhotoEditorHeight);
writer.WriteBoolean(GENERAL, "PEMax", _PhotoEditorMax);
writer.WriteString(GENERAL, "DefaultAlbumFolder", _DefaultAlbumFolder);
writer.WriteBoolean(GENERAL, "AssocVPOA", _AssocVPOA);
writer.WriteInt32(GENERAL, "APSplitPos", _APSplitPos);
writer.WriteBoolean(GENERAL, "ShowQuickAlbumInfo", _ShowQuickAlbumInfo);
writer.WriteBoolean(GENERAL, "ShowQuickPhotoInfo", _ShowQuickPhotoInfo);
}
private void SavePhotoSettings(TXmlWriter writer) {
writer.WriteInt32(PHOTO, "SlideShowInterval", _SlideShowInterval);
writer.WriteInt32(PHOTO, "ThumbWidth", _ThumbWidth);
writer.WriteInt32(PHOTO, "ThumbHeight", _ThumbHeight);
writer.WriteBoolean(PHOTO, "ShowImgRes", _ShowImgRes);
}
#endregion
#region General Vars accessors
public bool FirstStart {
get { return _FirstStart; }
set { _FirstStart = value; }
}
public string LangFile {
get {
return XmlHandler.LangFile.Substring(0, XmlHandler.LangFile.Length - 4);
}
set {
try {
if (value.Substring(value.Length - 4) != ".xml")
value += ".xml";
}
catch {
value += ".xml";
}
finally {
XmlHandler.LangFile = value;
}
}
}
public int MainWidth {
get { return _MainWidth; }
set { _MainWidth = value; }
}
public int MainHeight {
get { return _MainHeight; }
set { _MainHeight = value; }
}
public bool MainMaximized {
get { return _MainMaximized; }
set { _MainMaximized = value; }
}
public int PhotoEditorWidth {
get { return _PhotoEditorWidth; }
set { _PhotoEditorWidth = value; }
}
public int PhotoEditorHeight {
get { return _PhotoEditorHeight; }
set { _PhotoEditorHeight = value; }
}
public bool PhotoEditorMax {
get { return _PhotoEditorMax; }
set { _PhotoEditorMax = value; }
}
public string DefaultAlbumFolder {
get { return _DefaultAlbumFolder; }
set { _DefaultAlbumFolder = value; }
}
public bool AssocVPOA {
get { return _AssocVPOA; }
set { _AssocVPOA = value; }
}
public int APSplitPos {
get { return _APSplitPos; }
set { _APSplitPos = value; }
}
public bool ShowQuickAlbumInfo {
get { return _ShowQuickAlbumInfo; }
set { _ShowQuickAlbumInfo = value; }
}
public bool ShowQuickPhotoInfo {
get { return _ShowQuickPhotoInfo; }
set { _ShowQuickPhotoInfo = value; }
}
#endregion
#region Photo Vars accessors
public int SlideShowInterval {
get { return _SlideShowInterval; }
set { _SlideShowInterval = value; }
}
public int ThumbWidth {
get { return _ThumbWidth; }
set { _ThumbWidth = value; }
}
public int ThumbHeight {
get { return _ThumbHeight; }
set { _ThumbHeight = value; }
}
public bool ShowImgRes {
get { return _ShowImgRes; }
set { _ShowImgRes = value; }
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -