-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
576 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
191 changes: 123 additions & 68 deletions
191
source/Grabacr07.KanColleViewer/Models/Settings/SettingsHost.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,123 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading.Tasks; | ||
using MetroTrilithon.Serialization; | ||
|
||
namespace Grabacr07.KanColleViewer.Models.Settings | ||
{ | ||
public abstract class SettingsHost | ||
{ | ||
private static readonly Dictionary<Type, SettingsHost> instances = new Dictionary<Type, SettingsHost>(); | ||
private readonly Dictionary<string, object> cachedProperties = new Dictionary<string, object>(); | ||
|
||
protected virtual string CategoryName => this.GetType().Name; | ||
|
||
protected SettingsHost() | ||
{ | ||
instances[this.GetType()] = this; | ||
} | ||
|
||
/// <summary> | ||
/// 現在のインスタンスにキャッシュされている <see cref="SerializableProperty{T}"/> | ||
/// を取得します。 キャッシュがない場合は <see cref="create"/> に従って生成します。 | ||
/// </summary> | ||
/// <returns></returns> | ||
protected SerializableProperty<T> Cache<T>(Func<string, SerializableProperty<T>> create, [CallerMemberName] string propertyName = "") | ||
{ | ||
var key = this.CategoryName + "." + propertyName; | ||
|
||
object obj; | ||
if (this.cachedProperties.TryGetValue(key, out obj) && obj is SerializableProperty<T>) return (SerializableProperty<T>)obj; | ||
|
||
var property = create(key); | ||
this.cachedProperties[key] = property; | ||
|
||
return property; | ||
} | ||
|
||
|
||
public static void Load() | ||
{ | ||
#pragma warning disable 612 | ||
// 古い設定が存在する可能性があるので、読んでおく | ||
// (ただし、1 度読んだら新しい方に移行するので保存はしない | ||
Migration._Settings.Load(); | ||
#pragma warning restore 612 | ||
|
||
Providers.Local.Load(); | ||
Providers.Roaming.Load(); | ||
} | ||
|
||
public static void Save() | ||
{ | ||
Providers.Local.Save(); | ||
Providers.Roaming.Save(); | ||
} | ||
|
||
/// <summary> | ||
/// <typeparamref name="T"/> 型の設定オブジェクトの唯一のインスタンスを取得します。 | ||
/// </summary> | ||
public static T Instance<T>() where T : SettingsHost, new() | ||
{ | ||
SettingsHost host; | ||
return instances.TryGetValue(typeof(T), out host) ? (T)host : new T(); | ||
} | ||
} | ||
} | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using MetroTrilithon.Serialization; | ||
|
||
namespace Grabacr07.KanColleViewer.Models.Settings | ||
{ | ||
public abstract class SettingsHost | ||
{ | ||
private static readonly Dictionary<Type, SettingsHost> instances = new Dictionary<Type, SettingsHost>(); | ||
private readonly Dictionary<string, object> cachedProperties = new Dictionary<string, object>(); | ||
|
||
protected virtual string CategoryName => this.GetType().Name; | ||
|
||
protected SettingsHost() | ||
{ | ||
instances[this.GetType()] = this; | ||
} | ||
|
||
/// <summary> | ||
/// 現在のインスタンスにキャッシュされている <see cref="SerializableProperty{T}"/> | ||
/// を取得します。 キャッシュがない場合は <see cref="create"/> に従って生成します。 | ||
/// </summary> | ||
/// <returns></returns> | ||
protected SerializableProperty<T> Cache<T>(Func<string, SerializableProperty<T>> create, [CallerMemberName] string propertyName = "") | ||
{ | ||
var key = this.CategoryName + "." + propertyName; | ||
|
||
object obj; | ||
if (this.cachedProperties.TryGetValue(key, out obj) && obj is SerializableProperty<T>) return (SerializableProperty<T>)obj; | ||
|
||
var property = create(key); | ||
this.cachedProperties[key] = property; | ||
|
||
return property; | ||
} | ||
|
||
|
||
#region Load / Save | ||
|
||
public static void Load() | ||
{ | ||
#pragma warning disable 612 | ||
// 古い設定が存在する可能性があるので、読んでおく | ||
// (ただし、1 度読んだら新しい方に移行するので保存はしない | ||
Migration._Settings.Load(); | ||
#pragma warning restore 612 | ||
|
||
#region const message | ||
|
||
const string message = @"設定ファイル ({0}) の読み込みに失敗しました。このファイルを削除することで解決する可能性があります。 | ||
エラーの詳細: {1}"; | ||
|
||
#endregion | ||
|
||
try | ||
{ | ||
Providers.Local.Load(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
MessageBox.Show(string.Format(message, Providers.LocalFilePath, ex.Message), "エラー", MessageBoxButton.OK, MessageBoxImage.Error); | ||
throw; | ||
} | ||
|
||
try | ||
{ | ||
Providers.Roaming.Load(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
MessageBox.Show(string.Format(message, Providers.RoamingFilePath, ex.Message), "エラー", MessageBoxButton.OK, MessageBoxImage.Error); | ||
throw; | ||
} | ||
} | ||
|
||
public static void Save() | ||
{ | ||
#region const message | ||
|
||
const string message = @"設定ファイル ({0}) の保存に失敗しました。 | ||
エラーの詳細: {1}"; | ||
|
||
#endregion | ||
|
||
try | ||
{ | ||
Providers.Local.Save(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
MessageBox.Show(string.Format(message, Providers.LocalFilePath, ex.Message), "エラー", MessageBoxButton.OK, MessageBoxImage.Error); | ||
throw; | ||
} | ||
|
||
try | ||
{ | ||
Providers.Roaming.Save(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
MessageBox.Show(string.Format(message, Providers.RoamingFilePath, ex.Message), "エラー", MessageBoxButton.OK, MessageBoxImage.Error); | ||
throw; | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
/// <summary> | ||
/// <typeparamref name="T"/> 型の設定オブジェクトの唯一のインスタンスを取得します。 | ||
/// </summary> | ||
public static T Instance<T>() where T : SettingsHost, new() | ||
{ | ||
SettingsHost host; | ||
return instances.TryGetValue(typeof(T), out host) ? (T)host : new T(); | ||
} | ||
} | ||
} |
110 changes: 55 additions & 55 deletions
110
source/Grabacr07.KanColleViewer/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,55 @@ | ||
using System; | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
using System.Windows; | ||
|
||
// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。 | ||
// アセンブリに関連付けられている情報を変更するには、 | ||
// これらの属性値を変更してください。 | ||
[assembly: AssemblyTitle("提督業も忙しい!")] | ||
[assembly: AssemblyDescription("提督業も忙しい!")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("grabacr.net")] | ||
[assembly: AssemblyProduct("KanColleViewer")] | ||
[assembly: AssemblyCopyright("Copyright © 2013 Grabacr07")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
[assembly: Guid("101B49A6-7E7B-422D-95FF-500F9EF483A8")] | ||
|
||
// ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから | ||
// 参照不可能になります。COM からこのアセンブリ内の型にアクセスする場合は、 | ||
// その型の ComVisible 属性を true に設定してください。 | ||
[assembly: ComVisible(false)] | ||
|
||
//ローカライズ可能なアプリケーションのビルドを開始するには、 | ||
//.csproj ファイルの <UICulture>CultureYouAreCodingWith</UICulture> を | ||
//<PropertyGroup> 内部で設定します。たとえば、 | ||
//ソース ファイルで英語を使用している場合、<UICulture> を en-US に設定します。次に、 | ||
//下の NeutralResourceLanguage 属性のコメントを解除します。下の行の "en-US" を | ||
//プロジェクト ファイルの UICulture 設定と一致するよう更新します。 | ||
|
||
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] | ||
|
||
|
||
[assembly: ThemeInfo( | ||
// テーマ固有のリソース ディクショナリが置かれている場所 | ||
// (リソースがページ、またはアプリケーション リソース ディクショナリに見つからない場合に使用されます) | ||
ResourceDictionaryLocation.None, | ||
|
||
// 汎用リソース ディクショナリが置かれている場所 | ||
// (リソースがページ、アプリケーション、またはいずれのテーマ固有のリソース ディクショナリにも見つからない場合に使用されます) | ||
ResourceDictionaryLocation.SourceAssembly | ||
)] | ||
|
||
|
||
// アセンブリのバージョン情報は、以下の 4 つの値で構成されています: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を | ||
// 既定値にすることができます: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("4.0.0.0")] | ||
using System; | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
using System.Windows; | ||
|
||
// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。 | ||
// アセンブリに関連付けられている情報を変更するには、 | ||
// これらの属性値を変更してください。 | ||
[assembly: AssemblyTitle("提督業も忙しい!")] | ||
[assembly: AssemblyDescription("提督業も忙しい!")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("grabacr.net")] | ||
[assembly: AssemblyProduct("KanColleViewer")] | ||
[assembly: AssemblyCopyright("Copyright © 2013 Grabacr07")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
[assembly: Guid("101B49A6-7E7B-422D-95FF-500F9EF483A8")] | ||
|
||
// ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから | ||
// 参照不可能になります。COM からこのアセンブリ内の型にアクセスする場合は、 | ||
// その型の ComVisible 属性を true に設定してください。 | ||
[assembly: ComVisible(false)] | ||
|
||
//ローカライズ可能なアプリケーションのビルドを開始するには、 | ||
//.csproj ファイルの <UICulture>CultureYouAreCodingWith</UICulture> を | ||
//<PropertyGroup> 内部で設定します。たとえば、 | ||
//ソース ファイルで英語を使用している場合、<UICulture> を en-US に設定します。次に、 | ||
//下の NeutralResourceLanguage 属性のコメントを解除します。下の行の "en-US" を | ||
//プロジェクト ファイルの UICulture 設定と一致するよう更新します。 | ||
|
||
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] | ||
|
||
|
||
[assembly: ThemeInfo( | ||
// テーマ固有のリソース ディクショナリが置かれている場所 | ||
// (リソースがページ、またはアプリケーション リソース ディクショナリに見つからない場合に使用されます) | ||
ResourceDictionaryLocation.None, | ||
|
||
// 汎用リソース ディクショナリが置かれている場所 | ||
// (リソースがページ、アプリケーション、またはいずれのテーマ固有のリソース ディクショナリにも見つからない場合に使用されます) | ||
ResourceDictionaryLocation.SourceAssembly | ||
)] | ||
|
||
|
||
// アセンブリのバージョン情報は、以下の 4 つの値で構成されています: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を | ||
// 既定値にすることができます: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("4.1.0.0")] |
Oops, something went wrong.