void ShowGameUpdateWindow(out bool wasUpdated) { RxLogger.Logger.Instance.Write("Showing game update window"); 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 { //Get the previous vid that plays and store it. Nullify the playing vid so no handle is open Uri previousVid = sv_MapPreviewVid.Source; sv_MapPreviewVid.Source = null; // 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(); RxLogger.Logger.Instance.Write($"Starting game update | TargetDir: {targetDir} | AppDir: {applicationDir} | PatchPath: {patchPath},| PatchVersion: {patchVersion}"); Task task = RxPatcher.Instance.ApplyPatchFromWeb(patchPath, targetDir, applicationDir, progress, cancellationTokenSource.Token, VersionCheck.InstructionsHash); RxLogger.Logger.Instance.Write("Download complete, Showing ApplyUpdateWindow"); var window = new ApplyUpdateWindow(task, RxPatcher.Instance, progress, patchVersion, cancellationTokenSource, ApplyUpdateWindow.UpdateWindowType.Update); window.Owner = this; window.ShowDialog(); VersionCheck.UpdateGameVersion(); wasUpdated = true; //Resume playback of vid sv_MapPreviewVid.Source = previousVid; sv_MapPreviewVid.Play(); // Refresh server list StartRefreshingServers(); } }
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> /// 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(); } }