private bool DownloadAndInstall(string gameVersion, string downloadURL, bool isLatest) { if (!Installer.IsGameInstalled(m_gameTitle, gameVersion)) { if (!Download(gameVersion, downloadURL)) { return(false); } if (!Install(gameVersion)) { return(false); } } Installer.RecordLatestInstalledVersion(m_gameTitle, gameVersion, isLatest); return(true); }
private bool ExtractAndInstall() { string embeddedGameVersion = Installer.GetEmbeddedGameVersion(m_gameTitle); if (!Installer.IsGameInstalled(m_gameTitle, embeddedGameVersion)) { if (!Extract()) { return(false); } if (!Install(embeddedGameVersion)) { return(false); } } Installer.RecordLatestInstalledVersion(m_gameTitle, embeddedGameVersion, false); return(true); }
private bool Install(string gameVersion) { if (!Installer.IsGameInstalled(m_gameTitle, gameVersion)) { Stage = GameUpdateStage.InstallingUpdate; if (!Installer.InstallGame(m_gameTitle, gameVersion, delegate(int progress) { StageProgress = (double)progress / 100.0; }, this)) { return(false); } if (Cancelled) { return(false); } StageProgress = 1.0; } return(true); }
public static bool LaunchGame(string gameTitle, string gameVersion) { if (Installer.IsGameInstalled(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 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 Process.Start(gamePath); return(true); } } return(false); }
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(); } }); } }