44
55using ReactiveMarbles . CacheDatabase . Core ;
66using ReactiveMarbles . CacheDatabase . Settings . Core ;
7+
78#if ENCRYPTED
9+
810using ReactiveMarbles . CacheDatabase . EncryptedSqlite3 ;
11+
912#else
1013using ReactiveMarbles . CacheDatabase . Sqlite3 ;
1114#endif
15+
1216using System . Reflection ;
1317
1418#if ENCRYPTED
19+
1520namespace ReactiveMarbles . CacheDatabase . EncryptedSettings
1621#else
1722namespace ReactiveMarbles . CacheDatabase . Settings
@@ -46,7 +51,7 @@ static AppInfo()
4651 /// <value>
4752 /// The settings cache path.
4853 /// </value>
49- public static string ? SettingsCachePath { get ; }
54+ public static string ? SettingsCachePath { get ; private set ; }
5055
5156 /// <summary>
5257 /// Gets the executing assembly.
@@ -76,49 +81,71 @@ static AppInfo()
7681
7782 internal static Dictionary < string , ISettingsStorage ? > SettingsStores { get ; }
7883
84+ /// <summary>
85+ /// Overrides the settings cache path.
86+ /// </summary>
87+ /// <param name="path">The path.</param>
88+ public static void OverrideSettingsCachePath ( string path )
89+ {
90+ SettingsCachePath = path ;
91+ }
92+
7993 /// <summary>
8094 /// Deletes the settings store.
8195 /// </summary>
8296 /// <typeparam name="T">The type of store to delete.</typeparam>
83- /// <returns>A Task.</returns>
84- public static async Task DeleteSettingsStore < T > ( )
97+ /// <param name="overrideDatabaseName">Name of the override database.</param>
98+ /// <returns>
99+ /// A Task.
100+ /// </returns>
101+ public static async Task DeleteSettingsStore < T > ( string ? overrideDatabaseName = null )
85102 {
86103 await DisposeSettingsStore < T > ( ) . ConfigureAwait ( false ) ;
87- File . Delete ( Path . Combine ( SettingsCachePath ! , $ "{ typeof ( T ) . Name } .db") ) ;
104+ File . Delete ( Path . Combine ( SettingsCachePath ! , $ "{ overrideDatabaseName ?? typeof ( T ) . Name } .db") ) ;
88105 }
89106
90107 /// <summary>
91108 /// Gets the settings store.
92109 /// </summary>
93110 /// <typeparam name="T">The store to get.</typeparam>
94- /// <returns>A Settings Store.</returns>
95- public static ISettingsStorage ? GetSettingsStore < T > ( ) =>
96- SettingsStores [ typeof ( T ) . Name ] ;
111+ /// <param name="overrideDatabaseName">Name of the override database.</param>
112+ /// <returns>
113+ /// A Settings Store.
114+ /// </returns>
115+ public static ISettingsStorage ? GetSettingsStore < T > ( string ? overrideDatabaseName = null ) =>
116+ SettingsStores [ overrideDatabaseName ?? typeof ( T ) . Name ] ;
97117
98118 /// <summary>
99119 /// Disposes the settings store.
100120 /// </summary>
101121 /// <typeparam name="T">The type of store.</typeparam>
102- /// <returns>A Task.</returns>
103- public static async Task DisposeSettingsStore < T > ( )
122+ /// <param name="overrideDatabaseName">Name of the override database.</param>
123+ /// <returns>
124+ /// A Task.
125+ /// </returns>
126+ public static async Task DisposeSettingsStore < T > ( string ? overrideDatabaseName = null )
104127 {
105- await GetSettingsStore < T > ( ) ! . DisposeAsync ( ) . ConfigureAwait ( false ) ;
106- await BlobCaches [ typeof ( T ) . Name ] ! . DisposeAsync ( ) . ConfigureAwait ( false ) ;
128+ await GetSettingsStore < T > ( overrideDatabaseName ) ! . DisposeAsync ( ) . ConfigureAwait ( false ) ;
129+ await BlobCaches [ overrideDatabaseName ?? typeof ( T ) . Name ] ! . DisposeAsync ( ) . ConfigureAwait ( false ) ;
107130 }
108131
109132#if ENCRYPTED
133+
110134 /// <summary>
111135 /// Setup the secure settings store.
112136 /// </summary>
113137 /// <typeparam name="T">The Type of settings store.</typeparam>
114138 /// <param name="password">Secure password.</param>
115139 /// <param name="initialise">Initialise the Settings values.</param>
116- /// <returns>The Settings store.</returns>
117- public static async Task < T ? > SetupSettingsStore < T > ( string password , bool initialise = true )
140+ /// <param name="overrideDatabaseName">Name of the override database.</param>
141+ /// <returns>
142+ /// The Settings store.
143+ /// </returns>
144+ public static async Task < T ? > SetupSettingsStore < T > ( string password , bool initialise = true , string ? overrideDatabaseName = null )
118145 where T : ISettingsStorage ? , new ( )
119146 {
120147 Directory . CreateDirectory ( SettingsCachePath ! ) ;
121- BlobCaches [ typeof ( T ) . Name ] = new EncryptedSqliteBlobCache ( Path . Combine ( SettingsCachePath ! , $ "{ typeof ( T ) . Name } .db") , password ) ;
148+ BlobCaches [ typeof ( T ) . Name ] = new EncryptedSqliteBlobCache ( Path . Combine ( SettingsCachePath ! , $ "{ overrideDatabaseName ?? typeof ( T ) . Name } .db") , password ) ;
122149
123150 var viewSettings = new T ( ) ;
124151 SettingsStores [ typeof ( T ) . Name ] = viewSettings ;
@@ -129,19 +156,23 @@ public static async Task DisposeSettingsStore<T>()
129156
130157 return viewSettings ;
131158 }
159+
132160#else
133161
134162 /// <summary>
135163 /// Setup the settings store.
136164 /// </summary>
137165 /// <typeparam name="T">The Type of settings store.</typeparam>
138166 /// <param name="initialise">Initialise the Settings values.</param>
139- /// <returns>The Settings store.</returns>
140- public static async Task < T ? > SetupSettingsStore < T > ( bool initialise = true )
167+ /// <param name="overrideDatabaseName">Name of the override database.</param>
168+ /// <returns>
169+ /// The Settings store.
170+ /// </returns>
171+ public static async Task < T ? > SetupSettingsStore < T > ( bool initialise = true , string ? overrideDatabaseName = null )
141172 where T : ISettingsStorage ? , new ( )
142173 {
143174 Directory . CreateDirectory ( SettingsCachePath ! ) ;
144- BlobCaches [ typeof ( T ) . Name ] = new SqliteBlobCache ( Path . Combine ( SettingsCachePath ! , $ "{ typeof ( T ) . Name } .db") ) ;
175+ BlobCaches [ typeof ( T ) . Name ] = new SqliteBlobCache ( Path . Combine ( SettingsCachePath ! , $ "{ overrideDatabaseName ?? typeof ( T ) . Name } .db") ) ;
145176
146177 var viewSettings = new T ( ) ;
147178 SettingsStores [ typeof ( T ) . Name ] = viewSettings ;
0 commit comments