示例#1
0
    /// <summary>
    ///   Called to perform the upgrade.
    /// </summary>
    /// <remarks>
    ///   Sets up the resources required to upgrade the install log, and then
    ///   call <see cref="DoUpgrade()" /> so implementers can do the upgrade.
    /// </remarks>
    /// <returns>
    ///   <lang langref="true" /> if the upgrade completed; <lang langref="false" />
    ///   if the user cancelled.
    /// </returns>
    internal bool PerformUpgrade()
    {
      FileManager = new TxFileManager();
      var booComplete = false;
      using (var tsTransaction = new TransactionScope())
      {
        FileManager.Snapshot(InstallLog.Current.InstallLogPath);

        using (ProgressWorker = new BackgroundWorkerProgressDialog(DoUpgrade))
        {
          ProgressWorker.OverallMessage = "Upgrading FOMM Files";
          if (ProgressWorker.ShowDialog() == DialogResult.OK)
          {
            booComplete = true;
            tsTransaction.Complete();
          }
        }
        FileManager = null;
      }
      return booComplete;
    }
示例#2
0
    /// <summary>
    ///   Runs the install script.
    /// </summary>
    /// <remarks>
    ///   This contains the boilerplate code that needs to be done for all install-type
    ///   scripts. Implementers must override the <see cref="DoScript()" /> method to
    ///   implement their script-specific functionality.
    /// </remarks>
    /// <param name="p_booSuppressSuccessMessage">
    ///   Indicates whether to
    ///   supress the success message. This is useful for batch installs.
    /// </param>
    /// <seealso cref="DoScript()" />
    protected bool Run(bool p_booSuppressSuccessMessage, bool p_booSetFOModReadOnly)
    {
      var booSuccess = false;
      if (CheckAlreadyDone())
      {
        booSuccess = true;
      }

      if (!booSuccess)
      {
        try
        {
          //the install process modifies INI and config files.
          // if multiple sources (i.e., installs) try to modify
          // these files simultaneously the outcome is not well known
          // (e.g., one install changes SETTING1 in a config file to valueA
          // while simultaneously another install changes SETTING1 in the
          // file to value2 - after each install commits its changes it is
          // not clear what the value of SETTING1 will be).
          // as a result, we only allow one mod to be installed at a time,
          // hence the lock.
          lock (objInstallLock)
          {
            using (var tsTransaction = new TransactionScope())
            {
              m_tfmFileManager = new TxFileManager();
              using (Script = CreateInstallScript())
              {
                var booCancelled = false;
                if (p_booSetFOModReadOnly && (Fomod != null))
                {
                  if (Fomod.ReadOnlyInitStepCount > 1)
                  {
                    using (m_bwdProgress = new BackgroundWorkerProgressDialog(BeginFOModReadOnlyTransaction))
                    {
                      m_bwdProgress.OverallMessage = "Preparing FOMod...";
                      m_bwdProgress.ShowItemProgress = false;
                      m_bwdProgress.OverallProgressMaximum = Fomod.ReadOnlyInitStepCount;
                      m_bwdProgress.OverallProgressStep = 1;
                      try
                      {
                        Fomod.ReadOnlyInitStepStarted += Fomod_ReadOnlyInitStepStarted;
                        Fomod.ReadOnlyInitStepFinished += Fomod_ReadOnlyInitStepFinished;
                        if (m_bwdProgress.ShowDialog() == DialogResult.Cancel)
                        {
                          booCancelled = true;
                        }
                      }
                      finally
                      {
                        Fomod.ReadOnlyInitStepStarted -= Fomod_ReadOnlyInitStepStarted;
                        Fomod.ReadOnlyInitStepFinished -= Fomod_ReadOnlyInitStepFinished;
                      }
                    }
                  }
                  else
                  {
                    Fomod.BeginReadOnlyTransaction();
                  }
                }
                if (!booCancelled)
                {
                  booSuccess = DoScript();
                  if (booSuccess)
                  {
                    tsTransaction.Complete();
                  }
                }
              }
            }
          }
        }
        catch (Exception e)
        {
          var stbError = new StringBuilder(e.Message);
          if (e is FileNotFoundException)
          {
            stbError.Append(" (" + ((FileNotFoundException) e).FileName + ")");
          }
          if (e is IllegalFilePathException)
          {
            stbError.Append(" (" + ((IllegalFilePathException) e).Path + ")");
          }
          if (e.InnerException != null)
          {
            stbError.AppendLine().AppendLine(e.InnerException.Message);
          }
          if (e is RollbackException)
          {
            foreach (var erm in ((RollbackException) e).ExceptedResourceManagers)
            {
              stbError.AppendLine(erm.ResourceManager.ToString());
              stbError.AppendLine(erm.Exception.Message);
              if (erm.Exception.InnerException != null)
              {
                stbError.AppendLine(erm.Exception.InnerException.Message);
              }
            }
          }
          var strMessage = String.Format(ExceptionMessage, stbError);
          MessageBox.Show(strMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
          return false;
        }
        finally
        {
          m_tfmFileManager = null;
          m_ilmModInstallLog = null;
          if (Fomod != null)
          {
            Fomod.EndReadOnlyTransaction();
          }
        }
      }
      if (booSuccess && !p_booSuppressSuccessMessage && !String.IsNullOrEmpty(SuccessMessage))
      {
        MessageBox.Show(SuccessMessage, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
      }
      else if (!booSuccess && !String.IsNullOrEmpty(FailMessage))
      {
        MessageBox.Show(FailMessage, "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
      return booSuccess;
    }
示例#3
0
        /// <summary>
        /// Starts the migration, if necessary.
        /// </summary>
        /// <returns><lang cref="false"/> if the migration failed;
        /// <lang cref="true"/> otherwise.</returns>
        public bool Migrate()
        {
            if (Properties.Settings.Default.migratedFromPre0130)
                return true;

            #if TRACE
            Trace.WriteLine("Check for old FOMM to migrate from...");
            Trace.Indent();
            #endif
            string strOldFOMMLocation = (Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Fallout Mod Manager_is1", "InstallLocation", "") ?? "").ToString();
            #if TRACE
            Trace.WriteLine("First guess: " + strOldFOMMLocation);
            #endif
            if (String.IsNullOrEmpty(strOldFOMMLocation))
            {
                strOldFOMMLocation = (Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Fallout Mod Manager_is1", "InstallLocation", "") ?? "").ToString();
            #if TRACE
                Trace.WriteLine("Second guess: " + strOldFOMMLocation);
            #endif
            }
            if (String.IsNullOrEmpty(strOldFOMMLocation))
            {
            #if TRACE
                Trace.WriteLine("No need to migrate");
                Trace.Unindent();
            #endif
                return true;
            }

            string strMessage = "An older version of the mod manager was detected. Would you like to migrate your mods into the new programme?" + Environment.NewLine +
                                "If you answer \"No\", you will have to manually copy your mods into: " + Environment.NewLine +
                                Program.GameMode.ModDirectory + Environment.NewLine +
                                "You will also have to reinstall the mods, so make sure you deactivate them in the old FOMM first." + Environment.NewLine +
                                "Clicking \"Cancel\" will close the programme so you can deactivate the mods in the old FOMM, if you so choose." + Environment.NewLine +
                                "If you are confused, click \"Yes\".";
            switch (MessageBox.Show(strMessage, "Migrate", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
            {
                case DialogResult.Cancel:
                    return false;
                case DialogResult.No:
                    Properties.Settings.Default.migratedFromPre0130 = true;
                    Properties.Settings.Default.Save();
                    return true;
            }

            using (TransactionScope tsTransaction = new TransactionScope())
            {
                using (m_bwdProgress = new BackgroundWorkerProgressDialog(DoMigration))
                {
                    m_bwdProgress.OverallProgressMaximum = 3;
                    m_bwdProgress.OverallProgressStep = 1;
                    m_bwdProgress.ItemProgressStep = 1;
                    m_bwdProgress.OverallMessage = "Migrating...";
                    m_bwdProgress.WorkMethodArguments = strOldFOMMLocation;
                    if (m_bwdProgress.ShowDialog() == DialogResult.Cancel)
                        return false;

                }
                tsTransaction.Complete();
            }

            Properties.Settings.Default.migratedFromPre0130 = true;
            Properties.Settings.Default.Save();

            return true;
        }
示例#4
0
        /// <summary>
        /// Called to perform the upgrade.
        /// </summary>
        /// <remarks>
        /// Sets up the resources required to upgrade the install log, and then
        /// call <see cref="DoUpgrade()"/> so implementers can do the upgrade.
        /// </remarks>
        /// <returns><lang cref="true"/> if the upgrade completed; <lang cref="false"/>
        /// if the user cancelled.</returns>
        internal bool PerformUpgrade()
        {
            #if TRACE
            Trace.WriteLine("Beginning Install Log Upgrade.");
            #endif
            m_tfmFileManager = new TxFileManager();
            bool booComplete = false;
            using (TransactionScope tsTransaction = new TransactionScope())
            {
                m_tfmFileManager.Snapshot(InstallLog.Current.InstallLogPath);

                using (m_pgdProgress = new BackgroundWorkerProgressDialog(DoUpgrade))
                {
                    m_pgdProgress.OverallMessage = "Upgrading FOMM Files";
                    if (m_pgdProgress.ShowDialog() == DialogResult.OK)
                    {
                        booComplete = true;
                        tsTransaction.Complete();
                    }
                }
                m_tfmFileManager = null;
            }
            return booComplete;
        }