public bool addMetadataToDB(long id, string metadata) { if (this.readOnly) { return(false); } try { long width = 0, height = 0, area = 0; MetadataTemplate mt = new MetadataTemplate(metadata); if (mt.metadata.ContainsKey("imagewidth")) { width = Convert.ToInt32(mt.metadata["imagewidth"]); } if (mt.metadata.ContainsKey("imageheight")) { height = Convert.ToInt32(mt.metadata["imageheight"]); } area = width * height; SQLiteCommand command = new SQLiteCommand("INSERT OR REPLACE INTO `Metadata` (`id`, `all`, `width`, `height`, `area`) VALUES (@id, @metadata, @width, @height, @area);", this.metaDataDbConnector.connection); command.Parameters.AddWithValue("@id", id); command.Parameters.AddWithValue("@metadata", metadata); command.Parameters.AddWithValue("@width", width); command.Parameters.AddWithValue("@height", height); command.Parameters.AddWithValue("@area", area); command.ExecuteNonQuery(); command = new SQLiteCommand("UPDATE `FileNodes` SET `metainfoindexed` = 1 WHERE id = @id;", this.dbConnector.connection); command.Parameters.AddWithValue("@id", id); command.ExecuteNonQuery(); this.filterOutOfDate += 5; } catch (System.Data.SQLite.SQLiteException se) { if (se.ErrorCode == DBConnector.DatabaseIsLocked) { this.readOnly = true; return(false); } } catch (System.FormatException fe) { return(true); } return(true); }
public void readMetadataImage() { if (this.currentImage != null) { //string metadata = ""; string rawMetadata = null; this.imageSettings.Clear(); this.imageSettings["metadata"] = ""; string path = Convert.ToString(this.currentImage["path"]); string root = ""; string filename = Path.GetFileNameWithoutExtension(path); string extension = Path.GetExtension(path); List<string> folders = Utils.stringToList(Convert.ToString(this.screensaver.config.getPersistant("folders"))); foreach (string folder in folders) { if (path.StartsWith(folder)) { root = folder; break; } } // Whatever is leftover are the subfolders string subfolders = path.Substring(root.Length, path.Length - root.Length - filename.Length - extension.Length); this.imageSettings["path.root"] = root; this.imageSettings["path.subfolders"] = subfolders; this.imageSettings["path.filename"] = filename; this.imageSettings["path.extension"] = extension; if (this.currentImage.Table.Columns.Contains("all")) { rawMetadata = Convert.ToString(this.currentImage["all"]); } if (rawMetadata == null || rawMetadata == "") { rawMetadata = this.screensaver.fileNodes.getMetadataById(Convert.ToInt32(this.currentImage["id"])); if (rawMetadata == null) { try { rawMetadata = this.screensaver.fileNodes.exifToolGetMetadata(Convert.ToString(this.currentImage["path"]) + Constants.ExifToolMetadataOptions, Convert.ToInt32(this.currentImage["id"])); } catch (System.IO.FileNotFoundException fnfe) { this.imageSettings["metadata"] = "ExifTool not found: '" + this.screensaver.config.getPersistant("exifTool") + "'"; } catch (Exception e) { this.imageSettings["metadata"] = e.Message; } } } if (rawMetadata != null && rawMetadata != "") { this.quickMetadata = new MetadataTemplate(rawMetadata, Utils.HtmlDecode(this.screensaver.config.getPersistantString("quickMetadata"))); this.imageSettings["metadata"] = this.quickMetadata.fillTemplate(); } this.imageSettings["mediatype"] = "image"; if (Convert.ToString(this.screensaver.config.getPersistant("videoExtensions")).IndexOf(Path.GetExtension(Convert.ToString(this.currentImage["path"]).ToLower())) > -1) { this.imageSettings["mediatype"] = "video"; } switch(Path.GetExtension(Convert.ToString(this.currentImage["path"]).ToLower())) { case ".wmv": case ".avi": this.imageSettings["mediatype"] = "object"; break; } switch (Convert.ToString(this.imageSettings["mediatype"])) { case "image": this.imageSettings["stretchSmallImages"] = this.screensaver.config.getPersistantBool("stretchSmallImages"); int rotate = 0; if (this.screensaver.config.getPersistantBool("exifRotate")) { if (this.quickMetadata != null && this.quickMetadata.metadata.ContainsKey("orientation#")) { switch (Convert.ToInt32(this.quickMetadata.metadata["orientation#"])) { case (int)Constants.Orientation.Rotate_180: rotate = 180; break; case (int)Constants.Orientation.Rotate_90_CW: case (int)Constants.Orientation.Mirror_Horizontal_Rotate_90_CW: rotate = 90; break; case (int)Constants.Orientation.Rotate_270_CW: case (int)Constants.Orientation.Mirror_Horizontal_Rotate_270_CW: rotate = 270; break; } } this.resizeRatio(rotate); if (rotate != 0) { this.imageSettings["exifRotate"] = rotate; } } if (this.quickMetadata != null && this.quickMetadata.metadata.ContainsKey("imagewidth") && this.quickMetadata.metadata.ContainsKey("imageheight")) { int width; int height; try { width = Convert.ToInt32(Regex.Match(this.quickMetadata.metadata["imagewidth"], @"\d+").Value); height = Convert.ToInt32(Regex.Match(this.quickMetadata.metadata["imageheight"], @"\d+").Value); } catch (Exception e) { this.showInfoOnMonitor("Error determining width/height of media:" + Environment.NewLine + e.Message); return; } float imgRatio = (float)width / (float)height; this.imageSettings["width"] = width; this.imageSettings["height"] = height; this.imageSettings["ratio"] = imgRatio; this.imageSettings["backgroundImage"] = this.screensaver.config.getPersistantBool("backgroundImage"); this.imageSettings["imageShadow"] = this.screensaver.config.getPersistantBool("imageShadow"); this.imageSettings["fitTo"] = this.screensaver.config.getPersistantString("fitTo"); bool fitToDimensionHeight; if ((double)this.Bounds.Width / (double)this.Bounds.Height < (double)width / (double)height) { //this.imageSettings["fitToDimension"] = "height"; fitToDimensionHeight = true; } else { //this.imageSettings["fitToDimension"] = "width"; fitToDimensionHeight = false; } if (fitToDimensionHeight) this.imageSettings["fitToDimension"] = "height"; else this.imageSettings["fitToDimension"] = "width"; /* this.imageSettings["smallUnstretchedImage"] = false; if (!this.screensaver.config.getPersistantBool("stretchSmallImages") && width < this.Bounds.Width && height < this.Bounds.Height) { this.imageSettings["smallUnstretchedImage"] = true; }*/ if (rotate != 90 && rotate != 270 && this.screensaver.getNrMonitors() > 1 && this.screensaver.config.getPersistantBool("stretchPanoramas") && imgRatio >= (this.screensaver.desktopRatio * (1 - Convert.ToDouble(this.screensaver.config.getPersistant("stretchPanoramaTolerance"))/100))) { if (this.screensaver.config.getPersistantBool("stretchSmallImages") || width > this.Bounds.Width || height > this.Bounds.Height) { //this.imageSettings["fitToDimension"] = "width"; this.imageSettings["pano"] = true; Rectangle pano, cover; pano = Constants.FitIntoBounds(new Rectangle(0, 0, width, height), this.screensaver.Desktop, this.screensaver.config.getPersistantBool("stretchSmallImages"), this.screensaver.config.getPersistantString("fitTo") == "cover"); cover = Constants.FitIntoBounds(new Rectangle(0, 0, width, height), this.screensaver.Desktop, this.screensaver.config.getPersistantBool("stretchSmallImages"), true); if (this.id != 0 && this.Bounds.Height != this.screensaver.monitors[0].Bounds.Height) { this.imageSettings["pano.top"] = (this.Bounds.Height - pano.Height) / 2; this.imageSettings["pano.cover.top"] = (this.Bounds.Height - cover.Height) / 2; } else { this.imageSettings["pano.top"] = pano.Y - this.Bounds.Y; this.imageSettings["pano.cover.top"] = cover.Y - this.Bounds.Y; } this.imageSettings["pano.width"] = pano.Width; this.imageSettings["pano.left"] = pano.X - this.Bounds.X; this.imageSettings["pano.height"] = pano.Height; this.imageSettings["pano.cover.width"] = cover.Width; this.imageSettings["pano.cover.left"] = cover.X - this.Bounds.X; this.imageSettings["pano.cover.height"] = cover.Height; } } else { for (int i = 0; i < this.screensaver.monitors.Length; i++) { this.screensaver.monitors[i].panoramaPart = false; } } } break; case "object": case "video": this.imageSettings["stretchSmallVideos"] = this.screensaver.config.getPersistantBool("stretchSmallVideos"); this.imageSettings["showcontrols"] = this.screensaver.config.getPersistantBool("showControls"); this.imageSettings["loop"] = this.screensaver.config.getPersistantBool("videosLoop"); this.imageSettings["mute"] = this.screensaver.config.getPersistantBool("videosMute"); this.imageSettings["videosPlay"] = this.screensaver.config.getPersistantString("videosPlay"); break; } } }
public bool addMetadataToDB(long id, string metadata) { if (this.readOnly) return false; try { long width=0, height=0, area=0; MetadataTemplate mt = new MetadataTemplate(metadata); if (mt.metadata.ContainsKey("imagewidth")) width = Convert.ToInt32(mt.metadata["imagewidth"]); if (mt.metadata.ContainsKey("imageheight")) height = Convert.ToInt32(mt.metadata["imageheight"]); area = width * height; SQLiteCommand command = new SQLiteCommand("INSERT OR REPLACE INTO `Metadata` (`id`, `all`, `width`, `height`, `area`) VALUES (@id, @metadata, @width, @height, @area);", this.metaDataDbConnector.connection); command.Parameters.AddWithValue("@id", id); command.Parameters.AddWithValue("@metadata", metadata); command.Parameters.AddWithValue("@width", width); command.Parameters.AddWithValue("@height", height); command.Parameters.AddWithValue("@area", area); command.ExecuteNonQuery(); command = new SQLiteCommand("UPDATE `FileNodes` SET `metainfoindexed` = 1 WHERE id = @id;", this.dbConnector.connection); command.Parameters.AddWithValue("@id", id); command.ExecuteNonQuery(); this.filterOutOfDate+=5; } catch (System.Data.SQLite.SQLiteException se) { if (se.ErrorCode == DBConnector.DatabaseIsLocked) { this.readOnly = true; return false; } } catch (System.FormatException fe) { return true; } return true; }