private void InstallTSO() { if (File.Exists(Path.GetTempPath() + "\\The Sims Online Setup Files.zip")) { this.Dispatcher.Invoke(() => { m_TSOInstallPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\Maxis\\The Sims Online"; var Result = MessageBox.Show("Installation Path", "The default installation path is: " + m_TSOInstallPath + "\r\nDo you wish to change it?", ButtonType.YesNo); if (Result != false) { FolderBrowserDialog FBrowserDiag = new FolderBrowserDialog(); if (FBrowserDiag.ShowDialog() != System.Windows.Forms.DialogResult.Cancel) { m_TSOInstallPath = FBrowserDiag.SelectedPath; } } UpdateUI(UIState.DownloadedTSO); }); FileStream FStream = File.Open(Path.GetTempPath() + "\\The Sims Online Setup Files.zip", FileMode.Open); ZipArchive Archive = new ZipArchive(FStream, ZipArchiveMode.Update); //Normalize the path. m_TSOInstallPath = Path.GetFullPath(m_TSOInstallPath); // Ensures that the last character on the extraction path // is the directory separator char. // Without this, a malicious zip file could try to traverse outside of the expected // extraction path. if (!m_TSOInstallPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal)) { m_TSOInstallPath += Path.DirectorySeparatorChar; } Directory.CreateDirectory(m_TSOInstallPath); int TopmostValue = 100; //In percent. int TotalCount = 0; int EntryCount = 1; //Run through the entries and only count actual files, not dirs. foreach (ZipArchiveEntry Entry in Archive.Entries) { if (Path.HasExtension(m_PDInstallPath + "\\" + Entry.Name)) { TotalCount++; } } Debug.WriteLine("Number of entries that are files: " + TotalCount); Debug.WriteLine("Total number of entries: " + Archive.Entries.Count); foreach (ZipArchiveEntry Entry in Archive.Entries) { // Gets the full path to ensure that relative segments are removed. string DestinationPath = Path.GetFullPath(Path.Combine(m_TSOInstallPath, Entry.FullName)); if (Path.HasExtension(m_TSOInstallPath + "\\" + Entry.Name)) { // Ordinal match is safest, case-sensitive volumes can be mounted within volumes that // are case-insensitive. if (DestinationPath.StartsWith(m_TSOInstallPath, StringComparison.Ordinal)) { Entry.ExtractToFile(DestinationPath, true); EntryCount++; } } else { Directory.CreateDirectory(DestinationPath); } UpdateUI(UIState.InstallingTSO, ((TopmostValue * EntryCount) / TotalCount)); } FStream.Close(); WindowsInstaller.CreateRegistry(m_TSOInstallPath); this.Dispatcher.Invoke(() => { var Result = MessageBox.Show("Finished", "Installation completed successfully!\r\n " + "Do you want a desktop icon to Project Dollhouse?", ButtonType.YesNo); if (Result == true) { WindowsInstaller.CreateDesktopIcon("ProjectDollhouse", m_PDInstallPath + m_PDEXECUTABLE, m_PDInstallPath); } UpdateUI(UIState.InstalledTSO); }); } }
private void CheckForPDDownloadEnd() { bool Continue = false; while (true) { lock (m_PDInstallationEndedLocker) { if (m_PDInstallationEnded) { Debug.WriteLine("PD installation ended!"); Continue = true; } } if (Continue) { if (!Directory.Exists(m_PDInstallPath)) { Directory.CreateDirectory(m_PDInstallPath); } if (File.Exists(Path.GetTempPath() + "\\PD.zip")) { InstallPD(); } if (!WindowsInstaller.CheckRegistry()) { var Result = false; this.Dispatcher.Invoke(() => { Result = (bool)MessageBox.Show("The Sims Online", "The Sims Online was not installed on your system. " + "\r\nIt is required to run Project Dollhouse. " + "\r\nDo you wish to install it now?"); }); if (Result == true) { if (!File.Exists(Path.GetTempPath() + "\\The Sims Online Setup Files.zip")) { lock (m_TSODownloadStartedLocker) { this.Dispatcher.Invoke(() => { LblCurrentlyDownloading.Content = "Downloading The Sims Online..."; }); m_Downloader.DownloadFileAsync("https://drive.google.com/file/d/1OmA9ms3PlJRubc9nIchW5mz8hdGrxzyK/view?usp=sharing", Path.GetTempPath() + "\\The Sims Online Setup Files.zip"); m_TSODownloadStarted = true; } } else { lock (m_TSODownloadStartedLocker) { if (!m_TSODownloadStarted) { InstallTSO(); } } } } else { lock (m_PDInstallationEndedLocker) { m_PDInstallationEnded = false; Continue = false; } this.Dispatcher.Invoke(() => { var Result = MessageBox.Show("Finished", "Installation completed successfully!\r\n " + "Do you want a desktop icon to Project Dollhouse?", ButtonType.YesNo); if (Result == true) { WindowsInstaller.CreateDesktopIcon("Project Dollhouse", m_PDInstallPath + m_PDEXECUTABLE, m_PDInstallPath); } UpdateUI(UIState.InstalledTSO); }); } lock (m_PDInstallationEndedLocker) { m_PDInstallationEnded = false; Continue = false; } } else //No need to install TSO, so we're #finished! { lock (m_PDInstallationEndedLocker) { m_PDInstallationEnded = false; Continue = false; } this.Dispatcher.Invoke(() => { var Result = MessageBox.Show("Finished", "Installation completed successfully!\r\n " + "Do you want a desktop icon to Project Dollhouse?", ButtonType.YesNo); if (Result == true) { WindowsInstaller.CreateDesktopIcon("Project Dollhouse", m_PDInstallPath + m_PDEXECUTABLE, m_PDInstallPath); } UpdateUI(UIState.InstalledTSO); }); } } //Task was cancelled, probably because the user pressed the exit button. if (m_PDDownloadEndTaskToken.IsCancellationRequested) { break; } } }