1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
|
/*
* Cadencii.cs
* Copyright © 2009-2011 kbinani
*
* This file is part of org.kbinani.cadencii.
*
* org.kbinani.cadencii is free software; you can redistribute it and/or
* modify it under the terms of the GPLv3 License.
*
* org.kbinani.cadencii is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#if JAVA
import org.kbinani.*;
import org.kbinani.apputil.*;
import org.kbinani.cadencii.*;
#else
using System;
using System.Threading;
using System.Windows.Forms;
using org.kbinani;
using org.kbinani.apputil;
namespace org.kbinani.cadencii
{
using boolean = System.Boolean;
#endif
#if JAVA
public class Cadencii implements Thread.UncaughtExceptionHandler
#else
public class Cadencii
#endif
{
#if !JAVA
delegate void VoidDelegate();
public static FormSplash splash = null;
static Thread splashThread = null;
#endif
private static String mPathVsq = "";
private static String mPathResource = "";
private static boolean mPrintVersion = false;
/// <summary>
/// 起動時に渡されたコマンドライン引数を評価します。
/// 戻り値は、コマンドライン引数のうちVSQ,またはXVSQファイルとして指定された引数、または空文字です。
/// </summary>
/// <param name="arg"></param>
private static void parseArguments( String[] arg )
{
String currentparse = "";
for ( int i = 0; i < arg.Length; i++ ) {
String argi = arg[i];
if ( str.startsWith( argi, "-" ) ) {
currentparse = argi;
if ( str.compare( argi, "--version" ) ) {
mPrintVersion = true;
currentparse = "";
}
} else {
if ( str.compare( currentparse, "" ) ) {
mPathVsq = argi;
} else if ( str.compare( currentparse, "-resources" ) ) {
mPathResource = argi;
}
currentparse = "";
}
}
}
private static void handleUnhandledException( Exception ex )
{
ExceptionNotifyFormController controller = new ExceptionNotifyFormController();
controller.setReportTarget( ex );
controller.getUi().showDialog( null );
}
#if JAVA
public static void main( String[] args )
#if DEBUG
throws Exception
#endif
{
Thread.setDefaultUncaughtExceptionHandler( new Cadencii() );
// 引数を解釈
parseArguments( args );
if( mPrintVersion ){
System.out.print( BAssemblyInfo.fileVersion );
return;
}
String file = mPathVsq;
if ( !str.compare( mPathResource, "" ) ) {
Resources.setBasePath( mPathResource );
}
try{
Messaging.loadMessages();
}catch( Exception ex ){
Logger.write( Cadencii.class + ".main; ex=" + ex + "\n" );
serr.println( "Cadencii.main; ex=" + ex );
}
AppManager.init();
AppManager.mMainWindowController = new FormMainController();
AppManager.mMainWindow = new FormMain( AppManager.mMainWindowController, file );
AppManager.mMainWindow.setVisible( true );
#if DEBUG
throw new Exception( "foo" );
#endif
}
@Override
public void uncaughtException( Thread arg0, Throwable arg1 )
{
Exception ex = new Exception( "unknown exception handled at 'Cadencii::Cadencii_UnhandledException" );
if( arg1 != null && arg1 instanceof Exception ){
ex = (Exception)arg1;
}
handleUnhandledException( ex );
}
#else
[STAThread]
public static void Main( String[] args )
{
Application.ThreadException += new ThreadExceptionEventHandler( Application_ThreadException );
Thread.GetDomain().UnhandledException += new UnhandledExceptionEventHandler( Cadencii_UnhandledException );
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault( false );
// 引数を解釈
parseArguments( args );
if ( mPrintVersion ) {
Console.Write( BAssemblyInfo.fileVersion );
return;
}
String file = mPathVsq;
if ( !str.compare( mPathResource, "" ) ) {
Resources.setBasePath( mPathResource );
}
Logger.setEnabled( false );
String logfile = PortUtil.createTempFile() + ".txt";
Logger.setPath( logfile );
#if DEBUG
Logger.setEnabled( true );
#endif
#if !DEBUG
try {
#endif
// 言語設定を読み込み
try {
Messaging.loadMessages();
// システムのデフォルトの言語を調べる.
// EditorConfigのコンストラクタは,この判定を自動でやるのでそれを利用
EditorConfig ec = new EditorConfig();
Messaging.setLanguage( ec.Language );
} catch ( Exception ex ) {
Logger.write( typeof( FormMain ) + ".ctor; ex=" + ex + "\n" );
serr.println( "FormMain#.ctor; ex=" + ex );
}
// 開発版の場合の警告ダイアログ
String str_minor = BAssemblyInfo.fileVersionMinor;
int minor = 0;
try {
minor = str.toi( str_minor );
} catch ( Exception ex ) {
}
if ( (minor % 2) != 0 ) {
AppManager.showMessageBox(
PortUtil.formatMessage(
_( "Info: This is test version of Cadencii version {0}" ),
BAssemblyInfo.fileVersionMeasure + "." + (minor + 1) ),
"Cadencii",
org.kbinani.windows.forms.Utility.MSGBOX_DEFAULT_OPTION,
org.kbinani.windows.forms.Utility.MSGBOX_INFORMATION_MESSAGE );
}
// スプラッシュを表示するスレッドを開始
#if !MONO
splashThread = new Thread( new ThreadStart( showSplash ) );
splashThread.TrySetApartmentState( ApartmentState.STA );
splashThread.Start();
#endif
// AppManagerの初期化
AppManager.init();
#if ENABLE_SCRIPT
try {
ScriptServer.reload();
PaletteToolServer.init();
} catch ( Exception ex ) {
serr.println( "Cadencii::Main; ex=" + ex );
Logger.write( typeof( Cadencii ) + ".Main; ex=" + ex + "\n" );
}
#endif
AppManager.mMainWindowController = new FormMainController();
AppManager.mMainWindow = new FormMain( AppManager.mMainWindowController, file );
#if !MONO
AppManager.mMainWindow.Load += mainWindow_Load;
#endif
Application.Run( AppManager.mMainWindow );
#if !DEBUG
} catch ( Exception ex ) {
String str_ex = getExceptionText( ex, 0 );
FormCompileResult dialog = new FormCompileResult(
_( "Failed to launch Cadencii. Please send the exception report to developer" ),
str_ex );
dialog.setTitle( _( "Error" ) );
dialog.showDialog();
if ( splash != null ) {
VoidDelegate splash_close = new VoidDelegate( splash.close );
if ( splash != null ) {
splash.Invoke( splash_close );
}
}
Logger.write( typeof( Cadencii ) + ".Main; ex=" + ex + "\n" );
}
#endif
}
private static void Cadencii_UnhandledException( object sender, UnhandledExceptionEventArgs e )
{
Exception ex = new Exception( "unknown exception handled at 'Cadencii::Cadencii_UnhandledException" );
if ( e.ExceptionObject != null && e.ExceptionObject is Exception ) {
ex = (Exception)e.ExceptionObject;
}
handleUnhandledException( ex );
}
private static void Application_ThreadException( object sender, ThreadExceptionEventArgs e )
{
handleUnhandledException( e.Exception );
}
/// <summary>
/// 内部例外を含めた例外テキストを再帰的に取得します。
/// </summary>
/// <param name="ex"></param>
/// <param name="depth_count"></param>
/// <returns></returns>
private static String getExceptionText( Exception ex, int depth_count )
{
String ret = ex.ToString();
if ( ex.InnerException != null ) {
ret += "\n" +
"-- InnerException; Depth Level " + depth_count + " -----------------------" +
getExceptionText( ex.InnerException, depth_count + 1 );
}
return ret;
}
private static String _( String id )
{
return Messaging.getMessage( id );
}
static void showSplash()
{
splash = new FormSplash();
splash.showDialog( null );
}
static void closeSplash()
{
splash.close();
}
public static void mainWindow_Load( Object sender, EventArgs e )
{
if ( splash != null ) {
VoidDelegate deleg = new VoidDelegate( closeSplash );
if ( deleg != null ) {
splash.Invoke( deleg );
}
}
splash = null;
AppManager.mMainWindow.Load -= mainWindow_Load;
}
#endif
}
#if !JAVA
}
#endif
|