Esempio n. 1
0
        public Download()
        {
            Urlfile = new Registre().ReadRegUrlfile(Urlfile);
            ImgLoc = new Registre().ReadRegImgloc(ImgLoc);

            try
            {
                WebClient wc = new WebClient();// Création d'un objet WebClient (c'est lui qui permet de télécharger un fichier)
                wc.Headers["User-Agent"] = "Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0)" + " (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";// Détermine le User-Agent du WebClient.
                wc.DownloadFile(Urlfile, Application.StartupPath + "\\Temp\\TempWPImg.jpg");// Lancement du téléchargement / argument 1 : url du fichier source / argument 2 : l'emplacement ou enregistrer le fichier sur le disque dur
                wc.Dispose();//Destruction de l'objet WebClient

            #if DEBUG
                int Hour = 8;
                int Minute = 0;
                if ((DateTime.Now.Hour == Hour) && ((DateTime.Now.Minute >= Minute) && (DateTime.Now.Minute <= Minute+21)))
                {
                    System.IO.File.Copy(Application.StartupPath + "\\Temp\\TempWPImg.jpg",
                        Application.StartupPath + @"\SavedImages\Projection\" + DateTime.Now.ToString("yyyy_MM_dd") + String.Format("_{0:D2}_{1:D2}.jpg",Hour,Minute));

                    // Download hemisphere view
                    wc = new WebClient(); // Création d'un objet WebClient (c'est lui qui permet de télécharger un fichier)
                    wc.Headers["User-Agent"] = "Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0)" + " (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";// Détermine le User-Agent du WebClient.
                    wc.DownloadFile(@"http://static.die.net/earth/hemisphere/1600.jpg",
                        Application.StartupPath + @"\SavedImages\Hemisphere\" + DateTime.Now.ToString("yyyy_MM_dd") + String.Format("_{0:D2}_{1:D2}.jpg", Hour, Minute));
                        // Lancement du téléchargement / argument 1 : url du fichier source / argument 2 : l'emplacement ou enregistrer le fichier sur le disque dur
                    wc.Dispose();//Destruction de l'objet WebClient
                }
            #endif

                using(Image img = Image.FromFile(Application.StartupPath + "\\Temp\\TempWPImg.jpg"))
                {
                    Graphics g = Graphics.FromImage(img);
                    g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                    StringFormat strFormat = new StringFormat();
                    strFormat.Alignment = StringAlignment.Far;
                    strFormat.LineAlignment = StringAlignment.Far;
                    g.DrawString("Last update: " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(), new Font("Calibri", 24, FontStyle.Regular), Brushes.Red, new Rectangle(0, 0, img.Width-100, img.Height-5), strFormat);

                    img.Save(Application.StartupPath + "\\Image\\Wallpaper.bmp", ImageFormat.Bmp);
                    g.Dispose();
                }
            #if DEBUG
                StreamWriter log = File.AppendText(Application.StartupPath + "\\Temp\\log.txt");
                log.WriteLine(DateTime.Now.ToString());
                log.Close();
            #endif

                //File.Delete(Application.StartupPath + "\\Temp\\TempWPImg.jpg");
            }

            catch(Exception)// Interception des erreurs.
            {
                throw;
            }
            return;
        }
Esempio n. 2
0
 public OptionForm()
 {
     //
     // The InitializeComponent() call is required for Windows Forms designer support.
     //
     InitializeComponent();
     GetWidthScreen();
     Urlfile = new Registre().ReadRegUrlfile(Urlfile);// Read Urlfile var from Windows reg
     Delai = new Registre().ReadRegDelai(Delai);// Read Delai var from Windows reg
     launch = new Registre().ReadRegAutolaunch(launch);// Read Autorun var from Windows reg
     TileWP = new Registre().ReadRegTilewp(TileWP); // Read the Tilewallpaper var from Windows reg
     StyleWP = new Registre().ReadRegStylewp(StyleWP); // Read the WallpaperStyle var from Windows reg
     //Call methods.
     InitComboBoxList();
     InitRadioButtons();
     InitNumUpDown();
     InitLaunchChkBox();
     InitTypeWP();
 }
            public static void Main(string[] args)
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                int DelaiValue = 15;
                DelaiValue = new Registre().ReadRegDelai(DelaiValue);
                 		System.Timers.Timer aTimer = new System.Timers.Timer();//Initialisation du timer
                   		aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);// Evenement déclenché par le timer.
                   		aTimer.Interval = (double) DelaiValue * 60000;// Défini l'interval choisi dans les options..
                   		aTimer.Enabled = true;//Démarre le timer

                bool isFirstInstance;

                // Please use a unique name for the mutex to prevent conflicts with other programs
                using (Mutex mtx = new Mutex(true, "EarthLiveWallpaper", out isFirstInstance)) {
                if (isFirstInstance) {
                    NotificationIcon notificationIcon = new NotificationIcon();
                    notificationIcon.notifyIcon.Text = "EarthLiveWallpaper";
                    notificationIcon.notifyIcon.Visible = true;
                    new OptionForm().GetWidthScreen();
                    new ConnectToNet();//Verify internet connection before launch download
                    new ImgWP(); // Refresh the wallpaper
                    //------------------------------------
                    Application.Run();
                    notificationIcon.notifyIcon.Dispose();
                } else {
                    // The application is already running
                    Application.Exit();
                }
                } // releases the Mutex
            }