private async Task GetFoldersAsync() { if (!Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.ContainsItem(FolderToken)) { return; } FolderLinks.Clear(); var baseFolder = await Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.GetFolderAsync(FolderToken); var folders = (await baseFolder.GetFoldersAsync()); foreach (var f in folders) { var files = await f.GetFilesAsync(); var folder = new AudioFolder { Name = f.Name, Path = f.Path, Files = files.Select(p => new AudioFile { Name = p.Name, Path = p.Path, Extension = p.FileType, File = p }).ToList() }; FolderLinks.Add(folder); } }
private async Task RefreshAudioFiles(AudioFolder clickedItem) { AudioButtonGrid.Children.Clear(); if (clickedItem != null) { foreach (var file in clickedItem.Files) { // load files into memory var memoryStream = new InMemoryRandomAccessStream(); using (var inputStream = await file.File.OpenReadAsync()) { await RandomAccessStream.CopyAsync(inputStream, memoryStream); } // <Button Content ="Name" Height="150" Width="150" Background="Red" Foreground="White" FontSize="24" /> var button = new Button { Height = 150, Width = 150, FontSize = 24 }; // <TextBlock Text ="Customer Locations" TextWrapping="Wrap" /> button.Content = new TextBlock { Text = file.Name, TextWrapping = TextWrapping.WrapWholeWords }; button.Background = clickedItem.BackgroundColor; button.Foreground = InvertColor(clickedItem.BackgroundColor.Color); button.BorderBrush = new SolidColorBrush(Colors.White); button.Tag = memoryStream; button.Click += AudioButton_Click; button.ContextRequested += AudioButton_ContextRequested; AudioButtonGrid.Children.Add(button); } } }
public static async Task DeleteStuckFiles() { var undeletedDir = GetUndeletedFilesDirectory(); try { // Remove undeleted files var undeletedFolder = await StorageFolder.GetFolderFromPathAsync(undeletedDir); foreach (var storageFile in await undeletedFolder.GetFilesAsync()) { try { var badFilePath = await FileIO.ReadTextAsync(storageFile); await SafeFileDelete(badFilePath); await SafeFileDelete(storageFile); } catch { // Continue } } // Remove failed downloads var queryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, new[] { DownloadableViewModelBase.DownloadExtension }); queryOptions.FolderDepth = FolderDepth.Deep; var storageFiles = (await BaseFolder.CreateFileQueryWithOptions(queryOptions).GetFilesAsync()) .Concat(await AudioFolder.CreateFileQueryWithOptions(queryOptions).GetFilesAsync()); foreach (var storageFile in storageFiles) { try { await SafeFileDelete(storageFile); } catch { // Continue } } } catch { // Do nothing } }