Files
ChanSort/source/ChanSort/Config.cs
Horst Beham ece2cd7e66 - improved IniFile and Mapping to better handle missing settings
- working on philips *.db/FLASH* file format (identified 3 different variations so far)
2021-09-15 10:59:05 +02:00

116 lines
3.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Xml.Serialization;
namespace ChanSort.Ui
{
public class Config
{
private static readonly XmlSerializer Serializer;
private static readonly string ConfigFilePath;
#region class ColumnInfo
public class ColumnInfo
{
[XmlAttribute("name")] public string Name { get; set; }
[XmlAttribute("width")] public int Width { get; set; }
[XmlAttribute("visible")]//[Obsolete("For XML serialization only. Use Visible instead")] // won't be serialized/deserialized when marked [Obsolete]
public bool VisibleXml
{
get => this.Visible ?? true;
set => this.Visible = value;
}
[XmlIgnore]
public bool? Visible { get; set; }
}
#endregion
#region static ctor()
static Config()
{
Serializer = new XmlSerializer(typeof(Config));
try
{
ConfigFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "ChanSort", "config.xml");
if (File.Exists(ConfigFilePath))
{
using var stream = new StreamReader(ConfigFilePath, System.Text.Encoding.UTF8);
Default = (Config)Serializer.Deserialize(stream);
return;
}
}
catch
{
// ignore
}
Default = new Config();
}
#endregion
public static Config Default { get; set; }
public string Language { get; set; } = "";
public string Encoding { get; set; } = "";
public Size WindowSize { get; set; } = new Size(0,0);
public int LeftPanelWidth { get; set; } = 0;
public bool ShowWarningsAfterLoading { get; set; } = false;
public bool CloseGaps { get; set; } = true;
[XmlArray("MruFiles")]
public List<string> MruFiles { get; set; } = new List<string>();
public string ReferenceListFolder { get; set; }
public string PrintFontName { get; set; } = "Segoe UI";
public decimal PrintFontSize { get; set; } = 12;
public bool PrintSortByName { get; set; } = false;
public int PrintColumnCount { get; set; } = 2;
public bool ExplorerIntegration { get; set; } = false;
public bool CheckForUpdates { get; set; } = true;
public int FontSizeDelta { get; set; } = 1;
[XmlArrayItem("Column")]
public List<ColumnInfo> LeftColumns { get; set; } = new();
[XmlArrayItem("Column")]
public List<ColumnInfo> RightColumns { get; set; } = new();
public bool AutoHideColumns { get; set; } = true;
public bool LoadLastListAfterStart { get; set; } = true;
/// <summary>
/// The LeftGridLayout and RightGridLayout contain Width values which are scaled to this ScaleFactor.
/// The WindowSize, LeftPanelWidth and other properties are already at a neutral 96dpi/100% scale
/// </summary>
public SizeF ScaleFactor { get; set; }
public bool SplitView { get; set; } = true;
public string SkinName { get; set; } = "Office 2019 Colorful";
private bool allowSave = true;
public void Save()
{
if (!allowSave)
return;
var folder = Path.GetDirectoryName(ConfigFilePath) ?? ".";
Directory.CreateDirectory(folder);
using var stream = new FileStream(ConfigFilePath, FileMode.Create);
using var writer = new StreamWriter(stream, System.Text.Encoding.UTF8);
Serializer.Serialize(writer, this);
}
public void Reset()
{
if (File.Exists(ConfigFilePath))
File.Delete(ConfigFilePath);
allowSave = false;
}
}
}