public static PendingUpdates GetPendingUpdateQueues(ClientService.ClientService service) { //Initialize Checksum class to use SHA1 var encryption = new Encryption <SHA1>(); PendingUpdates returnValue = new PendingUpdates(); var lobbies = ServiceHandler.Service.CheckAvailableLobbies(); foreach (LobbyResult lobby in lobbies) { //Get autoupdate files associated with lobby var results = service.CheckForUpdates(lobby.LobbyId, true); //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(); 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; } if (lastResults == null) { Log.Write("No prior autoupdate records, will updated: " + path); updateQueue.Add(file); continue; } //Check if we don't have a record of the file at all if (!lastResults.ContainsKey(file.Filename)) { Log.Write("No record of file in autoupdate history, will update: " + path); updateQueue.Add(file); continue; } //Check that all file versions match if (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; } //Compare hashes with all protected files to those on-disk if (file.IsProtected) { var checksum = encryption.Calculate(path); if (!string.Equals(file.ValidChecksum, checksum)) { Log.Write("File checksum mismatch, will update: " + path + ", server checksum: " + file.ValidChecksum + ", local checksum: " + checksum); updateQueue.Add(file); } } } returnValue.AutoUpdateBaseAddress.Add(lobby.LobbyId, results.AutoUpdateBaseAddress); returnValue.AllFilesInUpdatePackage.Add(lobby.LobbyId, results.Files); returnValue.PendingUpdateList.Add(lobby.LobbyId, updateQueue); } return(returnValue); }
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); }