Exemple #1
0
        private void picBoxClick(int index)
        {
            if (bPictureDownloaded[index])
            {
                bool bSucc = BingImage.setWallpaper(strPicTempPath[index]);
                if (bSucc)
                {
                    bWallpaperApplied = true;
                }
                else
                {
                    bWallpaperApplied = false;
                    MessageBox.Show("!!!>:( \n只支持Win7以上操作系统!", "Bing每日壁纸",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                this.notifyIcon.Text = "Bing每日壁纸";
            }

            if (Settings.AutoExit && bWallpaperApplied)
            {
                this.Close();
            }
        }
Exemple #2
0
        private void updateWorkerThread()
        {
            while (!Settings.AutoExit)
            {
                Thread.Sleep(TimeSpan.FromSeconds(10.0));
            }

            loadSettings();
            bWallpaperApplied = false;

            BingImage bing = new BingImage(356, cachePath);

            updateNotifyIconText("Bing每日壁纸(正在更新今日壁纸)");

            for (int i = 0; i < TOTAL; i++)
            {
                if (bStopWorker)
                {
                    break;
                }

                if (updateIndexOnly != -1 && i != updateIndexOnly)
                {
                    continue;
                }

                updateDateLabel(i, getTodayDateString(strLocale[i]));

                if (updateIndexOnly == -1 && !bUpdateAll && i >= 2)
                {
                    continue;
                }

                try
                {
                    bPictureDownloaded[i] = false;
                    strPicTempPath[i]     = Path.Combine(this.tempPath,
                                                         getTodayDateString(strLocale[i]) + "-" + strLocale[i] + ".jpg");

                    if (!File.Exists(strPicTempPath[i]))
                    {
                        //try to download
                        ImageInfo info = bing.getTodayImageInfo(strLocale[i]);
                        if (info != null)
                        {
                            BingImage.DownloadFile(info.url, strPicTempPath[i]);
                            Settings.Title(strLocale[i], info.title);
                            Settings.Copyright(strLocale[i], info.copyright);
                        }
                    }

                    if (File.Exists(strPicTempPath[i]))
                    {
                        bPictureDownloaded[i] = true;
                        showRefreshButton(false, i);
                        pics[i].Invoke(new MethodInvoker(
                                           () =>
                        {
                            string caption = "点击设置为壁纸";
                            string captionTemp;
                            string picTitle = Settings.Title(strLocale[i]);

                            if (!String.IsNullOrEmpty(picTitle))
                            {
                                captionTemp = picTitle;

                                string picCopyright = Settings.Copyright(strLocale[i]);
                                if (picCopyright != "")
                                {
                                    captionTemp += (" " + picCopyright);
                                }

                                caption = captionTemp + Environment.NewLine + Environment.NewLine + caption;
                            }

                            infoTooltip.SetToolTip(pics[i], caption);

                            pics[i].Image = Image.FromFile(strPicTempPath[i]);
                        }));
                    }
                    else
                    {
                        updateNotifyIconText("Bing每日壁纸(网络异常,请稍后重试)");
                        showRefreshButton(true, i);
                    }
                }
                catch
                {
                    updateNotifyIconText("Bing每日壁纸(网络异常,请稍后重试)");
                    showRefreshButton(true, i);
                }

                Thread.Sleep(TimeSpan.FromSeconds(1.0));
            }

            bing.trimTemp(this.tempPath, dwTrimTemp);
        }