@@ -23,6 +23,14 @@ public partial class MainWindowController : NSWindowController
23
23
private BackgroundWorker backgroundWorker ;
24
24
private bool userCancelled ;
25
25
26
+ public enum Worker
27
+ {
28
+ File ,
29
+ Directory ,
30
+ SDCard ,
31
+ Invalid = - 1
32
+ }
33
+
26
34
private List < Title > titles = new List < Title > ( ) ;
27
35
28
36
public MainWindowController ( IntPtr handle ) : base ( handle )
@@ -131,14 +139,7 @@ public void OpenFile(NSMenuItem menuItem)
131
139
132
140
Window . BeginSheet ( sheet , ProgressComplete ) ;
133
141
134
- List < string > filenames = openPanel . Urls . Select ( ( arg ) => arg . Path ) . ToList ( ) ;
135
- filenames . Sort ( ) ;
136
-
137
- Process . log ? . WriteLine ( "{0} files selected" , filenames . Count ) ;
138
-
139
- title . StringValue = String . Format ( "Opening {0} files" , filenames . Count ) ;
140
-
141
- backgroundWorker . RunWorkerAsync ( filenames ) ;
142
+ backgroundWorker . RunWorkerAsync ( ( Worker . File , openPanel . Urls . Select ( ( arg ) => arg . Path ) . ToList ( ) ) ) ;
142
143
}
143
144
} ) ;
144
145
}
@@ -181,15 +182,7 @@ public void OpenDirectory(NSMenuItem menuItem)
181
182
182
183
Window . BeginSheet ( sheet , ProgressComplete ) ;
183
184
184
- List < string > filenames = Directory . EnumerateFiles ( openPanel . Urls . First ( ) . Path , "*.*" , SearchOption . AllDirectories )
185
- . Where ( filename => filename . ToLower ( ) . EndsWith ( ".xci" ) || filename . ToLower ( ) . EndsWith ( ".nsp" ) || filename . ToLower ( ) . EndsWith ( ".nro" ) ) . ToList ( ) ;
186
- filenames . Sort ( ) ;
187
-
188
- Process . log ? . WriteLine ( "{0} files selected" , filenames . Count ) ;
189
-
190
- title . StringValue = String . Format ( "Opening {0} files from directory {1}" , filenames . Count , openPanel . Urls . First ( ) . Path ) ;
191
-
192
- backgroundWorker . RunWorkerAsync ( filenames ) ;
185
+ backgroundWorker . RunWorkerAsync ( ( Worker . Directory , openPanel . Urls . First ( ) . Path ) ) ;
193
186
}
194
187
} ) ;
195
188
}
@@ -263,7 +256,7 @@ public void OpenSDCard(NSMenuItem menuItem)
263
256
264
257
Window . BeginSheet ( sheet , ProgressComplete ) ;
265
258
266
- backgroundWorker . RunWorkerAsync ( openPanel . Urls . First ( ) . Path ) ;
259
+ backgroundWorker . RunWorkerAsync ( ( Worker . SDCard , openPanel . Urls . First ( ) . Path ) ) ;
267
260
}
268
261
} ) ;
269
262
}
@@ -337,7 +330,7 @@ public void Export(NSMenuItem menuItem)
337
330
title . firmware ,
338
331
title . masterkeyString ,
339
332
title . filename ,
340
- NSByteCountFormatter . Format ( title . filesize , NSByteCountFormatterCountStyle . File ) ,
333
+ title . filesizeString ,
341
334
title . typeString ,
342
335
title . distribution ,
343
336
title . structureString ,
@@ -362,45 +355,60 @@ void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
362
355
363
356
titles . Clear ( ) ;
364
357
365
- if ( e . Argument is List < string > filenames )
358
+ if ( e . Argument is ValueTuple < Worker , List < string > > argumentFile )
366
359
{
367
- int count = filenames . Count , index = 0 ;
368
-
369
- foreach ( var filename in filenames )
360
+ if ( argumentFile . Item1 == Worker . File && argumentFile . Item2 is List < string > filenames )
370
361
{
371
- if ( worker . CancellationPending ) break ;
362
+ filenames . Sort ( ) ;
372
363
373
- worker . ReportProgress ( 100 * index ++ / count , filename ) ;
364
+ Process . log ? . WriteLine ( "{0} files selected" , filenames . Count ) ;
365
+
366
+ worker . ReportProgress ( - 1 , String . Format ( "Opening {0} files" , filenames . Count ) ) ;
374
367
375
- Title title = Process . processFile ( filename ) ;
376
- if ( title != null )
368
+ int count = filenames . Count , index = 0 ;
369
+
370
+ foreach ( var filename in filenames )
377
371
{
378
- titles . Add ( title ) ;
372
+ if ( worker . CancellationPending ) break ;
373
+
374
+ worker . ReportProgress ( 100 * index ++ / count , filename ) ;
375
+
376
+ Title title = Process . processFile ( filename ) ;
377
+ if ( title != null )
378
+ {
379
+ titles . Add ( title ) ;
380
+ }
379
381
}
380
- }
381
382
382
- if ( ! worker . CancellationPending )
383
- {
384
- worker . ReportProgress ( 100 , "" ) ;
385
- }
383
+ if ( ! worker . CancellationPending )
384
+ {
385
+ worker . ReportProgress ( 100 , "" ) ;
386
+ }
386
387
387
- Process . log ? . WriteLine ( "\n {0} titles processed" , titles . Count ) ;
388
+ Process . log ? . WriteLine ( "\n {0} titles processed" , titles . Count ) ;
389
+ }
388
390
}
389
- else if ( e . Argument is string path )
391
+ else if ( e . Argument is ValueTuple < Worker , string > argumentPath )
390
392
{
391
- List < FsTitle > fsTitles = Process . processSd ( path ) ;
392
-
393
- if ( fsTitles != null )
393
+ if ( argumentPath . Item1 == Worker . Directory && argumentPath . Item2 is string path )
394
394
{
395
- int count = fsTitles . Count , index = 0 ;
395
+ List < string > filenames = Directory . EnumerateFiles ( path , "*.*" , SearchOption . AllDirectories )
396
+ . Where ( filename => filename . ToLower ( ) . EndsWith ( ".xci" ) || filename . ToLower ( ) . EndsWith ( ".nsp" ) || filename . ToLower ( ) . EndsWith ( ".nro" ) ) . ToList ( ) ;
397
+ filenames . Sort ( ) ;
398
+
399
+ Process . log ? . WriteLine ( "{0} files selected" , filenames . Count ) ;
396
400
397
- foreach ( var fsTitle in fsTitles )
401
+ worker . ReportProgress ( - 1 , String . Format ( "Opening {0} files from directory {1}" , filenames . Count , path ) ) ;
402
+
403
+ int count = filenames . Count , index = 0 ;
404
+
405
+ foreach ( var filename in filenames )
398
406
{
399
407
if ( worker . CancellationPending ) break ;
400
408
401
- worker . ReportProgress ( 100 * index ++ / count , fsTitle . MainNca ? . Filename ) ;
409
+ worker . ReportProgress ( 100 * index ++ / count , filename ) ;
402
410
403
- Title title = Process . processTitle ( fsTitle ) ;
411
+ Title title = Process . processFile ( filename ) ;
404
412
if ( title != null )
405
413
{
406
414
titles . Add ( title ) ;
@@ -414,13 +422,44 @@ void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
414
422
415
423
Process . log ? . WriteLine ( "\n {0} titles processed" , titles . Count ) ;
416
424
}
417
- else
425
+ else if ( argumentPath . Item1 == Worker . SDCard && argumentPath . Item2 is string pathSd )
418
426
{
419
- string error = "SD card \" Contents\" directory could not be found" ;
420
- Process . log ? . WriteLine ( error ) ;
427
+ List < FsTitle > fsTitles = Process . processSd ( pathSd ) ;
428
+
429
+ if ( fsTitles != null )
430
+ {
431
+ int count = fsTitles . Count , index = 0 ;
432
+
433
+ foreach ( var fsTitle in fsTitles )
434
+ {
435
+ if ( worker . CancellationPending ) break ;
436
+
437
+ worker . ReportProgress ( 100 * index ++ / count , fsTitle . MainNca ? . Filename ) ;
438
+
439
+ Title title = Process . processTitle ( fsTitle ) ;
440
+ if ( title != null )
441
+ {
442
+ titles . Add ( title ) ;
443
+ }
444
+ }
445
+
446
+ if ( ! worker . CancellationPending )
447
+ {
448
+ worker . ReportProgress ( 100 , "" ) ;
449
+ }
450
+
451
+ Process . log ? . WriteLine ( "\n {0} titles processed" , titles . Count ) ;
452
+ }
453
+ else
454
+ {
455
+ worker . ReportProgress ( 0 , "" ) ;
456
+
457
+ string error = "SD card \" Contents\" directory could not be found" ;
458
+ Process . log ? . WriteLine ( error ) ;
421
459
422
- e . Result = error ;
423
- return ;
460
+ e . Result = error ;
461
+ return ;
462
+ }
424
463
}
425
464
}
426
465
@@ -429,8 +468,15 @@ void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
429
468
430
469
void BackgroundWorker_ProgressChanged ( object sender , ProgressChangedEventArgs e )
431
470
{
432
- message . StringValue = e . UserState as string ;
433
- progress . DoubleValue = e . ProgressPercentage ;
471
+ if ( e . ProgressPercentage == - 1 )
472
+ {
473
+ title . StringValue = e . UserState as string ;
474
+ }
475
+ else
476
+ {
477
+ message . StringValue = e . UserState as string ;
478
+ progress . DoubleValue = e . ProgressPercentage ;
479
+ }
434
480
}
435
481
436
482
void BackgroundWorker_RunWorkerCompleted ( object sender , RunWorkerCompletedEventArgs e )
@@ -583,7 +629,7 @@ public override NSView GetViewForItem(NSTableView tableView, NSTableColumn table
583
629
textField . StringValue = title . filename ?? "" ;
584
630
break ;
585
631
case "FileSize" :
586
- textField . StringValue = NSByteCountFormatter . Format ( title . filesize , NSByteCountFormatterCountStyle . File ) ?? "" ;
632
+ textField . StringValue = title . filesizeString ?? "" ;
587
633
break ;
588
634
case "Type" :
589
635
textField . StringValue = title . typeString ?? "" ;
0 commit comments