//initializes the Updater private void Initialize() { StatusChanged(this, new StatusEventArgs("Loading Updater configuration file...")); //load Updater configuration file if (!updaterConfig.Load(updaterConfigurationFile)) { StatusChanged(this, new StatusEventArgs("Error! Bad Updater configuration file.")); MessageBox.Show("Error! Bad Updater configuration file.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); OnClose(this, EventArgs.Empty); return; } //delete temporary download folder DeleteTempFolder(); //set background image StatusChanged(this, new StatusEventArgs("Loading background...")); SetBackgroundImg(); //set number of the last background image to the next number StatusChanged(this, new StatusEventArgs("Writing updater configuration file...")); if (!updaterConfig.SaveLastBackgroundImg(updaterConfigurationFile, updaterConfig.NextBackgroundImgNumber)) { StatusChanged(this, new StatusEventArgs("Error! Can't write to Updater configuration file.")); MessageBox.Show("Error! Can't write to Updater configuration file.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); OnClose(this, EventArgs.Empty); return; } //next action --> get new Updater NextAction("getNewUpdater"); }
//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"); }
//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"); } }