예제 #1
0
        internal frmDownloading(string appName, string localPath, LocalXml localXml, UpdateXml updateXml)
        {
            InitializeComponent();
            this.localXml  = localXml;
            this.updateXml = updateXml;
            this.localPath = localPath;
            this.appName   = appName;
            this.Text      = appName + " - Download Update";

            bgwInstall = new BackgroundWorker();
            bgwInstall.WorkerReportsProgress = true;

            bgwInstall.DoWork             += bgwInstall_DoWork;
            bgwInstall.RunWorkerCompleted += bgwInstall_RunWorkerCompleted;
        }
예제 #2
0
 internal static DialogResult DownloadUpdate(string appName, string localPath, LocalXml localXml, UpdateXml updateXml)
 {
     downloading = new frmDownloading(appName, localPath, localXml, updateXml);
     downloading.ShowDialog();
     return(result);
 }
예제 #3
0
        public static void UpdateApp(bool isManualCheck)
        {
            string appName   = Application.ProductName;
            string localPath = Application.StartupPath;
            //check exists config file
            string configFilePath = Path.Combine(localPath, "AutoUpdate.xml");

            if (!File.Exists(configFilePath))
            {
                if (isManualCheck)
                {
                    MessageBox.Show(string.Format("The local configuration file does not exist\n{0}.", configFilePath), appName + " - Update", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return;
            }
            //read Local config
            LocalXml localXml = LocalXml.Get_LocalXml(configFilePath);

            if (localXml == null)
            {
                if (isManualCheck)
                {
                    MessageBox.Show(string.Format("Error reading local configuration file\n{0}.", configFilePath), appName + " - Update", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return;
            }

            //Check on server
            if (!UpdateXml.Check_ExistsOnServer(localXml))
            {
                if (isManualCheck)
                {
                    MessageBox.Show("Failed to connect to FTP server.", appName + " - Update", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return;
            }
            //Get Info update
            UpdateXml updateValue = UpdateXml.Get_InfoUpdate(localXml);

            if (updateValue == null)
            {
                if (isManualCheck)
                {
                    MessageBox.Show(string.Format("Error reading configuration file on FTP server.\n{0}", localXml.Url), appName + " - Update", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return;
            }
            //Check version
            if (!updateValue.Version.Equals(localXml.Version))
            {
                //update
                if (frmUpdateAccept.Show(appName, localXml.Version, updateValue.Version, updateValue.Description) == DialogResult.Yes)
                {
                    DialogResult result = frmDownloading.DownloadUpdate(appName, localPath, localXml, updateValue);
                    if (result == DialogResult.No)
                    {
                        MessageBox.Show("There was a problem downloading the update.\nPlease try again later.", appName + " - Update", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (result == DialogResult.Abort)
                    {
                        MessageBox.Show("The update download was cancelled.\nThis program has not been modified.", appName + " - Update", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (result == DialogResult.None)
                    {
                        MessageBox.Show("Error extracting zipped file.\nPlease check the [Ionic] library or zip file.", appName + " - Update", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else if (isManualCheck)
            {
                MessageBox.Show("You have the latest version already!", appName + " - Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }