Beispiel #1
0
 private void Form1_Load(object sender, EventArgs e)
 {
     try
     {
         MyFiles.Log("欢迎使用\n");
         MyFiles.Log("初始化进度条\n");
         MyFiles.Progress         = 1;
         label_Progress.Size      = new Size(1, 42);
         label_Progress.BackColor = Color.DarkGreen;
         label_Progress.Location  = new Point(0, Height - label_Progress.Height);
         this.KeyPreview          = true;
         //MyFiles.Init();
         label_Path.Text      = MyFiles.Path_Save;
         myFiles              = new MyFiles();
         FindURL              = new Thread(myFiles.GetURLofImage);
         FindURL.IsBackground = true;
         MyFiles.Log("开始搜索图片\n");
         FindURL.Start();
         MyFiles.Log("开始状态检查\n");
         timer_Load.Start();
     }
     catch (Exception ex)
     {
         MyFiles.Log(ex.Message + '\n');
     }
 }
Beispiel #2
0
        public void FindUpdate()
        {
            try
            {
                WebClient wc = new WebClient();

                string NewVersion = wc.DownloadString("http://bybz.tech/html/version/beta");
                if (NewVersion != null)
                {
                    BetaVersion = NewVersion;
                }
                else
                {
                    BetaVersion = "error";
                }
                MyFiles.Log("BetaVersion: " + BetaVersion + "\n");

                NewVersion = wc.DownloadString("http://bybz.tech/html/version/release");
                if (NewVersion != null)
                {
                    ReleaseVersion = NewVersion;
                }
                else
                {
                    ReleaseVersion = "error";
                }
                MyFiles.Log("ReleaseVersion: " + ReleaseVersion + "\n");
            }
            catch
            {
                BetaVersion    = "error";
                ReleaseVersion = "error";
                MyFiles.Log("检查更新时出现异常");
            }
        }
Beispiel #3
0
        }//开始下载

        private void Download()
        {
            try
            {
                if (MyFiles.Picture != null)
                {
                    MyFiles.Save();
                    if (!IfSaved())
                    {
                        if (MyFiles.Download() != null)
                        {
                            MyFiles.Save();
                            IfSaved();
                        }
                        else
                        {
                            MyFiles.Log("收藏失败\n");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.HResult == -2147467259)
                {
                    MyFiles.Log("该收藏目录需要管理员权限\n");
                }
                else
                {
                    MyFiles.Log(ex.Message + '\n');
                }
            }
        }
Beispiel #4
0
 private void timer_Refresh_Tick(object sender, EventArgs e)
 {
     if (tried == 0)
     {
         ++tried;
         Form_Hide();
         About.Show("您与必应之间的连接可能出了点问题", @"iexplore.exe", @"http://cn.bing.com/", "测试一下");
         Form_Show();
     }
     webBrowser1.Refresh();
     MyFiles.Log("抓取失败,重新抓取\n");
 }
Beispiel #5
0
 private void 必应中国ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         About.Show("壁纸图片来自必应中国,\n请依照微软中国相关协议使用,\n如若违反,\n本工具作者不承担任何责任。", "explorer", @"http://cn.bing.com/", "必应中国");
         //System.Diagnostics.Process.Start("explorer.exe", @"http://cn.bing.com/");
     }
     catch (Exception ex)
     {
         MyFiles.Log(ex.Message + '\n');
     }
 }
Beispiel #6
0
 private void 检查更新ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     try
     {
         ((ToolStripItem)sender).Enabled = false;
         ((ToolStripItem)sender).Text    = "正在检查";
         FindLatest = new Thread(FindUpdate);
         FindLatest.IsBackground = true;
         FindLatest.Start();
         MyFiles.Log("开始检查更新\n");
     }
     catch (Exception ex)
     {
         MyFiles.Log(ex.Message + '\n');
     }
 }
Beispiel #7
0
 private void OneKeyWork()
 {
     if (Program.OneKey)
     {
         string filepath = System.IO.Path.GetTempPath() + @"\tmp.tmp";
         try
         {
             MyFiles.Picture.Save(filepath, System.Drawing.Imaging.ImageFormat.Bmp);
             SystemParametersInfo(20, 0, filepath, 0x2);
             Application.Exit();
         }
         catch (Exception ex)
         {
             MyFiles.Log(ex.Message + '\n');
         }
     }
 }
Beispiel #8
0
 private void timer_Load_Tick(object sender, EventArgs e)
 {
     //处理进度条
     label_Progress.Size = new Size(Width * MyFiles.Progress / 6, 42);
     if (9 < MyFiles.Getted && MyFiles.Getted <= 18)
     {
         if (label_Progress.BackColor != Color.Yellow)
         {
             label_Progress.BackColor = Color.Yellow;
         }
     }
     else if (18 < MyFiles.Getted && MyFiles.Getted <= 27)
     {
         if (label_Progress.BackColor != Color.OrangeRed)
         {
             label_Progress.BackColor = Color.OrangeRed;
         }
     }
     else if (MyFiles.Getted > 27)
     {
         if (label_Progress.BackColor != Color.Red)
         {
             label_Progress.BackColor = Color.Red;
         }
     }
     else
     {
         ;
     }
     if (MyFiles.Progress == 6)
     {
         if (label_Progress.Visible)
         {
             label_Progress.Visible = false;
         }
     }
     HTML2URLAndInfo();
     //更新Log
     if (richTextBox_Logs.Text != MyFiles.Log())
     {
         richTextBox_Logs.Text = MyFiles.Log();
     }
 }
Beispiel #9
0
 private void label_Path_Click(object sender, EventArgs e)
 {
     try
     {
         if (Directory.Exists(MyFiles.Path_Save))
         {
             System.Diagnostics.Process.Start("explorer.exe", MyFiles.Path_Save);
         }
         else
         {
             Directory.CreateDirectory(MyFiles.Path_Save);
             System.Diagnostics.Process.Start("explorer.exe", MyFiles.Path_Save);
         }
     }
     catch (Exception ex)
     {
         MyFiles.Log(ex.Message + '\n');
     }
 }
Beispiel #10
0
 private void SetWallpaper()
 {
     try
     {
         Download();
         MyFiles.SetWallpaper();
     }
     catch (Exception ex)
     {
         if (ex.HResult == -2147467259)
         {
             MyFiles.Log("当前的收藏目录需要更高权限,建议您更改收藏目录。如果一定要在此目录,请将本程序以管理员方式启动。\n");
         }
         else
         {
             MyFiles.Log(ex.Message + '\n');
         }
     }
 }
Beispiel #11
0
 private void label_ChooseFolder_Click(object sender, EventArgs e)
 {
     MyFiles.Set_Path_Save();
     if (label_Path.Text != MyFiles.Path_Save)
     {
         MessageBoxButtons mbb = MessageBoxButtons.OKCancel;
         DialogResult      dr  = MessageBox.Show("请问您是否需要将已收藏壁纸全部复制到新的目录?", "对了", mbb);
         if (dr == DialogResult.OK)
         {
             Process          process   = new Process();//创建进程对象
             string           command   = "copy /y " + label_Path.Text + "\\*.jpg " + MyFiles.Path_Save + "\\";
             ProcessStartInfo startInfo = new ProcessStartInfo();
             startInfo.FileName               = "cmd.exe";       //设定需要执行的命令
             startInfo.Arguments              = "/C " + command; //“/C”表示执行完命令后马上退出
             startInfo.UseShellExecute        = false;           //不使用系统外壳程序启动
             startInfo.RedirectStandardInput  = false;           //不重定向输入
             startInfo.RedirectStandardOutput = true;            //重定向输出
             startInfo.CreateNoWindow         = true;            //不创建窗口
             process.StartInfo = startInfo;
             try
             {
                 if (process.Start())//开始进程
                 {
                     process.WaitForExit();
                 }
             }
             catch (Exception ex)
             {
                 MyFiles.Log(ex.Message + '\n');
             }
             finally
             {
                 if (process != null)
                 {
                     process.Close();
                 }
             }
         }
     }
     label_Path.Text = MyFiles.Path_Save;
     IfSaved();
 }
Beispiel #12
0
        private void HTML2URLAndInfo()
        {
            try
            {
                //抓取图片信息
                HtmlDocument html = webBrowser1.Document;
                if (html != null)
                {
                    //HtmlElement bgDiv = html.GetElementById("bgDiv");
                    HtmlElement hplaT = html.GetElementById("hplaT");

                    ////获取图片URL
                    //if (bgDiv != null)
                    //{
                    //    string style = bgDiv.Style;//包含壁纸地址的div
                    //    if (style != null)
                    //    {
                    //        MyFiles.HTML = style;
                    //    }
                    //}
                    MyFiles.HTML = webBrowser1.DocumentText;

                    //抓取信息
                    HtmlElement sh_cp = html.GetElementById("sh_cp");
                    if (sh_cp != null)
                    {
                        if (图片信息ToolStripMenuItem.Enabled == false)
                        {
                            string info = sh_cp.GetAttribute("title");
                            if (info != null)
                            {
                                MyFiles.Information           = info;
                                图片信息ToolStripMenuItem.Enabled = true;//使查看图片信息按钮可用
                                MyFiles.Log("抓取到图片信息\n" + MyFiles.Information + '\n');
                            }
                        }
                    }
                    //抓取信息2
                    if (hplaT != null)
                    {
                        if (图片信息ToolStripMenuItem.Enabled == false)
                        {
                            HtmlElement hplaTtl = hplaT.FirstChild;
                            if (hplaTtl != null)
                            {
                                HtmlElement tmp = hplaTtl.NextSibling;
                                if (tmp != null)
                                {
                                    HtmlElement first = tmp.FirstChild;
                                    if (first != null)
                                    {
                                        HtmlElement next = first.NextSibling;
                                        if (next != null)
                                        {
                                            string title    = hplaTtl.InnerText; //标题
                                            string location = next.InnerText;    //拍摄地
                                            if (title != null && location != null)
                                            {
                                                if (!图片信息ToolStripMenuItem.Enabled)
                                                {
                                                    MyFiles.Information           = title + '\n' + location;
                                                    图片信息ToolStripMenuItem.Enabled = true;//使查看图片信息按钮可用
                                                    MyFiles.Log("抓取到图片信息\n" + MyFiles.Information + '\n');
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                //显示图片
                if (MyFiles.Picture != null)
                {
                    if (pictureBox1.Image == null)
                    {
                        MyFiles.Log("抓取到图片\n");
                        pictureBox1.Image = MyFiles.Picture;
                        EnableLabels();
                        OneKeyWork();
                    }
                }

                //停止timer_refresh
                if (pictureBox1.Image != null && MyFiles.Information != null && MyFiles.Information != "")
                {
                    if (timer_Refresh.Enabled)
                    {
                        timer_Refresh.Stop();
                        MyFiles.Log("停止抓取\n");
                    }
                }

                //检查新版本
                if (BetaVersion != "" && ReleaseVersion != "")
                {
                    //去掉可能存在的换行符
                    if (BetaVersion[BetaVersion.Length - 1] == '\n')
                    {
                        BetaVersion = BetaVersion.Substring(0, BetaVersion.Length - 1);
                    }
                    if (ReleaseVersion[ReleaseVersion.Length - 1] == '\n')
                    {
                        ReleaseVersion = ReleaseVersion.Substring(0, ReleaseVersion.Length - 1);
                    }
                    MyFiles.Log("LocalVersion: " + myVersion + "\n");

                    if (myVersion != BetaVersion && myVersion != ReleaseVersion)
                    {
                        string Version;
                        if (BetaVersion != "error")
                        {
                            Version = BetaVersion;
                        }
                        else
                        {
                            Version = ReleaseVersion;
                        }

                        string info = Version;
                        Form_Hide();
                        检查更新ToolStripMenuItem.Text    = "检查更新";
                        检查更新ToolStripMenuItem.Enabled = true;
                        if (Version == "error")
                        {
                            About.Show("更新检查貌似出了点问题\n" + info, @"explore", @"http://bybz.tech/html/jump/fromupdate.html", "手动检查");
                        }
                        else
                        {
                            About.Show("已检查到更新版本\n" + info, @"explore", @"http://bybz.tech/html/jump/fromupdate.html", "立即更新");
                        }
                        Form_Show();
                        检查更新ToolStripMenuItem.Text    = "检查更新";
                        检查更新ToolStripMenuItem.Enabled = true;
                    }
                    else
                    {
                        MyFiles.Log("不存在更新版本\n");
                        检查更新ToolStripMenuItem.Text = "暂无更新";
                    }
                    BetaVersion    = "";
                    ReleaseVersion = "";
                }
            }
            catch (Exception ex)
            {
                MyFiles.Log(ex.Message + '\n');
            }
        }