public static async Task <bool> CheckIfNeedToUpdate() { try { QueryOptions Options = new QueryOptions { ApplicationSearchFilter = "System.FileName:BingDailyPicture_Cache*", FolderDepth = FolderDepth.Shallow, IndexerOption = IndexerOption.UseIndexerWhenAvailable }; StorageFileQueryResult QueryResult = ApplicationData.Current.TemporaryFolder.CreateFileQueryWithOptions(Options); IReadOnlyList <StorageFile> AllPreviousPictureList = await QueryResult.GetFilesAsync(); if (AllPreviousPictureList.All((Item) => DateTime.TryParseExact(Regex.Match(Item.Name, @"(?<=\[)(.+)(?=\])").Value, "yyyy-MM-dd HH-mm-ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out DateTime LastUpdateDate) && LastUpdateDate < DateTime.Now.Date)) { foreach (StorageFile ToDelete in AllPreviousPictureList) { await ToDelete.DeleteAsync(StorageDeleteOption.PermanentDelete); } return(true); } else { return(false); } }
public static async Task <bool> CheckIfNeedToUpdate() { try { if (await FileSystemStorageItemBase.OpenAsync(ApplicationData.Current.TemporaryFolder.Path) is FileSystemStorageFolder TempFolder) { IEnumerable <FileSystemStorageItemBase> AllPreviousPictureList = await TempFolder.GetChildItemsAsync(false, false, Filter : ItemFilters.File, AdvanceFilter : (Name) => Name.StartsWith("BingDailyPicture_Cache", StringComparison.OrdinalIgnoreCase)); if (AllPreviousPictureList.All((Item) => DateTime.TryParseExact(Regex.Match(Item.Name, @"(?<=\[)(.+)(?=\])").Value, "yyyy-MM-dd HH-mm-ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out DateTime LastUpdateDate) && LastUpdateDate < DateTime.Now.Date)) { foreach (FileSystemStorageItemBase ToDelete in AllPreviousPictureList) { await ToDelete.DeleteAsync(true); } return(true); } else { return(false); } } else { return(false); } }
public static async Task <bool> CheckIfNeedToUpdate() { try { IEnumerable <StorageFile> AllPreviousPictureList = (await ApplicationData.Current.TemporaryFolder.GetFilesAsync()).Where((Item) => Item.Name.StartsWith("BingDailyPicture_Cache")); if (AllPreviousPictureList.All((Item) => DateTime.TryParseExact(Regex.Match(Item.Name, @"(?<=\[)(.+)(?=\])").Value, "yyyy-MM-dd HH-mm-ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out DateTime LastUpdateDate) && LastUpdateDate < DateTime.Now.Date)) { foreach (StorageFile ToDelete in AllPreviousPictureList) { await ToDelete.DeleteAsync(StorageDeleteOption.PermanentDelete); } return(true); } else { return(false); } }