@@ -171,12 +171,44 @@ private void newClassToolStripButton_Click(object sender, EventArgs e)
171
171
172
172
private void openProjectToolStripMenuItem_Click ( object sender , EventArgs e )
173
173
{
174
- SelectAndLoadFileFromPath ( null ) ;
174
+ try
175
+ {
176
+ var path = ShowOpenProjectFileDialog ( ) ;
177
+ if ( path != null )
178
+ {
179
+ var project = new ReClassNetProject ( ) ;
180
+
181
+ LoadFileFromPath ( path , ref project ) ;
182
+
183
+ // If the file is a ReClass.NET file remember the path.
184
+ if ( Path . GetExtension ( path ) == ReClassNetFile . FileExtension )
185
+ {
186
+ project . Path = path ;
187
+ }
188
+
189
+ SetProject ( project ) ;
190
+ }
191
+ }
192
+ catch ( Exception ex )
193
+ {
194
+ Program . Logger . Log ( ex ) ;
195
+ }
175
196
}
176
197
177
198
private void mergeWithProjectToolStripMenuItem_Click ( object sender , EventArgs e )
178
199
{
179
- SelectAndLoadFileFromPath ( CurrentProject ) ;
200
+ try
201
+ {
202
+ var path = ShowOpenProjectFileDialog ( ) ;
203
+ if ( path != null )
204
+ {
205
+ LoadFileFromPath ( path , ref currentProject ) ;
206
+ }
207
+ }
208
+ catch ( Exception ex )
209
+ {
210
+ Program . Logger . Log ( ex ) ;
211
+ }
180
212
}
181
213
182
214
private void clearProjectToolStripMenuItem_Click ( object sender , EventArgs e )
@@ -388,7 +420,26 @@ private void MainForm_DragDrop(object sender, DragEventArgs e)
388
420
var files = e . Data . GetData ( DataFormats . FileDrop ) as string [ ] ;
389
421
if ( files != null && files . Any ( ) )
390
422
{
391
- LoadFileFromPath ( files . First ( ) , null ) ;
423
+ try
424
+ {
425
+ var path = files . First ( ) ;
426
+
427
+ var project = new ReClassNetProject ( ) ;
428
+
429
+ LoadFileFromPath ( path , ref project ) ;
430
+
431
+ // If the file is a ReClass.NET file remember the path.
432
+ if ( Path . GetExtension ( path ) == ReClassNetFile . FileExtension )
433
+ {
434
+ project . Path = path ;
435
+ }
436
+
437
+ SetProject ( project ) ;
438
+ }
439
+ catch ( Exception ex )
440
+ {
441
+ Program . Logger . Log ( ex ) ;
442
+ }
392
443
}
393
444
}
394
445
@@ -527,7 +578,9 @@ private void AskAddOrInsertBytes(string title, Action<int> callback)
527
578
}
528
579
}
529
580
530
- private void SelectAndLoadFileFromPath ( ReClassNetProject project )
581
+ /// <summary>Shows an <see cref="OpenFileDialog"/> with all valid file extensions.</summary>
582
+ /// <returns>The path to the selected file or null if no file was selected.</returns>
583
+ public static string ShowOpenProjectFileDialog ( )
531
584
{
532
585
using ( var ofd = new OpenFileDialog ( ) )
533
586
{
@@ -540,50 +593,43 @@ private void SelectAndLoadFileFromPath(ReClassNetProject project)
540
593
541
594
if ( ofd . ShowDialog ( ) == DialogResult . OK )
542
595
{
543
- LoadFileFromPath ( ofd . FileName , project ) ;
596
+ return ofd . FileName ;
544
597
}
545
598
}
599
+
600
+ return null ;
546
601
}
547
602
548
- private void LoadFileFromPath ( string filePath , ReClassNetProject project )
603
+ /// <summary>Loads the file into the given project.</summary>
604
+ /// <param name="filePath">Full pathname of the file.</param>
605
+ /// <param name="project">[in,out] The project.</param>
606
+ private void LoadFileFromPath ( string filePath , ref ReClassNetProject project )
549
607
{
550
608
Contract . Requires ( filePath != null ) ;
551
-
552
- var loadProject = project ?? new ReClassNetProject ( ) ;
609
+ Contract . Requires ( project != null ) ;
553
610
554
611
IReClassImport import = null ;
555
612
switch ( Path . GetExtension ( filePath ) )
556
613
{
557
614
case ReClassNetFile . FileExtension :
558
- import = new ReClassNetFile ( loadProject ) ;
559
- loadProject . Path = filePath ;
615
+ import = new ReClassNetFile ( project ) ;
560
616
break ;
561
617
case ReClassQtFile . FileExtension :
562
- import = new ReClassQtFile ( loadProject ) ;
618
+ import = new ReClassQtFile ( project ) ;
563
619
break ;
564
620
case ReClassFile . FileExtension :
565
- import = new ReClassFile ( loadProject ) ;
621
+ import = new ReClassFile ( project ) ;
566
622
break ;
567
623
case ReClass2007File . FileExtension :
568
- import = new ReClass2007File ( loadProject ) ;
624
+ import = new ReClass2007File ( project ) ;
569
625
break ;
570
626
default :
571
627
Program . Logger . Log ( LogLevel . Error , $ "The file '{ filePath } ' has an unknown type.") ;
572
628
break ;
573
629
}
574
630
if ( import != null )
575
631
{
576
- try
577
- {
578
- import . Load ( filePath , Program . Logger ) ;
579
-
580
- SetProject ( loadProject ) ;
581
- }
582
- catch ( Exception ex )
583
- {
584
- Program . Logger . Log ( ex ) ;
585
- }
586
-
632
+ import . Load ( filePath , Program . Logger ) ;
587
633
}
588
634
}
589
635
}
0 commit comments