private void TryToLaunchWizard()

in Configurator/UI/Forms/MainForm.cs [113:231]


    private void TryToLaunchWizard(bool launchedFromMainIcon)
    {
      // Update execution mode if current configuration needs to be upgraded.
      var controller = _serverInstallation.Controller;
      if (controller == null)
      {
        throw new ArgumentNullException(nameof(controller));
      }

      var upgradeHistoryFileExists = false;
      Version existingServerVersion = new Version();
      if (AppConfiguration.ExecutionMode == ExecutionMode.Configure)
      {
        var path = Path.Combine(controller.DataDirectory, "Data", MySqlUpgradeHistoryManager.UPGRADE_HISTORY_FILE_NAME);
        upgradeHistoryFileExists = File.Exists(path);

        // TODO: Enable upgrade history file regeneration when server bug is fixed.
        /*
        // If upgrade history file does not exist, stop and start server to regenerate it.
        if (!upgradeHistoryFileExists
            && controller.IsThereServerDataFiles
            && _package.Version.Major >= 8
            && _package.Version.Minor >= 4)
        {
          var serverInstance = new LocalServerInstance(controller);
          serverInstance.DataDir = controller.DataDirectory;
          if (serverInstance.IsRunning)
          {
            serverInstance.StopInstance();
          }

          serverInstance.StartInstanceAsProcess("--upgrade=MINIMAL");
          upgradeHistoryFileExists = File.Exists(path);
        }
        */

        if (controller.IsThereServerDataFiles
            && upgradeHistoryFileExists)
        {
          (Version, bool) result = MySqlUpgradeHistoryManager.GetUpgradeHistoryLatestVersion(controller.DataDirectory);
          existingServerVersion = result.Item1;
          bool hasMetadata = result.Item2;
          
          // If the version is lower or if version is the same but we have metadata it means that this is
          // an updated version of the current package and needs to be upgraded.
          if (existingServerVersion != null
              && (existingServerVersion < _serverInstallation.Version)
                  || (existingServerVersion == _serverInstallation.Version
                      && hasMetadata))
          {
            var validUpgrade = _serverInstallation.Version.ServerSupportsInPlaceUpgrades(existingServerVersion);
            if (validUpgrade == UpgradeViability.Supported
                && _serverInstallation.Version.Major == existingServerVersion.Major
                && _serverInstallation.Version.Minor == existingServerVersion.Minor)
            {
              Logger.LogInformation(Resources.ExecutionModeSwitch);
              AppConfiguration.ExecutionMode = ExecutionMode.Upgrade;
              controller.IsSameDirectoryUpgrade = true;
            }
          }
        }
      }
      
      // Show wizard matching the selected execution mode.
      ConfigurationType configurationType;
      switch (AppConfiguration.ExecutionMode)
      {
        case ExecutionMode.Configure:
          configurationType = ConfigurationType.Reconfigure;
          var configWizard = new ConfigWizard();
          Controls.Add(configWizard);
          configWizard.WizardCanceled += WizardClosed;
          configWizard.WizardClosed += WizardClosed;
          configWizard.ShowWizard(_serverInstallation, this, configurationType);
          break;

        case ExecutionMode.Remove:
        case ExecutionMode.RemoveNoShow:
          configurationType = ConfigurationType.Remove;
          var removeWizard = new RemoveProductsWizard();
          Controls.Add(removeWizard);
          removeWizard.WizardCanceled += WizardClosed;
          removeWizard.WizardClosed += WizardClosed;
          removeWizard.ShowWizard(_serverInstallation, this);
          break;

        case ExecutionMode.Upgrade:
          configurationType = ConfigurationType.Upgrade;
          configWizard = new ConfigWizard();
          Controls.Add(configWizard);
          configWizard.WizardCanceled += WizardClosed;
          configWizard.WizardClosed += WizardClosed;
          configWizard.ShowWizard(_serverInstallation, this, configurationType);
          break;

        default:
          throw new ConfiguratorException(ConfiguratorError.InvalidExecutionMode);
      }

      // Update status bar.
      StatusStrip.Visible = true;
      var controllerConfigurationType = _serverInstallation.Controller.ConfigurationType;
      VersionLabel.Text = controllerConfigurationType != ConfigurationType.Upgrade
        ? $"MySQL Server {_serverInstallation.Version.ToString()}"
        : $"MySQL Server {(upgradeHistoryFileExists ? existingServerVersion.ToString() : "Unknown")} -> {_serverInstallation.VersionString}";
      var stringConfigurationType = string.Empty;
      stringConfigurationType = controllerConfigurationType.ToString();
      ConfigurationTypeLabel.Text = stringConfigurationType;
      if (controllerConfigurationType == ConfigurationType.Reconfigure
          || controllerConfigurationType == ConfigurationType.Remove
          || controllerConfigurationType == ConfigurationType.Upgrade)
      {
        var serverController = _serverInstallation.Controller as ServerConfigurationController;
        DataDirectoryLabel.Text = $"Data Directory: {serverController.DataDirectory}";
      }

      Logger.LogInformation($"Status: {ConfigurationTypeLabel.Text};{VersionLabel.Text};{DataDirectoryLabel.Text}");
      StatusStrip.Refresh();
    }