private bool Download(string gameVersion, string downloadURL, string username = null, string password = null) { if (!Installer.IsGameDownloaded(m_gameTitle, gameVersion)) { Stage = GameUpdateStage.DownloadingUpdate; string embeddedGameTitle, embeddedGameVersion, embeddedGameURL, embeddedUsername, embeddedPassword; if (Installer.GetEmbeddedGameInfo(out embeddedGameTitle, out embeddedGameVersion, out embeddedGameURL, out embeddedUsername, out embeddedPassword)) { if (username == null) { username = embeddedUsername; } if (password == null) { password = embeddedPassword; } } bool authFailure; if (!Installer.DownloadGame( m_gameTitle, gameVersion, downloadURL, username, password, delegate(int progress) { StageProgress = (double)progress / 100.0; }, this, out authFailure )) { if (Cancelled) { return(false); } if (authFailure) { if (embeddedUsername == null && embeddedPassword == null) { if (ShowUsernameAndPasswordPrompt(ref username, ref password)) { return(Download(gameVersion, downloadURL, username, password)); } } else if (embeddedUsername == null) { if (ShowUsernamePrompt(ref username)) { return(Download(gameVersion, downloadURL, username, embeddedPassword)); } } else if (embeddedPassword == null) { if (ShowPasswordPrompt(ref password)) { return(Download(gameVersion, downloadURL, embeddedUsername, password)); } } } return(false); } if (Cancelled) { return(false); } StageProgress = 1.0; } return(true); }
public void Start() { if (Stage == GameUpdateStage.NotStarted) { Task.Factory.StartNew(delegate() { try { string latestInstalledVersion = Installer.GetLatestInstalledVersion(m_gameTitle); string embeddedGameVersion = Installer.GetEmbeddedGameVersion(m_gameTitle); if (m_optionalGameVersion != null) { // A specific version has been requested // Try to locate it: if (Installer.IsGameInstalled(m_gameTitle, m_optionalGameVersion)) { if (m_optionalGameVersion == embeddedGameVersion) { // Try to extract it if (!ExtractAndInstall()) { FailOrCancel(); return; } } else if (m_optionalUpdateURL != null) { // Try to download it string downloadURL; bool isNewest; if (!GetSpecificDownloadURL(m_optionalUpdateURL, m_optionalGameVersion, out downloadURL, out isNewest)) { FailOrCancel(); return; } if (!DownloadAndInstall(m_optionalGameVersion, downloadURL, isNewest)) { FailOrCancel(); return; } } else { // Give up Fail(); return; } } // Try to run it if (!Launch(m_optionalGameVersion)) { FailOrCancel(); return; } // Finish Finish(); } else { // The "latest" version has been requested // Try to determine what it is: string latestVersion = null; string latestVersionDownloadURL = null; if (m_optionalUpdateURL != null) { if (!GetLatestDownloadURL(m_optionalUpdateURL, out latestVersion, out latestVersionDownloadURL)) { if (TryCancel()) { return; } } } string launchVersion = null; if (latestVersion != null) { if (Installer.IsGameInstalled(m_gameTitle, latestVersion)) { // If we already have it, there's nothing to do launchVersion = latestVersion; Installer.RecordLatestInstalledVersion(m_gameTitle, latestVersion, true); } else { // Try to download it (with the users consent) if (latestVersionDownloadURL != null) { bool fallbackAvailable = (latestInstalledVersion != null) || (embeddedGameVersion != null); bool userPromptResult = false; if (fallbackAvailable) { userPromptResult = ShowPrompt(GameUpdatePrompt.DownloadNewVersion); if (TryCancel()) { return; } } if (!fallbackAvailable || userPromptResult) { if (TryCancel()) { return; } if (DownloadAndInstall(latestVersion, latestVersionDownloadURL, true)) { launchVersion = latestVersion; } else { if (TryCancel()) { return; } if (!fallbackAvailable) { Fail(); return; } else if (!ShowPrompt(GameUpdatePrompt.LaunchOldVersion)) { Fail(); return; } } } } } } // Try one of the fallback methods if (launchVersion == null) { if (latestInstalledVersion != null) { launchVersion = latestInstalledVersion; } else if (embeddedGameVersion != null) { if (ExtractAndInstall()) { launchVersion = embeddedGameVersion; } else { FailOrCancel(); return; } } else { Fail(); return; } } // Try to run it if (!Launch(launchVersion)) { FailOrCancel(); return; } // Finish Finish(); } } catch (Exception e) { Console.WriteLine(e.ToString()); Console.WriteLine(e.StackTrace); Fail(); } }); } }
public static bool LaunchGame(string gameTitle, string gameVersion) { if (Installer.IsGameInstalled(gameTitle, gameVersion)) { Logger.Log("Determining path to game exe ({0} {1})", gameTitle, gameVersion); // Search for a suitable exe to run string gamePath = Installer.GetInstallPath(gameTitle, gameVersion); string launchPath = null; switch (Program.Platform) { case Platform.Windows: { string exePath = Path.Combine(gamePath, gameTitle + ".exe"); if (File.Exists(exePath)) { launchPath = exePath; break; } string batPath = Path.Combine(gamePath, gameTitle + ".bat"); if (File.Exists(batPath)) { launchPath = batPath; break; } break; } case Platform.OSX: { string appPath = Path.Combine(gamePath, gameTitle + ".app"); if (Directory.Exists(appPath)) { launchPath = appPath; break; } string shPath = Path.Combine(gamePath, gameTitle + ".sh"); if (File.Exists(shPath)) { launchPath = shPath; break; } break; } case Platform.Linux: default: { string shPath = Path.Combine(gamePath, gameTitle + ".sh"); if (File.Exists(shPath)) { launchPath = shPath; break; } break; } } if (launchPath != null) { // Run the exe Logger.Log("Launching {0}", launchPath); if (Path.GetExtension(launchPath) == ".sh") { var startInfo = new ProcessStartInfo(); startInfo.FileName = "/bin/sh"; startInfo.WorkingDirectory = gamePath; startInfo.Arguments = Path.GetFileName(launchPath); Process.Start(startInfo); return(true); } else { var startInfo = new ProcessStartInfo(); startInfo.FileName = launchPath; startInfo.WorkingDirectory = gamePath; Process.Start(startInfo); return(true); } } else { // If no exe was found, just open the folder Logger.Log("Opening {0}", gamePath); Process.Start(gamePath); return(true); } } return(false); }