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 Extract() { string embeddedGameVersion = Installer.GetEmbeddedGameVersion(m_gameTitle); if (!Installer.IsGameDownloaded(m_gameTitle, embeddedGameVersion)) { Stage = GameUpdateStage.ExtractingUpdate; if (!Installer.ExtractEmbeddedGame(delegate(int progress) { StageProgress = (double)progress / 100.0; }, this)) { 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(); } }); } }