private void checkBox1_CheckedChanged(object sender, EventArgs e) { //开机启启 if (checkBox1.Checked) { string taskname = "one_fuck_one_tu"; if (!OnBoot.TaskIsExists(taskname)) { if (UserAdmin.AdminIsExists()) { string strAssName = Application.ExecutablePath; OnBoot.TaskCreate(taskname, strAssName); } else { //重启获取管理员权限 UserAdmin.Upgrade(); } } } else { string taskname = "one_fuck_one_tu"; if (OnBoot.TaskIsExists(taskname)) { if (UserAdmin.AdminIsExists()) { OnBoot.DeleteTask(taskname); } else { //重启获取管理员权限 UserAdmin.Upgrade(); } } } }
public Form1(string[] args) { InitializeComponent(); //取启动参数 this.arg = args; //设置窗口大小 PxProcessing(1.5); //创建htmllabel htmlLabel = new TheArtOfDev.HtmlRenderer.WinForms.HtmlLabel(); htmlLabel.Dock = DockStyle.Bottom; htmlLabel.AutoSizeHeightOnly = true; htmlLabel.BorderStyle = BorderStyle.Fixed3D; //string zheng = @"(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?.jpg"; string zheng = "\"url\":(.*?(jpg|jpeg|gif|png))"; string url = "http://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1"; UrlProcessing up = new UrlProcessing(); string content = up.UrlParsing(url, zheng, 0); //截取地址 string zurl = content.Substring(7); content = "http://www.bing.com" + zurl; if (content != null) { //分辨率设置 if (!Settings.Default.Resolution) { content = content.Replace("1920x1080", "1366x768"); } try { //将图片并显示到pictureBox上 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(content); Stream s = request.GetResponse().GetResponseStream(); pictureBox1.Image = Image.FromStream(s); s.Dispose(); //释放资源 //讲图片保存到配置路径作为缓存 string SettingPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\OneFuckOneTu"; string cachePath = SettingPath + "\\CacheImage.jpg"; //不存在路径就创建 if (!Directory.Exists(SettingPath)) { Directory.CreateDirectory(SettingPath); } pictureBox1.Image.Save(cachePath); } catch (Exception) { htmlLabel.Text = "<span><div style='padding: 3px 5px; '>" + "出现异常,请尝试重新打开软件" + "</div></span>"; pictureBox1.Controls.Add(htmlLabel); htmlLabel.Visible = true; return; } //取美图故事 url = "http://cn.bing.com/cnhp/coverstory/"; zheng = "\"para1\":\"(?<para1>.*?)\",\"para2\":\""; content = up.UrlParsing(url, zheng, 1); htmlLabel.Text = "<span><div style='padding: 3px 5px; line-height:23px;'>" + content + "</div></span>"; pictureBox1.Controls.Add(htmlLabel); //取配置处理 UserConfigProcessing(); } else { //为空则判断是否有网络 if (UrlProcessing.ping()) { htmlLabel.Text = "<span><div style='padding: 3px 5px; '>" + "有网络但下载图片失败,请尝试重新打开软件" + "</div></span>"; } else { htmlLabel.Text = "<span><div style='padding: 3px 5px; '>" + "无网络链接,图片获取失败" + "</div></span>"; } pictureBox1.Controls.Add(htmlLabel); htmlLabel.Visible = true; } //判断是否修改标题栏 if (UserAdmin.AdminIsExists()) { this.Text = "Bing每日美图 ( 管理员模式 )"; } else { this.Text = "Bing每日美图"; } }