public static void NextBackground() { int index; int interval; string path; // Read registry values using (var key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true)) { index = (int)key.GetValue("WWU CurrentIndex", -1); interval = (int)key.GetValue("WWU CurrentInterval", 0); path = (string)key.GetValue("WWU CurrentDir", null); } if (path == null || interval == 0) { throw new Exception("No slideshow currently in progress"); } // Get the current images in the given directory string[] images = GetBackgroundsInFolder(path); // Wrap index if (++index >= images.Length) { index = 0; } // Set blank if no images in folder if (images.Length == 0) { WallpaperInterop.SetWallpaper("", PicturePosition.Center, false); } // Otherwise set background to the next image else { var pos = WallpaperInterop.GetWallpaperPosition(); WallpaperInterop.SetWallpaper(images[index], pos, false); } // Save registry values using (var key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true)) { key.SetValue("WWU CurrentIndex", index); key.SetValue("WWU CurrentInterval", interval); key.SetValue("WWU CurrentDir", path); } }
static void Main(string[] args) { try { // Output current wallpaper details if (args.Length == 0) { Console.WriteLine("Current Wallpaper "); Console.WriteLine("\t Filepath: \"{0}\"", WallpaperInterop.GetWallpaperFilepath()); Console.WriteLine("\t Position: {0}", WallpaperInterop.GetWallpaperPosition()); Console.WriteLine("Current login background "); Console.WriteLine("\t Filepath: \"{0}\"", WallpaperInterop.GetLoginBGFilepath()); } // Output usage info else if (args.Contains("/?")) { Program.printUsage(); } // Handle just next background else if (args[0] == "/next") { SlideshowHelper.NextBackground(); } // Handle just endshow else if (args[0] == "/endshow") { SlideshowHelper.CancelSlideshow(); } else if (args[0] == "/login") { if (args.Length == 1) { Program.errorOut("Expected path for option '/login'"); } WallpaperInterop.SetLoginBG(args[1]); } // Perform wallpaper change else { string path = args[0]; var opts = new ProgramOptions(args); // End show as requested if (opts.EndShow) { SlideshowHelper.CancelSlideshow(); } if (opts.Slideshow) { // Begin slideshow SlideshowHelper.BeginSlideshow(path, opts.Position, opts.ShowInterval, opts.ShowIndex); } else { // Get random image if selecting from directory if (opts.Directory) { string[] walls = SlideshowHelper.GetBackgroundsInFolder(path); path = walls[new Random().Next(0, walls.Length)]; } // Call interop code WallpaperInterop.SetWallpaper(path, opts.Position, opts.Copy); } } } catch (Exception e) { errorOut(e.Message); } }