コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: HaiqTop/HWallpaper
 /// <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);
     }
 }
コード例 #2
0
        private void InitBtnState(ImgInfo imgInfo)
        {
            btn_love.Foreground    = Brushes.White;
            btn_dislike.Foreground = Brushes.White;
            btn_down.Foreground    = Brushes.White;

            Love love = UserDataManage.GetLove(imgInfo.Id);

            if (love != null)
            {
                if (love.Type == 1)
                {
                    btn_love.Foreground = Brushes.Red;
                }
                else if (love.Type == -1)
                {
                    btn_dislike.Foreground = Brushes.Red;
                }
            }
            Download down     = UserDataManage.GetDown(imgInfo.Id);
            string   fullName = System.IO.Path.Combine(this.DownPath, imgInfo.GetFileName());

            if (System.IO.File.Exists(fullName))
            {
                btn_down.Foreground = Brushes.Red;
                if (down == null)
                {
                    down = new Download()
                    {
                        PictureId = imgInfo.Id, Time = DateTime.Now, FullName = fullName, Valid = 1
                    };
                }
                else if (down.Valid == 0)
                {
                    down.Valid = 1;
                }
                UserDataManage.SaveDown(down, imgInfo);
            }
        }
コード例 #3
0
ファイル: ImageList.xaml.cs プロジェクト: HaiqTop/HWallpaper
        /// <summary>
        /// 初始化壁纸上显示的按钮状态
        /// </summary>
        /// <param name="imgInfo"></param>
        private void InitBtnState(ImgInfo imgInfo)
        {
            if (imgInfo == null)
            {
                return;
            }
            btnPanel.Tag             = imgInfo;
            btn_love.Foreground      = Brushes.White;
            btn_wallpaper.Foreground = Brushes.White;
            btn_dislike.Foreground   = Brushes.White;
            btn_down.Foreground      = Brushes.White;

            btnPanel.Visibility = Visibility.Visible;

            Love love = UserDataManage.GetLove(imgInfo.Id);

            if (love != null)
            {
                if (love.Type == 1)
                {
                    btn_love.Foreground = Brushes.Red;
                }
                else if (love.Type == -1)
                {
                    btn_dislike.Foreground = Brushes.Red;
                }
            }
            Download down     = UserDataManage.GetDown(imgInfo.Id);
            string   fullName = System.IO.Path.Combine(this.DownPath, imgInfo.GetFileName());

            if (System.IO.File.Exists(fullName))
            {
                btn_down.Foreground = Brushes.Red;
                UserDataManage.SetDown(fullName, imgInfo);
            }
        }
コード例 #4
0
 private void EffectPicture(object source, ElapsedEventArgs e)
 {
     try
     {
         ImgInfo info = imgHelper.GetNextImage();
         if (UserDataManage.IsDislike(info.Id))
         {
             info = imgHelper.GetNextImage();
         }
         picBox.Dispatcher.BeginInvoke(new Action <Image, ImgInfo>((image, imgInfo) =>
         {
             timerP.Stop();
             imageQueue.Queue(picBox, info);
         }), new Object[] { picBox, info });
     }
     catch (Exception ex)
     {
         Common.LogHelper.WriteLog(ex.Message, Common.EnumLogLevel.Error);
         picBox.Dispatcher.BeginInvoke(new Action <Exception>((exc) =>
         {
             Growl.Error("壁纸切换异常:\n\t" + exc.Message);
         }), new Object[] { ex });
     }
 }
コード例 #5
0
ファイル: ImageList.xaml.cs プロジェクト: HaiqTop/HWallpaper
        /// <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;
            }
        }
コード例 #6
0
        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;
            }
        }