Exemplo n.º 1
0
        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
            }
        }