/// <inheritdoc/> public async Task DeleteLocalSoundAsync(string id) { if (string.IsNullOrWhiteSpace(id) || !await IsSoundInstalledAsync(id)) { return; } // Delete from cache var soundForDeletion = _localSoundCache.First(x => x.Id == id); _localSoundCache.Remove(soundForDeletion); // Write changes to file await WriteCacheAsync(); // Delete sound file if (!string.IsNullOrWhiteSpace(soundForDeletion.FilePath)) { StorageFile soundFile = await StorageFile.GetFileFromPathAsync(soundForDeletion.FilePath); await soundFile.DeleteAsync(); } // Delete image file if (!string.IsNullOrWhiteSpace(soundForDeletion.ImagePath)) { StorageFile imageFile = await StorageFile.GetFileFromPathAsync(soundForDeletion.ImagePath); await imageFile.DeleteAsync(); } LocalSoundDeleted?.Invoke(this, soundForDeletion.Id); }
/// <inheritdoc/> public async Task DeleteLocalSoundAsync(string id) { if (string.IsNullOrWhiteSpace(id) || !await IsSoundInstalledAsync(id)) { return; } // Delete from cache var soundForDeletion = _localSoundCache.First(x => x.Id == id); _localSoundCache.Remove(soundForDeletion); // Write changes to file StorageFile localDataFile = await ApplicationData.Current.LocalFolder.CreateFileAsync( LocalDataFileName, CreationCollisionOption.OpenIfExists); string json = JsonSerializer.Serialize(_localSoundCache); await FileIO.WriteTextAsync(localDataFile, json); // Delete sound file StorageFile soundFile = await StorageFile.GetFileFromPathAsync(soundForDeletion.FilePath); await soundFile.DeleteAsync(); // Delete image file StorageFile imageFile = await StorageFile.GetFileFromPathAsync(soundForDeletion.ImagePath); await imageFile.DeleteAsync(); LocalSoundDeleted?.Invoke(this, soundForDeletion.Id); }