Exemple #1
0
        /// <summary>
        ///   Determines if the given archive is a valid PFP.
        /// </summary>
        /// <param name="p_arcPFP">The archive to validate as a PFP.</param>
        /// <returns>
        ///   An error string describing why the specified file is not a valid PFP, or
        ///   <lang langref="null" /> if the given archive is a valid PFP.
        /// </returns>
        protected static string ValidatePFP(Archive p_arcPFP)
        {
            if (!p_arcPFP.ContainsFile("metadata.xml"))
            {
                return("Missing metadata.xml file.");
            }

            var xmlMeta = new XmlDocument();

            using (var msmMeta = new MemoryStream(p_arcPFP.GetFileContents("metadata.xml")))
            {
                xmlMeta.Load(msmMeta);
                msmMeta.Close();
            }

            var xndSources = xmlMeta.SelectSingleNode("premadeFomodPack/sources");

            foreach (XmlNode xndSource in xndSources.ChildNodes)
            {
                if ((xndSource.Attributes["name"] == null) || String.IsNullOrEmpty(xndSource.Attributes["name"].Value) ||
                    (xndSource.Attributes["url"] == null) || String.IsNullOrEmpty(xndSource.Attributes["url"].Value))
                {
                    return("Invalid metadata.xml file.");
                }
            }
            return(null);
        }
Exemple #2
0
    /// <summary>
    ///   Determines if the given archive is a valid PFP.
    /// </summary>
    /// <param name="p_arcPFP">The archive to validate as a PFP.</param>
    /// <returns>
    ///   An error string describing why the specified file is not a valid PFP, or
    ///   <lang langref="null" /> if the given archive is a valid PFP.
    /// </returns>
    protected static string ValidatePFP(Archive p_arcPFP)
    {
      if (!p_arcPFP.ContainsFile("metadata.xml"))
      {
        return "Missing metadata.xml file.";
      }

      var xmlMeta = new XmlDocument();
      using (var msmMeta = new MemoryStream(p_arcPFP.GetFileContents("metadata.xml")))
      {
        xmlMeta.Load(msmMeta);
        msmMeta.Close();
      }

      var xndSources = xmlMeta.SelectSingleNode("premadeFomodPack/sources");
      foreach (XmlNode xndSource in xndSources.ChildNodes)
      {
        if ((xndSource.Attributes["name"] == null) || String.IsNullOrEmpty(xndSource.Attributes["name"].Value) ||
            (xndSource.Attributes["url"] == null) || String.IsNullOrEmpty(xndSource.Attributes["url"].Value))
        {
          return "Invalid metadata.xml file.";
        }
      }
      return null;
    }
Exemple #3
0
 /// <summary>
 ///   Gets the contents of the specified file.
 /// </summary>
 /// <remarks>
 ///   This method accounts for the <see cref="PathPrefix" />.
 /// </remarks>
 /// <param name="p_strPath">The path of the file whose contents are to be retrieved.</param>
 /// <returns>The contents of the specified file.</returns>
 public byte[] GetFileContents(string p_strPath)
 {
     if ((m_arcCacheFile != null) && m_arcCacheFile.ContainsFile(GetPrefixAdjustedPath(p_strPath)))
     {
         return(m_arcCacheFile.GetFileContents(GetPrefixAdjustedPath(p_strPath)));
     }
     return(FomodFile.GetFileContents(GetPrefixAdjustedPath(p_strPath)));
 }
Exemple #4
0
 /// <summary>
 /// A simple constructor that initializes the object with the given values.
 /// </summary>
 /// <param name="p_strPFPPath">The path to the PFP file.</param>
 public PremadeFomodPack(string p_strPFPPath)
 {
     m_arcPFP = new Archive(p_strPFPPath);
     string strError = ValidatePFP(m_arcPFP);
     if (!String.IsNullOrEmpty(strError))
         throw new ArgumentException("Specified Premade FOMod Pack is not valid: " + strError, "p_strPFPPath");
     m_xmlMeta = new XmlDocument();
     using (MemoryStream msmMeta = new MemoryStream(m_arcPFP.GetFileContents("metadata.xml")))
     {
         m_xmlMeta.Load(msmMeta);
         msmMeta.Close();
     }
     foreach (string strDirectory in m_arcPFP.GetDirectories("/"))
         if (strDirectory.StartsWith("Premade", StringComparison.InvariantCultureIgnoreCase))
         {
             m_strPremadePath = strDirectory;
             break;
         }
 }
Exemple #5
0
        /// <summary>
        ///   A simple constructor that initializes the object with the given values.
        /// </summary>
        /// <param name="p_strPFPPath">The path to the PFP file.</param>
        public PremadeFomodPack(string p_strPFPPath)
        {
            m_arcPFP = new Archive(p_strPFPPath);
            var strError = ValidatePFP(m_arcPFP);

            if (!String.IsNullOrEmpty(strError))
            {
                throw new ArgumentException("Specified Premade FOMod Pack is not valid: " + strError, "p_strPFPPath");
            }
            m_xmlMeta = new XmlDocument();
            using (var msmMeta = new MemoryStream(m_arcPFP.GetFileContents("metadata.xml")))
            {
                m_xmlMeta.Load(msmMeta);
                msmMeta.Close();
            }
            foreach (var strDirectory in m_arcPFP.GetDirectories("/"))
            {
                if (strDirectory.StartsWith("Premade", StringComparison.InvariantCultureIgnoreCase))
                {
                    PremadePath = strDirectory;
                    break;
                }
            }
        }