Manage your ASL charts, play aids and other documents.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
asl-charts/src/Program.cs

80 lines
3.0 KiB

using System ;
using System.Windows.Forms ;
using System.IO ;
using System.Diagnostics ;
using log4net.Config ;
// --------------------------------------------------------------------
public static class Program
{
public const string APP_NAME = "ASL Charts" ;
private static string mBaseDir ;
private static string mDataDir ;
private static JsonConfig mAppConfig = null ;
private static JsonConfig mDataConfig = null ;
private static JsonConfig mDebugConfig = null ;
private static MainForm mMainForm = null ;
[STAThread]
static void Main( string[] args )
{
// initialize
mBaseDir = Application.StartupPath ;
// configure logging
string fname = Path.Combine( mBaseDir, "log4net.xml" ) ;
if ( ! File.Exists( fname ) )
fname = Path.Combine( mBaseDir, "../log4net.xml" ) ;
if ( File.Exists( fname ) )
XmlConfigurator.Configure( new FileInfo( fname ) ) ;
// locate the data directory
mDataDir = Path.Combine( mBaseDir , "data" ) ;
if ( ! Directory.Exists( mDataDir ) ) {
mDataDir = Path.Combine( mBaseDir , "../data" ) ;
if ( ! Directory.Exists( mDataDir ) )
mDataDir = mBaseDir ;
}
try {
// load the app config
string fname0 = Path.GetFileNameWithoutExtension( System.Reflection.Assembly.GetEntryAssembly().Location ) + ".json" ;
fname = Path.Combine( mBaseDir, fname0 ) ;
if ( ! File.Exists( fname ) ) {
fname = Path.Combine( mDataDir, fname0 ) ;
if ( ! File.Exists( fname ) )
fname = Path.Combine( mBaseDir, "../"+fname0 ) ;
}
mAppConfig = new JsonConfig( "app config", fname ) ;
// load the data config
mDataConfig = new JsonConfig( "data config", Path.Combine( mDataDir, "config.json" ) ) ;
// load the debug config
mDebugConfig = new JsonConfig( "debug config", Path.Combine( mBaseDir, "debug.json" ) ) ;
} catch( Exception ex ) {
showErrorMsg( "Initialization failed:\n\n" + ex.Message ) ;
return ;
}
// run the application
Application.EnableVisualStyles() ;
Application.SetCompatibleTextRenderingDefault( false ) ;
mMainForm = new MainForm() ;
Application.Run( mMainForm ) ;
}
public static void showInfoMsg( string msg ) { MessageBox.Show(msg,APP_NAME,MessageBoxButtons.OK,MessageBoxIcon.Information) ; }
public static void showWarningMsg( string msg ) { MessageBox.Show(msg,APP_NAME,MessageBoxButtons.OK,MessageBoxIcon.Warning) ; }
public static void showErrorMsg( string msg ) { MessageBox.Show(msg,APP_NAME,MessageBoxButtons.OK,MessageBoxIcon.Error) ; }
public static JsonConfig appConfig { get { return mAppConfig ; } }
public static JsonConfig dataConfig { get { return mDataConfig ; } }
public static JsonConfig debugConfig { get { return mDebugConfig ; } }
public static string dataDir { get { return mDataDir ; } }
}