2018-01-09 00:04:23 +08:00
|
|
|
//! \file ResourceSettings.cs
|
|
|
|
//! \date 2018 Jan 08
|
|
|
|
//! \brief Persistent resource settings implementation.
|
|
|
|
//
|
|
|
|
|
2018-03-17 16:16:53 +08:00
|
|
|
using System;
|
2018-01-11 22:39:43 +08:00
|
|
|
using System.ComponentModel.Composition;
|
2018-03-17 16:16:53 +08:00
|
|
|
using System.Diagnostics;
|
2018-02-18 07:55:00 +08:00
|
|
|
using System.Text;
|
2018-01-12 23:56:25 +08:00
|
|
|
using GameRes.Formats.Strings;
|
2018-01-11 22:39:43 +08:00
|
|
|
|
2018-01-09 00:04:23 +08:00
|
|
|
namespace GameRes.Formats
|
|
|
|
{
|
|
|
|
internal class LocalResourceSetting : ResourceSettingBase
|
|
|
|
{
|
|
|
|
public override object Value {
|
|
|
|
get { return Properties.Settings.Default[Name]; }
|
|
|
|
set { Properties.Settings.Default[Name] = value; }
|
|
|
|
}
|
2018-01-12 23:56:25 +08:00
|
|
|
|
|
|
|
public LocalResourceSetting () { }
|
|
|
|
|
2018-09-05 18:05:31 +08:00
|
|
|
public LocalResourceSetting (string name) : this (name, name) { }
|
|
|
|
|
|
|
|
public LocalResourceSetting (string name, string text)
|
2018-01-12 23:56:25 +08:00
|
|
|
{
|
|
|
|
Name = name;
|
2018-09-05 18:05:31 +08:00
|
|
|
Text = arcStrings.ResourceManager.GetString (text, arcStrings.Culture) ?? text;
|
2018-01-12 23:56:25 +08:00
|
|
|
}
|
2018-01-09 00:04:23 +08:00
|
|
|
}
|
2018-01-11 22:39:43 +08:00
|
|
|
|
2018-02-18 07:55:00 +08:00
|
|
|
internal class EncodingSetting : LocalResourceSetting
|
|
|
|
{
|
2018-03-17 16:16:53 +08:00
|
|
|
static readonly Encoding DefaultEncoding = Encodings.cp932;
|
|
|
|
|
2018-02-18 07:55:00 +08:00
|
|
|
public override object Value {
|
2018-03-17 16:16:53 +08:00
|
|
|
get {
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return Encoding.GetEncoding ((int)base.Value);
|
|
|
|
}
|
|
|
|
catch // fallback to CP932
|
|
|
|
{
|
|
|
|
Trace.WriteLine (string.Format ("Unknown encoding code page {0}", base.Value));
|
|
|
|
return DefaultEncoding;
|
|
|
|
}
|
|
|
|
}
|
2018-02-18 07:55:00 +08:00
|
|
|
set { base.Value = ((Encoding)value).CodePage; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public EncodingSetting () { }
|
|
|
|
|
|
|
|
public EncodingSetting (string name) : base (name) { }
|
2018-09-05 18:05:31 +08:00
|
|
|
|
|
|
|
public EncodingSetting (string name, string text) : base (name, text) { }
|
2018-02-18 07:55:00 +08:00
|
|
|
}
|
|
|
|
|
2018-01-11 22:39:43 +08:00
|
|
|
[Export(typeof(ISettingsManager))]
|
|
|
|
internal class SettingsManager : ISettingsManager
|
|
|
|
{
|
|
|
|
public void UpgradeSettings ()
|
|
|
|
{
|
|
|
|
if (Properties.Settings.Default.UpgradeRequired)
|
|
|
|
{
|
|
|
|
Properties.Settings.Default.Upgrade();
|
|
|
|
Properties.Settings.Default.UpgradeRequired = false;
|
|
|
|
Properties.Settings.Default.Save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SaveSettings ()
|
|
|
|
{
|
|
|
|
Properties.Settings.Default.Save();
|
|
|
|
}
|
|
|
|
}
|
2018-01-09 00:04:23 +08:00
|
|
|
}
|