Exemplo n.º 1
0
        /// <summary>
        ///   Edits the specified shader with the specified data.
        /// </summary>
        /// <param name="p_intPackage">The package containing the shader to edit.</param>
        /// <param name="p_strShaderName">The shader to edit.</param>
        /// <param name="p_bteData">The value to which to edit the shader.</param>
        /// <returns>
        ///   <lang langref="true" /> if the value was set; <lang langref="false" />
        ///   if the user chose not to overwrite the existing value.
        /// </returns>
        /// <exception cref="ShaderException">Thrown if the shader could not be edited.</exception>
        public virtual bool EditShader(int p_intPackage, string p_strShaderName, byte[] p_bteData)
        {
            var strShaderKey = String.Format("sdp:{0}/{1}", p_intPackage, p_strShaderName);
            var strOldMod    = InstallLog.Current.GetCurrentGameSpecifcValueEditorModName(strShaderKey);

            if (strOldMod != null)
            {
                var strMessage = String.Format("Shader '{0}' in package '{1}' has already been overwritten by '{2}'\n" +
                                               "Overwrite the changes?", p_strShaderName, p_intPackage, strOldMod);
                if (
                    System.Windows.Forms.MessageBox.Show(strMessage, "Confirm Overwrite", MessageBoxButtons.YesNo,
                                                         MessageBoxIcon.Question) != DialogResult.Yes)
                {
                    return(false);
                }
            }

            PermissionsManager.CurrentPermissions.Assert();
            byte[] oldData;
            if (!SDPArchives.EditShader(p_intPackage, p_strShaderName, p_bteData, out oldData))
            {
                throw new ShaderException("Failed to edit the shader");
            }

            //if we are overwriting an original shader, back it up
            if ((strOldMod == null) || (oldData != null))
            {
                Installer.MergeModule.BackupOriginalGameSpecificValueEdit(strShaderKey, oldData);
            }

            Installer.MergeModule.AddGameSpecificValueEdit(strShaderKey, p_bteData);
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Edits the specified game specific value.
        /// </summary>
        /// <remarks>
        /// This method writes the given value in the specified game specific value, if it
        /// is owned by the mod being upgraded. If the specified edit is not owned by the
        /// mod being upgraded, the edit is archived in the install log.
        ///
        /// If the edit was not previously installed by the mod, then the normal install
        /// rules apply, including confirming overwrite if applicable.
        /// </remarks>
        /// <param name="p_strKey">The key of the edited Game Specific Value.</param>
        /// <param name="p_bteValue">The value to install.</param>
        /// <returns><c>true</c> if the value was set; <c>false</c> otherwise.</returns>
        public override bool EditGameSpecificValue(string p_strKey, byte[] p_bteValue)
        {
            IList <IMod> lstInstallers = InstallLog.GetGameSpecificValueEditInstallers(p_strKey);

            if (lstInstallers.Contains(Mod, ModComparer.Filename))
            {
                if (!ModComparer.Filename.Equals(lstInstallers[lstInstallers.Count - 1], Mod))
                {
                    InstallLog.ReplaceGameSpecificValueEdit(Mod, p_strKey, p_bteValue);
                }
                else
                {
                    ShaderEdit  sedShader  = new ShaderEdit(p_strKey);
                    SDPArchives sdpManager = new SDPArchives(GameModeInfo, FileUtility);
                    if (!TouchedFiles.Contains(sdpManager.GetPath(sedShader.Package)))
                    {
                        TouchedFiles.Add(sdpManager.GetPath(sedShader.Package));
                        TransactionalFileManager.Snapshot(sdpManager.GetPath(sedShader.Package));
                    }
                    byte[] oldData;
                    if (!sdpManager.EditShader(sedShader.Package, sedShader.ShaderName, p_bteValue, out oldData))
                    {
                        throw new Exception("Failed to edit the shader");
                    }
                }
                OriginallyInstalledEdits.Remove(p_strKey);
                return(true);
            }

            return(base.EditGameSpecificValue(p_strKey, p_bteValue));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Edits the specified game specific value.
        /// </summary>
        /// <param name="p_strKey">The key of the edited Game Specific Value.</param>
        /// <param name="p_bteValue">The value to install.</param>
        /// <returns><c>true</c> if the value was set; <c>false</c> otherwise.</returns>
        public virtual bool EditGameSpecificValue(string p_strKey, byte[] p_bteValue)
        {
            if (m_booDontOverwriteAll)
            {
                return(false);
            }

            ShaderEdit  sedShader  = new ShaderEdit(p_strKey);
            SDPArchives sdpManager = new SDPArchives(GameModeInfo, FileUtility);

            if (!TouchedFiles.Contains(sdpManager.GetPath(sedShader.Package)))
            {
                TouchedFiles.Add(sdpManager.GetPath(sedShader.Package));
                TransactionalFileManager.Snapshot(sdpManager.GetPath(sedShader.Package));
            }

            IMod modOldMod = InstallLog.GetCurrentGameSpecificValueEditOwner(p_strKey);

            if (!m_booOverwriteAll && (modOldMod != null))
            {
                string strMessage = String.Format("Shader '{0}' in package '{1}' has already been overwritten by '{2}'\n" +
                                                  "Overwrite the changes?", sedShader.ShaderName, sedShader.Package, modOldMod.ModName);
                switch (m_dlgOverwriteConfirmationDelegate(strMessage, false, false))
                {
                case OverwriteResult.YesToAll:
                    m_booOverwriteAll = true;
                    break;

                case OverwriteResult.NoToAll:
                    m_booDontOverwriteAll = true;
                    break;

                case OverwriteResult.Yes:
                    break;

                default:
                    return(false);
                }
            }

            byte[] oldData;
            if (!sdpManager.EditShader(sedShader.Package, sedShader.ShaderName, p_bteValue, out oldData))
            {
                throw new Exception("Failed to edit the shader");
            }

            //if we are overwriting an original shader, back it up
            if ((modOldMod == null) && (oldData != null))
            {
                InstallLog.LogOriginalGameSpecificValue(p_strKey, oldData);
            }

            InstallLog.AddGameSpecificValueEdit(Mod, p_strKey, p_bteValue);
            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        ///   Edits the specified shader with the specified data.
        /// </summary>
        /// <remarks>
        ///   This method edits the specified shader, if the latest edit is owned
        ///   by the fomod being upgraded. If the latest edit is not owned by the fomod
        ///   being upgraded, the edit is simply archived in the appropriate location in the
        ///   install log.
        ///   If the edit was not previously installed by the fomod, then the normal install rules apply,
        ///   including confirming overwrite if applicable.
        /// </remarks>
        /// <param name="p_intPackage">The package containing the shader to edit.</param>
        /// <param name="p_strShaderName">The shader to edit.</param>
        /// <param name="p_bteData">The value to which to edit the shader.</param>
        /// <returns>
        ///   <lang langref="true" /> if the value was set; <lang langref="false" />
        ///   if the user chose not to overwrite the existing value.
        /// </returns>
        /// <exception cref="ShaderException">Thrown if the shader could not be edited.</exception>
        public override bool EditShader(int p_intPackage, string p_strShaderName, byte[] p_bteData)
        {
            PermissionsManager.CurrentPermissions.Assert();

            var            strShaderKey  = String.Format("sdp:{0}/{1}", p_intPackage, p_strShaderName);
            IList <string> lstInstallers = InstallLog.Current.GetGameSpecifcValueInstallingMods(strShaderKey);

            if (lstInstallers.Contains(Fomod.BaseName))
            {
                if (lstInstallers[lstInstallers.Count - 1].Equals(Fomod.BaseName))
                {
                    byte[] oldData;
                    if (!SDPArchives.EditShader(p_intPackage, p_strShaderName, p_bteData, out oldData))
                    {
                        throw new ShaderException("Failed to edit the shader");
                    }
                }
                Installer.MergeModule.AddGameSpecificValueEdit(strShaderKey, p_bteData);
                return(true);
            }

            return(base.EditShader(p_intPackage, p_strShaderName, p_bteData));
        }