private void applyBT_Click(object sender, EventArgs e) { if (pictureBox1.Image == null || pictureBox1 == null) { MessageBox.Show("No image selected"); } else { string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Wallpaper Changer\res"; Wallpaper.ChangeWallpaper(path, true); MessageBox.Show("Wallpaper Applied!"); } }
static void Main(string[] args) { string apikey = ""; if (args.Length == 0) { Console.WriteLine("Please set Unsplash API Key in first arg."); return; } else { apikey = args[0]; } var client = new UnsplasharpClient(apikey); Unsplasharp.Models.Photo randomPhoto = null; string imagePath = ""; Task task = Task.Factory.StartNew(async() => { randomPhoto = await client.GetRandomPhoto(); }).Unwrap(); task.Wait(); // %TEMP%に保存 // imagePath = Path.GetTempPath() + randomPhoto.Id + ".jpg"; // jpg決め打ちでいいのかな・・・ WebClient wc = new WebClient(); wc.DownloadFile(randomPhoto.Links.Download, imagePath); Wallpaper.SetWallpaper(imagePath, WallpaperStyle.ResizeFill); // Wallpaper.UnsetWallpaper(); Console.WriteLine("Set Wallpaper."); }
private void SetNextWallpaper(Action callback) { if (!_wallpaperFiles.Any()) { var wallpaperPath = Settings.Default.WallpaperPath; if (!Directory.Exists(wallpaperPath)) { return; } var files = Directory.GetFiles(wallpaperPath, "*", SearchOption.AllDirectories).ToList(); _wallpaperFiles.AddRange(files); } var tileType = (Style)Settings.Default.SelectedStyle; var file = GetNewWallpaperFile(); Wallpaper.SetRandomWallpaperFromPath(file, tileType); CurrentWallpaper = file.ToString(); _history.Push(file.ToString()); callback(); }
static int Main(string[] args) { String help = "\nCopyright (c) 2005-" + DateTime.Now.Year.ToString() + " Phillip Hansen http://sg20.com (version 1.8)\n" + "Source available at: https://github.com/philhansen/WallpaperChanger\n\nSyntax is: <file|directory> <style> <location>\n\n" + " <file> is the complete path to the file\n" + " <directory> is the complete path to a directory containing image files\n" + " a random image from the directory will be set as the background\n" + " <style> is an integer (if no style is specified it defaults to Stretched):\n" + " 0 for Tiled\n 1 for Centered\n 2 for Stretched\n 3 for Fit (Windows 7 or later)\n 4 for Fill (Windows 7 or later)\n" + " <location> is the complete path to a directory for storing the generated file\n" + " defaults to the temp folder which should be fine in most cases"; help += "\n\nIf the style argument is not specified it will default to Stretched."; help += "\n\nOptional flags:\n" + " -h, -help - Display the usage help\n" + " -r, -remove - Remove the current wallpaper\n" + " -m, -monitor <index> - Set the image on the specified monitor (0 indexed)\n" + " When using this option the full syntax is:\n" + " -m <index> <file|directory> <location>"; help += "\n\nAlternatively a config file can be placed in the same directory as the WallpaperChanger executable. " + "The file should be named 'config' without any file extension. Each line in the file should have the full path " + "to an image and can optionally include the monitor index or the style code to use. If the style is not specified it will default to Stretched." + "\n\nWhen setting the monitor index in the config file the format of the line should be: <file> -m <index>"; help += "\n"; String path = ""; bool usingConfig = false; bool setMonitor = false; int monitorIndex = 0; Style style = Style.Stretched; // default value // Use png file for Win 8 or higher, otherwise use bmp file String fileType = "png"; if (!IsWin8OrHigher()) { fileType = "bmp"; } // get the path to the user's temp folder String storagePath = Path.Combine(Path.GetTempPath(), "wallpaper." + fileType); // check the arguments if (args.Length == 0) { // a config file can be stored in the same directory as the wallpaper changer String configFile = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "config"); if (File.Exists(configFile)) { path = configFile; usingConfig = true; } else { Console.WriteLine(help); return(1); } } if (!usingConfig) { // special check for a help flag if (args[0] == "-h" || args[0] == "--help" || args[0] == "-help") { Console.WriteLine(help); return(1); } // remove wallpaper flag else if (args[0] == "-r" || args[0] == "-remove") { return(Remove()); } // specify monitor else if (args[0] == "-m" || args[0] == "-monitor") { if (!IsWin8OrHigher()) { Console.WriteLine("Specifying a monitor is only supported on Windows 8 or higher\n"); return(1); } if (args.Length < 3) { Console.WriteLine(help); return(1); } setMonitor = true; monitorIndex = int.Parse(args[1]); path = args[2]; } // retrieve file/directory if we are not using config file else { path = args[0]; if (args.Length >= 2) { style = (Wallpaper.Style)Enum.Parse(typeof(Wallpaper.Style), args[1]); } } } int index = (setMonitor) ? 3 : 2; // location directory may be specified if (args.Length >= index + 1) { // make sure it's a directory if (!Directory.Exists(args[index])) { Console.WriteLine("\n{0} is not a valid directory.", args[index]); return(1); } storagePath = Path.Combine(args[index], "wallpaper." + fileType); } if (usingConfig) { String file; ProcessConfig(path, out file, out style, out setMonitor, out monitorIndex); if (file == null) { Console.WriteLine("\nNo valid images found in the config file: {0}", path); return(1); } int status = 0; if (setMonitor) { status = Wallpaper.SetMonitor(monitorIndex, file, storagePath); } else { status = Wallpaper.Set(file, style, storagePath); } if (status == 1) { return(1); } } else if (File.Exists(path)) { int status = 0; if (setMonitor) { status = Wallpaper.SetMonitor(monitorIndex, path, storagePath); } else { status = Wallpaper.Set(path, style, storagePath); } if (status == 1) { return(1); } } else if (Directory.Exists(path)) { String file = ProcessDirectory(path); if (file == null) { Console.WriteLine("\nNo valid images found in {0}.", path); return(1); } int status = 0; if (setMonitor) { status = Wallpaper.SetMonitor(monitorIndex, file, storagePath); } else { status = Wallpaper.Set(file, style, storagePath); } if (status == 1) { return(1); } } else { Console.WriteLine("\n{0} is not a valid file or directory.", path); return(1); } return(0); }
static int Main(string[] args) { String help = "\nCopyright (c) 2014 Phillip Hansen http://sg20.com (version 1.4)\n\nSyntax is: <file|directory> <style> <location>\n\n <file> is the complete path to the file\n <directory> is the complete path to a directory containing image files\n a random image from the directory will be set as the background\n <style> is an integer (if no style is specified it defaults to Stretched):\n 0 for Tiled\n 1 for Centered\n 2 for Stretched\n 3 for Fit (Windows 7 or later)\n 4 for Fill (Windows 7 or later)\n <location> is the complete path to a directory for storing the generated file\n defaults to the temp folder which should be fine in most cases"; help += "\n\nIf the style argument is not specified it will default to Stretched."; help += "\n\nOptional flags:\n -h, -help - Display the usage help\n -r, -remove - Remove the current wallpaper"; help += "\n\nAlternatively a config file can be placed in the same directory as the WallpaperChanger executable. The file should be named 'config' without any file extension. Each line in the file should have the full path to an image and can optionally include the style code to use. If the style is not specified it will default to Stretched."; String path = ""; bool usingConfig = false; // check the arguments if (args.Length == 0) { // a config file can be stored in the same directory as the wallpaper changer String configFile = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "config"); if (File.Exists(configFile)) { path = configFile; usingConfig = true; } else { Console.WriteLine(help); return(1); } } if (!usingConfig) { // special check for a help flag if (args[0] == "-h" || args[0] == "--help" || args[0] == "-help") { Console.WriteLine(help); return(1); } // remove wallpaper flag else if (args[0] == "-r" || args[0] == "-remove") { return(Remove()); } // retrieve file/directory if we are not using config file path = args[0]; } Style style = Style.Stretched; // default value // get the path to the user's temp folder String storagePath = Path.Combine(Path.GetTempPath(), "wallpaper.bmp"); if (args.Length >= 2) { style = (Wallpaper.Style)Enum.Parse(typeof(Wallpaper.Style), args[1]); } if (args.Length == 3) { // make sure it's a directory if (!Directory.Exists(args[2])) { Console.WriteLine("\n{0} is not a valid directory.", args[2]); return(1); } storagePath = Path.Combine(args[2], "wallpaper.bmp"); } if (usingConfig) { String file; ProcessConfig(path, out file, out style); if (file == null) { Console.WriteLine("\nNo valid images found in the config file: {0}", path); return(1); } int status = Wallpaper.Set(file, style, storagePath); if (status == 1) { return(1); } } else if (File.Exists(path)) { int status = Wallpaper.Set(path, style, storagePath); if (status == 1) { return(1); } } else if (Directory.Exists(path)) { String file = ProcessDirectory(path); if (file == null) { Console.WriteLine("\nNo valid images found in {0}.", path); return(1); } int status = Wallpaper.Set(file, style, storagePath); if (status == 1) { return(1); } } else { Console.WriteLine("\n{0} is not a valid file or directory.", path); return(1); } return(0); }
private void Update_Click(object sender, EventArgs e) { Wallpaper.GetWallpaper(); Wallpaper.Update(); }
private void randomizeBT_Click(object sender, EventArgs e) { pictureBox1.Load(Wallpaper.UpdatePictureBox()); }
private void searchBT_Click(object sender, EventArgs e) { // check if the query was just checked, and if they search was successful. DONT allow if true // Takes the key, search q, orietnation string searchQuery = searchQueryTB.Text; string orientation; if (verticalRB.Checked) { orientation = "vertical"; } else { orientation = "horizontal"; } JsonObject response; if (!String.IsNullOrEmpty(searchQuery) && !String.IsNullOrWhiteSpace(searchQuery)) { searchQuery = searchQuery.Trim().Replace(" ", "+"); // removes leading and trailing spaces // replaces spaces in string with + easier for Json query // calls JsonParser // MessageBox.Show(searchQuery + "/'"); response = InfoProcessor.JsonParser(searchQuery, orientation); if (response == null || response.Hits.Count() == 0) { MessageBox.Show("Couldn't find any pictures. Try another search term"); applyBT.Enabled = false; randomizeBT.Enabled = false; } else { applyBT.Enabled = true; randomizeBT.Enabled = true; // Stores the obj that is returned Properties.Settings.Default.imageList = response; Properties.Settings.Default.Save(); JsonObject tempObj = Properties.Settings.Default.imageList; /* * foreach (var item in tempObj.Hits) * { * MessageBox.Show(item.largeImageURL); * } */ // Calls UpdatePictureBox pictureBox1.Load(Wallpaper.UpdatePictureBox()); } } }
public void Execute(IJobExecutionContext context) { Wallpaper.GetWallpaper(); Wallpaper.Update(); }