public static selectProgramAppDataFolder ( string filename ) : string | ||
filename | string | |
return | string |
public FileDatabase(bool readOnly) { this.readOnly = readOnly; this.dbConnector = new DBConnector(Constants.selectProgramAppDataFolder(Constants.DbFileName), Constants.FileNodesDefinition); // Connect to metadata regardless so it can be switched on whilst running string mdbPath = Constants.selectProgramAppDataFolder(Constants.MetadataFileName); this.metaDataDbConnector = new DBConnector( mdbPath, Constants.MetadataDefinition, false ); this.dbConnector.ExecuteNonQuery(@"ATTACH DATABASE '" + mdbPath + "' AS mdb;"); }
public void generateWallpaper(long monitor, string[] paths) { // Wallpaper will have exact size of monitors so wallpaper style (Tile, Center, Stretch, Fit, Fill) shouldn't matter string wallpaperPath = Constants.selectProgramAppDataFolder(Constants.WallpaperFileName); Rectangle r = Constants.getDesktopBounds(); Bitmap wallpaper = new Bitmap(r.Width, r.Height); Graphics g = Graphics.FromImage(wallpaper); GraphicsUnit units = GraphicsUnit.Pixel; if (monitor != Screensaver.CM_ALL) { if (File.Exists(wallpaperPath)) { try { Image old = Image.FromFile(wallpaperPath); g.DrawImage(old, old.GetBounds(ref units)); old.Dispose(); } catch (Exception ex) { this.screensaver.showInfoOnMonitors(ex.Message); } } } Color c = (Color) new ColorConverter().ConvertFromString(Convert.ToString(this.screensaver.config.getPersistant("wallpaperBackgroundColour"))); System.Drawing.Brush fill = new System.Drawing.SolidBrush(c); for (int i = 0; i < Screen.AllScreens.Length; i++) { if (monitor == Screensaver.CM_ALL || monitor == i) { bool readSuccess = false; Image image = null; try { image = Image.FromFile(paths[i]); readSuccess = true; } catch (OutOfMemoryException ex) { this.screensaver.monitors[i].showInfoOnMonitor("Out of memory reading '" + paths[i] + "' for wallpaper"); } catch (FileNotFoundException ex) { this.screensaver.monitors[i].showInfoOnMonitor("File not found '" + paths[i] + "' for wallpaper"); } catch (System.ArgumentNullException ex) { this.screensaver.monitors[i].showInfoOnMonitor("No file found for wallpaper"); } if (readSuccess) { float imgRatio = (float)image.Width / (float)image.Height; string path = paths[i]; // Panorama Rectangle bounds; Rectangle backgroundBounds; if (i == 0 && this.screensaver.config.getPersistantBool("stretchPanoramas") && imgRatio >= (this.screensaver.desktopRatio * (1 - Convert.ToDouble(this.screensaver.config.getPersistant("stretchPanoramaTolerance")) / 100))) { // ToDo: Stretch wallpaper parts to fit monitor(s) bounds = this.screensaver.Desktop; i = Screen.AllScreens.Length; } else { bounds = Screen.AllScreens[i].Bounds; } g.FillRectangle(fill, bounds); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; // Draw faded background image or covered front image if (this.screensaver.config.getPersistantBool("wallpaperBackgroundImage") || this.screensaver.config.getPersistantString("wallpaperFitTo") == "cover") { ColorMatrix colorMatrix = new ColorMatrix(); if (this.screensaver.config.getPersistantString("wallpaperFitTo") == "cover") { colorMatrix.Matrix33 = (float)1; } else { colorMatrix.Matrix33 = (float)0.5; } ImageAttributes imageAttributes = new ImageAttributes(); imageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); // Get scaled union of screen and image Rectangle source = Constants.FitIntoBounds(bounds, Rectangle.Round(image.GetBounds(ref units)), true, false); Point[] dest = { bounds.Location, new Point(bounds.Right, bounds.Top), new Point(bounds.Left, bounds.Bottom) }; g.DrawImage(image, dest, source, GraphicsUnit.Pixel, imageAttributes, null); } // Draw font image only if not full cover if (this.screensaver.config.getPersistantString("wallpaperFitTo") != "cover") { g.DrawImage(image, Constants.FitIntoBounds(Rectangle.Round(image.GetBounds(ref units)), bounds, this.screensaver.config.getPersistantBool("wallpaperStretchSmall"), this.screensaver.config.getPersistantString("wallpaperFitTo") == "cover"), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel); } if (this.screensaver.config.getPersistantBool("wallpaperFilenames")) { // ToDo: Get font settings from config.html Font font = new Font("Arial", 10); g.DrawString(path, font, new SolidBrush(Color.Black), bounds.Left + 1, bounds.Top + 1); g.DrawString(path, font, new SolidBrush(Color.White), bounds.Left, bounds.Top); } } } } if (!Directory.Exists(Path.GetDirectoryName(wallpaperPath))) { Cursor.Show(); if (DialogResult.OK != MessageBox.Show("Create folder '" + Path.GetDirectoryName(wallpaperPath) + "'>\n\nOk: Creates folder for backgrounds\nCancel doesn't change background image.", "Installation folder for background not found!", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation)) { return; } Cursor.Hide(); Directory.CreateDirectory(Path.GetDirectoryName(wallpaperPath)); } //try { wallpaper.Save(wallpaperPath, System.Drawing.Imaging.ImageFormat.Bmp); //} catch(Exception ex) {} this.screensaver.config.setPersistant("wallpaperLastChange", Convert.ToString(DateTime.Today)); Utils.RunTaskScheduler(@"SetWallpaper", Application.ExecutablePath, "/x \"" + wallpaperPath + "\""); //Wallpaper.setWallpaper(wallpaperPath); }