Ejemplo n.º 1
0
        /// <summary>
        /// Undoes the edit made to the specified game specific value.
        /// </summary>
        /// <param name="p_strKey">The key of the edited Game Specific Value.</param>
        public void UnEditGameSpecificValue(string p_strKey)
        {
            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));
            }

            string strKey             = InstallLog.GetModKey(Mod);
            string strCurrentOwnerKey = InstallLog.GetCurrentGameSpecificValueEditOwnerKey(p_strKey);

            //if we didn't edit the shader, then leave it alone
            if (!strKey.Equals(strCurrentOwnerKey))
            {
                return;
            }

            //if we did edit the shader, replace it with the shader we overwrote
            // if we didn't overwrite the shader, then just delete it
            byte[] btePreviousData = InstallLog.GetPreviousGameSpecificValue(p_strKey);
            if (btePreviousData != null)
            {
                /*TODO (likely never): I'm not sure if this is the strictly correct way to unedit a shader
                 * the original unedit code was:
                 *
                 *	if (m_xelModInstallLogSdpEdits != null)
                 *	{
                 *		foreach (XmlNode node in m_xelModInstallLogSdpEdits.ChildNodes)
                 *		{
                 *			//TODO (likely never): Remove this workaround for the release version
                 *			if (node.Attributes.GetNamedItem("crc") == null)
                 *			{
                 *				InstallLog.UndoShaderEdit(int.Parse(node.Attributes.GetNamedItem("package").Value), node.Attributes.GetNamedItem("shader").Value, 0);
                 *			}
                 *			else
                 *			{
                 *				InstallLog.UndoShaderEdit(int.Parse(node.Attributes.GetNamedItem("package").Value), node.Attributes.GetNamedItem("shader").Value,
                 *					uint.Parse(node.Attributes.GetNamedItem("crc").Value));
                 *			}
                 *		}
                 *	}
                 *
                 * where InstallLog.UndoShaderEdit was:
                 *
                 *	public void UndoShaderEdit(int package, string shader, uint crc)
                 *	{
                 *		XmlNode node = sdpEditsNode.SelectSingleNode("sdp[@package='" + package + "' and @shader='" + shader + "']");
                 *		if (node == null) return;
                 *		byte[] b = new byte[node.InnerText.Length / 2];
                 *		for (int i = 0; i < b.Length; i++)
                 *		{
                 *			b[i] = byte.Parse("" + node.InnerText[i * 2] + node.InnerText[i * 2 + 1], System.Globalization.NumberStyles.AllowHexSpecifier);
                 *		}
                 *		if (SDPArchives.RestoreShader(package, shader, b, crc)) sdpEditsNode.RemoveChild(node);
                 *	}
                 *
                 * after looking at SDPArchives it is not clear to me why a crc was being used.
                 * if ever it becomes evident that a crc is required, I will have to alter the log to store
                 *  a crc and pass it to the RestoreShader method.
                 */
                if (!sdpManager.RestoreShader(sedShader.Package, sedShader.ShaderName, btePreviousData, 0))
                {
                    throw new Exception("Failed to unedit the shader");
                }
            }
            //TODO (likely never): how do we delete a shader? Right now, if there was no previous shader the current shader
            // remains
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Undoes the edit made to the specified shader.
        /// </summary>
        /// <param name="p_intPackage">The package containing the shader to edit.</param>
        /// <param name="p_strShaderName">The shader to edit.</param>
        /// <exception cref="ShaderException">Thrown if the shader could not be unedited.</exception>
        protected void UneditShader(int p_intPackage, string p_strShaderName)
        {
            var strShaderKey       = String.Format("sdp:{0}/{1}", p_intPackage, p_strShaderName);
            var strKey             = InstallLog.Current.GetModKey(Fomod.BaseName);
            var strCurrentOwnerKey = InstallLog.Current.GetCurrentGameSpecifcValueEditorModKey(strShaderKey);

            //if we didn't edit the shader, then leave it alone
            if (!strKey.Equals(strCurrentOwnerKey))
            {
                return;
            }

            //if we did edit the shader, replace it with the shader we overwrote
            // if we didn't overwrite the shader, then just delete it
            var btePreviousData = InstallLog.Current.GetPreviousGameSpecifcValueData(strShaderKey);

            if (btePreviousData != null)
            {
                /*TODO: I'm not sure if this is the strictly correct way to unedit a shader
                 * the original unedit code was:
                 *
                 *  if (m_xelModInstallLogSdpEdits != null)
                 *  {
                 *    foreach (XmlNode node in m_xelModInstallLogSdpEdits.ChildNodes)
                 *    {
                 *      //TODO: Remove this workaround for the release version
                 *      if (node.Attributes.GetNamedItem("crc") == null)
                 *      {
                 *        InstallLog.UndoShaderEdit(int.Parse(node.Attributes.GetNamedItem("package").Value), node.Attributes.GetNamedItem("shader").Value, 0);
                 *      }
                 *      else
                 *      {
                 *        InstallLog.UndoShaderEdit(int.Parse(node.Attributes.GetNamedItem("package").Value), node.Attributes.GetNamedItem("shader").Value,
                 *          uint.Parse(node.Attributes.GetNamedItem("crc").Value));
                 *      }
                 *    }
                 *  }
                 *
                 * where InstallLog.UndoShaderEdit was:
                 *
                 *  public void UndoShaderEdit(int package, string shader, uint crc)
                 *  {
                 *    XmlNode node = sdpEditsNode.SelectSingleNode("sdp[@package='" + package + "' and @shader='" + shader + "']");
                 *    if (node == null) return;
                 *    byte[] b = new byte[node.InnerText.Length / 2];
                 *    for (int i = 0; i < b.Length; i++)
                 *    {
                 *      b[i] = byte.Parse("" + node.InnerText[i * 2] + node.InnerText[i * 2 + 1], System.Globalization.NumberStyles.AllowHexSpecifier);
                 *    }
                 *    if (SDPArchives.RestoreShader(package, shader, b, crc)) sdpEditsNode.RemoveChild(node);
                 *  }
                 *
                 * after looking at SDPArchives it is not clear to me why a crc was being used.
                 * if ever it becomes evident that a crc is required, I will have to alter the log to store
                 *  a crc and pass it to the RestoreShader method.
                 */

                PermissionsManager.CurrentPermissions.Assert();
                if (!SDPArchives.RestoreShader(p_intPackage, p_strShaderName, btePreviousData, 0))
                {
                    throw new ShaderException("Failed to unedit the shader");
                }
            }
            //TODO: how do we delete a shader? Right now, if there was no previous shader the current shader
            // remains
        }