예제 #1
0
        /// <summary>
        /// Download program
        /// </summary>
        /// <param name="downloadList"></param>
        private void StartDownload(DownloadFileInfo downloadList)
        {
            DownloadProgress dp = new DownloadProgress(downloadList, AppName, newversion, newsize);

            if (dp.ShowDialog() == DialogResult.OK)
            {
                //
                if (DialogResult.Cancel == dp.ShowDialog())
                {
                    return;
                }

                if (bNeedRestart)
                {
                    MessageBox.Show(ConstFile.APPLYTHEUPDATE, ConstFile.MESSAGETITLE, MessageBoxButtons.OK, MessageBoxIcon.Information);

                    // Launch setup of application downloaded
                    string setupexe = Path.Combine(downloadList.TargetUrl, downloadList.FileName);
                    System.Diagnostics.Process.Start(setupexe);

                    // Stop this instance of the application
                    CommonUnitity.StopApplication();
                }
            }
        }
예제 #2
0
        public DownloadConfirm(DownloadFileInfo downloadfileList, string tAppName, string tversion, long tsize)
        {
            AppName    = tAppName;
            newversion = tversion;
            newsize    = tsize;

            InitializeComponent();

            downloadFileList = downloadfileList;

            this.label2.Text = "A new version of " + AppName + " is available: (" + newversion.ToString() + ")";
            this.label3.Text = "Name:  " + AppName;
        }
예제 #3
0
        public DownloadProgress(DownloadFileInfo downloadFileListTemp, string tAppName, string tversion, long tsize)
        {
            AppName    = tAppName;
            newversion = tversion;
            newsize    = tsize;

            InitializeComponent();

            this.label3.Text = "Updating " + AppName;
            this.label7.Text = "Name: " + AppName;
            this.Text        = "Updating " + AppName;

            this.downloadFileList = downloadFileListTemp;
            allFileList           = new DownloadFileInfo(downloadFileListTemp.DownloadUrl, downloadFileListTemp.TargetUrl, downloadFileListTemp.FileName, downloadFileListTemp.LastVer, downloadFileListTemp.Size);
        }
예제 #4
0
        private void ProcDownload(object o)
        {
            evtPerDonwload = new ManualResetEvent(false);

            if (downloadFileList != null)
            {
                total += downloadFileList.Size;
            }


            try
            {
                while (!evtDownload.WaitOne(0, false))
                {
                    if (downloadFileList == null)
                    {
                        break;
                    }

                    DownloadFileInfo file = downloadFileList;

                    this.ShowCurrentDownloadFileName(file.FileName);

                    //Download
                    clientDownload = new WebClient();

                    //Added the function to support proxy
                    System.Net.IWebProxy iwpxy = WebRequest.GetSystemWebProxy();
                    clientDownload.Proxy = iwpxy;

                    //clientDownload.Proxy = WebProxy.GetDefaultProxy();


                    clientDownload.Proxy.Credentials = CredentialCache.DefaultCredentials;
                    clientDownload.Credentials       = System.Net.CredentialCache.DefaultCredentials;
                    //End added


                    // Progress changed
                    clientDownload.DownloadProgressChanged += (object sender, DownloadProgressChangedEventArgs e) =>
                    {
                        try
                        {
                            this.SetProcessBar(e.ProgressPercentage, (int)((nDownloadedTotal + e.BytesReceived) * 100 / total));
                        }
                        catch
                        {
                            //log the error message,you can use the application's log code
                        }
                    };


                    // Download completed
                    clientDownload.DownloadFileCompleted += (object sender, AsyncCompletedEventArgs e) =>
                    {
                        try
                        {
                            DownloadFileInfo dfile = e.UserState as DownloadFileInfo;
                            nDownloadedTotal += dfile.Size;
                            this.SetProcessBar(0, (int)(nDownloadedTotal * 100 / total));
                            evtPerDonwload.Set();
                        }
                        catch (Exception)
                        {
                            //log the error message,you can use the application's log code
                        }
                    };

                    evtPerDonwload.Reset();

                    //Download

                    // Telecharge le fichier dans le repertoire downloads
                    clientDownload.DownloadFileAsync(new Uri(file.DownloadUrl), Path.Combine(file.TargetUrl, file.FileName), file);

                    //Wait for the download complete
                    evtPerDonwload.WaitOne();

                    clientDownload.Dispose();
                    clientDownload = null;

                    downloadFileList = null;
                }
            }
            catch (Exception)
            {
                ShowErrorAndRestartApplication();
                //throw;
            }

            //After dealed with all files, clear the data
            allFileList = null;

            if (downloadFileList == null)
            {
                Exit(true);
            }
            else
            {
                Exit(false);
            }

            evtDownload.Set();
        }
예제 #5
0
        public void Update()
        {
            if (!config.Enabled)
            {
                return;
            }

            // Retrieve list of remote files to update
            Dictionary <string, RemoteFile> listRemotFile = ParseRemoteXml(config.ServerUrl);



            // Create download list
            DownloadFileInfo downloadList = null;

            if (listRemotFile.ContainsKey(AppName))
            {
                RemoteFile rf = listRemotFile[AppName];

                // FAB
                this._serverUrl = rf.Url;
                Uri uri = new Uri(@rf.Url);
                _serverUrl = "http://" + uri.Host + "/AutoupdateService.xml";

                Version v1 = new Version(rf.LastVer);
                Version v2 = new Version(localfile.LastVer);
                if (v1 > v2)
                {
                    // Add to download list all files having a greater version
                    downloadList      = new DownloadFileInfo(rf.Url, localfile.Path, rf.Url, rf.LastVer, rf.Size);
                    localfile.LastVer = rf.LastVer;
                    localfile.Size    = rf.Size;

                    newversion = rf.LastVer;
                    newsize    = rf.Size;

                    if (rf.NeedRestart)
                    {
                        bNeedRestart = true;
                    }

                    bDownload = true;
                }
                // Remove from list
                listRemotFile.Remove(AppName);
            }



            // Display form download confirm
            if (bDownload)
            {
                DownloadConfirm dc = new DownloadConfirm(downloadList, AppName, newversion, newsize);

                if (this.OnShow != null)
                {
                    this.OnShow();
                }

                if (DialogResult.OK == dc.ShowDialog())
                {
                    StartDownload(downloadList);
                }
            }
        }