Пример #1
0
        /// <summary>
        /// Copies an xml file from an archive or directory path and unpacks it from binary Xml to human-readable Xml
        /// </summary>
        /// <param name="xmlUnpack">The Xml unpack instructions object</param>
        /// <param name="unpackBuilder">The stringBuilder to log the generated files location for the install log</param>
        public static bool UnpackXmlFile(XmlUnpack xmlUnpack, StringBuilder unpackBuilder)
        {
            //log info for debugging if need be
            Logging.Info(xmlUnpack.DumpInfoToLog);

            //check if new destination name for replacing
            string destinationFilename     = string.IsNullOrWhiteSpace(xmlUnpack.NewFileName) ? xmlUnpack.FileName : xmlUnpack.NewFileName;
            string destinationCompletePath = Path.Combine(xmlUnpack.ExtractDirectory, destinationFilename);
            string sourceCompletePath      = Path.Combine(xmlUnpack.DirectoryInArchive, xmlUnpack.FileName);

            //if the destination file already exists, then don't copy it over
            if (File.Exists(destinationCompletePath))
            {
                Logging.Info("Replacement file already exists, skipping");
                return(true);
            }

            FileUtils.Unpack(xmlUnpack.Pkg, sourceCompletePath, destinationCompletePath);
            unpackBuilder.AppendLine(destinationCompletePath);

            Logging.Info("unpacking Xml binary file (if binary)");
            try
            {
                XmlBinaryHandler binaryHandler = new XmlBinaryHandler();
                binaryHandler.UnpackXmlFile(destinationCompletePath);
                return(true);
            }
            catch (Exception xmlUnpackExceptino)
            {
                Logging.Exception(xmlUnpackExceptino.ToString());
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// Parse a list of Xml unpack instructions from an Xml file into XmlUnpack objects
        /// </summary>
        /// <param name="xmlUnpacks">The list of XmlUnpacks to parse into</param>
        /// <param name="filename">The name of the file to parse from</param>
        public static void AddXmlUnpackFromFile(List <XmlUnpack> xmlUnpacks, string filename)
        {
            //make an Xml document to get all Xml Unpacks
            XmlDocument doc = LoadXmlDocument(filename, XmlLoadType.FromFile);

            if (doc == null)
            {
                Logging.Error("failed to parse Xml file");
                return;
            }
            //make new patch object for each entry
            //remember to add lots of logging
            XmlNodeList XMLUnpacks = GetXmlNodesFromXPath(doc, "//files/file");

            if (XMLUnpacks == null || XMLUnpacks.Count == 0)
            {
                Logging.Error("File {0} contains no XmlUnapck entries", filename);
                return;
            }
            Logging.Info("Adding {0} Xml unpack entries from file: {1}", XMLUnpacks.Count, filename);
            foreach (XmlNode patchNode in XMLUnpacks)
            {
                XmlUnpack xmlup = new XmlUnpack();
                //we have the patchNode "patch" object, now we need to get it's children to actually get the properties of said patch
                foreach (XmlNode property in patchNode.ChildNodes)
                {
                    //each element in the Xml gets put into the
                    //the corresponding attribute for the Patch instance
                    switch (property.Name)
                    {
                    case "pkg":
                        xmlup.Pkg = property.InnerText.Trim();
                        break;

                    case "directoryInArchive":
                        xmlup.DirectoryInArchive = property.InnerText.Trim();
                        break;

                    case "fileName":
                        xmlup.FileName = property.InnerText.Trim();
                        break;

                    case "extractDirectory":
                        xmlup.ExtractDirectory = property.InnerText.Trim();
                        break;

                    case "newFileName":
                        xmlup.NewFileName = property.InnerText.Trim();
                        break;
                    }
                }
                xmlUnpacks.Add(xmlup);
            }
        }