static int Main(string[] args) { SysCall.EnableDpiAwareness(); Console.WriteLine("Hello in Roller v0.2 I will choose proper wallpaper for you (in terms of your primary screen resolution)"); ; // args = new[] {"https://picsum.photos/1980/1200"}; // Check param string wallPath; if (args.Length == 1) { wallPath = args[0]; } else { Console.WriteLine("You must url to wallpaper as first param! Exiting..."); return(1); } Console.WriteLine($"Downloading wallpaper from { wallPath }"); var downloadTask = DownloadWallpaper(wallPath); while (!downloadTask.IsCompleted) { Console.Write("."); Thread.Sleep(1000); } Console.WriteLine(); var photo = downloadTask.Result; // Setting wallpaper if (Roller.PaintWall(photo, Roller.Style.Center)) { Console.WriteLine("Successfully changed wallpaper to https://picsum.photos/" + downloadTask.Result.PicsumId + "!"); } else { Console.WriteLine("Wallpaper change failed :< (https://picsum.photos/" + downloadTask.Result.PicsumId + ")"); return(4); } try { File.Delete(photo.TempPath); } catch { //ignored } return(0); }
public static bool PaintWall(PicsumPhoto photo, Style style) { var primaryFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); string destWallFilePath = Path.Combine(primaryFolder + @"\Microsoft\Windows\Themes", photo.PicsumId + ".jpg"); Image img = null; Bitmap imgTemp = null; try { img = Image.FromFile(Path.GetFullPath(photo.TempPath)); imgTemp = new Bitmap(img); imgTemp.Save(destWallFilePath, System.Drawing.Imaging.ImageFormat.Jpeg); img.Dispose(); Console.WriteLine("Wallpaper saved to primary path: " + destWallFilePath); } catch (Exception e1) { Console.WriteLine(e1); try { var secondaryFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); destWallFilePath = Path.Combine(secondaryFolder, "rollerWallpaper.bmp"); imgTemp.Save(destWallFilePath, System.Drawing.Imaging.ImageFormat.Bmp); Console.WriteLine("Wallpaper saved to secondary path: " + destWallFilePath); } catch (Exception e2) { Console.WriteLine(e2); return(false); } } try { RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true); if (style == Style.Fill) { key.SetValue(@"WallpaperStyle", 10.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == Style.Fit) { key.SetValue(@"WallpaperStyle", 6.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == Style.Span) // Windows 8 or newer only! { key.SetValue(@"WallpaperStyle", 22.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == Style.Stretch) { key.SetValue(@"WallpaperStyle", 2.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } if (style == Style.Tile) { key.SetValue(@"WallpaperStyle", 0.ToString()); key.SetValue(@"TileWallpaper", 1.ToString()); } if (style == Style.Center) { key.SetValue(@"WallpaperStyle", 0.ToString()); key.SetValue(@"TileWallpaper", 0.ToString()); } SysCall.SetSystemWallpaper(destWallFilePath); return(true); } catch (Exception e) { Console.WriteLine(e); return(false); } }
static int Main(string[] args) { SysCall.EnableDpiAwareness(); Console.WriteLine("Hello in Roller v0.2 I will choose proper wallpaper for you (in terms of your primary screen resolution)"); // Check param string wallPath; if (args.Length == 1) { wallPath = args[0]; } else { Console.WriteLine("You must supply path to wallpapers as first param! Exiting..."); return(1); } // Get wallpaper files var wallpaperCandidates = Hunter.GetWallTuples(wallPath); if (wallpaperCandidates == null) { Console.WriteLine("Incorrect / inaccessible path supplied! Exiting..."); return(2); } if (wallpaperCandidates.Count == 0) { Console.WriteLine("No files matching '<something>_<ResX>x<ResY>.jpg' found! Exiting..."); return(3); } // Get screen resolution var mainScreenResX = Screen.PrimaryScreen.Bounds.Width; var mainScreenResY = Screen.PrimaryScreen.Bounds.Height; Console.WriteLine("Primary screen resolution is: " + mainScreenResX + "x" + mainScreenResY); // Try to find proper resolution string thePathOfTheChosenOne; var theChosenOne = wallpaperCandidates.FirstOrDefault(x => (x.xRes == mainScreenResX && x.yRes == mainScreenResY)); if (!string.IsNullOrEmpty(theChosenOne.fullPath)) { // It's Neo! thePathOfTheChosenOne = theChosenOne.fullPath; Console.WriteLine("Found perfect match - " + thePathOfTheChosenOne); } else { // So maybe there is 1024x768 Neo? theChosenOne = wallpaperCandidates.FirstOrDefault(x => (x.xRes == 1024 && x.yRes == 768)); if (!string.IsNullOrEmpty(theChosenOne.fullPath)) { // We are saved! thePathOfTheChosenOne = theChosenOne.fullPath; Console.WriteLine("Perfect match not found but default resolution found - " + thePathOfTheChosenOne); } else { // Ehh... so a first one will be Neo! theChosenOne = wallpaperCandidates.FirstOrDefault(); thePathOfTheChosenOne = theChosenOne.fullPath; Console.WriteLine("Perfect res nor default res not found so choosing first - " + thePathOfTheChosenOne); } } // Now the ceremony if (Roller.PaintWall(thePathOfTheChosenOne, Roller.Style.Center)) { Console.WriteLine("Successfully changed wallpaper to " + thePathOfTheChosenOne + "!"); return(0); } else { Console.WriteLine("Wallpaper change failed :< (" + thePathOfTheChosenOne + ")"); return(4); } }