@@ -34,7 +34,7 @@ public MainWindowViewModel()
3434 Settings . Load ( ) ;
3535 } catch ( Exception ex )
3636 {
37-
37+ Log . Add ( Log . LogSeverity . Error , "MainWindowViewModel" , ex ) ;
3838 }
3939 }
4040
@@ -54,41 +54,47 @@ private void AddWorkingFile(string path)
5454 /// </summary>
5555 internal async void OpenFile ( )
5656 {
57- FilePickerOpenOptions options = new FilePickerOpenOptions ( ) ;
58- options . AllowMultiple = true ;
59- options . Title = "Open VP files" ;
60- if ( Settings . LastVPLoadPath != null )
57+ try
6158 {
62- options . SuggestedStartLocation = await MainWindow . Instance ! . StorageProvider . TryGetFolderFromPathAsync ( Settings . LastVPLoadPath ) ;
63- }
64- options . FileTypeFilter = new List < FilePickerFileType > {
59+ FilePickerOpenOptions options = new FilePickerOpenOptions ( ) ;
60+ options . AllowMultiple = true ;
61+ options . Title = "Open VP files" ;
62+ if ( Settings . LastVPLoadPath != null )
63+ {
64+ options . SuggestedStartLocation = await MainWindow . Instance ! . StorageProvider . TryGetFolderFromPathAsync ( Settings . LastVPLoadPath ) ;
65+ }
66+ options . FileTypeFilter = new List < FilePickerFileType > {
6567 new ( "VP files (*.vp, *.vpc)" ) { Patterns = new [ ] { "*.vp" , "*.vpc" } } ,
6668 new ( "All files (*.*)" ) { Patterns = new [ ] { "*" } }
6769 } ;
6870
6971
70- var result = await MainWindow . Instance ! . StorageProvider . OpenFilePickerAsync ( options ) ;
72+ var result = await MainWindow . Instance ! . StorageProvider . OpenFilePickerAsync ( options ) ;
7173
72- if ( result != null && result . Count > 0 )
73- {
74- var newPath = ( await result [ 0 ] . GetParentAsync ( ) ) ? . Path . LocalPath ;
75- if ( Settings . LastVPLoadPath != newPath )
74+ if ( result != null && result . Count > 0 )
7675 {
77- Settings . LastVPLoadPath = newPath ;
78- Settings . Save ( ) ;
79- }
80-
81- foreach ( var file in result )
82- {
83- try
76+ var newPath = ( await result [ 0 ] . GetParentAsync ( ) ) ? . Path . LocalPath ;
77+ if ( Settings . LastVPLoadPath != newPath )
8478 {
85- AddWorkingFile ( file . Path . LocalPath ) ;
79+ Settings . LastVPLoadPath = newPath ;
80+ Settings . Save ( ) ;
8681 }
87- catch ( Exception ex )
82+
83+ foreach ( var file in result )
8884 {
89- System . Diagnostics . Debug . WriteLine ( ex . ToString ( ) ) ;
85+ try
86+ {
87+ AddWorkingFile ( file . Path . LocalPath ) ;
88+ }
89+ catch ( Exception ex )
90+ {
91+ Log . Add ( Log . LogSeverity . Error , "MainWindowViewModel.OpenFile(1)" , ex ) ;
92+ }
9093 }
9194 }
95+ } catch ( Exception ex )
96+ {
97+ Log . Add ( Log . LogSeverity . Error , "MainWindowViewModel.OpenFile(2)" , ex ) ;
9298 }
9399 }
94100
@@ -97,34 +103,40 @@ internal async void OpenFile()
97103 /// </summary>
98104 internal async void OpenFolder ( )
99105 {
100- FolderPickerOpenOptions options = new FolderPickerOpenOptions ( ) ;
101- options . Title = "Open a folder containing VP files" ;
102- if ( Settings . LastVPLoadPath != null )
103- {
104- options . SuggestedStartLocation = await MainWindow . Instance ! . StorageProvider . TryGetFolderFromPathAsync ( Settings . LastVPLoadPath ) ;
105- }
106- var result = await MainWindow . Instance ! . StorageProvider . OpenFolderPickerAsync ( options ) ;
107-
108- if ( result != null && result . Count > 0 )
106+ try
109107 {
110-
111- string [ ] files = Directory . GetFiles ( result [ 0 ] . Path . LocalPath , "*.vp*" ) ;
112- if ( Settings . LastVPLoadPath != result [ 0 ] . Path . LocalPath )
108+ FolderPickerOpenOptions options = new FolderPickerOpenOptions ( ) ;
109+ options . Title = "Open a folder containing VP files" ;
110+ if ( Settings . LastVPLoadPath != null )
113111 {
114- Settings . LastVPLoadPath = result [ 0 ] . Path . LocalPath ;
115- Settings . Save ( ) ;
112+ options . SuggestedStartLocation = await MainWindow . Instance ! . StorageProvider . TryGetFolderFromPathAsync ( Settings . LastVPLoadPath ) ;
116113 }
117- foreach ( var file in files )
114+ var result = await MainWindow . Instance ! . StorageProvider . OpenFolderPickerAsync ( options ) ;
115+
116+ if ( result != null && result . Count > 0 )
118117 {
119- try
118+
119+ string [ ] files = Directory . GetFiles ( result [ 0 ] . Path . LocalPath , "*.vp*" ) ;
120+ if ( Settings . LastVPLoadPath != result [ 0 ] . Path . LocalPath )
120121 {
121- AddWorkingFile ( file ) ;
122+ Settings . LastVPLoadPath = result [ 0 ] . Path . LocalPath ;
123+ Settings . Save ( ) ;
122124 }
123- catch ( Exception ex )
125+ foreach ( var file in files )
124126 {
125- System . Diagnostics . Debug . WriteLine ( ex . ToString ( ) ) ;
127+ try
128+ {
129+ AddWorkingFile ( file ) ;
130+ }
131+ catch ( Exception ex )
132+ {
133+ Log . Add ( Log . LogSeverity . Error , "MainWindowViewModel.OpenFolder(1)" , ex ) ;
134+ }
126135 }
127136 }
137+ } catch ( Exception ex )
138+ {
139+ Log . Add ( Log . LogSeverity . Error , "MainWindowViewModel.OpenFolder(2)" , ex ) ;
128140 }
129141 }
130142
@@ -136,13 +148,19 @@ internal async void OpenFolder()
136148 internal void RemoveFile ( VpViewModel file )
137149 {
138150 Dispatcher . UIThread . Invoke ( ( ) =>
139- {
140- //We are closing the file it is currently open in view?
141- if ( FolderViewModel . VpFilePath == file . VpPath )
151+ {
152+ try
153+ {
154+ //We are closing the file it is currently open in view?
155+ if ( FolderViewModel . VpFilePath == file . VpPath )
156+ {
157+ FolderViewModel . ResetView ( ) ;
158+ }
159+ WorkingFiles . Remove ( file ) ;
160+ } catch ( Exception ex )
142161 {
143- FolderViewModel . ResetView ( ) ;
162+ Log . Add ( Log . LogSeverity . Error , "MainWindowViewModel.RemoveFile()" , ex ) ;
144163 }
145- WorkingFiles . Remove ( file ) ;
146164 } ) ;
147165 }
148166
0 commit comments