protected virtual async Task <bool> DownloadPhotoAsync(TumblrPost downloadItem) { string url = Url(downloadItem); if (!(files.CheckIfFileExistsInDB(url) || blog.CheckIfBlogShouldCheckDirectory(GetCoreImageUrl(url)))) { string blogDownloadLocation = blog.DownloadLocation(); string fileName = FileName(downloadItem); string fileLocation = FileLocation(blogDownloadLocation, fileName); string fileLocationUrlList = FileLocationLocalized(blogDownloadLocation, Resources.FileNamePhotos); DateTime postDate = PostDate(downloadItem); UpdateProgressQueueInformation(Resources.ProgressDownloadImage, fileName); if (await DownloadBinaryFile(fileLocation, fileLocationUrlList, url)) { SetFileDate(fileLocation, postDate); UpdateBlogDB("DownloadedPhotos", fileName); if (shellService.Settings.EnablePreview) { if (!fileName.EndsWith(".gif")) { blog.LastDownloadedPhoto = Path.GetFullPath(fileLocation); } else { blog.LastDownloadedVideo = Path.GetFullPath(fileLocation); } } return(true); } return(false); } return(true); }
private bool CheckIfFileExistsInDB(string url) { if (shellService.Settings.LoadAllDatabases) { return(managerService.CheckIfFileExistsInDB(url)); } return(files.CheckIfFileExistsInDB(url) || blog.CheckIfBlogShouldCheckDirectory(GetCoreImageUrl(url))); }
private bool CheckIfFileExistsInDB(TumblrPost downloadItem) { string filename = FileName(downloadItem); string filenameNew = FileNameNew(downloadItem); if (shellService.Settings.LoadAllDatabases) { return(managerService.CheckIfFileExistsInDB(filename)); } return(files.CheckIfFileExistsInDB(filename) || blog.CheckIfBlogShouldCheckDirectory(filename, filenameNew)); }
protected virtual async Task <bool> DownloadBinaryPostAsync(TumblrPost downloadItem) { if (CheckIfFileExistsInDB(downloadItem)) { string fileName = FileName(downloadItem); UpdateProgressQueueInformation(Resources.ProgressSkipFile, fileName); } else if (!shellService.Settings.LoadAllDatabases && blog.CheckDirectoryForFiles && blog.CheckIfBlogShouldCheckDirectory(FileName(downloadItem), FileNameNew(downloadItem))) { string fileName = AddFileToDb(downloadItem); UpdateProgressQueueInformation(Resources.ProgressSkipFile, fileName); } else if ((shellService.Settings.LoadAllDatabases || !blog.CheckDirectoryForFiles) && CheckIfLinkRestored(downloadItem)) { string fileName = AddFileToDb(downloadItem); UpdateProgressQueueInformation(Resources.ProgressSkipFile, fileName); } else { string blogDownloadLocation = blog.DownloadLocation(); string fileName = AddFileToDb(downloadItem); string fileLocation = FileLocation(blogDownloadLocation, fileName); string fileLocationUrlList = FileLocationLocalized(blogDownloadLocation, downloadItem.TextFileLocation); DateTime postDate = PostDate(downloadItem); UpdateProgressQueueInformation(Resources.ProgressDownloadImage, fileName); if (!await DownloadBinaryFileAsync(fileLocation, fileLocationUrlList, Url(downloadItem))) { return(false); } SetFileDate(fileLocation, postDate); UpdateBlogDB(downloadItem.DbType); //TODO: Refactor if (!shellService.Settings.EnablePreview) { return(true); } if (suffixes.Any(suffix => fileName.EndsWith(suffix))) { blog.LastDownloadedPhoto = Path.GetFullPath(fileLocation); } else { blog.LastDownloadedVideo = Path.GetFullPath(fileLocation); } return(true); } return(true); }