public void AddToFavorites(BasePost webPost, string fileToCopy)
{
// Replace http paths with the drive paths to the images, ideally caching should solve this problem, but this needs testing
BasePost favPost = new BasePost(webPost);
string thumbPath = string.Empty;
string bigPath = string.Empty;
try
{
if (!string.IsNullOrEmpty(webPost.PreviewURL))
{
thumbPath = Path.Combine(_favoritesThumbFolder, Path.GetFileName(webPost.PreviewURL));
File.Copy(webPost.PreviewURL, thumbPath, true);
favPost.PreviewURL = thumbPath;
favPost.URLStore = thumbPath;
}
else if (!string.IsNullOrEmpty(webPost.URLStore))
{
thumbPath = Path.Combine(_favoritesThumbFolder, Path.GetFileName(webPost.URLStore));
File.Copy(webPost.URLStore, thumbPath, true);
favPost.PreviewURL = thumbPath;
favPost.URLStore = thumbPath;
}
}
catch
{
//
}
try
{
bigPath = Path.Combine(_favoritesFolder, Path.GetFileName(fileToCopy));
File.Copy(fileToCopy, bigPath, true);
favPost.FullPictureURL = bigPath;
}
catch
{
//
}
//We can ignore the fails, file access for thumbnails isnt always instantly freed if same file is being added/removed
if (!string.IsNullOrEmpty(thumbPath) && !string.IsNullOrEmpty(bigPath) && _favoritesList.FirstOrDefault(x => x.PreviewURL == thumbPath && x.FullPictureURL == bigPath) == null)
{
_favoritesList.Add(favPost);
UpdateFavoritesConfigFile();
}
}