const int BufferSize = 30720; //bytes

        #endregion

        #region Methods

		private static string GetLobbyPath(LobbyResult lobby, string filename)
		{
			string root = null;
			string path;

			try
			{
				root = AllegianceRegistry.LobbyPath;
				path = Path.Combine(Path.Combine(root, lobby.Name), filename);
			}
			catch (Exception ex)
			{
				throw new Exception("Couldn't combine path, root: " + root + ", lobby.Name: " + lobby.Name + ", file.Filename: " + filename + ", registryRoot: " + AllegianceRegistry.Root + ", Version: " + AllegianceRegistry.Version, ex);
			}

			return path;
		}
示例#2
0
        const int BufferSize = 30720; //bytes

        #endregion

        #region Methods

        private static string GetLobbyPath(LobbyResult lobby, string filename)
        {
            string root = null;
            string path;

            try
            {
                root = AllegianceRegistry.LobbyPath;
                path = Path.Combine(Path.Combine(root, lobby.Name), filename);
            }
            catch (Exception ex)
            {
                throw new Exception("Couldn't combine path, root: " + root + ", lobby.Name: " + lobby.Name + ", file.Filename: " + filename + ", registryRoot: " + AllegianceRegistry.Root + ", Version: " + AllegianceRegistry.Version, ex);
            }

            return(path);
        }
示例#3
0
        /// <summary>
        /// If the CfgFile is not set in the allegiance registry key, then point it to the current lobby.
        /// If the CfgFile does not match the current lobby host, then point it to the config file hosted at the lobby.
        /// Note: If you are debugging, be sure to add a mime header for text/plain to your local IIS
        /// to enable it to serve .cfg files.
        /// </summary>
        /// <param name="lobby"></param>
        private static void UpdateConfigurationUrlForSelectedLobby(LobbyResult lobby)
        {
            Uri currentConfigurationUri;

            if (String.IsNullOrEmpty(AllegianceRegistry.CfgFile) == true || Uri.IsWellFormedUriString(AllegianceRegistry.CfgFile, UriKind.Absolute) == false)
            {
                currentConfigurationUri = new Uri(string.Format("http://{0}/allegiance.cfg", lobby.Host));
            }
            else
            {
                currentConfigurationUri = new Uri(AllegianceRegistry.CfgFile);
            }

            if (currentConfigurationUri.Host.Equals(lobby.Host, StringComparison.InvariantCultureIgnoreCase) == false)
            {
                currentConfigurationUri = new Uri(string.Format("http://{0}/allegiance.cfg", lobby.Host));
            }
        }
        public void GetPendingUpdateQueues()
        {
            LobbyResult lobbyResult = new LobbyResult()
            {
                Host             = "www.test.com",
                LobbyId          = 1,
                LobbyIdSpecified = true,
                Name             = "TestUpdate"
            };



            string testPath = Path.Combine(Allegiance.CommunitySecuritySystem.Client.Integration.AllegianceRegistry.LobbyPath, lobbyResult.Name);

            if (Directory.Exists(testPath) == false)
            {
                Directory.CreateDirectory(testPath);
            }

            File.WriteAllText(Path.Combine(testPath, "test1.txt"), "this is a test file. It is for testing.");

            var encryption = new Encryption <SHA1>();
            var checksum   = encryption.Calculate(Path.Combine(testPath, "test1.txt"));

            AutoUpdateResult autoUpdateResult = new AutoUpdateResult()
            {
                AutoUpdateBaseAddress = "http://www.pork.com",
                Files = new FindAutoUpdateFilesResult[]
                {
                    new FindAutoUpdateFilesResult()
                    {
                        AutoUpdateFileId          = 1,
                        AutoUpdateFileIdSpecified = true,
                        CurrentVersion            = "1.0.0.0",
                        DateCreated           = DateTime.Parse("4/8/2014"),
                        DateCreatedSpecified  = true,
                        DateModified          = DateTime.Parse("4/8/2014"),
                        DateModifiedSpecified = true,
                        Filename             = "test1-notfound.txt",
                        IsProtected          = false,
                        IsProtectedSpecified = true,
                        LobbyId          = 1,
                        LobbyIdSpecified = true,
                        ValidChecksum    = checksum
                    }
                }
            };

            if (File.Exists("autoupdate.ds") == true)
            {
                File.Delete("autoupdate.ds");
            }

            List <FindAutoUpdateFilesResult> result = Client.Service.AutoUpdate.ProcessPendingUpdates(lobbyResult, autoUpdateResult);

            Assert.AreEqual(1, result.Count, "File was not found, one update should have applied.");

            autoUpdateResult.Files[0].Filename = "test1.txt";

            result = Client.Service.AutoUpdate.ProcessPendingUpdates(lobbyResult, autoUpdateResult);

            Assert.AreEqual(0, result.Count, "No updates should have been done, checksums match.");

            autoUpdateResult.Files[0].ValidChecksum = "INVALID_CHECKSUM";

            result = Client.Service.AutoUpdate.ProcessPendingUpdates(lobbyResult, autoUpdateResult);

            Assert.AreEqual(1, result.Count, "One update should have been done, checksum miss-match with no prior update record.");

            var autoUpdate = DataStore.Open("autoupdate.ds", "Ga46^#a042");

            var lastResults = new Dictionary <string, FindAutoUpdateFilesResult>();
            //foreach (var res in result)
            //	lastResults.Add(res.Filename, res);

            string dataKey = "Files_" + lobbyResult.LobbyId;

            autoUpdate[dataKey] = lastResults;

            autoUpdate.Save();

            result = Client.Service.AutoUpdate.ProcessPendingUpdates(lobbyResult, autoUpdateResult);

            Assert.AreEqual(1, result.Count, "One update should have been done, checksum miss-match prior update dictionary exists, but no record for file.");

            autoUpdateResult.Files[0].ValidChecksum = checksum;

            foreach (var res in result)
            {
                lastResults.Add(res.Filename, res);
            }

            autoUpdate[dataKey] = lastResults;

            autoUpdate.Save();

            result = Client.Service.AutoUpdate.ProcessPendingUpdates(lobbyResult, autoUpdateResult);

            Assert.AreEqual(0, result.Count, "No updates should have been done, versions match.");

            autoUpdateResult.Files[0].CurrentVersion = "1.0.0.1";

            result = Client.Service.AutoUpdate.ProcessPendingUpdates(lobbyResult, autoUpdateResult);

            Assert.AreEqual(1, result.Count, "File version miss-match with previous version of file, update applied.");

            autoUpdateResult.Files[0].CurrentVersion = "1.0.0.0";
            autoUpdateResult.Files[0].IsProtected    = false;
            autoUpdateResult.Files[0].ValidChecksum  = "INVALID_CHECKSUM";

            result = Client.Service.AutoUpdate.ProcessPendingUpdates(lobbyResult, autoUpdateResult);

            Assert.AreEqual(1, result.Count, "updates should have been done, versions are same, checksum is different, file is not protected and the user has not modified the file.");

            autoUpdateResult.Files[0].DateModified = DateTime.Parse("1/1/2015");

            result = Client.Service.AutoUpdate.ProcessPendingUpdates(lobbyResult, autoUpdateResult);

            Assert.AreEqual(0, result.Count, "updates should not have been done, versions are same, checksum is different, file is not protected and the user has modified the file since the last update.");

            //autoUpdateResult.Files[0].DateModified = DateTime.Parse("4/8/2014");

            autoUpdateResult.Files[0].CurrentVersion = "1.0.0.0";
            autoUpdateResult.Files[0].IsProtected    = true;
            autoUpdateResult.Files[0].ValidChecksum  = "INVALID_CHECKSUM";

            result = Client.Service.AutoUpdate.ProcessPendingUpdates(lobbyResult, autoUpdateResult);

            Assert.AreEqual(1, result.Count, "updates should have been done, versions are same, checksum is different, file is protected and the user has modified the file.");
        }
示例#5
0
        public static bool ProcessPendingUpdates(PendingUpdates pendingUpdates, LobbyResult lobby, AutoupdateProgressCallback progressCallback, Control parentControl)
        {
            string dataKey    = "Files_" + lobby.LobbyId;
            var    autoUpdate = DataStore.Open("autoupdate.ds", "Ga46^#a042");
            bool   updateExe  = false;
            int    received   = 0;
            bool   continueDownloadingFiles = true;

            //Get files from auto-update
            foreach (var file in pendingUpdates.PendingUpdateList[lobby.LobbyId])
            {
                if (continueDownloadingFiles == false)
                {
                    return(false);
                }

                var filename     = file.Filename;
                var downloadPath = String.Empty;

                //Check if filename matches the ClientExecutableName
                if (string.Equals(file.Filename, GlobalSettings.ClientExecutableName))
                {
                    filename     = GlobalSettings.TempExecutableName;
                    updateExe    = true;
                    downloadPath = Path.Combine(AllegianceRegistry.LobbyPath, filename);
                }
                // Launcher.PDB also goes into the lobby root.
                else if (string.Equals(file.Filename, GlobalSettings.ClientExecutablePDB))
                {
                    downloadPath = Path.Combine(AllegianceRegistry.LobbyPath, file.Filename);
                }
                else
                {
                    downloadPath = GetLobbyPath(lobby, filename);
                }

                if (!Directory.Exists(Path.GetDirectoryName(downloadPath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(downloadPath));
                }

                var message = string.Format("Updating {0}...", file.Filename);

                try
                {
                    continueDownloadingFiles = DownloadFile(++received, pendingUpdates.PendingUpdateList[lobby.LobbyId].Count, pendingUpdates.AutoUpdateBaseAddress[lobby.LobbyId],
                                                            lobby.LobbyId, file.Filename, downloadPath, lobby.Name, progressCallback);

                    message += " Succeeded.";
                }
                catch (Exception error)
                {
                    message += string.Concat(" Failed: ", error.Message);
                    message += "\n autoUpdateURL: " + pendingUpdates.AutoUpdateBaseAddress[lobby.LobbyId];
                    message += "\n lobby.LobbyId: " + lobby.LobbyId;
                    message += "\n received: " + received;
                    message += "\n updateQueue.Count: " + pendingUpdates.PendingUpdateList[lobby.LobbyId].Count;
                    message += "\n file.Filename: " + file.Filename;
                    message += "\n downloadPath: " + downloadPath;
                    message += "\n exception details: " + error.ToString();
                    throw;
                }
                finally
                {
                    Log.Write(message);
                }
            }

            //Save updated AutoUpdateResults dictionary to datastore
            if (pendingUpdates.PendingUpdateList[lobby.LobbyId].Count != 0)
            {
                var dictionary = new Dictionary <string, FindAutoUpdateFilesResult>();
                foreach (var f in pendingUpdates.AllFilesInUpdatePackage[lobby.LobbyId])
                {
                    dictionary.Add(f.Filename, f);
                }

                autoUpdate[dataKey] = dictionary;
                autoUpdate.Save();
            }

            if (updateExe)             //Start the new executable, which will wait for this process to complete its autoupdate
            {
                var signal = new UiInteraction(delegate()
                {
                    MessageBox.Show("The Allegiance Security Client has an update and must restart.");
                    var tempLauncher = Path.Combine(AllegianceRegistry.LobbyPath, GlobalSettings.TempExecutableName);
                    Process.Start(tempLauncher);
                    Application.Exit();
                });

                if (parentControl.InvokeRequired == true)
                {
                    parentControl.Invoke(signal);
                }
                else
                {
                    signal();
                }
            }
            else
            {
                //Update the registry to assign the configuration url to the lobby's host value
                UpdateConfigurationUrlForSelectedLobby(lobby);
            }

            return(updateExe);
        }
示例#6
0
        public static List <FindAutoUpdateFilesResult> ProcessPendingUpdates(LobbyResult lobby, AutoUpdateResult results)
        {
            //Initialize Checksum class to use SHA1
            var encryption = new Encryption <SHA1>();

            //var root        = AllegianceRegistry.EXEPath; //Allegiance root directory
            var    autoUpdate  = DataStore.Open("autoupdate.ds", "Ga46^#a042");
            string dataKey     = "Files_" + lobby.LobbyId;
            var    lastResults = autoUpdate[dataKey] as Dictionary <string, FindAutoUpdateFilesResult>;
            List <FindAutoUpdateFilesResult> updateQueue = new List <FindAutoUpdateFilesResult>();

            //Check files which need update
            foreach (var file in results.Files)
            {
                DebugDetector.AssertCheckRunning();

                // You can put this in if you are testing the launcher with the production CSS server.
                // Turn off file protection on the launcher on the CSS server's Auto Update version of the launcher,
                // then drop the debug version of the launcher into your local game directory. Then you can
                // launch the launcher from the debugger and work with it.
//#if DEBUG
//                if (file.Filename.EndsWith("Launcher.exe", StringComparison.InvariantCultureIgnoreCase) == true
//                    || file.Filename.EndsWith("Launcher.pdb", StringComparison.InvariantCultureIgnoreCase) == true)
//                    continue;
//#endif

                string path;

                if (string.Equals(file.Filename, GlobalSettings.ClientExecutableName) ||
                    string.Equals(file.Filename, GlobalSettings.ClientExecutablePDB))
                {
                    path = Path.Combine(AllegianceRegistry.LobbyPath, file.Filename);
                }
                else
                {
                    path = GetLobbyPath(lobby, file.Filename);
                }

                //Check that all files exist
                if (!File.Exists(path))
                {
                    Log.Write("File did not exist: " + path + ", will update.");
                    updateQueue.Add(file);
                    continue;
                }

                //Check that all file versions match
                if (lastResults != null && lastResults.ContainsKey(file.Filename) &&
                    (file.CurrentVersion != lastResults[file.Filename].CurrentVersion))
                {
                    Log.Write("File version mismatch, will update: " + file.Filename + ", server version: " + file.CurrentVersion + ", local version: " + lastResults[file.Filename].CurrentVersion);

                    updateQueue.Add(file);
                    continue;
                }

                // Test for checksum match, and if they don't replace the file if:
                // * This is the first time AutoUpdate has run for this installation.
                // * This is the first time this file has been seen by AutoUpdate
                // * The file has the protected flag turned on.
                var checksum = encryption.Calculate(path);
                if (!string.Equals(file.ValidChecksum, checksum))
                {
                    // If there haven't been any updates at all, and the checksums don't match, then overwrite the unknown file. (old installation / left over files from a previous uninstall)
                    if (lastResults == null)
                    {
                        Log.Write("No prior autoupdate records, will updated: " + path);
                        updateQueue.Add(file);
                        continue;
                    }

                    // If there wasn't a prior update applied for the file, and the checksums don't match, then overwrite the unknown file. (An older file is on disk, and was re-added to the auto update system)
                    if (!lastResults.ContainsKey(file.Filename))
                    {
                        Log.Write("No record of file in autoupdate history, will update: " + path);
                        updateQueue.Add(file);
                        continue;
                    }

                    // If the file was changed on the server, but not modified by the user, then update.
                    if (lastResults[file.Filename].DateModified == file.DateModified)
                    {
                        Log.Write("file was not user modified, and a change was detected from AU, will update: " + path);
                        updateQueue.Add(file);
                        continue;
                    }

                    // If the file is protected and the hashes don't match, then update.
                    if (file.IsProtected)
                    {
                        Log.Write("File checksum mismatch, will update: " + path + ", server checksum: " + file.ValidChecksum + ", local checksum: " + checksum);
                        updateQueue.Add(file);
                        continue;
                    }
                }
            }

            return(updateQueue);
        }
 private static LobbyResult GetProduction(LobbyResult[] results)
 {
     foreach (var l in results)
     {
         if (l.Name == "Production")
             return l;
     }
     throw new Exception("Could not find specified lobby.");
 }
        public void GetPendingUpdateQueues()
        {
            LobbyResult lobbyResult = new LobbyResult()
            {
                Host = "www.test.com",
                LobbyId = 1,
                LobbyIdSpecified = true,
                Name = "TestUpdate"
            };

            string testPath = Path.Combine(Allegiance.CommunitySecuritySystem.Client.Integration.AllegianceRegistry.LobbyPath, lobbyResult.Name);

            if(Directory.Exists(testPath) == false)
                Directory.CreateDirectory(testPath);

            File.WriteAllText(Path.Combine(testPath, "test1.txt"), "this is a test file. It is for testing.");

            var encryption = new Encryption<SHA1>();
            var checksum = encryption.Calculate(Path.Combine(testPath, "test1.txt"));

            AutoUpdateResult autoUpdateResult = new AutoUpdateResult()
            {
                AutoUpdateBaseAddress = "http://www.pork.com",
                Files = new FindAutoUpdateFilesResult[]
                {
                    new FindAutoUpdateFilesResult()
                    {
                        AutoUpdateFileId = 1,
                        AutoUpdateFileIdSpecified = true,
                         CurrentVersion = "1.0.0.0",
                         DateCreated = DateTime.Parse("4/8/2014"),
                         DateCreatedSpecified = true,
                         DateModified = DateTime.Parse("4/8/2014"),
                         DateModifiedSpecified = true,
                         Filename = "test1-notfound.txt",
                         IsProtected = false,
                         IsProtectedSpecified = true,
                         LobbyId = 1,
                         LobbyIdSpecified = true,
                         ValidChecksum = checksum
                    }
                }
            };

            if (File.Exists("autoupdate.ds") == true)
                File.Delete("autoupdate.ds");

            List<FindAutoUpdateFilesResult> result = Client.Service.AutoUpdate.ProcessPendingUpdates(lobbyResult, autoUpdateResult);

            Assert.AreEqual(1, result.Count, "File was not found, one update should have applied.");

            autoUpdateResult.Files[0].Filename = "test1.txt";

            result = Client.Service.AutoUpdate.ProcessPendingUpdates(lobbyResult, autoUpdateResult);

            Assert.AreEqual(0, result.Count, "No updates should have been done, checksums match.");

            autoUpdateResult.Files[0].ValidChecksum = "INVALID_CHECKSUM";

            result = Client.Service.AutoUpdate.ProcessPendingUpdates(lobbyResult, autoUpdateResult);

            Assert.AreEqual(1, result.Count, "One update should have been done, checksum miss-match with no prior update record.");

            var autoUpdate = DataStore.Open("autoupdate.ds", "Ga46^#a042");

            var lastResults = new Dictionary<string, FindAutoUpdateFilesResult>();
            //foreach (var res in result)
            //	lastResults.Add(res.Filename, res);

            string dataKey = "Files_" + lobbyResult.LobbyId;
            autoUpdate[dataKey] = lastResults;

            autoUpdate.Save();

            result = Client.Service.AutoUpdate.ProcessPendingUpdates(lobbyResult, autoUpdateResult);

            Assert.AreEqual(1, result.Count, "One update should have been done, checksum miss-match prior update dictionary exists, but no record for file.");

            autoUpdateResult.Files[0].ValidChecksum = checksum;

            foreach (var res in result)
                lastResults.Add(res.Filename, res);

            autoUpdate[dataKey] = lastResults;

            autoUpdate.Save();

            result = Client.Service.AutoUpdate.ProcessPendingUpdates(lobbyResult, autoUpdateResult);

            Assert.AreEqual(0, result.Count, "No updates should have been done, versions match.");

            autoUpdateResult.Files[0].CurrentVersion = "1.0.0.1";

            result = Client.Service.AutoUpdate.ProcessPendingUpdates(lobbyResult, autoUpdateResult);

            Assert.AreEqual(1, result.Count, "File version miss-match with previous version of file, update applied.");

            autoUpdateResult.Files[0].CurrentVersion = "1.0.0.0";
            autoUpdateResult.Files[0].IsProtected = false;
            autoUpdateResult.Files[0].ValidChecksum = "INVALID_CHECKSUM";

            result = Client.Service.AutoUpdate.ProcessPendingUpdates(lobbyResult, autoUpdateResult);

            Assert.AreEqual(1, result.Count, "updates should have been done, versions are same, checksum is different, file is not protected and the user has not modified the file.");

            autoUpdateResult.Files[0].DateModified = DateTime.Parse("1/1/2015");

            result = Client.Service.AutoUpdate.ProcessPendingUpdates(lobbyResult, autoUpdateResult);

            Assert.AreEqual(0, result.Count, "updates should not have been done, versions are same, checksum is different, file is not protected and the user has modified the file since the last update.");

            //autoUpdateResult.Files[0].DateModified = DateTime.Parse("4/8/2014");

            autoUpdateResult.Files[0].CurrentVersion = "1.0.0.0";
            autoUpdateResult.Files[0].IsProtected = true;
            autoUpdateResult.Files[0].ValidChecksum = "INVALID_CHECKSUM";

            result = Client.Service.AutoUpdate.ProcessPendingUpdates(lobbyResult, autoUpdateResult);

            Assert.AreEqual(1, result.Count, "updates should have been done, versions are same, checksum is different, file is protected and the user has modified the file.");
        }
		public static List<FindAutoUpdateFilesResult> ProcessPendingUpdates(LobbyResult lobby, AutoUpdateResult results)
		{
			//Initialize Checksum class to use SHA1
			var encryption = new Encryption<SHA1>();

			//var root        = AllegianceRegistry.EXEPath; //Allegiance root directory
			var autoUpdate = DataStore.Open("autoupdate.ds", "Ga46^#a042");
			string dataKey = "Files_" + lobby.LobbyId;
			var lastResults = autoUpdate[dataKey] as Dictionary<string, FindAutoUpdateFilesResult>;
			List<FindAutoUpdateFilesResult> updateQueue = new List<FindAutoUpdateFilesResult>();

			//Check files which need update
			foreach (var file in results.Files)
			{
				DebugDetector.AssertCheckRunning();

				// You can put this in if you are testing the launcher with the production CSS server. 
				// Turn off file protection on the launcher on the CSS server's Auto Update version of the launcher, 
				// then drop the debug version of the launcher into your local game directory. Then you can 
				// launch the launcher from the debugger and work with it.
//#if DEBUG
//                if (file.Filename.EndsWith("Launcher.exe", StringComparison.InvariantCultureIgnoreCase) == true
//                    || file.Filename.EndsWith("Launcher.pdb", StringComparison.InvariantCultureIgnoreCase) == true)
//                    continue;
//#endif 

				string path;

				if (string.Equals(file.Filename, GlobalSettings.ClientExecutableName)
					|| string.Equals(file.Filename, GlobalSettings.ClientExecutablePDB))
					path = Path.Combine(AllegianceRegistry.LobbyPath, file.Filename);
				else
					path = GetLobbyPath(lobby, file.Filename);

				//Check that all files exist
				if (!File.Exists(path))
				{
					Log.Write("File did not exist: " + path + ", will update.");
					updateQueue.Add(file);
					continue;
				}

				//Check that all file versions match
				if (lastResults != null && lastResults.ContainsKey(file.Filename)
					&& (file.CurrentVersion != lastResults[file.Filename].CurrentVersion))
				{
					Log.Write("File version mismatch, will update: " + file.Filename + ", server version: " + file.CurrentVersion + ", local version: " + lastResults[file.Filename].CurrentVersion);

					updateQueue.Add(file);
					continue;
				}

				// Test for checksum match, and if they don't replace the file if:
				// * This is the first time AutoUpdate has run for this installation.
				// * This is the first time this file has been seen by AutoUpdate
				// * The file has the protected flag turned on.
				var checksum = encryption.Calculate(path);
				if (!string.Equals(file.ValidChecksum, checksum))
				{
					// If there haven't been any updates at all, and the checksums don't match, then overwrite the unknown file. (old installation / left over files from a previous uninstall)
					if (lastResults == null)
					{
						Log.Write("No prior autoupdate records, will updated: " + path);
						updateQueue.Add(file);
						continue;
					}

					// If there wasn't a prior update applied for the file, and the checksums don't match, then overwrite the unknown file. (An older file is on disk, and was re-added to the auto update system)
					if (!lastResults.ContainsKey(file.Filename))
					{
						Log.Write("No record of file in autoupdate history, will update: " + path);
						updateQueue.Add(file);
						continue;
					}

					// If the file was changed on the server, but not modified by the user, then update.
					if (lastResults[file.Filename].DateModified == file.DateModified)
					{
						Log.Write("file was not user modified, and a change was detected from AU, will update: " + path);
						updateQueue.Add(file);
						continue;
					}

					// If the file is protected and the hashes don't match, then update.
					if (file.IsProtected)
					{
						Log.Write("File checksum mismatch, will update: " + path + ", server checksum: " + file.ValidChecksum + ", local checksum: " + checksum);
						updateQueue.Add(file);
						continue;
					}
				}
			}

			return updateQueue;
		}
		/// <summary>
		/// If the CfgFile is not set in the allegiance registry key, then point it to the current lobby.
		/// If the CfgFile does not match the current lobby host, then point it to the config file hosted at the lobby.
		/// Note: If you are debugging, be sure to add a mime header for text/plain to your local IIS 
		/// to enable it to serve .cfg files.
		/// </summary>
		/// <param name="lobby"></param>
		private static void UpdateConfigurationUrlForSelectedLobby(LobbyResult lobby)
		{
			Uri currentConfigurationUri;

			if (String.IsNullOrEmpty(AllegianceRegistry.CfgFile) == true || Uri.IsWellFormedUriString(AllegianceRegistry.CfgFile, UriKind.Absolute) == false)
				currentConfigurationUri = new Uri(string.Format("http://{0}/allegiance.cfg", lobby.Host));
			else
				currentConfigurationUri = new Uri(AllegianceRegistry.CfgFile);

			if(currentConfigurationUri.Host.Equals(lobby.Host, StringComparison.InvariantCultureIgnoreCase) == false)
				currentConfigurationUri = new Uri(string.Format("http://{0}/allegiance.cfg", lobby.Host));

		}
		public static bool ProcessPendingUpdates(PendingUpdates pendingUpdates, LobbyResult lobby, AutoupdateProgressCallback progressCallback, Control parentControl)
        {
			string dataKey = "Files_" + lobby.LobbyId; 
			var autoUpdate = DataStore.Open("autoupdate.ds", "Ga46^#a042");
			bool updateExe = false;
			int received = 0;
			bool continueDownloadingFiles = true;

            //Get files from auto-update
			foreach (var file in pendingUpdates.PendingUpdateList[lobby.LobbyId])
            {
				if (continueDownloadingFiles == false)
					return false;

                var filename    = file.Filename;
				var downloadPath = String.Empty;

                //Check if filename matches the ClientExecutableName
				if (string.Equals(file.Filename, GlobalSettings.ClientExecutableName))
				{
					filename = GlobalSettings.TempExecutableName;
					updateExe = true; 
					downloadPath = Path.Combine(AllegianceRegistry.LobbyPath, filename);
				}
				// Launcher.PDB also goes into the lobby root.
				else if (string.Equals(file.Filename, GlobalSettings.ClientExecutablePDB))
				{
					filename = GlobalSettings.TempExecutablePDB;
					downloadPath = Path.Combine(AllegianceRegistry.LobbyPath, filename);
				}
				else
				{
					downloadPath = GetLobbyPath(lobby, filename);
				}

                if (!Directory.Exists(Path.GetDirectoryName(downloadPath)))
                    Directory.CreateDirectory(Path.GetDirectoryName(downloadPath));

                var message = string.Format("Updating {0}...", file.Filename);

                try
                {
					continueDownloadingFiles = DownloadFile(++received, pendingUpdates.PendingUpdateList[lobby.LobbyId].Count, pendingUpdates.AutoUpdateBaseAddress[lobby.LobbyId], 
                        lobby.LobbyId, file.Filename, downloadPath, lobby.Name, progressCallback);

                    message += " Succeeded.";
                }
                catch (Exception error)
                {
                    message += string.Concat(" Failed: ", error.Message);
					message += "\n autoUpdateURL: " + pendingUpdates.AutoUpdateBaseAddress[lobby.LobbyId];
					message += "\n lobby.LobbyId: " + lobby.LobbyId;
					message += "\n received: " + received;
					message += "\n updateQueue.Count: " + pendingUpdates.PendingUpdateList[lobby.LobbyId].Count;
					message += "\n file.Filename: " + file.Filename;
					message += "\n downloadPath: " + downloadPath;
					message += "\n exception details: " + error.ToString();
                    throw;
                }
                finally
                {
                    Log.Write(message);
                }
            }

            //Save updated AutoUpdateResults dictionary to datastore
			if (pendingUpdates.PendingUpdateList[lobby.LobbyId].Count != 0)
            {
                var dictionary = new Dictionary<string, FindAutoUpdateFilesResult>();
				foreach (var f in pendingUpdates.AllFilesInUpdatePackage[lobby.LobbyId])
                    dictionary.Add(f.Filename, f);

				autoUpdate[dataKey] = dictionary;
                autoUpdate.Save();
            }

			if (updateExe) //Start the new executable, which will wait for this process to complete its autoupdate
			{
				var signal = new UiInteraction(delegate()
				{
					MessageBox.Show("The Allegiance Security Client has an update and must restart.");
					var tempLauncher = Path.Combine(AllegianceRegistry.LobbyPath, GlobalSettings.TempExecutableName);
					Process.Start(tempLauncher);
					Application.Exit();
				});

				if (parentControl.InvokeRequired == true)
					parentControl.Invoke(signal);
				else
					signal();
			}
            else
            {
                //Update the registry to assign the configuration url to the lobby's host value
				UpdateConfigurationUrlForSelectedLobby(lobby);
            }

            return updateExe;
        }
 private static LobbyResult GetLobbyByName(LobbyResult[] results, string lobbyName)
 {
     foreach (var l in results)
     {
         if (l.Name == lobbyName)
             return l;
     }
     throw new Exception("Could not find specified lobby: " + lobbyName);
 }