public void DestroyCustomCode()
    {
        // ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
        // Begin Wizard Added Object Disposal
        this.grdInput.InitializeLayout -= new Infragistics.Win.UltraWinGrid.InitializeLayoutEventHandler(this.grdInput_InitializeLayout);
        this.btnProcesss.Click         -= new System.EventHandler(this.btnProcesss_Click);
        this.btnClear.Click            -= new System.EventHandler(this.btnClear_Click);
        // End Wizard Added Object Disposal

        // Begin Custom Code Disposal

        // End Custom Code Disposal
        pbProgress.Dispose();
        pbProgress = null;

        this.worker.DoWork             -= new DoWorkEventHandler(this.worker_DoWork);
        this.worker.ProgressChanged    -= new ProgressChangedEventHandler(this.worker_ProgressChanged);
        this.worker.RunWorkerCompleted -= new RunWorkerCompletedEventHandler(this.worker_RunWorkerCompleted);
    }
        /// <summary>
        /// Downloads the driver and some other stuff
        /// </summary>
        private static void downloadDriver()
        {
            int DateDiff = (DateTime.Now - releaseDate).Days; // how many days between the two dates
            string theDate = null;

            if (DateDiff == 1) {
                theDate = DateDiff + " day ago";
            } else if (DateDiff < 1) {
                theDate = "today";
            } else {
                theDate = DateDiff + " days ago";
            }

            var message = "There is new gpu drivers up for download, do you want to download them now?" + Environment.NewLine + Environment.NewLine;

            string key = "Show Driver Description";
            string val = null;

            // loop
            while (val != "true" & val != "false") {
                val = SettingManager.readSetting(key); // refresh value each time

                if (val == "true") {
                    message = message + "Description: " + releaseDesc + Environment.NewLine;
                } else if (val == "false") {
                    break;
                } else {
                    // invalid value
                    SettingManager.setupSetting(key);
                }
            }

            message = message + "Driver version: " + OnlineGPUVersion + " (you're running " + OfflineGPUVersion + ")" + Environment.NewLine +
                        "Driver released: " + theDate + " (" + releaseDate.ToShortDateString() + ")";

            DialogResult dialog = MessageBox.Show(message, "TinyNvidiaUpdateChecker", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dialog == DialogResult.Yes) {

                Console.WriteLine();

                // @todo error handling could be better:
                // isolate saveFileDialog errors with accually downloading GPU driver

                // @todo add status bar for download progress
                // @todo do the saveFileDialog in a loop

                bool error = false;
                try
                {
                    string driverName = downloadURL.Split('/').Last(); // retrives file name from url

                    DialogResult result;

                    using (SaveFileDialog saveFileDialog = new SaveFileDialog()) {
                        saveFileDialog.Filter = "Executable|*.exe";
                        saveFileDialog.Title = "Choose save file for GPU driver";
                        saveFileDialog.FileName = driverName;

                        result = saveFileDialog.ShowDialog(); // show dialog and get status (will wait for input)

                        switch (result)
                        {
                            case DialogResult.OK:
                                savePath = saveFileDialog.FileName.ToString();
                                break;

                            default:
                                // savePath = Path.GetTempPath() + driverName;

                                // if something went wrong, fall back to downloads folder
                                savePath = getDownloadFolderPath() + driverName;
                                break;
                        }
                    }

                    if (debug == true) {
                        Console.WriteLine("savePath: " + savePath);
                        Console.WriteLine("result: " + result);
                    }

                    Console.Write("Downloading the driver . . . ");

                    using (WebClient webClient = new WebClient())
                    {
                        var notifier = new AutoResetEvent(false);
                        var progress = new ProgressBar();

                        webClient.DownloadProgressChanged += delegate (object sender, DownloadProgressChangedEventArgs e)
                        {
                            progress.Report((double)e.ProgressPercentage / 100);

                            if (e.BytesReceived >= e.TotalBytesToReceive) notifier.Set();
                        };

                        webClient.DownloadFileAsync(new Uri(downloadURL), savePath);

                        notifier.WaitOne(); // sync with the above
                        progress.Dispose(); // get rid of the progress bar
                    }

                }
                catch (Exception ex)
                {
                    error = true;
                    Console.Write("ERROR!");
                    LogManager.log(ex.Message, LogManager.Level.ERROR);
                    Console.WriteLine();
                    Console.WriteLine(ex.StackTrace);
                    Console.WriteLine();
                }

                if (error == false)
                {
                    Console.Write("OK!");
                    Console.WriteLine();
                }

                Console.WriteLine();
                Console.WriteLine("The downloaded file has been saved at: " + savePath);

                dialog = MessageBox.Show("Do you want view the release PDF?", "TinyNvidiaUpdateChecker", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialog == DialogResult.Yes) {
                    try {
                        Process.Start(pdfURL);
                    }
                    catch (Exception ex) {
                        Console.WriteLine(ex.StackTrace);
                    }
                }

                dialog = MessageBox.Show("Do you wish to run the driver installer?", "TinyNvidiaUpdateChecker", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dialog == DialogResult.Yes) {
                    try {
                        Process.Start(savePath);
                    } catch (Exception ex) {
                        Console.WriteLine(ex.StackTrace);
                    }

                }
            }
        }
Exemplo n.º 3
0
        private void cancelbutton_click
            (object sender, EventArgs e, WebClient client,PictureBox cancelbutton,
            ProgressBar progressbar,string filename,TextBox episode = null)
        {
            const string message = "确定取消下载么?";
            const string caption = "取消下载";
            if (cancelbutton.Name.StartsWith("batch"))
            {
                client.CancelAsync();
                client.Dispose(); //without it, deleting file would fail.
                batchpanel.Controls.Remove(episode);
                batchpanel.Controls.Remove(cancelbutton);
                batchpanel.Controls.Remove(progressbar);
                cancelbutton.Dispose();
                progressbar.Dispose();
                episode.Dispose();
                File.Delete(filename);
            }
            else 
            {
                var result = System.Windows.Forms.MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    client.CancelAsync();
                    client.Dispose();
                    infopanel.Controls.Remove(cancelbutton);
                    infopanel.Controls.Remove(progressbar);
                    cancelbutton.Dispose();
                    progressbar.Dispose();
                    File.Delete(filename);
                }
            }

        }
Exemplo n.º 4
0
        void Dibujar(object sender, PaintEventArgs e)
        {
            //Fondo
            if (selected)
            {
                e.Graphics.FillRectangle(new LinearGradientBrush(this.ClientRectangle, Color.FromArgb(217, 226, 234), Color.FromArgb(184, 200, 216), LinearGradientMode.Vertical)
                                         , 0, 0, this.Width, this.Height);
            }
            this.Height = Parent.ItemHeight;
            Rectangle rectangulo = AreaDibujo();

            //Imagen
            if (Image != null)
            {
                e.Graphics.DrawImage(this.Image, rectangulo.X, rectangulo.Y + (rectangulo.Height / 2 - Parent.ImageSize.Height / 2),
                                     Parent.ImageSize.Width, Parent.ImageSize.Height);
                rectangulo.X += Parent.ImageSize.Width + 3;
            }

            //Texto
            SizeF tamañoTexto = e.Graphics.MeasureString(this.texto, this.Font);

            if (valorBarraProgreso >= 0)
            {
                e.Graphics.DrawString(this.texto, this.Font, new SolidBrush(this.ForeColor), rectangulo.X,
                                      rectangulo.Y + (rectangulo.Height / 2) - (tamañoTexto.Height + Parent.ProgressBarHeight + 3) / 2);
            }
            else
            {
                e.Graphics.DrawString(this.texto, this.Font, new SolidBrush(this.ForeColor), rectangulo.X,
                                      rectangulo.Y + (rectangulo.Height / 2) - (tamañoTexto.Height / 2));
            }

            //Linea divisoria
            Pen lapiz = new Pen(Color.LightGray, 0.5f);

            for (int contador = 0; contador < this.Width; contador += 2)
            {
                e.Graphics.DrawRectangle(lapiz, contador, this.Height - 1, 0.5f, 0.5f);
            }

            //LinkLabels
            int maximoAncho = 0;

            if (LinkLabels != null)
            {
                foreach (LinkLabel label in LinkLabels)
                {
                    SizeF tamañoLabel = e.Graphics.MeasureString(label.Text, this.Font);
                    if (tamañoLabel.Width > maximoAncho)
                    {
                        maximoAncho = (int)tamañoLabel.Width;
                    }
                }
                int y = Parent.BorderTop + rectangulo.Height / 2 - (LinkLabels.Count * (int)tamañoTexto.Height) / 2;
                foreach (LinkLabel label in LinkLabels)
                {
                    label.Location = new Point(this.Width - Parent.BorderRight - maximoAncho, y);
                    y += (int)tamañoTexto.Height + 3;
                    label.BringToFront();
                    this.Controls.Add(label);
                }
            }

            //Barra de progreso
            if (valorBarraProgreso == -1)
            {
                if (barraProgreso != null)
                {
                    barraProgreso.Dispose();
                    barraProgreso = null;
                }
            }
            else if (barraProgreso != null)
            {
                barraProgreso.Size     = new Size(this.Width - rectangulo.X - Parent.BorderRight - maximoAncho - 15, Parent.ProgressBarHeight);
                barraProgreso.Location = new Point(rectangulo.X + 5, rectangulo.Y + (rectangulo.Height / 2) + (((int)tamañoTexto.Height + Parent.ProgressBarHeight + 3) / 2) - Parent.ProgressBarHeight);
                barraProgreso.Value    = valorBarraProgreso;
            }
            else if (barraProgreso == null && valorBarraProgreso >= 0)
            {
                barraProgreso         = new ProgressBar();
                barraProgreso.Minimum = minProgress;
                barraProgreso.Maximum = maxProgress;
                barraProgreso.Value   = valorBarraProgreso;

                barraProgreso.Size     = new Size(this.Width - rectangulo.X - Parent.BorderRight - maximoAncho - 15, Parent.ProgressBarHeight);
                barraProgreso.Location = new Point(rectangulo.X + 5, rectangulo.Y + (rectangulo.Height / 2) + (((int)tamañoTexto.Height + Parent.ProgressBarHeight + 3) / 2) - Parent.ProgressBarHeight);
                barraProgreso.Click   += new EventHandler(Seleccionar);
                barraProgreso.Click   += new EventHandler(ProgresoClick);
                this.Controls.Add(barraProgreso);
            }
        }