diff --git a/src/D2L.Bmx/BmxConfigProvider.cs b/src/D2L.Bmx/BmxConfigProvider.cs index 27b13445..96539e74 100644 --- a/src/D2L.Bmx/BmxConfigProvider.cs +++ b/src/D2L.Bmx/BmxConfigProvider.cs @@ -52,9 +52,6 @@ public BmxConfig GetConfiguration() { } public void SaveConfiguration( BmxConfig config ) { - if( !Directory.Exists( BmxPaths.BMX_DIR ) ) { - Directory.CreateDirectory( BmxPaths.BMX_DIR ); - } var op = new FileStreamOptions { Mode = FileMode.OpenOrCreate, Access = FileAccess.ReadWrite, diff --git a/src/D2L.Bmx/BmxPaths.cs b/src/D2L.Bmx/BmxPaths.cs index 29026d57..12f5045c 100644 --- a/src/D2L.Bmx/BmxPaths.cs +++ b/src/D2L.Bmx/BmxPaths.cs @@ -3,8 +3,9 @@ namespace D2L.Bmx; internal static class BmxPaths { public static readonly string USER_HOME_DIR = Environment.GetFolderPath( Environment.SpecialFolder.UserProfile ); public static readonly string BMX_DIR = Path.Join( USER_HOME_DIR, ".bmx" ); - public static readonly string SESSIONS_FILE_NAME = Path.Join( BMX_DIR, "sessions" ); + public static readonly string CACHE_DIR = Path.Join( BMX_DIR, "\\cache" ); + public static readonly string SESSIONS_FILE_NAME = Path.Join( CACHE_DIR, "sessions" ); public static readonly string CONFIG_FILE_NAME = Path.Join( BMX_DIR, "config" ); - public static readonly string UPDATE_CHECK_FILE_NAME = Path.Join( BMX_DIR, "update_check" ); - public static readonly string AWS_CREDS_CACHE_FILE_NAME = Path.Join( BMX_DIR, "awsCredsCache" ); + public static readonly string UPDATE_CHECK_FILE_NAME = Path.Join( CACHE_DIR, "updateCheck" ); + public static readonly string AWS_CREDS_CACHE_FILE_NAME = Path.Join( CACHE_DIR, "awsCreds" ); } diff --git a/src/D2L.Bmx/Okta/OktaSessionStorage.cs b/src/D2L.Bmx/Okta/OktaSessionStorage.cs index 2ad7d44f..a2b13e13 100644 --- a/src/D2L.Bmx/Okta/OktaSessionStorage.cs +++ b/src/D2L.Bmx/Okta/OktaSessionStorage.cs @@ -11,9 +11,6 @@ internal interface IOktaSessionStorage { internal class OktaSessionStorage : IOktaSessionStorage { void IOktaSessionStorage.SaveSessions( List sessions ) { - if( !Directory.Exists( BmxPaths.BMX_DIR ) ) { - Directory.CreateDirectory( BmxPaths.BMX_DIR ); - } string jsonString = JsonSerializer.Serialize( sessions, diff --git a/src/D2L.Bmx/Program.cs b/src/D2L.Bmx/Program.cs index 39ac8368..eb1f18e2 100644 --- a/src/D2L.Bmx/Program.cs +++ b/src/D2L.Bmx/Program.cs @@ -215,6 +215,17 @@ next ) => { await UpdateChecker.CheckForUpdatesAsync( configProvider.GetConfiguration() ); + //Creating new Cache directory and removing old files. + if( !Directory.Exists( BmxPaths.CACHE_DIR ) ) { + try { + Directory.CreateDirectory( BmxPaths.CACHE_DIR ); + File.Delete( Path.Join( BmxPaths.BMX_DIR, "awsCredsCache" ) ); + File.Delete( Path.Join( BmxPaths.BMX_DIR, "sessions" ) ); + File.Delete( Path.Join( BmxPaths.BMX_DIR, "update_check" ) ); + } catch( Exception ex ) { + Console.Error.WriteLine( "Error cleaning up old files continuing..." ); + } + } await next( context ); }, System.CommandLine.Invocation.MiddlewareOrder.ExceptionHandler + 1