@@ -17,6 +17,10 @@ namespace GitLab.VisualStudio.Services
1717 [ PartCreationPolicy ( CreationPolicy . Shared ) ]
1818 public class Storage : IStorage
1919 {
20+ public Storage ( )
21+ {
22+ LoadConfig ( ) ;
23+ }
2024 public bool IsLogined
2125 {
2226 get
@@ -167,11 +171,44 @@ private static void EraseCredential(string key)
167171 }
168172 }
169173
170- public string GetBaseRepositoryDirectory ( )
174+ public string GetBaseRepositoryDirectory ( ) => AppSettings ? . BasePath ;
175+
176+
177+ public AppSettings AppSettings { get ; set ; }
178+ public void LoadConfig ( )
171179 {
172- var user = Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) ;
173- var _path = System . IO . Path . Combine ( user , "Source" , "Repos" ) ;
174- return _path ;
180+ try
181+ {
182+ var filename = System . IO . Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) , "gitlab4vs.cfg" ) ;
183+ if ( System . IO . File . Exists ( filename ) )
184+ {
185+ AppSettings = JsonConvert . DeserializeObject < AppSettings > ( System . IO . File . ReadAllText ( filename ) ) ;
186+ }
187+ }
188+ catch ( Exception )
189+ {
190+ }
191+ if ( AppSettings == null )
192+ {
193+ AppSettings = new AppSettings ( ) ;
194+ }
195+ if ( string . IsNullOrEmpty ( AppSettings . BasePath ) )
196+ {
197+ var user = Environment . GetFolderPath ( Environment . SpecialFolder . MyDocuments ) ;
198+ AppSettings . BasePath = System . IO . Path . Combine ( user , "Source" , "Repos" ) ;
199+ }
200+ }
201+ public void SaveConfig ( )
202+ {
203+ try
204+ {
205+ var filename = System . IO . Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) , "gitlab4vs.cfg" ) ;
206+ System . IO . File . WriteAllText ( filename , JsonConvert . SerializeObject ( AppSettings ) ) ;
207+ }
208+ catch ( Exception )
209+ {
210+ OutputWindowHelper . WarningWriteLine ( "Can't save config!" ) ;
211+ }
175212 }
176213
177214 private Dictionary < string , ApiVersion > HostVersionInfo { get ; set ; }
@@ -223,7 +260,7 @@ public void LoadHostVersionInfo()
223260 catch ( Exception ex )
224261 {
225262 HostVersionInfo = new Dictionary < string , ApiVersion > ( ) ;
226- OutputWindowHelper . ExceptionWriteLine ( "LoadHostVersionInfo" , ex ) ;
263+ OutputWindowHelper . WarningWriteLine ( "Can't load host version infos" ) ;
227264 }
228265 if ( HostVersionInfo == null ) HostVersionInfo = new Dictionary < string , ApiVersion > ( ) ;
229266 if ( HostVersionInfo . Count == 0 )
@@ -268,7 +305,7 @@ private void SaveHostVersion()
268305 }
269306 catch ( Exception ex )
270307 {
271- OutputWindowHelper . ExceptionWriteLine ( "SaveHostVersion" , ex ) ;
308+ OutputWindowHelper . WarningWriteLine ( "Can't save host version info" ) ;
272309 }
273310 }
274311 }
0 commit comments