mirror of
https://github.com/crskycode/GARbro.git
synced 2025-01-11 12:39:16 +08:00
(GameRes): persistent resource settings infrastructure.
This commit is contained in:
parent
444a15b94a
commit
a3ce27da5f
@ -110,6 +110,7 @@ namespace GARbro.GUI
|
||||
{
|
||||
try
|
||||
{
|
||||
FormatCatalog.Instance.SaveSettings();
|
||||
Settings.Default.Save();
|
||||
}
|
||||
catch (Exception X)
|
||||
|
@ -107,6 +107,11 @@ namespace GameRes
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveSettings ()
|
||||
{
|
||||
Properties.Settings.Default.Save();
|
||||
}
|
||||
|
||||
private void AddResourceImpl (IEnumerable<IResource> formats, CompositionContainer container)
|
||||
{
|
||||
foreach (var impl in formats)
|
||||
|
@ -102,7 +102,10 @@ namespace GameRes
|
||||
/// <summary>Filename extensions peculiar to the resource.</summary>
|
||||
public IEnumerable<string> Extensions { get; protected set; }
|
||||
|
||||
/// <summary>Resource settings suitable for serialization.</summary>
|
||||
/// <summary>Persistent resource settings.</summary>
|
||||
public IEnumerable<IResourceSetting> Settings { get; protected set; }
|
||||
|
||||
/// <summary>Resource access scheme suitable for serialization.</summary>
|
||||
public virtual ResourceScheme Scheme { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
@ -85,7 +85,14 @@
|
||||
<Compile Include="ImageTIFF.cs" />
|
||||
<Compile Include="MultiDict.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ResourceSettings.cs" />
|
||||
<Compile Include="ScriptText.cs" />
|
||||
<Compile Include="Properties\Settings.cs" />
|
||||
<Compile Include="Strings\garStrings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
@ -107,7 +114,12 @@
|
||||
<EmbeddedResource Include="Strings\garStrings.zh-Hans.resx" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>PublicSettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
|
@ -46,24 +46,33 @@ namespace GameRes
|
||||
}
|
||||
|
||||
[Export(typeof(ImageFormat))]
|
||||
public class BmpFormat : ImageFormat
|
||||
public sealed class BmpFormat : ImageFormat
|
||||
{
|
||||
public override string Tag { get { return "BMP"; } }
|
||||
public override string Description { get { return "Windows device independent bitmap"; } }
|
||||
public override uint Signature { get { return 0; } }
|
||||
public override bool CanWrite { get { return true; } }
|
||||
|
||||
public BmpFormat ()
|
||||
{
|
||||
Settings = new[] { EnableExtensions };
|
||||
}
|
||||
|
||||
#pragma warning disable 649
|
||||
[ImportMany(typeof(IBmpExtension))]
|
||||
private IEnumerable<IBmpExtension> m_extensions;
|
||||
#pragma warning restore 649
|
||||
|
||||
bool EnableExtensions = true;
|
||||
LocalResourceSetting EnableExtensions = new LocalResourceSetting {
|
||||
Name = "BMPEnableExtensions",
|
||||
Text = "Enable BMP format extensions",
|
||||
Description = "Enables various extensions, such as transparency support.",
|
||||
};
|
||||
|
||||
public override ImageData Read (IBinaryStream file, ImageMetaData info)
|
||||
{
|
||||
var bmp_info = info as BmpMetaData;
|
||||
if (bmp_info != null && EnableExtensions && file.AsStream.CanSeek)
|
||||
if (bmp_info != null && EnableExtensions.Get<bool>() && file.AsStream.CanSeek)
|
||||
{
|
||||
foreach (var ext in m_extensions)
|
||||
{
|
||||
|
38
GameRes/Properties/Settings.Designer.cs
generated
Normal file
38
GameRes/Properties/Settings.Designer.cs
generated
Normal file
@ -0,0 +1,38 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace GameRes.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
|
||||
public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.UserScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("True")]
|
||||
public bool BMPEnableExtensions {
|
||||
get {
|
||||
return ((bool)(this["BMPEnableExtensions"]));
|
||||
}
|
||||
set {
|
||||
this["BMPEnableExtensions"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
28
GameRes/Properties/Settings.cs
Normal file
28
GameRes/Properties/Settings.cs
Normal file
@ -0,0 +1,28 @@
|
||||
namespace GameRes.Properties {
|
||||
|
||||
|
||||
// This class allows you to handle specific events on the settings class:
|
||||
// The SettingChanging event is raised before a setting's value is changed.
|
||||
// The PropertyChanged event is raised after a setting's value is changed.
|
||||
// The SettingsLoaded event is raised after the setting values are loaded.
|
||||
// The SettingsSaving event is raised before the setting values are saved.
|
||||
public sealed partial class Settings {
|
||||
|
||||
public Settings() {
|
||||
// // To add event handlers for saving and changing settings, uncomment the lines below:
|
||||
//
|
||||
// this.SettingChanging += this.SettingChangingEventHandler;
|
||||
//
|
||||
// this.SettingsSaving += this.SettingsSavingEventHandler;
|
||||
//
|
||||
}
|
||||
|
||||
private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
|
||||
// Add code to handle the SettingChangingEvent event here.
|
||||
}
|
||||
|
||||
private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
|
||||
// Add code to handle the SettingsSaving event here.
|
||||
}
|
||||
}
|
||||
}
|
9
GameRes/Properties/Settings.settings
Normal file
9
GameRes/Properties/Settings.settings
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="GameRes.Properties" GeneratedClassName="Settings">
|
||||
<Profiles />
|
||||
<Settings>
|
||||
<Setting Name="BMPEnableExtensions" Type="System.Boolean" Scope="User">
|
||||
<Value Profile="(Default)">True</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
79
GameRes/ResourceSettings.cs
Normal file
79
GameRes/ResourceSettings.cs
Normal file
@ -0,0 +1,79 @@
|
||||
//! \file ResourceSettings.cs
|
||||
//! \date 2018 Jan 08
|
||||
//! \brief Persistent resource settings implementation.
|
||||
//
|
||||
// Copyright (C) 2018 by morkt
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
namespace GameRes
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface to assembly app.config settings.
|
||||
/// </summary>
|
||||
public interface IResourceSetting
|
||||
{
|
||||
/// <summary>
|
||||
/// Internal setting name, should match the name defined in app.config.
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Short text description of the setting (suitable for use in GUI dialog).
|
||||
/// </summary>
|
||||
string Text { get; }
|
||||
|
||||
/// <summary>
|
||||
/// More elaborate setting description.
|
||||
/// </summary>
|
||||
string Description { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Actual setting value.
|
||||
/// </summary>
|
||||
object Value { get; set; }
|
||||
}
|
||||
|
||||
public abstract class ResourceSettingBase : IResourceSetting
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Text { get; set; }
|
||||
public string Description { get; set; }
|
||||
|
||||
public abstract object Value { get; set; }
|
||||
|
||||
public TValue Get<TValue> ()
|
||||
{
|
||||
var value = this.Value;
|
||||
if (null == value || !(value is TValue))
|
||||
return default(TValue);
|
||||
return (TValue)value;
|
||||
}
|
||||
}
|
||||
|
||||
internal class LocalResourceSetting : ResourceSettingBase
|
||||
{
|
||||
public override object Value {
|
||||
get { return GameRes.Properties.Settings.Default[Name]; }
|
||||
set { GameRes.Properties.Settings.Default[Name] = value; }
|
||||
}
|
||||
}
|
||||
}
|
15
GameRes/app.config
Normal file
15
GameRes/app.config
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
|
||||
<section name="GameRes.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
|
||||
</sectionGroup>
|
||||
</configSections>
|
||||
<userSettings>
|
||||
<GameRes.Properties.Settings>
|
||||
<setting name="BMPEnableExtensions" serializeAs="String">
|
||||
<value>True</value>
|
||||
</setting>
|
||||
</GameRes.Properties.Settings>
|
||||
</userSettings>
|
||||
</configuration>
|
Loading…
x
Reference in New Issue
Block a user