public InstallPresenter(IInstallView view, FOGameInfo game, InstallHandler installHandler, LogoManager logoManager, string scriptPath, string tempPath)
 {
     this.view = view;
     this.game = game;
     this.scriptPath = scriptPath;
     this.installHandler = installHandler;
     this.logoManager = logoManager;
     this.tempPath = tempPath;
 }
 public void SelectGame(FOGameInfo game, List<FOGameLaunchProgram> programs)
 {
     foreach (FOGameLaunchProgram program in programs)
     {
         Button btnCustom = new Button();
         btnCustom.Text = program.Name;
         btnCustom.Width = this.Main.btnInstall.Width;
         btnCustom.Height = this.Main.btnInstall.Height;
         btnCustom.Tag = program.File;
         btnCustom.Click += new EventHandler(btnCustom_Click);
         this.Main.flowMenu.Controls.Add(btnCustom);
     }
 }
        public bool InstallGame(FOGameInfo game, string scriptPath, string tempPath, string installPath, List<string> dependencyPaths, bool reviewCode)
        {
            // Fetch and run install script
            FOScriptInfo installScriptInfo = this.GetInstallScriptInfo(game.Id);

            string scriptName = Utils.GetFilenameFromUrl(installScriptInfo.Url);

            if (!Directory.Exists(scriptPath))
                Directory.CreateDirectory(scriptPath);

            string localScriptPath = Path.Combine(scriptPath, scriptName);

            // File exists, verify if checksum is the same...
            if (File.Exists(localScriptPath))
            {
                string localChecksum = Utils.GetSHA1Checksum(localScriptPath);
                if (localChecksum != installScriptInfo.Checksum)
                {
                    this.logger.Info("Local checksum of {0} = {1}, remote is {2}. More recent script is available or local file has been modified.", localScriptPath, localChecksum, installScriptInfo.Checksum);
                    this.DownloadInstallScript(installScriptInfo.Url, localScriptPath);
                }
            }
            else
            {
                this.logger.Info("{0} doesn't exist", localScriptPath);
                this.DownloadInstallScript(installScriptInfo.Url, localScriptPath);
            }

            if (!File.Exists(localScriptPath))
            {
                this.installError = string.Format("Failed to download {0} to {1}", installScriptInfo.Url, localScriptPath);
                return false;
            }

            if (reviewCode)
            {
                string[] code = File.ReadAllLines(localScriptPath);
                frmReviewCode review = new frmReviewCode(string.Join("\r\n",code));
                review.ShowDialog();
                if (review.Cancelled)
                {
                    this.installError = "Cancelled during script review.";
                    return false;
                }
            }

            this.logger.Debug("Running install script for {0}, temp path: {1}, install path: {2}", game.Name, tempPath, installPath);
            InstallHost installHost = new InstallHost();
            if (!installHost.RunInstallScript(localScriptPath, game.Name, tempPath, installPath))
            {
                this.logger.Error("Installation failed.");
                return false;
            }

            // Copy dependencies
            foreach (string path in dependencyPaths)
            {
                string filename = Path.GetFileName(path);
                string destPath = Path.Combine(installPath, filename);
                if (File.Exists(destPath))
                {
                    this.logger.Info("{0} already exists, skipping copy", destPath);
                    continue;
                }

                this.logger.Info("Copying {0} to {1}...", path, destPath);
                File.Copy(path, destPath);
                this.logger.Info("Copied {0} to {1}", path, destPath);
            }
            this.logger.Info("Adding installed game {0}, path {1}", game.Id, installPath);
            this.AddInstalledGame(game.Id, installPath);

            return true;
        }
        private void SelectGame(FOGameInfo game)
        {
            if (game == null) return;

            bool installed = installHandler.IsInstalled(game.Id);
            this.view.ClearGameSelection();
            if (!this.installHandler.IsInstalled(game.Id))
            {
                this.view.AddInstallButton();
            }
            else
            {
                var programs = this.installHandler.GetLaunchPrograms(game.Id);
                this.view.SelectGame(game, programs);
            }
            this.currentGame = game;
        }
        void OnInstallGame(object sender, FOGameInfo game)
        {
            if (game == null) return;

            this.AddGame(game);
        }
 void OnChangedGame(object sender, FOGameInfo game)
 {
     this.SelectGame(game);
 }
        private bool AddGame(FOGameInfo game)
        {
            if (!this.installHandler.HasInstallInfo(game.Id))
            {
                this.view.ShowError(string.Format("No install info available for {0} :( {1} If you want to install this game anyway, navigate to the webpage ({2}) instead.",
                    game.Name,
                    Environment.NewLine,
                    game.Website));
                return false;
            }

            if (view.AskYesNoQuestion("Is " + game.Name + " already installed on your computer?" + Environment.NewLine + "If this is the case, the installed directory can be added directly. This assumes that the game is working in its current state.", game.Name + " already installed?"))
            {
                string path = this.view.GetFolderPath();

                if (!this.installHandler.VerifyGameFolderPath(game.Id, path))
                {
                    this.view.ShowError(path + " does not contain a valid " + game.Name + " installation.");
                    return false;
                }

                game.InstallPath = path;

                string msg = "Successfully added " + game.Name + "!";
                this.view.ShowInfo(msg);
                this.installHandler.AddInstalledGame(game.Id, game.InstallPath);
            }
            else
            {
                if (installHandler.GetInstallScriptInfo(game.Id) == null)
                {
                    this.view.ShowError(string.Format("No install script available for {0} :( {1} If you want to install this game anyway, download and install the game manually from {2} and then add the install directory.",
                    game.Name,
                    Environment.NewLine,
                    game.Website));
                    return false;
                }

                InstallPresenter installer = new InstallPresenter(
                    new WinFormsInstallView(),
                    game, installHandler,
                    logoManager,
                    this.settings.Paths.Scripts,
                    this.settings.Paths.DownloadTemp);
                installer.Show();

                if (!installer.IsSuccess)
                    return false;

                this.currentGame.InstallPath = this.installHandler.GetInstallPath(game.Id);

                string msg = "Successfully installed " + game.Name + "!";
                this.view.ShowInfo(msg);
            }
            SaveInstalledStatus();
            return true;
        }
 public void SelectGame(FOGameInfo game, List<FOGameLaunchProgram> programs)
 {
     //throw new NotImplementedException();
 }