forked from SCToolsfactory/SCJMapper-V2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
111 lines (95 loc) · 4.06 KB
/
Program.cs
File metadata and controls
111 lines (95 loc) · 4.06 KB
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
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;
CultureInfo 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 );
}
}
CultureInfo 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" );
}
}
}