/// <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><c>true</c> if the value was set; <c>false</c> /// if the user chose not to overwrite the existing value.</returns> public virtual bool EditIni(string p_strSettingsFileName, string p_strSection, string p_strKey, string p_strValue) { if (m_booDontOverwriteAllIni) { return(false); } if (!TouchedFiles.Contains(p_strSettingsFileName)) { TouchedFiles.Add(p_strSettingsFileName); TransactionalFileManager.Snapshot(p_strSettingsFileName); } IMod modOldMod = InstallLog.GetCurrentIniEditOwner(p_strSettingsFileName, p_strSection, p_strKey); string strOldValue = IniMethods.GetPrivateProfileString(p_strSection, p_strKey, null, p_strSettingsFileName); if (!m_booOverwriteAllIni) { string strMessage = null; if (modOldMod != 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}}'", modOldMod.ModName); } 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 (m_dlgOverwriteConfirmationDelegate(String.Format(strMessage, p_strKey, p_strSection, p_strSettingsFileName, strOldValue, p_strValue), false, false)) { 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 ((modOldMod == null) && (strOldValue != null)) { InstallLog.LogOriginalIniValue(p_strSettingsFileName, p_strSection, p_strKey, strOldValue); } IniMethods.WritePrivateProfileString(p_strSection, p_strKey, p_strValue, p_strSettingsFileName); InstallLog.AddIniEdit(Mod, p_strSettingsFileName, p_strSection, p_strKey, p_strValue); return(true); }