• R/O
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

FreeTrainの進化系を目指す


Commit MetaInfo

Revision24 (tree)
Time2014-07-26 23:54:27
Authorc477

Log Message

Custom attribute to specifies class which requires initialization on assembly loaded.

Change Summary

Incremental Difference

--- trunk/starter/Starter.cs (revision 23)
+++ trunk/starter/Starter.cs (revision 24)
@@ -5,8 +5,11 @@
55 using nft.util;
66 using nft.ui.mainframe;
77 using System.Threading;
8+using System.Linq;
9+using nft.core;
10+using nft.framework;
811
9-namespace Starter
12+namespace nft.starter
1013 {
1114 public class Starter
1215 {
@@ -35,6 +38,8 @@
3538 Application.Run(new MainFrame(args));
3639 }
3740
41+
42+
3843 static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) {
3944 if(UIUtil.ShowException(e.Exception.Message, e.Exception, UIInformLevel.severe))
4045 throw e.Exception;
--- trunk/core/AssemblyInfo.cs (revision 23)
+++ trunk/core/AssemblyInfo.cs (revision 24)
@@ -1,5 +1,6 @@
11 using System.Reflection;
22 using System.Runtime.CompilerServices;
3+using nft.framework;
34
45 //
56 // アセンブリに関する一般情報は以下の
@@ -13,7 +14,8 @@
1314 [assembly: AssemblyProduct("NeoFT")]
1415 [assembly: AssemblyCopyright("(C)Copyright by c477 & K.Kawaguchi, 2004")]
1516 [assembly: AssemblyTrademark("")]
16-[assembly: AssemblyCulture("")]
17+[assembly: AssemblyCulture("")]
18+[assembly: InitializeOnLoad(typeof(nft.core.Core))]
1719
1820 //
1921 // アセンブリのバージョン情報は、以下の 4 つの属性で構成されます :
--- trunk/core/impl/game/GameImpl.cs (revision 23)
+++ trunk/core/impl/game/GameImpl.cs (revision 24)
@@ -31,7 +31,7 @@
3131 }
3232
3333 public GameImpl(ITerrainMap map, Calendar cal)
34- : this(I18n.T("GameManager","NewGame"), map, cal) {
34+ : this(I18n.T("GameManager", "NewGame"), map, cal) {
3535 }
3636
3737 public TerrainMapImpl TerrainMap {
--- trunk/core/core/Core.cs (revision 23)
+++ trunk/core/core/Core.cs (revision 24)
@@ -13,7 +13,7 @@
1313 /// <summary> Main resources. </summary>
1414 //public static readonly NftProperties resources = NftProperties.LoadFromFile(Directories.AppBaseDir + "nftcore.resource.xml", false);
1515
16- static Core()
16+ static Core()
1717 {
1818 I18n.LoadFile(Directories.AppBaseDir + "nftcore.resource.xml");
1919 ConfigureService.RegisterAssembly(Assembly.GetAssembly(Type.GetType("nft.core.Core")));
--- trunk/framework/nftfw.resource.xml (revision 23)
+++ trunk/framework/nftfw.resource.xml (revision 24)
@@ -2,74 +2,74 @@
22 <!--エラーメッセージは、改行やタブがそのまま使用されるので、ご注意ください。-->
33 <properties name="framework">
44 <properties name="Directories">
5- <property name="Directory '{0}' is not exist. Do you want to create?">{0}は存在しません。
5+ <property type="string" name="Directory '{0}' is not exist. Do you want to create?">{0}は存在しません。
66 作成しますか?</property>
7- <property name="Failed to create a directory '{0}'. Use default path instead.">{0}は作成できませんでした。
7+ <property type="string" name="Failed to create a directory '{0}'. Use default path instead.">{0}は作成できませんでした。
88 標準の設定を使用します。</property>
99 </properties>
1010 <properties name="PluginListDialog">
11- <property name="Uncheck to forbid cpu using this plug-in.">コンピューターに使わせたくないプラグインは、
11+ <property type="string" name="Uncheck to forbid cpu using this plug-in.">コンピューターに使わせたくないプラグインは、
1212 チェックを外して下さい。</property>
13- <property name="This contribution cannot invalidate.">このコントリビューションは無効化できません。</property>
13+ <property type="string" name="This contribution cannot invalidate.">このコントリビューションは無効化できません。</property>
1414 </properties>
1515 <properties name="nft.framework.plugin">
16- <property name="Too many plug-in load errors! Check out remaining errors in the 'Plug-in List'.">
16+ <property type="string" name="Too many plug-in load errors! Check out remaining errors in the 'Plug-in List'.">
1717 プラグインロードエラーが多すぎます。以降のエラーは省略します。
1818 エラーの発生したプラグインを確認するには、プラグイン一覧をご覧下さい。
1919 </property>
20- <property name="Dependent plug-in:{1} (required for the plug-in:{0}) is not found.">
20+ <property type="string" name="Dependent plug-in:{1} (required for the plug-in:{0}) is not found.">
2121 プラグイン{0}に必要な
2222 プラグイン{1}が見つかりません。
2323 </property>
24- <property name="Failed to load contribution[{1}] (ID={2}) from the file '{0}'.">
24+ <property type="string" name="Failed to load contribution[{1}] (ID={2}) from the file '{0}'.">
2525 ファイル{0}
2626 からのコントリビューション[{1}]のロードに失敗しました。
2727 ID={2}
2828 </property>
29- <property name="Failed to load plug-in:{0}.">プラグイン{0}がロードできませんでした。</property>
30- <property name="Failed to initialize contribution[{1}] in the plug-in:{0}.">
29+ <property type="string" name="Failed to load plug-in:{0}.">プラグイン{0}がロードできませんでした。</property>
30+ <property type="string" name="Failed to initialize contribution[{1}] in the plug-in:{0}.">
3131 プラグイン{0}内のコントリビューション[{1}]が初期化できませんでした。
3232 ID={2}
3333 </property>
34- <property name="Failed to create CommandEntity[type={0}, class={1}, method={2}].">
34+ <property type="string" name="Failed to create CommandEntity[type={0}, class={1}, method={2}].">
3535 コマンドコントリビューションを初期化できません。
3636 Type={0}
3737 Class={1}
3838 Method={2}
3939 </property>
40- <property name="An attribute '{1}' is required for the node '{0}'.">XMLノード[{0}]には[{1}]属性が必要です。
40+ <property type="string" name="An attribute '{1}' is required for the node '{0}'.">XMLノード[{0}]には[{1}]属性が必要です。
4141 ソース:{2}</property>
42- <property name="Failed to create an instance of the class '{0}'.">指定されたクラス[{0}]のインスタンス作成に失敗しました。
42+ <property type="string" name="Failed to create an instance of the class '{0}'.">指定されたクラス[{0}]のインスタンス作成に失敗しました。
4343 ソース:{1}</property>
44- <property name="Cannot cast the class'{0}' to the class'{1}'.">クラス[{0}]を[{1}]にキャストできません。
44+ <property type="string" name="Cannot cast the class'{0}' to the class'{1}'.">クラス[{0}]を[{1}]にキャストできません。
4545 ソース:{2}</property>
4646 </properties>
4747 <properties name="GlobalModules">
48- <property name="ERROR while loading a core module.">コア・モジュール読み込みエラー</property>
48+ <property type="string" name="ERROR while loading a core module.">コア・モジュール読み込みエラー</property>
4949 </properties>
5050 <properties name="WebLoader">
51- <property name="Web Exception: {0}(state={1}, url={2} ).">ファイルのダウンロードに失敗しました。
51+ <property type="string" name="Web Exception: {0}(state={1}, url={2} ).">ファイルのダウンロードに失敗しました。
5252 URL:{0}
5353 {1} state={2}</property>
54- <property name="Exception raised while downloading url={0} .">ダウンロード中に例外が発生しました。
54+ <property type="string" name="Exception raised while downloading url={0} .">ダウンロード中に例外が発生しました。
5555 URL:{0}</property>
5656 </properties>
5757 <properties name="nft.ui.command">
58- <property name="Exception raised while executing the command[ID={0}].">コマンド[ID={0}]の実行中に例外が発生しました。</property>
58+ <property type="string" name="Exception raised while executing the command[ID={0}].">コマンド[ID={0}]の実行中に例外が発生しました。</property>
5959 </properties>
6060 <properties name="ImageUtil">
61- <property name="{0}bit RGB">{0}bit RGB</property>
62- <property name="{0}bit ARGB">{0}bit ARGB</property>
63- <property name="Indexed {1} Colors">{1}色パレット</property>
64- <property name="Indexed {1} Gray scales">{1}色グレー</property>
65- <property name="{0}bit Gray scales">{0}bit グレー</property>
61+ <property type="string" name="{0}bit RGB">{0}bit RGB</property>
62+ <property type="string" name="{0}bit ARGB">{0}bit ARGB</property>
63+ <property type="string" name="Indexed {1} Colors">{1}色パレット</property>
64+ <property type="string" name="Indexed {1} Gray scales">{1}色グレー</property>
65+ <property type="string" name="{0}bit Gray scales">{0}bit グレー</property>
6666 </properties>
6767 <properties name="UiUtil">
68- <property name="Are you sure to exit 'NeoFT'?">NeoFTを終了してよろしいですか?</property>
68+ <property type="string" name="Are you sure to exit 'NeoFT'?">NeoFTを終了してよろしいですか?</property>
6969 </properties>
7070 <properties name="MainFrame">
71- <property name="long_title">Neo Free Train</property>
72- <property name="short_title">NeoFT</property>
71+ <property type="string" name="long_title">Neo Free Train</property>
72+ <property type="string" name="short_title">NeoFT</property>
7373 </properties>
7474
7575 </properties>
\ No newline at end of file
--- trunk/framework/framework/InitializeOnLoadAttribute.cs (nonexistent)
+++ trunk/framework/framework/InitializeOnLoadAttribute.cs (revision 24)
@@ -0,0 +1,20 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Text;
4+
5+namespace nft.framework {
6+ [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
7+ public class InitializeOnLoadAttribute : Attribute {
8+ Type type;
9+
10+ public InitializeOnLoadAttribute(Type type) {
11+ this.type = type;
12+ }
13+
14+ public Type Type {
15+ get {
16+ return type;
17+ }
18+ }
19+ }
20+}
--- trunk/framework/framework/Main.cs (revision 23)
+++ trunk/framework/framework/Main.cs (revision 24)
@@ -12,6 +12,7 @@
1212 using System.Drawing;
1313 using System.Runtime;
1414 using nft.framework.drawing;
15+using System.Reflection;
1516
1617 namespace nft.framework
1718 {
@@ -71,7 +72,8 @@
7172 {
7273 I18n.LoadFile(Directories.AppBaseDir + "nftfw.resource.xml");
7374 Hashtable h_args = paresArgs(args);
74- Directories.Initialize(h_args);
75+ InitializeAssemblies();
76+ Directories.Initialize(h_args);
7577
7678 //InformationService service = new InformationService();
7779 theFrame = frame;
@@ -112,6 +114,25 @@
112114 }
113115 return table;
114116 }
115-
117+
118+ private static void InitializeAssemblies() {
119+ AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(AssemblyInitializer);
120+ Assembly[] asms = AppDomain.CurrentDomain.GetAssemblies();
121+ foreach (Assembly asm in asms) {
122+ AssemblyInitializer(null, new AssemblyLoadEventArgs(asm));
123+ }
124+ }
125+
126+ private static void AssemblyInitializer(object sender, AssemblyLoadEventArgs args) {
127+ Assembly asm = args.LoadedAssembly;
128+ if (asm.GlobalAssemblyCache)
129+ return;
130+ // force static constructors in types specified by InitializeOnLoad
131+ object[] attributes = asm.GetCustomAttributes(typeof(InitializeOnLoadAttribute), false);
132+ foreach (InitializeOnLoadAttribute attr in attributes) {
133+ System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(attr.Type.TypeHandle);
134+ Debug.WriteLine("Init class on load assembly: class="+attr.Type.FullName+ ", module="+ Path.GetFileName(asm.CodeBase));
135+ }
136+ }
116137 }
117138 }