@@ -15,7 +15,7 @@ namespace Microsoft.Toolkit.Uwp.Helpers
15
15
/// <summary>
16
16
/// Storage helper for files and folders living in Windows.Storage.ApplicationData storage endpoints.
17
17
/// </summary>
18
- public class ApplicationDataStorageHelper : IFileStorageHelper , ISettingsStorageHelper
18
+ public partial class ApplicationDataStorageHelper : IFileStorageHelper , ISettingsStorageHelper
19
19
{
20
20
/// <summary>
21
21
/// Get a new instance using ApplicationData.Current and the provided serializer.
@@ -43,11 +43,17 @@ public static async Task<ApplicationDataStorageHelper> GetForUserAsync(User user
43
43
/// <summary>
44
44
/// Gets the settings container.
45
45
/// </summary>
46
- protected ApplicationData AppData { get ; private set ; }
46
+ public ApplicationDataContainer Settings => AppData . LocalSettings ;
47
47
48
- private ApplicationDataContainer DefaultSettings => AppData . LocalSettings ;
48
+ /// <summary>
49
+ /// Gets the storage folder.
50
+ /// </summary>
51
+ public StorageFolder Folder => AppData . LocalFolder ;
49
52
50
- private StorageFolder DefaultFolder => AppData . LocalFolder ;
53
+ /// <summary>
54
+ /// Gets the storage host.
55
+ /// </summary>
56
+ protected ApplicationData AppData { get ; private set ; }
51
57
52
58
private readonly Toolkit . Helpers . IObjectSerializer _serializer ;
53
59
@@ -65,15 +71,15 @@ public ApplicationDataStorageHelper(ApplicationData appData, Toolkit.Helpers.IOb
65
71
/// <inheritdoc />
66
72
public bool KeyExists ( string key )
67
73
{
68
- return DefaultSettings . Values . ContainsKey ( key ) ;
74
+ return Settings . Values . ContainsKey ( key ) ;
69
75
}
70
76
71
77
/// <inheritdoc />
72
78
public bool KeyExists ( string compositeKey , string key )
73
79
{
74
80
if ( KeyExists ( compositeKey ) )
75
81
{
76
- ApplicationDataCompositeValue composite = ( ApplicationDataCompositeValue ) DefaultSettings . Values [ compositeKey ] ;
82
+ ApplicationDataCompositeValue composite = ( ApplicationDataCompositeValue ) Settings . Values [ compositeKey ] ;
77
83
if ( composite != null )
78
84
{
79
85
return composite . ContainsKey ( key ) ;
@@ -86,7 +92,7 @@ public bool KeyExists(string compositeKey, string key)
86
92
/// <inheritdoc />
87
93
public T Read < T > ( string key , T @default = default )
88
94
{
89
- if ( ! DefaultSettings . Values . TryGetValue ( key , out var value ) || value == null )
95
+ if ( ! Settings . Values . TryGetValue ( key , out var value ) || value == null )
90
96
{
91
97
return @default ;
92
98
}
@@ -97,7 +103,7 @@ public T Read<T>(string key, T @default = default)
97
103
/// <inheritdoc />
98
104
public T Read < T > ( string compositeKey , string key , T @default = default )
99
105
{
100
- ApplicationDataCompositeValue composite = ( ApplicationDataCompositeValue ) DefaultSettings . Values [ compositeKey ] ;
106
+ ApplicationDataCompositeValue composite = ( ApplicationDataCompositeValue ) Settings . Values [ compositeKey ] ;
101
107
if ( composite != null )
102
108
{
103
109
string value = ( string ) composite [ key ] ;
@@ -113,15 +119,15 @@ public T Read<T>(string compositeKey, string key, T @default = default)
113
119
/// <inheritdoc />
114
120
public void Save < T > ( string key , T value )
115
121
{
116
- DefaultSettings . Values [ key ] = _serializer . Serialize ( value ) ;
122
+ Settings . Values [ key ] = _serializer . Serialize ( value ) ;
117
123
}
118
124
119
125
/// <inheritdoc />
120
126
public void Save < T > ( string compositeKey , IDictionary < string , T > values )
121
127
{
122
128
if ( KeyExists ( compositeKey ) )
123
129
{
124
- ApplicationDataCompositeValue composite = ( ApplicationDataCompositeValue ) DefaultSettings . Values [ compositeKey ] ;
130
+ ApplicationDataCompositeValue composite = ( ApplicationDataCompositeValue ) Settings . Values [ compositeKey ] ;
125
131
126
132
foreach ( KeyValuePair < string , T > setting in values )
127
133
{
@@ -143,60 +149,60 @@ public void Save<T>(string compositeKey, IDictionary<string, T> values)
143
149
composite . Add ( setting . Key , _serializer . Serialize ( setting . Value ) ) ;
144
150
}
145
151
146
- DefaultSettings . Values [ compositeKey ] = composite ;
152
+ Settings . Values [ compositeKey ] = composite ;
147
153
}
148
154
}
149
155
150
156
/// <inheritdoc />
151
157
public void Delete ( string key )
152
158
{
153
- DefaultSettings . Values . Remove ( key ) ;
159
+ Settings . Values . Remove ( key ) ;
154
160
}
155
161
156
162
/// <inheritdoc />
157
163
public void Delete ( string compositeKey , string key )
158
164
{
159
165
if ( KeyExists ( compositeKey ) )
160
166
{
161
- ApplicationDataCompositeValue composite = ( ApplicationDataCompositeValue ) DefaultSettings . Values [ compositeKey ] ;
167
+ ApplicationDataCompositeValue composite = ( ApplicationDataCompositeValue ) Settings . Values [ compositeKey ] ;
162
168
composite . Remove ( key ) ;
163
169
}
164
170
}
165
171
166
172
/// <inheritdoc />
167
173
public Task < bool > ItemExistsAsync ( string itemName )
168
174
{
169
- return ItemExistsAsync ( DefaultFolder , itemName ) ;
175
+ return ItemExistsAsync ( Folder , itemName ) ;
170
176
}
171
177
172
178
/// <inheritdoc />
173
179
public Task < T > ReadFileAsync < T > ( string filePath , T @default = default )
174
180
{
175
- return ReadFileAsync < T > ( DefaultFolder , filePath , @default ) ;
181
+ return ReadFileAsync < T > ( Folder , filePath , @default ) ;
176
182
}
177
183
178
184
/// <inheritdoc />
179
185
public Task < IList < Tuple < DirectoryItemType , string > > > ReadFolderAsync ( string folderPath )
180
186
{
181
- return ReadFolderAsync ( DefaultFolder , folderPath ) ;
187
+ return ReadFolderAsync ( Folder , folderPath ) ;
182
188
}
183
189
184
190
/// <inheritdoc />
185
191
public Task CreateFileAsync < T > ( string filePath , T value )
186
192
{
187
- return SaveFileAsync < T > ( DefaultFolder , filePath , value ) ;
193
+ return SaveFileAsync < T > ( Folder , filePath , value ) ;
188
194
}
189
195
190
196
/// <inheritdoc />
191
197
public Task CreateFolderAsync ( string folderPath )
192
198
{
193
- return CreateFolderAsync ( DefaultFolder , folderPath ) ;
199
+ return CreateFolderAsync ( Folder , folderPath ) ;
194
200
}
195
201
196
202
/// <inheritdoc />
197
203
public Task DeleteItemAsync ( string itemPath )
198
204
{
199
- return DeleteItemAsync ( DefaultFolder , itemPath ) ;
205
+ return DeleteItemAsync ( Folder , itemPath ) ;
200
206
}
201
207
202
208
/// <summary>
@@ -208,7 +214,7 @@ public Task DeleteItemAsync(string itemPath)
208
214
/// <returns>A task with the result of the file query.</returns>
209
215
public Task < bool > FileExistsAsync ( string fileName , bool isRecursive = false )
210
216
{
211
- return FileExistsAsync ( DefaultFolder , fileName , isRecursive ) ;
217
+ return FileExistsAsync ( Folder , fileName , isRecursive ) ;
212
218
}
213
219
214
220
/// <summary>
@@ -220,7 +226,7 @@ public Task<bool> FileExistsAsync(string fileName, bool isRecursive = false)
220
226
/// <returns>Waiting task until completion.</returns>
221
227
public Task < StorageFile > SaveFileAsync < T > ( string filePath , T value )
222
228
{
223
- return SaveFileAsync < T > ( DefaultFolder , filePath , value ) ;
229
+ return SaveFileAsync < T > ( Folder , filePath , value ) ;
224
230
}
225
231
226
232
private async Task < bool > ItemExistsAsync ( StorageFolder folder , string itemName )
0 commit comments