public void ResetHistory()
        {
            DeployDialog cachedDlg = _dlgs[0];

            _dlgs.Clear();
            _dlgs.Add(cachedDlg);
        }
        public DeployTool()
        {
            //Create necessary directory tree
            if (!Directory.Exists(Application.StartupPath + "\\deploy"))
            {
                Directory.CreateDirectory(Application.StartupPath + "\\deploy");
            }

            //Set default folders
            InstallationProperties.Instance.Set("MPDir",
                                                Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) +
                                                "\\Team MediaPortal\\MediaPortal");
            InstallationProperties.Instance.Set("TVServerDir",
                                                Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) +
                                                "\\Team MediaPortal\\MediaPortal TV Server");

            string tmpPrg = Environment.GetEnvironmentVariable("ProgramW6432");

            if (!string.IsNullOrEmpty(tmpPrg))
            {
                InstallationProperties.Instance.Set("ProgramFiles", tmpPrg);
            }
            else
            {
                InstallationProperties.Instance.Set("ProgramFiles", Environment.GetEnvironmentVariable("ProgramFiles"));
            }

            // Paint first screen
            InitializeComponent();
            Icon = System.Drawing.Icon.ExtractAssociatedIcon(Application.ExecutablePath);
            Localizer.SwitchCulture("en-US");
            UpdateUI();

            // Delete Run registry key
            DialogType firstDlg;

            if (Utils.AutoRunApplication("delete"))
            {
                firstDlg = DialogType.Installation;
                InstallationProperties.Instance.Load();
                Localizer.SwitchCulture(InstallationProperties.Instance["language"]);
                _restart = true;
            }
            else
            {
                firstDlg = DialogType.Welcome;
                Localizer.SwitchCulture("en-US");
                _restart = false;
            }
            _currentDialog = DialogFlowHandler.Instance.GetDialogInstance(firstDlg);
            splitContainer2.Panel1.Controls.Add(_currentDialog);
            InstallationProperties.Instance.Set("InstallTypeHeader", "Choose installation type");
            backButton.Visible = false;
            UpdateUI();
            if (_restart)
            {
                nextButton.Text = Localizer.GetBestTranslation("Install_buttonInstall");
            }
            nextButton.Focus();
        }
 private void SwitchDialog(DeployDialog dlg)
 {
     splitContainer2.Panel1.Controls.Clear();
     splitContainer2.Panel1.Controls.Add(dlg);
     dlg.Focus();
     nextButton.Focus();
 }
        private void backButton_Click(object sender, EventArgs e)
        {
            bool isFirstDlg = false;

            _currentDialog = DialogFlowHandler.Instance.GetPreviousDlg(ref isFirstDlg);
            if (isFirstDlg)
            {
                backButton.Visible = false;
            }
            nextButton.Text = Localizer.GetBestTranslation("MainWindow_nextButton");
            SwitchDialog(_currentDialog);
        }
        public DeployDialog GetDialogInstance(DialogType dlgType)
        {
            DeployDialog dlg = FindDialog(dlgType);

            if (dlg == null)
            {
                switch (dlgType)
                {
                case DialogType.Welcome:
                    dlg = new WelcomeDlg();
                    break;

                case DialogType.DownloadOnly:
                    dlg = new DownloadOnlyDlg();
                    break;

                case DialogType.DownloadSettings:
                    dlg = new DownloadSettingsDlg();
                    break;

                case DialogType.Upgrade:
                    dlg = new UpgradeDlg();
                    break;

                case DialogType.WatchTV:
                    dlg = new WatchTVDlg();
                    break;

                case DialogType.BASE_INSTALLATION_TYPE_WITHOUT_TVENGINE:
                    dlg = new BaseInstallationTypeWithoutTvEngineDlg();
                    break;

                case DialogType.BASE_INSTALLATION_TYPE:
                    dlg = new BaseInstallationTypeDlg();
                    break;

                case DialogType.CUSTOM_INSTALLATION_TYPE:
                    dlg = new CustomInstallationTypeDlg();
                    break;

                case DialogType.DBMSType:
                    dlg = new DBMSTypeDlg();
                    break;

                case DialogType.DBMSSettings:
                    dlg = new DBMSSettingsDlg();
                    break;

                case DialogType.MPSettings:
                    dlg = new MPSettingsDlg();
                    break;

                case DialogType.TvServerSettings:
                    dlg = new TvServerSettingsDlg();
                    break;

                case DialogType.Installation:
                    dlg = new InstallDlg();
                    break;

                case DialogType.Finished:
                    dlg = new FinishedDlg();
                    break;

                case DialogType.SkinChoice:
                    dlg = new SkinChoice();
                    break;

                case DialogType.ExtensionChoice:
                    dlg = new ExtensionChoice();
                    break;
                }
                if (dlg != null)
                {
                    _dlgs.Add(dlg);
                }
            }
            else
            {
                dlg.UpdateUI();
            }
            _currentDlgIndex++;
            return(dlg);
        }
        private void nextButton_Click(object sender, EventArgs e)
        {
            //
            // check Internet connection unless files have already been downloaded
            //
            if (_currentDialog.type == DialogType.DownloadOnly &&
                Directory.GetFiles(Application.StartupPath + "\\deploy").Length < 3)
            {
                if (!InstallationChecks.InternetChecker.CheckConnection())
                {
                    MessageBox.Show(Localizer.GetBestTranslation("DownloadOnly_NoConnectionWarning"), "MediaPortal",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

            //
            // check if there's is sufficient hard disk space for installation
            //
            if (_currentDialog.type == DialogType.DBMSSettings || _currentDialog.type == DialogType.TvServerSettings ||
                _currentDialog.type == DialogType.MPSettings)
            {
                // at least 0.5 GB free disk space are required for installation
                const double requiredDiskSpace = 0.5;
                double       actualDiskSpace   =
                    InstallationChecks.DiskSpaceChecker.GetRemainingHardDiskCapacity(_currentDialog.installationPath);

                if (actualDiskSpace < requiredDiskSpace)
                {
                    MessageBox.Show(string.Format(Localizer.GetBestTranslation("DiskSpace_Error"), requiredDiskSpace * 1000),
                                    "MediaPortal", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            if (nextButton.Text == Localizer.GetBestTranslation("MainWindow_buttonClose"))
            {
                //
                // If in download_only mode, start explorer to show downloaded stuff
                //
                if (InstallationProperties.Instance["InstallType"] == "download_only")
                {
                    try
                    {
                        Process process = new Process();
                        process.StartInfo.FileName        = "explorer.exe";
                        process.StartInfo.Arguments       = "/e, " + Application.StartupPath + "\\deploy";
                        process.StartInfo.UseShellExecute = true;
                        process.Start();
                    }
                    // Starting processes might fail - prefer a not opening Explorer instead of a big crash window...
                    catch (Exception)
                    {
                    }
                }
                Close();
                return;
            }
            if (nextButton.Text == Localizer.GetBestTranslation("Install_buttonDownload") ||
                nextButton.Text == Localizer.GetBestTranslation("Install_buttonInstall"))
            {
                nextButton.Enabled = false;
            }
            if (!_currentDialog.SettingsValid())
            {
                return;
            }
            _currentDialog.SetProperties();
            if (InstallationProperties.Instance["language"] != _currentCulture)
            {
                _currentCulture = InstallationProperties.Instance["language"];
                Localizer.SwitchCulture(_currentCulture);
                UpdateUI();
            }
            _currentDialog = _currentDialog.GetNextDialog();
            SwitchDialog(_currentDialog);
            if (!backButton.Visible)
            {
                backButton.Visible = true;
            }
            if (InstallationProperties.Instance["finished"] == "yes")
            {
                backButton.Visible = false;
                nextButton.Enabled = true;
                nextButton.Text    = Localizer.GetBestTranslation("MainWindow_buttonClose");
            }
            if (!_restart && InstallationProperties.Instance["Install_Dialog"] == "yes")
            {
                nextButton.Text = InstallationProperties.Instance["InstallType"] == "download_only"
                            ? Localizer.GetBestTranslation("Install_buttonDownload")
                            : Localizer.GetBestTranslation("Install_buttonInstall");
                InstallationProperties.Instance.Set("Install_Dialog", "no");
            }
        }
    public DeployTool()
    {
      //Create necessary directory tree
      if (!Directory.Exists(Application.StartupPath + "\\deploy"))
        Directory.CreateDirectory(Application.StartupPath + "\\deploy");

      //Set default folders
      InstallationProperties.Instance.Set("MPDir",
                                          Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) +
                                          "\\Team MediaPortal\\MediaPortal");
      InstallationProperties.Instance.Set("TVServerDir",
                                          Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) +
                                          "\\Team MediaPortal\\MediaPortal TV Server");

      string tmpPrg = Environment.GetEnvironmentVariable("ProgramW6432");
      if (!string.IsNullOrEmpty(tmpPrg))
      {
        InstallationProperties.Instance.Set("ProgramFiles", tmpPrg);
      }
      else
      {
        InstallationProperties.Instance.Set("ProgramFiles", Environment.GetEnvironmentVariable("ProgramFiles"));
      }

      // Paint first screen
      InitializeComponent();
      Icon = System.Drawing.Icon.ExtractAssociatedIcon(Application.ExecutablePath);
      Localizer.SwitchCulture("en-US");
      UpdateUI();

      // Delete Run registry key
      DialogType firstDlg;
      if (Utils.AutoRunApplication("delete"))
      {
        firstDlg = DialogType.Installation;
        InstallationProperties.Instance.Load();
        Localizer.SwitchCulture(InstallationProperties.Instance["language"]);
        _restart = true;
      }
      else
      {
        firstDlg = DialogType.Welcome;
        Localizer.SwitchCulture("en-US");
        _restart = false;
      }
      _currentDialog = DialogFlowHandler.Instance.GetDialogInstance(firstDlg);
      splitContainer2.Panel1.Controls.Add(_currentDialog);
      InstallationProperties.Instance.Set("InstallTypeHeader", "Choose installation type");
      backButton.Visible = false;
      UpdateUI();
      if (_restart)
      {
        nextButton.Text = Localizer.GetBestTranslation("Install_buttonInstall");
      }
      nextButton.Focus();
    }
 private void backButton_Click(object sender, EventArgs e)
 {
   bool isFirstDlg = false;
   _currentDialog = DialogFlowHandler.Instance.GetPreviousDlg(ref isFirstDlg);
   if (isFirstDlg)
     backButton.Visible = false;
   nextButton.Text = Localizer.GetBestTranslation("MainWindow_nextButton");
   SwitchDialog(_currentDialog);
 }
    private void nextButton_Click(object sender, EventArgs e)
    {
      //
      // check Internet connection unless files have already been downloaded
      //
      if (_currentDialog.type == DialogType.DownloadOnly &&
          Directory.GetFiles(Application.StartupPath + "\\deploy").Length < 3)
      {
        if (!InstallationChecks.InternetChecker.CheckConnection())
        {
          MessageBox.Show(Localizer.GetBestTranslation("DownloadOnly_NoConnectionWarning"), "MediaPortal",
                          MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
      }

      // 
      // check if there's is sufficient hard disk space for installation
      // 
      if (_currentDialog.type == DialogType.DBMSSettings || _currentDialog.type == DialogType.TvServerSettings ||
          _currentDialog.type == DialogType.MPSettings)
      {
        // at least 0.5 GB free disk space are required for installation
        const double requiredDiskSpace = 0.5;
        double actualDiskSpace =
          InstallationChecks.DiskSpaceChecker.GetRemainingHardDiskCapacity(_currentDialog.installationPath);

        if (actualDiskSpace < requiredDiskSpace)
        {
          MessageBox.Show(string.Format(Localizer.GetBestTranslation("DiskSpace_Error"), requiredDiskSpace * 1000),
                          "MediaPortal", MessageBoxButtons.OK, MessageBoxIcon.Error);
          return;
        }
      }

      if (nextButton.Text == Localizer.GetBestTranslation("MainWindow_buttonClose"))
      {
        //
        // If in download_only mode, start explorer to show downloaded stuff
        //
        if (InstallationProperties.Instance["InstallType"] == "download_only")
        {
          try
          {
            Process process = new Process();
            process.StartInfo.FileName = "explorer.exe";
            process.StartInfo.Arguments = "/e, " + Application.StartupPath + "\\deploy";
            process.StartInfo.UseShellExecute = true;
            process.Start();
          }
            // Starting processes might fail - prefer a not opening Explorer instead of a big crash window...
          catch (Exception)
          {
          }
        }
        Close();
        return;
      }
      if (nextButton.Text == Localizer.GetBestTranslation("Install_buttonDownload") ||
          nextButton.Text == Localizer.GetBestTranslation("Install_buttonInstall"))
      {
        nextButton.Enabled = false;
      }
      if (!_currentDialog.SettingsValid())
        return;
      _currentDialog.SetProperties();
      if (InstallationProperties.Instance["language"] != _currentCulture)
      {
        _currentCulture = InstallationProperties.Instance["language"];
        Localizer.SwitchCulture(_currentCulture);
        UpdateUI();
      }
      _currentDialog = _currentDialog.GetNextDialog();
      SwitchDialog(_currentDialog);
      if (!backButton.Visible)
        backButton.Visible = true;
      if (InstallationProperties.Instance["finished"] == "yes")
      {
        backButton.Visible = false;
        nextButton.Enabled = true;
        nextButton.Text = Localizer.GetBestTranslation("MainWindow_buttonClose");
      }
      if (!_restart && InstallationProperties.Instance["Install_Dialog"] == "yes")
      {
        nextButton.Text = InstallationProperties.Instance["InstallType"] == "download_only"
                            ? Localizer.GetBestTranslation("Install_buttonDownload")
                            : Localizer.GetBestTranslation("Install_buttonInstall");
        InstallationProperties.Instance.Set("Install_Dialog", "no");
      }
    }
 private void SwitchDialog(DeployDialog dlg)
 {
   splitContainer2.Panel1.Controls.Clear();
   splitContainer2.Panel1.Controls.Add(dlg);
   dlg.Focus();
   nextButton.Focus();
 }