public static Image GetImage(ImageDetails details) { lock (imageCache) { if (imageCache.ContainsKey(details.MD5)) { return(imageCache [details.MD5]); } Image image = new Image(details, details); imageCache [details.MD5] = image; return(image); } }
Image GetNextImageProc() { ImageDetails data = null; while (data == null) { lock (this.reader) { data = this.reader.GetNextImage(); } } return(Image.GetImage(data)); }
private void AddImage(ImageDetails data) { if (!System.IO.File.Exists(data.Path)) { BooruApp.BooruApplication.Log.Log(BooruLog.Category.Files, BooruLog.Severity.Warning, "Could not find file " + data.Path); //return; } var image = Image.GetImage(data); image.CacheThumbnail(); this.model.QueueAddedImage(image); image.Release(); this.ResultCount++; }
public ImageDetails GetImageDetails(string md5) { ImageDetails result = null; BooruApp.BooruApplication.Database.Mutex.ExecuteCriticalSection(() => { using (var reader = Queries.Images.Get.Execute(md5)) { if (reader.Read()) { ImageDetails details = new ImageDetails(); details.InitFromReader(reader); result = details; } } }); return(result); }
private Image(ImageDetails details, ImageDetails details2) { this.Details = details; this.SubImageName = ""; this.ReloadTags(); }
public static Gdk.PixbufAnimation LoadPixbufAnimationForImage(ImageDetails data) { return(PixbufLoader.LoadPixbufAnimationForImage(data.Path, data.MD5)); }
public void ImportEntry(ImageEntry entry) { entry.Status = "Getting File Type"; CallUpdate(entry); bool callBooru = false; BooruImageType fileType = BooruImageTypeHelper.IdentifyType(entry.path, out callBooru); switch (fileType) { case BooruImageType.Unknown: BooruApp.BooruApplication.Log.Log(BooruLog.Category.Files, BooruLog.Severity.Warning, "Unsupported file type: " + entry.path); entry.Status = "Unsupported file type"; CallUpdate(entry); return; case BooruImageType.Image: entry.IsImage = true; entry.IsAnim = false; break; case BooruImageType.Animation: entry.IsImage = true; entry.IsAnim = true; break; case BooruImageType.Video: entry.IsImage = false; entry.IsAnim = true; break; } entry.Status = "Getting MD5"; CallUpdate(entry); entry.MD5 = GetEntryMD5(entry); List <string> tags; bool tagMeExpired = false; ImageDetails details = BooruApp.BooruApplication.Database.GetImageDetails(entry.MD5); if (details != null) { tags = BooruApp.BooruApplication.Database.GetImageTags(entry.MD5); tags.Sort(); entry.TagString = string.Join(" ", tags); var timeSinceUpdate = DateTime.Now.Subtract(details.Updated); double daysSinceUpdate = timeSinceUpdate.TotalDays; entry.LastUpdated = ReadableTimeSpan(details.Updated); // has image a tagme tag and last update was some time ago, ask servers again if (tags.Contains("tagme") && daysSinceUpdate > 30) { tagMeExpired = true; } } else { entry.LastUpdated = "never"; tags = new List <string>(); } entry.Tags = tags; CallUpdate(entry); bool askedServer = false; entry.Status = "Asking plugins..."; CallUpdate(entry); if (BooruApp.BooruApplication.PluginLoader.TagFinderPlugins.FindTagsForFile(entry.path, entry.MD5, tagMeExpired, tags)) { askedServer = true; } CallUpdate(entry); if (details == null) { var tmpPixBuf = PixbufLoader.LoadPixbufAnimationForImage(entry.path, entry.MD5); if (tmpPixBuf != null) { BooruApp.BooruApplication.Database.SetImageSize(entry.MD5, new Point2D(tmpPixBuf.Width, tmpPixBuf.Height)); tmpPixBuf.Dispose(); } } entry.TagString = string.Join(" ", entry.Tags); if (askedServer || details == null || details.Updated.Ticks == 0) { entry.Status = (details == null)?"Adding to DB":"Updating"; CallUpdate(entry); if (details == null || askedServer) { int tries = 1; while (!BooruApp.BooruApplication.Database.AddImageIfNew(entry.path, entry.MD5, entry.TagString, fileType)) { BooruApp.BooruApplication.Log.Log(BooruLog.Category.Files, BooruLog.Severity.Error, "Database error: " + entry.path); entry.Status = string.Format("DB Error. Retrying... {0}", tries); CallUpdate(entry); tries++; Thread.Sleep(1000); } } Queries.Images.UpdateUpdated.Execute(entry.MD5); entry.Status = (details == null)?"Added":"Updated"; CallUpdate(entry); } else { entry.Status = "No change"; CallUpdate(entry); } }