Beispiel #1
0
        public static OverwriteResult ShowDialog(string msg, bool allowFolder, bool allowMod)
        {
            var of = new Overwriteform(msg, allowFolder, allowMod);

            of.ShowDialog();
            return(of.result);
        }
Beispiel #2
0
        /// <summary>
        ///   Verifies if the given file can be written.
        /// </summary>
        /// <remarks>
        ///   This method checks if the given path is valid. If so, and the file does not
        ///   exist, the file can be written. If the file does exist, than the user is
        ///   asked to overwrite the file.
        /// </remarks>
        /// <param name="p_strPath">The file path, relative to the Data folder, whose writability is to be verified.</param>
        /// <returns>
        ///   <lang langref="true" /> if the location specified by <paramref name="p_strPath" />
        ///   can be written; <lang langref="false" /> otherwise.
        /// </returns>
        protected bool TestDoOverwrite(string p_strPath)
        {
            var strDataPath = Path.Combine(Program.GameMode.PluginsPath, p_strPath);
            var strOldMod   = InstallLog.Current.GetCurrentFileOwnerName(p_strPath);

            if (!File.Exists(strDataPath))
            {
                return(true);
            }
            var strLoweredPath = strDataPath.ToLowerInvariant();

            if (m_lstOverwriteFolders.Contains(Path.GetDirectoryName(strLoweredPath)))
            {
                return(true);
            }
            if (m_lstDontOverwriteFolders.Contains(Path.GetDirectoryName(strLoweredPath)))
            {
                return(false);
            }
            if (m_booOverwriteAll)
            {
                return(true);
            }
            if (m_booDontOverwriteAll)
            {
                return(false);
            }
            if (m_lstOverwriteMods.Contains(strOldMod))
            {
                return(true);
            }
            if (m_lstDontOverwriteMods.Contains(strOldMod))
            {
                return(false);
            }

            string strMessage;

            if (strOldMod != null)
            {
                strMessage = String.Format("Data file '{{0}}' has already been installed by '{0}'" + Environment.NewLine +
                                           "Overwrite with this mod's file?", strOldMod);
            }
            else
            {
                strMessage = "Data file '{0}' already exists." + Environment.NewLine +
                             "Overwrite with this mod's file?";
            }
            switch (Overwriteform.ShowDialog(String.Format(strMessage, p_strPath), true, (strOldMod != null)))
            {
            case OverwriteResult.Yes:
                return(true);

            case OverwriteResult.No:
                return(false);

            case OverwriteResult.NoToAll:
                m_booDontOverwriteAll = true;
                return(false);

            case OverwriteResult.YesToAll:
                m_booOverwriteAll = true;
                return(true);

            case OverwriteResult.NoToMod:
                m_lstDontOverwriteMods.Add(strOldMod);
                return(false);

            case OverwriteResult.YesToMod:
                m_lstOverwriteMods.Add(strOldMod);
                return(true);

            case OverwriteResult.NoToFolder:
                var folders = new Queue <string>();
                folders.Enqueue(Path.GetDirectoryName(strLoweredPath));
                while (folders.Count > 0)
                {
                    strLoweredPath = folders.Dequeue();
                    if (!m_lstOverwriteFolders.Contains(strLoweredPath))
                    {
                        m_lstDontOverwriteFolders.Add(strLoweredPath);
                        foreach (var s in Directory.GetDirectories(strLoweredPath))
                        {
                            folders.Enqueue(s.ToLowerInvariant());
                        }
                    }
                }
                return(false);

            case OverwriteResult.YesToFolder:
                folders = new Queue <string>();
                folders.Enqueue(Path.GetDirectoryName(strLoweredPath));
                while (folders.Count > 0)
                {
                    strLoweredPath = folders.Dequeue();
                    if (!m_lstDontOverwriteFolders.Contains(strLoweredPath))
                    {
                        m_lstOverwriteFolders.Add(strLoweredPath);
                        foreach (var s in Directory.GetDirectories(strLoweredPath))
                        {
                            folders.Enqueue(s.ToLowerInvariant());
                        }
                    }
                }
                return(true);

            default:
                throw new Exception(
                          "Sanity check failed: OverwriteDialog returned a value not present in the OverwriteResult enum");
            }
        }
Beispiel #3
0
 public static OverwriteResult ShowDialog(string msg, bool allowFolder, bool allowMod)
 {
   var of = new Overwriteform(msg, allowFolder, allowMod);
   of.ShowDialog();
   return of.result;
 }
Beispiel #4
0
        /// <summary>
        ///   Sets the specified value in the specified Ini file to the given value.
        /// </summary>
        /// <param name="p_strSettingsFileName">The name of the settings file to edit.</param>
        /// <param name="p_strSection">The section in the Ini file to edit.</param>
        /// <param name="p_strKey">The key in the Ini file to edit.</param>
        /// <param name="p_strValue">The value to which to set the key.</param>
        /// <returns>
        ///   <lang langref="true" /> if the value was set; <lang langref="false" />
        ///   if the user chose not to overwrite the existing value.
        /// </returns>
        protected virtual bool EditINI(string p_strSettingsFileName, string p_strSection, string p_strKey, string p_strValue)
        {
            var strFile = p_strSettingsFileName;

            if (m_booDontOverwriteAllIni)
            {
                return(false);
            }

            PermissionsManager.CurrentPermissions.Assert();
            var strLoweredFile    = strFile.ToLowerInvariant();
            var strLoweredSection = p_strSection.ToLowerInvariant();
            var strLoweredKey     = p_strKey.ToLowerInvariant();
            var strOldMod         = InstallLog.Current.GetCurrentIniEditorModName(strFile, p_strSection, p_strKey);
            var strOldValue       = NativeMethods.GetPrivateProfileString(p_strSection, p_strKey, null, strFile);

            if (!m_booOverwriteAllIni)
            {
                string strMessage;
                if (strOldMod != null)
                {
                    strMessage =
                        String.Format("Key '{{0}}' in section '{{1}}' of {{2}}} has already been overwritten by '{0}'\n" +
                                      "Overwrite again with this mod?\n" +
                                      "Current value '{{3}}', new value '{{4}}'", strOldMod);
                }
                else
                {
                    strMessage = "The mod wants to modify key '{0}' in section '{1}' of {2}.\n" +
                                 "Allow the change?\n" +
                                 "Current value '{3}', new value '{4}'";
                }
                switch (
                    Overwriteform.ShowDialog(String.Format(strMessage, p_strKey, p_strSection, strFile, strOldValue, p_strValue),
                                             false, (strOldMod != null)))
                {
                case OverwriteResult.YesToAll:
                    m_booOverwriteAllIni = true;
                    break;

                case OverwriteResult.NoToAll:
                    m_booDontOverwriteAllIni = true;
                    break;

                case OverwriteResult.Yes:
                    break;

                default:
                    return(false);
                }
            }

            //if we are overwriting an original value, back it up
            if ((strOldMod == null) || (strOldValue != null))
            {
                Installer.MergeModule.BackupOriginalIniValue(strLoweredFile, strLoweredSection, strLoweredKey, strOldValue);
            }

            NativeMethods.WritePrivateProfileStringA(strLoweredSection, strLoweredKey, p_strValue, strLoweredFile);
            Installer.MergeModule.AddIniEdit(strLoweredFile, strLoweredSection, strLoweredKey, p_strValue);
            return(true);
        }