@@ -50,15 +50,25 @@ class Program {
5050 /// <summary>
5151 /// Display SPD contents in color
5252 /// </summary>
53- public static bool ShowColor = true ;
53+ public static bool ShowColor ;
54+
55+ /// <summary>
56+ /// Silent state
57+ /// </summary>
58+ public static bool Silent ;
59+
60+ /// <summary>
61+ /// Input or output file path
62+ /// </summary>
63+ public static string FilePath = "" ;
5464
5565 static void Main ( string [ ] args ) {
5666
5767 Args = args ;
5868
59- if ( Data . ArrayContains ( Args , "/nocolor" ) ) {
60- ShowColor = false ;
61- }
69+ Silent = Data . ArrayContains ( Args , "/silent" ) ;
70+ ShowColor = ! Data . ArrayContains ( Args , "/nocolor" ) ;
71+ FilePath = Args . Length >= 4 && Args [ 3 ] . Contains ( "/" ) ? "" : Args [ 3 ] ;
6272
6373 if ( IsAdmin ( ) ) {
6474 Smbus = new Smbus ( ) ;
@@ -254,24 +264,22 @@ private static void EnablePswp() {
254264 private static void WriteEeprom ( ) {
255265
256266 string mode = Args [ 0 ] ;
257- string filePath = Args . Length >= 4 ? Args [ 3 ] : "" ;
258- bool silent = Args . Length >= 5 && Args [ 4 ] == "/silent" ;
259267 byte i2CAddress = ( byte ) int . Parse ( Args [ 2 ] ) ;
260268
261- if ( filePath . Length < 1 ) {
269+ if ( FilePath . Length < 1 ) {
262270 throw new ArgumentException ( "File path is mandatory for write mode." ) ;
263271 }
264272
265- if ( ! File . Exists ( filePath ) ) {
266- throw new FileNotFoundException ( $ "File \" { filePath } \" not found.") ;
273+ if ( ! File . Exists ( FilePath ) ) {
274+ throw new FileNotFoundException ( $ "File \" { FilePath } \" not found.") ;
267275 }
268276
269277 byte [ ] inputFile ;
270278 try {
271- inputFile = File . ReadAllBytes ( filePath ) ;
279+ inputFile = File . ReadAllBytes ( FilePath ) ;
272280 }
273281 catch {
274- throw new FileLoadException ( $ "Unable to read { filePath } ") ;
282+ throw new FileLoadException ( $ "Unable to read { FilePath } ") ;
275283 }
276284
277285 Connect ( ) ;
@@ -280,13 +288,13 @@ private static void WriteEeprom() {
280288
281289 Console . WriteLine (
282290 "Writing \" {0}\" ({1} {2}) to EEPROM at address {3}\n " ,
283- filePath ,
291+ FilePath ,
284292 inputFile . Length ,
285293 inputFile . Length > 1 ? "bytes" : "byte" ,
286294 Arduino . I2CAddress ) ;
287295
288296 if ( inputFile . Length > Spd . GetSpdSize ( Arduino ) ) {
289- throw new Exception ( $ "File \" { filePath } \" is larger than { Arduino . DataLength } bytes.") ;
297+ throw new Exception ( $ "File \" { FilePath } \" is larger than { Arduino . DataLength } bytes.") ;
290298 }
291299
292300 int bytesWritten = 0 ;
@@ -308,7 +316,7 @@ private static void WriteEeprom() {
308316
309317 bytesWritten ++ ;
310318
311- if ( ! silent ) {
319+ if ( ! Silent ) {
312320 ConsoleDisplayByte ( i , b , 16 , true , ShowColor ) ;
313321 }
314322 }
@@ -328,16 +336,15 @@ private static void WriteEeprom() {
328336 /// Reads data from EEPROM
329337 /// </summary>
330338 private static void ReadEeprom ( ) {
331- string filePath = Args . Length >= 4 ? Args [ 3 ] : "" ;
332- bool silent = Args . Length >= 5 && Args [ 4 ] == "/silent" ;
339+
333340 byte i2CAddress = ( byte ) int . Parse ( Args [ 2 ] ) ;
334341 byte [ ] spdDump = new byte [ 0 ] ;
335342 string name ;
336343
337344 Console . Write ( $ "Reading EEPROM at address { i2CAddress } ") ;
338345
339- if ( filePath . Length > 0 ) {
340- Console . WriteLine ( $ " to { filePath } ") ;
346+ if ( FilePath . Length > 0 ) {
347+ Console . WriteLine ( $ " to { FilePath } ") ;
341348 }
342349 Console . WriteLine ( "\n " ) ;
343350
@@ -372,7 +379,7 @@ private static void ReadEeprom() {
372379
373380 int endTick = Environment . TickCount ;
374381
375- if ( ! silent ) {
382+ if ( ! Silent ) {
376383 for ( int i = 0 ; i < spdDump . Length ; i ++ ) {
377384 ConsoleDisplayByte ( i , spdDump [ i ] , 16 , true , ShowColor ) ;
378385 }
@@ -385,14 +392,14 @@ private static void ReadEeprom() {
385392 name ,
386393 endTick - startTick ) ;
387394
388- if ( filePath . Length > 0 && ! filePath . Contains ( "/" ) ) {
395+ if ( FilePath . Length > 0 ) {
389396 try {
390- File . WriteAllBytes ( filePath , spdDump ) ;
397+ File . WriteAllBytes ( FilePath , spdDump ) ;
391398 }
392399 catch {
393- throw new Exception ( $ "Unable to write to { filePath } ") ;
400+ throw new Exception ( $ "Unable to write to { FilePath } ") ;
394401 }
395- Console . Write ( $ " to file \" { filePath } \" ") ;
402+ Console . Write ( $ " to file \" { FilePath } \" ") ;
396403 }
397404 }
398405
0 commit comments