/// <summary> /// 下一张壁纸 /// </summary> private void NextWallpaper() { try { timerW.Stop(); LogHelper.WriteLog("更换壁纸", EnumLogLevel.Info); ImgInfo imgInfo = imgHelper.GetNextImage(); if (UserDataManage.IsDislike(imgInfo.Id)) { imgInfo = imgHelper.GetNextImage(); } string imgFullName = System.IO.Path.Combine(ConfigManage.Base.CachePath, imgInfo.GetFileName()); if (!File.Exists(imgFullName)) { // 判断下载目录中是否存在 imgFullName = System.IO.Path.Combine(ConfigManage.Base.DownPath, imgInfo.GetFileName()); if (!File.Exists(imgFullName)) { WebHelper.DownImage(imgInfo.url, imgFullName); } } if (File.Exists(imgFullName)) { Common.WinApi.SetWallpaper(imgFullName); UserDataManage.AddRecord(RecordType.AutoWallpaper, imgInfo); ConfigManage.Wallpaper.ReplaceLastTime = DateTime.Now; ConfigManage.Save(); } timerW.Start(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 壁纸上动态显示的按钮点击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Btn_Click(object sender, RoutedEventArgs e) { Button btn = sender as Button; if (btn == null) { return; } ImgInfo imgInfo; if ((btn.Parent as StackPanel).Tag is ImgInfo info) { imgInfo = info; } else { imgInfo = this.GetimgInfo((btn.Parent as StackPanel).Tag); } switch (btn.Name) { case "btn_down": { if (btn.Foreground == Brushes.White) { btn.IsEnabled = false; string imgFullName = System.IO.Path.Combine(this.DownPath, imgInfo.GetFileName()); if (!System.IO.File.Exists(imgFullName)) { System.Drawing.Image img = WebHelper.GetImage(imgInfo.url); img.Save(imgFullName); img.Dispose(); } btn.Foreground = Brushes.Red; btn.IsEnabled = true; Growl.Success("下载成功。"); UserDataManage.SetDown(imgFullName, imgInfo); if (btn_love.Foreground == Brushes.White) { UserDataManage.SetLove(LoveType.Love, imgInfo); btn_love.Foreground = Brushes.Red; btn_dislike.Foreground = Brushes.White; } } } break; case "btn_wallpaper": { if (btn.Foreground == Brushes.White) { btn.IsEnabled = false; string imgFullName = System.IO.Path.Combine(this.CachePath, imgInfo.GetFileName()); if (!System.IO.File.Exists(imgFullName)) { System.Drawing.Image img = WebHelper.GetImage(imgInfo.url); img.Save(imgFullName); img.Dispose(); } if (System.IO.File.Exists(imgFullName)) { WinApi.SetWallpaper(imgFullName); btn.Foreground = Brushes.Red; Growl.Success("壁纸设置成功。"); btn.IsEnabled = true; UserDataManage.AddRecord(RecordType.ManualWallpaper, imgInfo); } else { Growl.Error("未找到壁纸文件,壁纸设置失败。"); } } } break; case "btn_love": { if (btn.Foreground == Brushes.White) { UserDataManage.SetLove(LoveType.Love, imgInfo); btn.Foreground = Brushes.Red; btn_dislike.Foreground = Brushes.White; } } break; case "btn_dislike": { if (btn.Foreground == Brushes.White) { UserDataManage.SetLove(LoveType.Dislike, imgInfo); btn.Foreground = Brushes.Red; btn_love.Foreground = Brushes.White; } } break; } }
private void Btn_Click(object sender, RoutedEventArgs e) { Button btn = sender as Button; if (btn == null) { return; } ImgInfo imgInfo = (btn.Parent as StackPanel).Tag as ImgInfo; switch (btn.Name) { case "btn_down": { if (btn.Foreground == Brushes.White) { string imgFullName = System.IO.Path.Combine(this.DownPath, imgInfo.GetFileName()); if (!System.IO.File.Exists(imgFullName)) { System.Drawing.Image img = WebHelper.GetImage(imgInfo.url); img.Save(imgFullName); img.Dispose(); } btn.Foreground = Brushes.Red; UserDataManage.SetDown(imgFullName, imgInfo); Growl.Success("下载成功。"); if (btn_love.Foreground == Brushes.White) { UserDataManage.SetLove(LoveType.Love, imgInfo); btn_love.Foreground = Brushes.Red; btn_dislike.Foreground = Brushes.White; } } } break; case "btn_wallpaper": { if (btn.Foreground == Brushes.White) { string imgFullName = System.IO.Path.Combine(this.CachePath, imgInfo.GetFileName()); if (!System.IO.File.Exists(imgFullName)) { System.Drawing.Image img = WebHelper.GetImage(imgInfo.url); img.Save(imgFullName); img.Dispose(); } WinApi.SetWallpaper(imgFullName); btn.Foreground = Brushes.Red; Growl.Success("壁纸设置成功。"); UserDataManage.AddRecord(RecordType.ManualWallpaper, imgInfo); } } break; case "btn_love": { if (btn.Foreground == Brushes.White) { UserDataManage.SetLove(LoveType.Love, imgInfo); btn.Foreground = Brushes.Red; btn_dislike.Foreground = Brushes.White; } } break; case "btn_dislike": { if (btn.Foreground == Brushes.White) { UserDataManage.SetLove(LoveType.Dislike, imgInfo); btn.Foreground = Brushes.Red; btn_love.Foreground = Brushes.White; this.EffectPicture(null, null); } } break; } }