public async Task DownloadFiles(bool bForce = false) { AsyncWebClient awc = new AsyncWebClient(); if (Config.Region == Config.RegionDef.UK) { if (!await PersistHelper.FileExisits(ApplicationData.Current.LocalFolder, CinemasUKFileName) || bForce) { await awc.DownloadFileAsync(String.Format("{0}{1}", blobStorage, CinemasUKFileName), CinemasUKFileName); } if (!await PersistHelper.FileExisits(ApplicationData.Current.LocalFolder, FilmsUKFileName) || bForce) { await awc.DownloadFileAsync(String.Format("{0}{1}", blobStorage, FilmsUKFileName), FilmsUKFileName); } if (!await PersistHelper.FileExisits(ApplicationData.Current.LocalFolder, CinemaFilmsUKFileName) || bForce) { await awc.DownloadFileAsync(String.Format("{0}{1}", blobStorage, CinemaFilmsUKFileName), CinemaFilmsUKFileName); } if (!await PersistHelper.FileExisits(ApplicationData.Current.LocalFolder, FilmCinemasUKFileName) || bForce) { await awc.DownloadFileAsync(String.Format("{0}{1}", blobStorage, FilmCinemasUKFileName), FilmCinemasUKFileName); } } else { if (!await PersistHelper.FileExisits(ApplicationData.Current.LocalFolder, CinemasIEFileName) || bForce) { await awc.DownloadFileAsync(String.Format("{0}{1}", blobStorage, CinemasIEFileName), CinemasIEFileName); } if (!await PersistHelper.FileExisits(ApplicationData.Current.LocalFolder, FilmsIEFileName) || bForce) { await awc.DownloadFileAsync(String.Format("{0}{1}", blobStorage, FilmsIEFileName), FilmsIEFileName); } if (!await PersistHelper.FileExisits(ApplicationData.Current.LocalFolder, CinemaFilmsIEFileName) || bForce) { await awc.DownloadFileAsync(String.Format("{0}{1}", blobStorage, CinemaFilmsIEFileName), CinemaFilmsIEFileName); } if (!await PersistHelper.FileExisits(ApplicationData.Current.LocalFolder, FilmCinemasIEFileName) || bForce) { await awc.DownloadFileAsync(String.Format("{0}{1}", blobStorage, FilmCinemasIEFileName), FilmCinemasIEFileName); } } }
public async Task DownloadPosters() { await DownloadFile(MovieFilmPostersFileName, false); if (!Config.AnimateLockscreen) { return; } object o = await ReadMoviePosters(); if (o == null || !(o is JObject)) { return; } JObject data = (JObject)o; bool downloadFiles = true; IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication(); string folder = "Shared\\ShellContent"; if (!isf.DirectoryExists(folder)) { isf.CreateDirectory(folder); } else { if (isf.GetLastWriteTime(folder) >= isf.GetLastWriteTime(BaseStorageHelper.MovieFilmPostersFileName) && isf.GetFileNames("*.jpg").Length > 0) { downloadFiles = false; } } if (downloadFiles) { AsyncWebClient awc = new AsyncWebClient(); HashSet <string> newPosters = new HashSet <string>(); foreach (var item in data) { string filename = Path.GetFileName((string)item.Value); newPosters.Add(filename); string localPath = String.Format("{0}\\{1}", folder, filename); if (!isf.FileExists(localPath)) { await awc.DownloadFileAsync((string)item.Value, filename, folder); } } HashSet <string> allPosters = new HashSet <string>(isf.GetFileNames(String.Format("{0}\\*.*", folder))); allPosters.ExceptWith(newPosters); foreach (var file in allPosters) { try { isf.DeleteFile(file); } catch { } } allPosters.ExceptWith(newPosters); foreach (var file in allPosters) { try { isf.DeleteFile(file); } catch { } } } }