You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SCJMapper-V2/AApp/Program.cs

112 lines
4.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Configuration;
using log4net;
using log4net.Config;
using System.Globalization;
using System.Reflection;
//[assembly: log4net.Config.XmlConfigurator( Watch = true )]
[assembly: log4net.Config.XmlConfigurator( ConfigFile = "log4Net.config", Watch = true )]
namespace SCJMapper_V2
{
static class Program
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger ( System.Reflection.MethodBase.GetCurrentMethod( ).DeclaringType );
// not used as long as the culture change below works..
// internal static CultureInfo cultUS = new CultureInfo("en-US", false); // use strict US formats (this is used for numbers only)
// internal static NumberStyles nsNum = NumberStyles.Number;
// Thanks.. http://blog.rastating.com/setting-default-currentculture-in-all-versions-of-net/
static void SetDefaultCulture( CultureInfo culture )
{
// The CultureInfo class has two private static members named m_userDefaultCulture
// and m_userDefaultUICulture in versions prior to .NET 4.0;
// in 4.0 they are named s_userDefaultCulture and s_userDefaultUICulture.
Type type = typeof(CultureInfo);
try {
type.InvokeMember( "s_userDefaultCulture",
BindingFlags.SetField | BindingFlags.NonPublic | BindingFlags.Static,
null,
culture,
new object[] { culture } );
type.InvokeMember( "s_userDefaultUICulture",
BindingFlags.SetField | BindingFlags.NonPublic | BindingFlags.Static,
null,
culture,
new object[] { culture } );
}
catch { }
try {
type.InvokeMember( "m_userDefaultCulture",
BindingFlags.SetField | BindingFlags.NonPublic | BindingFlags.Static,
null,
culture,
new object[] { culture } );
type.InvokeMember( "m_userDefaultUICulture",
BindingFlags.SetField | BindingFlags.NonPublic | BindingFlags.Static,
null,
culture,
new object[] { culture } );
}
catch { }
}
/* Log Levels Inc Priority
* ALL
* DEBUG
* INFO
* WARN
* ERROR
* FATAL
* OFF
* */
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main( )
{
// Log file setup
log.InfoFormat( "\n" );
log.InfoFormat( "SCJMapper_V2 - Started" );
CultureInfo current = CultureInfo.CurrentCulture;
var modded = new CultureInfo( current.Name ); // that is the users locale
log.InfoFormat( "SCJMapper_V2 - using current culture : {0}", modded.Name );
if ( ! string.IsNullOrEmpty( AppConfiguration.AppConfig.culture ) ) {
try {
modded = new CultureInfo( AppConfiguration.AppConfig.culture ); // that is the users locale
log.InfoFormat( "SCJMapper_V2 - override culture from config file: {0}", modded.Name );
}
catch {
log.ErrorFormat( "SCJMapper_V2 - Error in culture name from config file: {0}", AppConfiguration.AppConfig.culture );
}
}
var us = new CultureInfo( "en-US" );
modded.NumberFormat = us.NumberFormat; // change the whole number format to US - should be safe ...
// change the applications formatting to US (the dec point is essential here)
SetDefaultCulture( modded ); // have to maintain number formats without tracking every piece of code with locales
log.InfoFormat( "SCJMapper_V2 - Changed to US number formatting" );
Application.EnableVisualStyles( );
Application.SetCompatibleTextRenderingDefault( false );
Application.Run( new MainForm( ) );
log.InfoFormat( "SCJMapper_V2 - Ended\n" );
}
}
}