示例#1
0
        //loads files for the new game version into the download list
        private bool LoadGameFilesIntoDownloadList(VersionsConfig versionsConfig)
        {
            XmlDocument docUpdate = new XmlDocument();
            XmlNode newFilesNode;
            XmlNode deletedFilesNode;
            long fileSize, version;
            string filePath, versionNumber;

            try
            {
                //iterate through the new version from the end to the beginning
                for (int i = versionsConfig.VersionsForUpdate.Keys.Count - 1; i >= 0; i--)
                {
                    //set the key
                    version = versionsConfig.VersionsForUpdate.Keys[i];
                    //set the version number
                    versionNumber = versionsConfig.VersionsForUpdate[version].VersionNumber;

                    //if the version is a full version
                    if (versionsConfig.VersionsForUpdate[version].IsFullVersion)
                    {
                        //load the configuration file of the full version
                        docUpdate.Load(updaterConfig.ServerPath + versionNumber + "/" +
                            updaterConfig.FullVersionConfigurationFile);
                        newFilesNode = docUpdate.SelectSingleNode("/files");
                    }
                    //if the version is an update
                    else
                    {
                        //load the configuration file of the update
                        docUpdate.Load(updaterConfig.ServerPath + versionNumber + "/" +
                            updaterConfig.UpdateConfigurationFile);
                        newFilesNode = docUpdate.SelectSingleNode("/update/newFiles");
                    }

                    //if new files are existing
                    if (newFilesNode != null)
                    {
                        //iterate through the new files and add them to the installation list if needed
                        foreach (XmlNode file in newFilesNode.ChildNodes)
                        {
                            filePath = file.Attributes["path"].Value;
                            fileSize = long.Parse(file.SelectSingleNode("size").InnerText);
                            if (!filesToDownload.ContainsKey(filePath) && !filesToDelete.ContainsKey(filePath))
                                filesToDownload.Add(filePath,
                                    new TransferFile(versionNumber + "/" + filePath, fileSize, filePath));
                        }
                    }

                    //if old files are existing
                    deletedFilesNode = docUpdate.SelectSingleNode("/update/deletedFiles");
                    if (deletedFilesNode != null)
                    {
                        //iterate through the old files and add them to the delete list if not needed anymore
                        foreach (XmlNode file in deletedFilesNode.ChildNodes)
                        {
                            filePath = file.Attributes["path"].Value;
                            if (!filesToDownload.ContainsKey(filePath) && !filesToDelete.ContainsKey(filePath))
                                filesToDelete.Add(filePath, versionNumber + "/" + filePath);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ErrorLog.Add(this, e.Message);
                return false;
            }

            return true;
        }
示例#2
0
        //loads files for the new game version into the download list
        private bool LoadGameFilesIntoDownloadList(VersionsConfig versionsConfig)
        {
            XmlDocument docUpdate = new XmlDocument();
            XmlNode     newFilesNode;
            XmlNode     deletedFilesNode;
            long        fileSize, version;
            string      filePath, versionNumber;

            try
            {
                //iterate through the new version from the end to the beginning
                for (int i = versionsConfig.VersionsForUpdate.Keys.Count - 1; i >= 0; i--)
                {
                    //set the key
                    version = versionsConfig.VersionsForUpdate.Keys[i];
                    //set the version number
                    versionNumber = versionsConfig.VersionsForUpdate[version].VersionNumber;

                    //if the version is a full version
                    if (versionsConfig.VersionsForUpdate[version].IsFullVersion)
                    {
                        //load the configuration file of the full version
                        docUpdate.Load(updaterConfig.ServerPath + versionNumber + "/" +
                                       updaterConfig.FullVersionConfigurationFile);
                        newFilesNode = docUpdate.SelectSingleNode("/files");
                    }
                    //if the version is an update
                    else
                    {
                        //load the configuration file of the update
                        docUpdate.Load(updaterConfig.ServerPath + versionNumber + "/" +
                                       updaterConfig.UpdateConfigurationFile);
                        newFilesNode = docUpdate.SelectSingleNode("/update/newFiles");
                    }

                    //if new files are existing
                    if (newFilesNode != null)
                    {
                        //iterate through the new files and add them to the installation list if needed
                        foreach (XmlNode file in newFilesNode.ChildNodes)
                        {
                            filePath = file.Attributes["path"].Value;
                            fileSize = long.Parse(file.SelectSingleNode("size").InnerText);
                            if (!filesToDownload.ContainsKey(filePath) && !filesToDelete.ContainsKey(filePath))
                            {
                                filesToDownload.Add(filePath,
                                                    new TransferFile(versionNumber + "/" + filePath, fileSize, filePath));
                            }
                        }
                    }

                    //if old files are existing
                    deletedFilesNode = docUpdate.SelectSingleNode("/update/deletedFiles");
                    if (deletedFilesNode != null)
                    {
                        //iterate through the old files and add them to the delete list if not needed anymore
                        foreach (XmlNode file in deletedFilesNode.ChildNodes)
                        {
                            filePath = file.Attributes["path"].Value;
                            if (!filesToDownload.ContainsKey(filePath) && !filesToDelete.ContainsKey(filePath))
                            {
                                filesToDelete.Add(filePath, versionNumber + "/" + filePath);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ErrorLog.Add(this, e.Message);
                return(false);
            }

            return(true);
        }
示例#3
0
        //checks if a new game version is existing and downloads it
        private void GetNewGame()
        {
            bool needsFullVersion;
            GameConfig gameConfig = new GameConfig();
            VersionsConfig versionsConfig = new VersionsConfig();
            DialogResult res;

            //check if there is a game path directory
            StatusChanged(this,new StatusEventArgs("Checking game path..."));
            if (!Directory.Exists(updaterConfig.GamePath))
            {
                NeedsGamePath(this, EventArgs.Empty);
                return;
            }

            //load the configuration file of the game
            StatusChanged(this,new StatusEventArgs("Loading game configuration file..."));
            //if there is NO configuration file a full version is needed
            if (!gameConfig.Load(updaterConfig.GamePath + updaterConfig.GameConfigurationFile))
            {
                StatusChanged(this, new StatusEventArgs("No game found in selected directory!"));
                res = MessageBox.Show("In the chosen folder was no game found. Shall it be installed into " +
                    "the selected directory?", "Install?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (res == DialogResult.No)
                {
                    NeedsGamePath(this, EventArgs.Empty);
                    return;
                }
                needsFullVersion = true;
            }
            //if there is A configuration file an update is needed
            else
                needsFullVersion = false;

            //load the new versions available on the server
            StatusChanged(this,new StatusEventArgs("Checking new game versions..."));
            versionsConfig.LoadNewVersions(updaterConfig.ServerPath + updaterConfig.VersionsConfigurationFile,
                gameConfig.VersionNumber, needsFullVersion);

            //if there are new versions
            if (versionsConfig.VersionsForUpdate.Count == 0)
            {
                if (gameConfig.VersionNumber == GameConfig.DefaultVersionNumber)
                {
                    StatusChanged(this, new StatusEventArgs("Unable to install. No version found on server."));
                    MessageBox.Show("Unable to install. No version found on server.", "No version found",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    OnClose(this, EventArgs.Empty);
                }
                else
                {
                    StatusChanged(this, new StatusEventArgs("No new Versions found!"));
                    UpdateFinished(this, EventArgs.Empty);
                }
                return;
            }

            //load files for download into list
            StatusChanged(this,new StatusEventArgs("Creating file lists..."));
            if (!LoadGameFilesIntoDownloadList(versionsConfig))
            {
                StatusChanged(this,new StatusEventArgs("Error on creating file lists for the game!"));
                MessageBox.Show("Error on creating file lists for the game!", "Error!",
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                OnClose(this, EventArgs.Empty);
                return;
            }

            //create temporary download directory
            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 the download
            StatusChanged(this,new StatusEventArgs("Downloading..."));
            fileTransfer.DownloadFilesAsync(filesToDownload.Values.ToList(), true,
                new Uri(updaterConfig.ServerPath), updaterConfig.TempFolder + "/",
                delegate(FileTransferResult result) //callback function after download is completed
                {
                    filesToDownload.Clear();
                    //download successful
                    if (result == FileTransferResult.Success)
                        InstallGame(versionsConfig.LatestUpdate);
                    //download unsuccessful
                    else
                    {
                        MessageBox.Show("Download Failure! Please Try Again",
                            "Failure!",MessageBoxButtons.OK, MessageBoxIcon.Error);
                        OnClose(this, EventArgs.Empty);
                    }
                }
            );
        }
示例#4
0
        //checks if a new game version is existing and downloads it
        private void GetNewGame()
        {
            bool           needsFullVersion;
            GameConfig     gameConfig     = new GameConfig();
            VersionsConfig versionsConfig = new VersionsConfig();
            DialogResult   res;

            //check if there is a game path directory
            StatusChanged(this, new StatusEventArgs("Checking game path..."));
            if (!Directory.Exists(updaterConfig.GamePath))
            {
                NeedsGamePath(this, EventArgs.Empty);
                return;
            }

            //load the configuration file of the game
            StatusChanged(this, new StatusEventArgs("Loading game configuration file..."));
            //if there is NO configuration file a full version is needed
            if (!gameConfig.Load(updaterConfig.GamePath + updaterConfig.GameConfigurationFile))
            {
                StatusChanged(this, new StatusEventArgs("No game found in selected directory!"));
                res = MessageBox.Show("In the chosen folder was no game found. Shall it be installed into " +
                                      "the selected directory?", "Install?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (res == DialogResult.No)
                {
                    NeedsGamePath(this, EventArgs.Empty);
                    return;
                }
                needsFullVersion = true;
            }
            //if there is A configuration file an update is needed
            else
            {
                needsFullVersion = false;
            }

            //load the new versions available on the server
            StatusChanged(this, new StatusEventArgs("Checking new game versions..."));
            versionsConfig.LoadNewVersions(updaterConfig.ServerPath + updaterConfig.VersionsConfigurationFile,
                                           gameConfig.VersionNumber, needsFullVersion);

            //if there are new versions
            if (versionsConfig.VersionsForUpdate.Count == 0)
            {
                if (gameConfig.VersionNumber == GameConfig.DefaultVersionNumber)
                {
                    StatusChanged(this, new StatusEventArgs("Unable to install. No version found on server."));
                    MessageBox.Show("Unable to install. No version found on server.", "No version found",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    OnClose(this, EventArgs.Empty);
                }
                else
                {
                    StatusChanged(this, new StatusEventArgs("No new Versions found!"));
                    UpdateFinished(this, EventArgs.Empty);
                }
                return;
            }

            //load files for download into list
            StatusChanged(this, new StatusEventArgs("Creating file lists..."));
            if (!LoadGameFilesIntoDownloadList(versionsConfig))
            {
                StatusChanged(this, new StatusEventArgs("Error on creating file lists for the game!"));
                MessageBox.Show("Error on creating file lists for the game!", "Error!",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                OnClose(this, EventArgs.Empty);
                return;
            }

            //create temporary download directory
            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 the download
            StatusChanged(this, new StatusEventArgs("Downloading..."));
            fileTransfer.DownloadFilesAsync(filesToDownload.Values.ToList(), true,
                                            new Uri(updaterConfig.ServerPath), updaterConfig.TempFolder + "/",
                                            delegate(FileTransferResult result) //callback function after download is completed
            {
                filesToDownload.Clear();
                //download successful
                if (result == FileTransferResult.Success)
                {
                    InstallGame(versionsConfig.LatestUpdate);
                }
                //download unsuccessful
                else
                {
                    MessageBox.Show("Download Failure! Please Try Again",
                                    "Failure!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    OnClose(this, EventArgs.Empty);
                }
            }
                                            );
        }