public static void Run(string cc = null)
        {
            if (Global.Image == null)
            {
                var homepage = new BingHomepage(cc ?? Settings.Fetch("cc"));
                Global.Image = Path.Combine(Global.Directory, $"image-{new Random().Next()}.bw");
                homepage.GetImage(Global.Image);
            }

            using (var registryKey = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true) ??
                                     throw new Exception("Unable to find registry key.")) {
                registryKey.SetValue(@"WallpaperStyle", Global.WallpaperStyle[Settings.Fetch("style")]);
                registryKey.SetValue(@"TileWallpaper", Settings.Fetch("style") == "Tile" ? "1" : "0");
            }

            SystemParametersInfo(20, 0, Global.Image, 0x01 | 0x02);

            new DirectoryInfo(Global.Directory)
            .GetFiles("image-*.bw", SearchOption.TopDirectoryOnly)
            .ToList()
            .ForEach(file => {
                try {
                    File.Delete(file.FullName);
                    Global.Log($"Deleted {file.Name}");
                }
                catch {
                    // ignored
                    Global.Log($"Unable to delete {file.Name}");
                }
            });
        }
Exemple #2
0
        private void LoadImage(string cc)
        {
            Loading.Visible = true;
            BingHomepage homepage = new BingHomepage(cc);

            Global.Image       = Path.Combine(Global.Directory, $"image-{new Random().Next()}.bw");
            imagePreview.Image = homepage.GetImage(Global.Image);
            InfoLabel.Text     = homepage.GetCopyright;
            Loading.Visible    = false;
            Global.Log($"Load image for {cc}");
        }
        public Form1()
        {
            InitializeComponent();
            var data = new BingHomepage();

            pictureBox1.Image = data.GetImage(Path.GetTempFileName());
            label1.Text       = data.GetCopyright;
            linkLabel1.Text   = data.GetCopyrightLink;
            linkLabel1.Click += (s, e) => new Process {
                StartInfo = new ProcessStartInfo(linkLabel1.Text)
            }.Start();
        }