private void ApplyResetOrVerify(ApplyUpdateWindow.UpdateWindowType type) { var targetDir = GameInstallation.GetRootPath(); var applicationDir = System.IO.Path.Combine(GameInstallation.GetRootPath(), "patch"); var patchUrls = VersionCheck.GamePatchUrls; var patchVersion = VersionCheck.GetLatestGameVersionName(); var progress = new Progress <DirectoryPatcherProgressReport>(); var cancellationTokenSource = new System.Threading.CancellationTokenSource(); Task task = new RXPatcher().ApplyPatchFromWeb(patchUrls, targetDir, applicationDir, progress, cancellationTokenSource.Token); var window = new ApplyUpdateWindow(task, progress, patchVersion, cancellationTokenSource, type); window.Owner = this; window.ShowDialog(); VersionCheck.UpdateGameVersion(); }
void ShowGameUpdateWindow(out bool wasUpdated) { UpdateAvailableWindow theWindow = new UpdateAvailableWindow(); theWindow.LatestVersionText.Content = VersionCheck.GetLatestGameVersionName(); theWindow.GameVersionText.Content = VersionCheck.GetGameVersionName(); theWindow.WindowTitle.Content = "Game update available!"; theWindow.Owner = this; theWindow.ShowDialog(); if (!theWindow.WantsToUpdate) { wasUpdated = false; } else { // Close any other instances of the RenX-Launcher if (InstanceHandler.IsAnotherInstanceRunning()) { InstanceHandler.KillDuplicateInstance(); } var targetDir = GameInstallation.GetRootPath(); var applicationDir = Path.Combine(GameInstallation.GetRootPath(), "patch"); var patchPath = VersionCheck.GamePatchPath; var patchUrls = VersionCheck.GamePatchUrls; var patchVersion = VersionCheck.GetLatestGameVersionName(); var progress = new Progress <DirectoryPatcherProgressReport>(); var cancellationTokenSource = new CancellationTokenSource(); var patcher = new RXPatcher(); Task task = patcher.ApplyPatchFromWeb(patchUrls.Select(url => url.ServerUri.AbsoluteUri).ToArray(), patchPath, targetDir, applicationDir, progress, cancellationTokenSource.Token, VersionCheck.InstructionsHash); var window = new ApplyUpdateWindow(task, patcher, progress, patchVersion, cancellationTokenSource, ApplyUpdateWindow.UpdateWindowType.Update); window.Owner = this; window.ShowDialog(); VersionCheck.UpdateGameVersion(); wasUpdated = true; } }
/// <summary> /// Initializes the updatewindow /// </summary> /// <param name="patchTask">The update task</param> /// <param name="progress"></param> /// <param name="targetVersionString">The version to update to</param> /// <param name="cancellationTokenSource">Cancellationsource for the updatetask</param> /// <param name="isInstall">Is this the first install</param> public ApplyUpdateWindow(Task patchTask, RXPatcher patcher, Progress <DirectoryPatcherProgressReport> progress, string targetVersionString, CancellationTokenSource cancellationTokenSource, UpdateWindowType type) { TargetVersionString = targetVersionString; CancellationTokenSource = cancellationTokenSource; string[] StatusTitle = new string[] { "updated", "update" }; Dictionary <UpdateWindowType, string[]> StatusTitleDict = new Dictionary <UpdateWindowType, string[]>() { { UpdateWindowType.Install, new string[] { "installed", "installation" } }, { UpdateWindowType.Update, new string[] { "updated", "update" } }, { UpdateWindowType.Verify, new string[] { "verified", "verification" } }, { UpdateWindowType.Reset, new string[] { "modified", "modification" } } }; StatusTitleDict.TryGetValue(type, out StatusTitle); this.StatusMessage = string.Format("Please wait while Renegade X is being {0}.", StatusTitle[0]); if (patcher.BaseURL == null || patcher.BaseURL == "") { this.ServerMessage = "pending"; } else { this.ServerMessage = patcher.BaseURL; } InitializeComponent(); this.Title = string.Format("Renegade X {0} ", StatusTitle[1]); DirectoryPatcherProgressReport lastReport = new DirectoryPatcherProgressReport(); progress.ProgressChanged += (o, report) => lastReport = report; Task backgroundTask = Task.Factory.StartNew(async() => { while (await Task.WhenAny(patchTask, Task.Delay(500)) != patchTask) { // URL could theoretically change at any point if (this.ServerMessage != patcher.BaseURL) { if (patcher.BaseURL == null) { this.ServerMessage = "pending"; } else { this.ServerMessage = patcher.BaseURL; } } ProgressReport = lastReport; } ProgressReport = lastReport; try { await patchTask; // Collect exceptions. this.StatusMessage = string.Format("Renegade X was successfully {0} to version {1}.", StatusTitle[0], TargetVersionString); } catch (Exception exception) { StatusMessage = string.Format("Renegade X could not be {0}. The following exception occurred:\n\n{1}", StatusTitle[0], exception.Message); } HasFinished = true; }); }
/// <summary> /// Function to control the first launch install. /// </summary> public async void FirstInstall() { VersionCheck.GetLatestGameVersionName(); await VersionCheck.UpdateLatestVersions(); //Get the current root path and prepare the installation var targetDir = GameInstallation.GetRootPath(); var applicationDir = System.IO.Path.Combine(GameInstallation.GetRootPath(), "patch"); var patchUrls = VersionCheck.GamePatchUrls; var patchVersion = VersionCheck.GetLatestGameVersionName(); //Create an empty var containing the progress report from the patcher var progress = new Progress <DirectoryPatcherProgressReport>(); var cancellationTokenSource = new System.Threading.CancellationTokenSource(); Task task = new RXPatcher().ApplyPatchFromWeb(patchUrls, targetDir, applicationDir, progress, cancellationTokenSource.Token); //Create the update window int index = await new UpdateServerSelector().SelectHostIndex(patchUrls); var window = new ApplyUpdateWindow(task, progress, patchVersion, cancellationTokenSource, ApplyUpdateWindow.UpdateWindowType.Install, new Uri(patchUrls[index]).Host); //window.Owner = this; //Show the dialog and wait for completion window.ShowDialog(); if (task.IsCompleted == true) { VersionCheck.UpdateGameVersion(); //Create the UE3 redist dialog if (UERedistDialog.DialogResult.Value == true) { //Determine which server has best ping String[] PatchUrls = VersionCheck.GamePatchUrls; RXPatchLib.UpdateServerSelector Selector = new RXPatchLib.UpdateServerSelector(); //Need to solve a import issue regarding duplicate classes Task <int> SelectorTask = Selector.SelectHostIndex(VersionCheck.GamePatchUrls); //NEed to suppress the ui from showing here await SelectorTask; Uri Redistserver = new Uri(PatchUrls[SelectorTask.Result]); //Create new URL based on the patch url (Without the patch part) String RedistUrl = "http://" + Redistserver.Host + "/redists/UE3Redist.exe"; string SystemUrl = GameInstallation.GetRootPath() + "Launcher\\Redist\\UE3Redist.exe"; //Create canceltokens to stop the downloaderthread if neccesary CancellationTokenSource downloaderTokenSource = new CancellationTokenSource(); CancellationToken downloaderToken = downloaderTokenSource.Token; //Task for downloading the redist from patch server Task RedistDownloader = new Task(() => { System.IO.Directory.CreateDirectory(GameInstallation.GetRootPath() + "Launcher\\Redist"); System.Net.WebClient RedistRequest = new WebClient(); RedistRequest.DownloadFileAsync(new Uri(RedistUrl), SystemUrl); while (RedistRequest.IsBusy && !downloaderToken.IsCancellationRequested) { if (downloaderToken.IsCancellationRequested) { RedistRequest.CancelAsync(); } //Thread.Sleep(1000); } }, downloaderToken); //Redist downloader statuswindow GeneralDownloadWindow RedistWindow = new GeneralDownloadWindow(downloaderTokenSource, "UE3Redist download"); RedistWindow.Show(); //Task to keep the status of the UE3Redist download Task RedistDownloadStatus = new Task(() => { WebRequest req = System.Net.HttpWebRequest.Create(RedistUrl); req.Method = "HEAD"; int ContentLength; using (WebResponse resp = req.GetResponse()) { int.TryParse(resp.Headers.Get("Content-Length"), out ContentLength); } RedistWindow.initProgressBar(ContentLength); while (RedistDownloader.Status == TaskStatus.Running) { RedistWindow.Status = "Downloading UE3Redist"; FileInfo inf = new FileInfo(SystemUrl); RedistWindow.updateProgressBar(inf.Length); //Thread.Sleep(1000); } }); //Start downloading RedistDownloader.Start(); RedistDownloadStatus.Start(); await RedistDownloader; RedistWindow.Close(); //When done, execute the UE3Redist here try { using (Process UE3Redist = Process.Start(GameInstallation.GetRootPath() + "Launcher\\Redist\\UE3Redist.exe")) { UE3Redist.WaitForExit(); if (UE3Redist.ExitCode != 0)//If redist install fails, notify the user { MessageBox.Show("Error while installing the UE3 Redist."); } else//Everything done! save installed flag and restart { Properties.Settings.Default.Installed = true; Properties.Settings.Default.Save(); try { System.IO.File.Delete(GameInstallation.GetRootPath() + "Launcher\\Redist\\UE3Redist.exe"); System.IO.Directory.Delete(GameInstallation.GetRootPath() + "Launcher\\Redist\\"); } catch (Exception) { MessageBox.Show("Could not cleanup the redist file. This won't hinder the game."); } } } } catch { MessageBox.Show("Error while executing the UE3 Redist."); } finally { //Restart launcher System.Diagnostics.Process.Start(Application.ResourceAssembly.Location); Application.Current.Shutdown(); } } else { ModernDialog notInstalledDialog = new ModernDialog(); notInstalledDialog.Title = "UE3 Redistributable"; notInstalledDialog.Content = MessageNotInstalled; notInstalledDialog.Buttons = new Button[] { notInstalledDialog.OkButton }; notInstalledDialog.ShowDialog(); //Shutdown launcher Application.Current.Shutdown(); } } else { Application.Current.Shutdown(); } }