@@ -259,7 +259,7 @@ public bool TryDelete(string compositeKey, string key)
259
259
/// <inheritdoc />
260
260
public Task CreateFileAsync < T > ( string filePath , T value )
261
261
{
262
- return this . SaveFileAsync < T > ( this . Folder , filePath , value ) ;
262
+ return this . CreateFileAsync < T > ( this . Folder , filePath , value ) ;
263
263
}
264
264
265
265
/// <inheritdoc />
@@ -269,21 +269,15 @@ public Task CreateFolderAsync(string folderPath)
269
269
}
270
270
271
271
/// <inheritdoc />
272
- public Task DeleteItemAsync ( string itemPath )
272
+ public Task < bool > TryDeleteItemAsync ( string itemPath )
273
273
{
274
- return this . DeleteItemAsync ( this . Folder , itemPath ) ;
274
+ return TryDeleteItemAsync ( this . Folder , itemPath ) ;
275
275
}
276
276
277
- /// <summary>
278
- /// Saves an object inside a file.
279
- /// </summary>
280
- /// <typeparam name="T">Type of object saved.</typeparam>
281
- /// <param name="filePath">Path to the file that will contain the object.</param>
282
- /// <param name="value">Object to save.</param>
283
- /// <returns>Waiting task until completion.</returns>
284
- public Task < StorageFile > SaveFileAsync < T > ( string filePath , T value )
277
+ /// <inheritdoc />
278
+ public Task < bool > TryRenameItemAsync ( string itemPath , string newName )
285
279
{
286
- return this . SaveFileAsync ( this . Folder , filePath , value ) ;
280
+ return TryRenameItemAsync ( this . Folder , itemPath , newName ) ;
287
281
}
288
282
289
283
private async Task < T ? > ReadFileAsync < T > ( StorageFolder folder , string filePath , T ? @default = default )
@@ -307,7 +301,7 @@ public Task<StorageFile> SaveFileAsync<T>(string filePath, T value)
307
301
} ) ;
308
302
}
309
303
310
- private Task < StorageFile > SaveFileAsync < T > ( StorageFolder folder , string filePath , T value )
304
+ private Task < StorageFile > CreateFileAsync < T > ( StorageFolder folder , string filePath , T value )
311
305
{
312
306
return StorageFileHelper . WriteTextToFileAsync ( folder , this . Serializer . Serialize ( value ) ? . ToString ( ) , filePath , CreationCollisionOption . ReplaceExisting ) ;
313
307
}
@@ -317,10 +311,32 @@ private async Task CreateFolderAsync(StorageFolder folder, string folderPath)
317
311
await folder . CreateFolderAsync ( folderPath , CreationCollisionOption . OpenIfExists ) ;
318
312
}
319
313
320
- private async Task DeleteItemAsync ( StorageFolder folder , string itemPath )
314
+ private async Task < bool > TryDeleteItemAsync ( StorageFolder folder , string itemPath )
321
315
{
322
- var item = await folder . GetItemAsync ( itemPath ) ;
323
- await item . DeleteAsync ( ) ;
316
+ try
317
+ {
318
+ var item = await folder . GetItemAsync ( itemPath ) ;
319
+ await item . DeleteAsync ( ) ;
320
+ return true ;
321
+ }
322
+ catch
323
+ {
324
+ return false ;
325
+ }
326
+ }
327
+
328
+ private async Task < bool > TryRenameItemAsync ( StorageFolder folder , string itemPath , string newName )
329
+ {
330
+ try
331
+ {
332
+ var item = await folder . GetItemAsync ( itemPath ) ;
333
+ await item . RenameAsync ( newName , NameCollisionOption . FailIfExists ) ;
334
+ return true ;
335
+ }
336
+ catch
337
+ {
338
+ return false ;
339
+ }
324
340
}
325
341
}
326
342
}
0 commit comments