public BooruImage GetThumbnail(BooruUser User, ulong PostID) { DataRow postRow = _DB.ExecuteRow(SQLStatements.GetPostByID, PostID); BooruPost post = BooruPost.FromRow(postRow); if (post != null) { string path = Path.Combine(ThumbFolder, "thumb" + PostID); if (User == null) { return(BooruImage.FromFile(path)); } else if (post.Rating <= User.MaxRating && IsPrivacyAllowed(post, User)) { return(BooruImage.FromFile(path)); } else { throw new BooruException(BooruException.ErrorCodes.NoPermission); } } else { throw new BooruException(BooruException.ErrorCodes.ResourceNotFound); } }
private static ProcessStartInfo GetPSI(string File) { using (BooruImage img = BooruImage.FromFile(File)) { if (img.ImageFormat == ImageFormat.Png) { return(GetPSI2(OPTI_PNG_EXE, OPTI_PNG_ARGS, File)); } else if (img.ImageFormat == ImageFormat.Jpeg) { return(GetPSI2(OPTI_JPG_EXE, OPTI_JPG_ARGS, File)); } else if (img.ImageFormat == ImageFormat.Gif) { return(GetPSI2(OPTI_GIF_EXE, OPTI_GIF_ARGS, File)); } else { throw new BadImageFormatException("Optimization not supported for this ImageFormat"); } } }
public BooruImage GetImage(BooruUser User, ulong PostID) { DataRow postRow = _DB.ExecuteRow(SQLStatements.GetPostByID, PostID); BooruPost post = BooruPost.FromRow(postRow); if (post != null) { if (User == null || (post.Rating <= User.MaxRating && IsPrivacyAllowed(post, User))) { BooruImage image = BooruImage.FromFile(Path.Combine(ImageFolder, "image" + PostID)); _DB.ExecuteNonQuery(SQLStatements.UpdateIncrementViewCount, PostID); return(image); } else { throw new BooruException(BooruException.ErrorCodes.NoPermission); } } else { throw new BooruException(BooruException.ErrorCodes.ResourceNotFound); } }