@@ -6,6 +6,9 @@ namespace DragWheel
66{
77 internal static class Config
88 {
9+ //--------------------------------------------------------------
10+ // Settings
11+
912 //----------------------------------------
1013 public static int MouseResolution
1114 {
@@ -16,7 +19,7 @@ public static int MouseResolution
1619 if ( String . IsNullOrEmpty ( configValue ) )
1720 return defaultMouseResolution ;
1821
19- return Int32 . Parse ( configValue , System . Globalization . CultureInfo . InvariantCulture ) ;
22+ return ( int ) _ParseUInt32 ( configValue ) ;
2023 }
2124 }
2225 static int defaultMouseResolution = 1200 ; //dpi
@@ -29,15 +32,16 @@ public static int? MouseButton
2932 string configValue = ConfigurationManager . AppSettings [ "MouseButton" ] ;
3033
3134 if ( String . IsNullOrEmpty ( configValue ) )
32- return null ;
35+ return defaultMouseButton ;
3336
34- int value = Int32 . Parse ( configValue , System . Globalization . CultureInfo . InvariantCulture ) ;
35- if ( value < 0 || value > 4 )
37+ uint value = _ParseUInt32 ( configValue ) ;
38+ if ( value > 4 )
3639 throw new ConfigurationErrorsException ( "MouseButton must be in range [0-4]" ) ;
3740
38- return value ;
41+ return ( int ) value ;
3942 }
4043 }
44+ static int ? defaultMouseButton = null ; //not mouse-activated
4145
4246 //----------------------------------------
4347 public static int ? JoystickButton
@@ -47,15 +51,146 @@ public static int? JoystickButton
4751 string configValue = ConfigurationManager . AppSettings [ "JoystickButton" ] ;
4852
4953 if ( String . IsNullOrEmpty ( configValue ) )
50- return null ;
54+ return defaultJoystickButton ;
5155
52- int value = Int32 . Parse ( configValue , System . Globalization . CultureInfo . InvariantCulture ) ;
53- if ( value < 0 || value > 31 )
56+ uint value = _ParseUInt32 ( configValue ) ;
57+ if ( value > 31 )
5458 throw new ConfigurationErrorsException ( "JoystickButton must be in range [0-31]" ) ;
5559
56- return value ;
60+ return ( int ) value ;
61+ }
62+ }
63+ static int ? defaultJoystickButton = null ; //not stick-activated
64+
65+ //----------------------------------------
66+ public static int ThrottleThrow
67+ {
68+ get
69+ {
70+ string configValue = ConfigurationManager . AppSettings [ "ThrottleThrow" ] ;
71+
72+ if ( String . IsNullOrEmpty ( configValue ) )
73+ return defaultThrottleThrow ;
74+
75+ uint value = _ParseUInt32 ( configValue ) ;
76+ if ( value > 1000 )
77+ throw new ConfigurationErrorsException ( "ThrottleThrow expected range: [0-1000]" ) ;
78+
79+ return ( int ) value ;
80+ }
81+ }
82+ static int defaultThrottleThrow = 125 ; //tested on Falcon BMS 4.35, with mousewheel-sensitivity set to minimum
83+ // tested on F-16 and F-18 .. TODO: test other planes?
84+
85+ //----------------------------------------
86+ public static int ThrottleMaxMIL
87+ {
88+ get
89+ {
90+ string configValue = ConfigurationManager . AppSettings [ "ThrottleMaxMIL" ] ;
91+
92+ if ( String . IsNullOrEmpty ( configValue ) )
93+ return defaultThrottleMaxMIL ;
94+
95+ uint value = _ParseUInt32 ( configValue ) ;
96+ if ( value > 1000 )
97+ throw new ConfigurationErrorsException ( "ThrottleMaxMIL expected range: [0-1000]" ) ;
98+
99+ return ( int ) value ;
100+ }
101+ }
102+ static int defaultThrottleMaxMIL = 83 ; //tested on Falcon BMS 4.35, with mousewheel-sensitivity set to minimum
103+ // tested on F-16 and F-18 .. TODO: test other planes?
104+
105+ //----------------------------------------
106+ public static string IdleStopSound
107+ {
108+ get
109+ {
110+ return ConfigurationManager . AppSettings [ "IdleStopSound" ] ;
111+ }
112+ }
113+
114+ //----------------------------------------
115+ public static string BurnerDetentUpSound
116+ {
117+ get
118+ {
119+ return ConfigurationManager . AppSettings [ "BurnerDetentUpSound" ] ;
120+ }
121+ }
122+
123+ //----------------------------------------
124+ public static string BurnerDetentDownSound
125+ {
126+ get
127+ {
128+ return ConfigurationManager . AppSettings [ "BurnerDetentDownSound" ] ;
129+ }
130+ }
131+
132+ //----------------------------------------
133+ public static string MaxBurnerSound
134+ {
135+ get
136+ {
137+ return ConfigurationManager . AppSettings [ "MaxBurnerSound" ] ;
138+ }
139+ }
140+
141+ //----------------------------------------
142+ public static byte ? ScancodeForMouseXButton1
143+ {
144+ get
145+ {
146+ string configValue = ConfigurationManager . AppSettings [ "ScancodeForMouseXButton1" ] ;
147+
148+ if ( String . IsNullOrEmpty ( configValue ) )
149+ return null ;
150+
151+ uint value = _ParseUInt32 ( configValue ) ;
152+ if ( value > 255 )
153+ throw new ConfigurationErrorsException ( "Scancode must be in range [0x00-0xFF]" ) ;
154+
155+ return ( byte ) value ;
57156 }
58157 }
158+
159+ //----------------------------------------
160+ public static byte ? ScancodeForMouseXButton2
161+ {
162+ get
163+ {
164+ string configValue = ConfigurationManager . AppSettings [ "ScancodeForMouseXButton2" ] ;
165+
166+ if ( String . IsNullOrEmpty ( configValue ) )
167+ return null ;
168+
169+ uint value = _ParseUInt32 ( configValue ) ;
170+ if ( value > 255 )
171+ throw new ConfigurationErrorsException ( "Scancode must be in range [0x00-0xFF]" ) ;
172+
173+ return ( byte ) value ;
174+ }
175+ }
176+
177+ //--------------------------------------------------------------
178+ // Helpers
179+
180+ //----------------------------------------
181+ static uint _ParseUInt32 ( string s )
182+ {
183+ System . Globalization . NumberStyles style = System . Globalization . NumberStyles . None ;
184+ if ( s . StartsWith ( "0x" ) )
185+ {
186+ style = System . Globalization . NumberStyles . HexNumber ;
187+ s = s . Substring ( 2 ) ;
188+ }
189+
190+ uint value = UInt32 . Parse ( s , style , System . Globalization . CultureInfo . InvariantCulture ) ;
191+ return value ;
192+ }
193+
59194 }
60195
61196 //------------------------------------------------------------------
0 commit comments