diff --git a/src/D2L.Bmx/Aws/AwsCredsCache.cs b/src/D2L.Bmx/Aws/AwsCredsCache.cs index c83c2ee4..5bbc3e1f 100644 --- a/src/D2L.Bmx/Aws/AwsCredsCache.cs +++ b/src/D2L.Bmx/Aws/AwsCredsCache.cs @@ -69,6 +69,13 @@ AwsCredentials credentials string jsonString = JsonSerializer.Serialize( prunedEntries.ToList(), SourceGenerationContext.Default.ListAwsCacheModel ); + if( !Directory.Exists( BmxPaths.CACHE_DIR ) ) { + 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" ) ); + } + WriteTextToFile( BmxPaths.AWS_CREDS_CACHE_FILE_NAME, jsonString ); } 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..5b6bd664 100644 --- a/src/D2L.Bmx/Okta/OktaSessionStorage.cs +++ b/src/D2L.Bmx/Okta/OktaSessionStorage.cs @@ -14,6 +14,12 @@ void IOktaSessionStorage.SaveSessions( List sessions ) { if( !Directory.Exists( BmxPaths.BMX_DIR ) ) { Directory.CreateDirectory( BmxPaths.BMX_DIR ); } + if( !Directory.Exists( BmxPaths.CACHE_DIR ) ) { + 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" ) ); + } string jsonString = JsonSerializer.Serialize( sessions, diff --git a/src/D2L.Bmx/UpdateChecker.cs b/src/D2L.Bmx/UpdateChecker.cs index 39982c5e..5d68ba6a 100644 --- a/src/D2L.Bmx/UpdateChecker.cs +++ b/src/D2L.Bmx/UpdateChecker.cs @@ -71,6 +71,12 @@ private static void SaveLatestVersion( string version ) { if( !Directory.Exists( BmxPaths.BMX_DIR ) ) { Directory.CreateDirectory( BmxPaths.BMX_DIR ); } + if( !Directory.Exists( BmxPaths.CACHE_DIR ) ) { + 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" ) ); + } if( string.IsNullOrWhiteSpace( version ) ) { return; }