/// <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 patchPath = VersionCheck.GamePatchPath; 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 = RxPatcher.Instance.ApplyPatchFromWeb(patchPath, targetDir, applicationDir, progress, cancellationTokenSource.Token, VersionCheck.InstructionsHash); //Create the update window var window = new ApplyUpdateWindow(task, RxPatcher.Instance, progress, patchVersion, cancellationTokenSource, ApplyUpdateWindow.UpdateWindowType.Install); window.Owner = this; //Show the dialog and wait for completion window.Show(); while (!task.IsCompleted) { await Task.Delay(1000); if (cancellationTokenSource.IsCancellationRequested) { task.Dispose(); } } RxLogger.Logger.Instance.Write($"Install complete, task state isCompleted = {task.IsCompleted}"); if (task?.IsCompleted == true && task?.Status != TaskStatus.Canceled) { VersionCheck.UpdateGameVersion(); //Create the UE3 redist dialog RxLogger.Logger.Instance.Write("Creating the UE3 Redist package dialog"); ModernDialog ueRedistDialog = new ModernDialog(); ueRedistDialog.Title = "UE3 Redistributable"; ueRedistDialog.Content = MessageRedistInstall; ueRedistDialog.Buttons = new Button[] { ueRedistDialog.OkButton, ueRedistDialog.CancelButton }; ueRedistDialog.ShowDialog(); RxLogger.Logger.Instance.Write($"Did the user want to install the UE3 Redist? - {ueRedistDialog.DialogResult.Value}"); if (ueRedistDialog.DialogResult.Value == true) { bool downloadSuccess = false; var bestPatchServer = RxPatcher.Instance.UpdateServerHandler.SelectBestPatchServer(); Uri RedistServer = bestPatchServer.Uri; //Create new URL based on the patch url (Without the patch part) String redistUrl = RedistServer + "redists/UE3Redist.exe"; string systemPath = GameInstallation.GetRootPath() + "Launcher\\Redist\\UE3Redist.exe"; //Create canceltokens to stop the downloaderthread if neccesary CancellationTokenSource downloaderTokenSource = new CancellationTokenSource(); CancellationToken downloaderToken = downloaderTokenSource.Token; //Redist downloader statuswindow GeneralDownloadWindow redistWindow = new GeneralDownloadWindow(downloaderTokenSource, "UE3Redist download"); redistWindow.Show(); //Start downloading redist RxLogger.Logger.Instance.Write($"Downloading UE3 Redist from {RedistServer.AbsoluteUri}"); downloadSuccess = await DownloadRedist(redistUrl, systemPath, downloaderToken, (received, size) => { redistWindow.UpdateProgressBar(received, size); }); RxLogger.Logger.Instance.Write("UE3 Redist Download Complete"); redistWindow.Close(); if (downloadSuccess) { //When done, execute the UE3Redist here try { using (Process ue3Redist = Process.Start(systemPath)) { 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(systemPath); 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(); } } if (downloadSuccess == false) { MessageBox.Show("Unable to download the UE3 Redist (corrupt download)"); } } 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(); } }
/// <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(); } }