Exemple #1
0
 public Updater(FileTransfer fileTransfer)
 {
     this.fileTransfer = fileTransfer;
     filesToDelete = new SortedList<string, string>();
     filesToDownload = new SortedList<string,TransferFile>();
     updaterConfig = new UpdaterConfig();
 }
Exemple #2
0
 public Updater(FileTransfer fileTransfer)
 {
     this.fileTransfer = fileTransfer;
     filesToDelete     = new SortedList <string, string>();
     filesToDownload   = new SortedList <string, TransferFile>();
     updaterConfig     = new UpdaterConfig();
 }
Exemple #3
0
        //loads files for the new Updater version into the download list
        private bool LoadUpdaterFilesIntoDownloadList(UpdaterConfig newUpdaterConfig)
        {
            long   size;
            string serverPath;
            string file;

            try
            {
                serverPath = updaterConfig.AbsUpdaterPathOnServer;

                //if the background images shall be updated too
                if (newUpdaterConfig.UpdatePictures)
                {
                    //get all background images
                    foreach (string imagePath in newUpdaterConfig.BackgroundImgList.Values)
                    {
                        size = GetFileSize(serverPath + imagePath);
                        filesToDownload.Add(imagePath, new TransferFile(imagePath, size, imagePath));
                    }
                }

                //get executeable of the Updater
                file = newUpdaterConfig.UpdaterExe;
                size = GetFileSize(serverPath + file);
                filesToDownload.Add(file, new TransferFile(file, size, file));

                //get the configuration file of the Updater
                file = updaterConfigurationFile;
                size = GetFileSize(serverPath + file);
                filesToDownload.Add(file, new TransferFile(file, size, file));

                //get the executeable of the Installer
                file = newUpdaterConfig.InstallerExe;
                size = GetFileSize(serverPath + file);
                filesToDownload.Add(file, new TransferFile(file, size, file));
            }
            catch (Exception e)
            {
                ErrorLog.Add(this, e.Message);
                return(false);
            }

            return(true);
        }
Exemple #4
0
        //loads files for the new Updater version into the download list
        private bool LoadUpdaterFilesIntoDownloadList(UpdaterConfig newUpdaterConfig)
        {
            long size;
            string serverPath;
            string file;

            try
            {
                serverPath = updaterConfig.AbsUpdaterPathOnServer;

                //if the background images shall be updated too
                if (newUpdaterConfig.UpdatePictures)
                {
                    //get all background images
                    foreach (string imagePath in newUpdaterConfig.BackgroundImgList.Values)
                    {
                        size = GetFileSize(serverPath + imagePath);
                        filesToDownload.Add(imagePath, new TransferFile(imagePath, size, imagePath));
                    }
                }

                //get executeable of the Updater
                file = newUpdaterConfig.UpdaterExe;
                size = GetFileSize(serverPath + file);
                filesToDownload.Add(file, new TransferFile(file, size, file));

                //get the configuration file of the Updater
                file = updaterConfigurationFile;
                size = GetFileSize(serverPath + file);
                filesToDownload.Add(file, new TransferFile(file, size, file));

                //get the executeable of the Installer
                file = newUpdaterConfig.InstallerExe;
                size = GetFileSize(serverPath + file);
                filesToDownload.Add(file, new TransferFile(file, size, file));
            }
            catch (Exception e)
            {
                ErrorLog.Add(this, e.Message);
                return false;
            }

            return true;
        }
Exemple #5
0
        //checks if a new version of the Updater is existing and downloads it
        private void GetNewUpdater()
        {
            //configuration file of the new Updater
            UpdaterConfig newUpdaterConfig = new UpdaterConfig();

            //load configuration file of the new Updater
            StatusChanged(this,new StatusEventArgs("Loading new Updater configuration file..."));
            if (!newUpdaterConfig.Load(updaterConfig.AbsUpdaterPathOnServer +
                updaterConfigurationFile))
            {
                StatusChanged(this,new StatusEventArgs("Error! Bad Updater configuration file on server."));
                MessageBox.Show("Error! Bad Updater configuration file on server.", "Error!", MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                OnClose(this, EventArgs.Empty);
                return;
            }

            //check if a new version of the Updater is existing
            StatusChanged(this,new StatusEventArgs("Checking version..."));
            if (Version.ToLong(newUpdaterConfig.VersionNumber) > Version.ToLong(updaterConfig.VersionNumber))
            {
                //load files into download list
                StatusChanged(this,new StatusEventArgs("Creating file list..."));
                if (!LoadUpdaterFilesIntoDownloadList(newUpdaterConfig))
                {
                    StatusChanged(this,new StatusEventArgs("Error on creating file list for self-update"));
                    MessageBox.Show("Error on creating file list for self-update.", "Error!", MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    OnClose(this, EventArgs.Empty);
                    return;
                }

                //create the temporary download folder
                StatusChanged(this,new StatusEventArgs("Creating temporary download directory..."));
                if (!CreateTempFolder())
                {
                    StatusChanged(this,new StatusEventArgs("Error on creating temporary download directory..."));
                    MessageBox.Show("Error on creating temporary download directory...", "Error!", MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    OnClose(this, EventArgs.Empty);
                    return;
                }

                //start download
                StatusChanged(this,new StatusEventArgs("Downloading..."));
                fileTransfer.DownloadFilesAsync(filesToDownload.Values.ToList(), true,
                    new Uri(updaterConfig.AbsUpdaterPathOnServer), updaterConfig.TempFolder + "/",
                    delegate(FileTransferResult result) //callback function after download is completed
                    {
                        filesToDownload.Clear();

                        //download successful
                        if (result == FileTransferResult.Success)
                        {
                            InstallUpdater();
                            NextAction("getNewGame");
                        }
                        //download unsuccessful
                        else
                        {
                            MessageBox.Show("Download Failure! Please try again.",
                                "Failure!",MessageBoxButtons.OK,MessageBoxIcon.Error);
                            OnClose(this, EventArgs.Empty);
                        }
                    }
                );
            }
            else //if no new version of the Updater was found
                NextAction("getNewGame");
        }
Exemple #6
0
        //checks if a new version of the Updater is existing and downloads it
        private void GetNewUpdater()
        {
            //configuration file of the new Updater
            UpdaterConfig newUpdaterConfig = new UpdaterConfig();

            //load configuration file of the new Updater
            StatusChanged(this, new StatusEventArgs("Loading new Updater configuration file..."));
            if (!newUpdaterConfig.Load(updaterConfig.AbsUpdaterPathOnServer +
                                       updaterConfigurationFile))
            {
                StatusChanged(this, new StatusEventArgs("Error! Bad Updater configuration file on server."));
                MessageBox.Show("Error! Bad Updater configuration file on server.", "Error!", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                OnClose(this, EventArgs.Empty);
                return;
            }

            //check if a new version of the Updater is existing
            StatusChanged(this, new StatusEventArgs("Checking version..."));
            if (Version.ToLong(newUpdaterConfig.VersionNumber) > Version.ToLong(updaterConfig.VersionNumber))
            {
                //load files into download list
                StatusChanged(this, new StatusEventArgs("Creating file list..."));
                if (!LoadUpdaterFilesIntoDownloadList(newUpdaterConfig))
                {
                    StatusChanged(this, new StatusEventArgs("Error on creating file list for self-update"));
                    MessageBox.Show("Error on creating file list for self-update.", "Error!", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    OnClose(this, EventArgs.Empty);
                    return;
                }

                //create the temporary download folder
                StatusChanged(this, new StatusEventArgs("Creating temporary download directory..."));
                if (!CreateTempFolder())
                {
                    StatusChanged(this, new StatusEventArgs("Error on creating temporary download directory..."));
                    MessageBox.Show("Error on creating temporary download directory...", "Error!", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    OnClose(this, EventArgs.Empty);
                    return;
                }

                //start download
                StatusChanged(this, new StatusEventArgs("Downloading..."));
                fileTransfer.DownloadFilesAsync(filesToDownload.Values.ToList(), true,
                                                new Uri(updaterConfig.AbsUpdaterPathOnServer), updaterConfig.TempFolder + "/",
                                                delegate(FileTransferResult result) //callback function after download is completed
                {
                    filesToDownload.Clear();

                    //download successful
                    if (result == FileTransferResult.Success)
                    {
                        InstallUpdater();
                        NextAction("getNewGame");
                    }
                    //download unsuccessful
                    else
                    {
                        MessageBox.Show("Download Failure! Please try again.",
                                        "Failure!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        OnClose(this, EventArgs.Empty);
                    }
                }
                                                );
            }
            else             //if no new version of the Updater was found
            {
                NextAction("getNewGame");
            }
        }