Exemple #1
0
        public static void ListTest()
        {
            String DIRECTORY_NAME   = "lists";
            String INTERPRETER_FILE = Path.Combine(FILEFORMAT_DIRECTORY_NAME, "Island_Gamedata.xml");

            String TESTFILE = Path.Combine(TEST_DIRECTORY_NAME, DIRECTORY_NAME, "gamedata_og.data");
            String DECOMPRESSED_TESTFILE = Path.Combine(TEST_DIRECTORY_NAME, DIRECTORY_NAME, "gamedata_decompressed.xml");
            String INTERPRETED_TESTFILE  = Path.Combine(TEST_DIRECTORY_NAME, DIRECTORY_NAME, "gamedata_interpreted.xml");
            String TOHEX_TESTFILE        = Path.Combine(TEST_DIRECTORY_NAME, DIRECTORY_NAME, "gamedata_backtohex.xml");
            String EXPORTED_TESTFILE     = Path.Combine(TEST_DIRECTORY_NAME, DIRECTORY_NAME, "gamedata.data");

            //decompress gamedata.data
            var interpreterDoc = new XmlDocument();

            interpreterDoc.Load(INTERPRETER_FILE);

            //decompress
            var decompressed = reader.ReadFile(TESTFILE);

            decompressed.Save(DECOMPRESSED_TESTFILE);

            //interpret
            var interpreted = interpreter.Interpret(decompressed, interpreterDoc);

            interpreted.Save(INTERPRETED_TESTFILE);

            //to hex
            var Hexed = exporter.Export(interpreted, interpreterDoc);

            Hexed.Save(TOHEX_TESTFILE);

            //back to gamedata
            writer.Export(Hexed, EXPORTED_TESTFILE);
        }
Exemple #2
0
        private static void Main(string[] args)
        {
            var reader      = new FileReader();
            var exporter    = new XmlExporter();
            var writer      = new FileWriter();
            var interpreter = new XmlInterpreter();


            //todo make this pretty by adjusting writing to reading flow.
            CommandLine.Parser.Default.ParseArguments <DecompressOptions, CompressOptions, InterpretOptions, toHexOptions, Decompress_Interpret_Options, Recompress_Export_Options>(args).MapResult(
                (DecompressOptions o) =>
            {
                foreach (String s in o.InputFiles)
                {
                    var doc = reader.ReadFile(s);
                    doc.Save(Path.ChangeExtension(s, "xml"));
                }
                Console.ReadKey();
                return(0);
            },
                (CompressOptions o) =>
            {
                var ext = "";
                if (o.OutputFileExtension != null)
                {
                    ext = o.OutputFileExtension;
                }
                else
                {
                    ext = ".filedb";
                }
                foreach (String s in o.InputFiles)
                {
                    writer.Export(s, ext);
                }
                Console.ReadKey();
                return(0);
            },
                (InterpretOptions o) =>
            {
                foreach (String s in o.InputFiles)
                {
                    var doc = interpreter.Interpret(s, o.Interpreter);
                    doc.Save(Path.ChangeExtension(HexHelper.AddSuffix(s, "_interpreted"), "xml"));
                }
                Console.ReadKey();
                return(0);
            },
                (toHexOptions o) =>
            {
                foreach (String s in o.InputFiles)
                {
                    var doc = exporter.Export(s, o.Interpreter);
                    doc.Save(Path.ChangeExtension(HexHelper.AddSuffix(s, "_exported"), "xml"));
                }

                Console.ReadKey();
                return(0);
            },
                (Decompress_Interpret_Options o) =>
            {
                foreach (String s in o.InputFiles)
                {
                    var interpreterDoc = new XmlDocument();
                    interpreterDoc.Load(o.Interpreter);
                    var doc = interpreter.Interpret(reader.ReadFile(s), interpreterDoc);
                    doc.Save(Path.ChangeExtension(HexHelper.AddSuffix(s, "_d_i"), "xml"));
                }
                Console.ReadKey();
                return(0);
            },
                (Recompress_Export_Options o) =>
            {
                var ext = "";
                if (o.OutputFileExtension != null)
                {
                    ext = o.OutputFileExtension;
                }
                else
                {
                    ext = ".filedb";
                }
                foreach (String s in o.InputFiles)
                {
                    var interpreterDoc = new XmlDocument();
                    interpreterDoc.Load(o.Interpreter);
                    writer.Export(exporter.Export(s, o.Interpreter), o.OutputFileExtension, s);
                }
                Console.ReadKey();
                return(0);
            },
                e => 1
                );
        }
Exemple #3
0
        public XmlDocument Export(XmlDocument doc, XmlDocument interpreter)
        {
            //default type
            XmlNode defaultAttrib = null;

            defaultAttrib = interpreter.SelectSingleNode("/Converts/Default");
            var converts        = interpreter.SelectNodes("/Converts/Converts/Convert");
            var internalFileDBs = interpreter.SelectNodes("/Converts/InternalCompression/Element");

            //converts
            foreach (XmlNode x in converts)
            {
                try
                {
                    String Path  = x.Attributes["Path"].Value;
                    var    Nodes = doc.SelectNodes(Path);
                    ConvertNodeSet(Nodes, x);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Path not correctly set lol");
                    Console.WriteLine(x.Attributes["Path"].Value);
                }
            }

            //defaultType
            if (defaultAttrib != null)
            {
                //get a combined xpath of all
                List <String> StringList = new List <string>();
                foreach (XmlNode convert in converts)
                {
                    StringList.Add(convert.Attributes["Path"].Value);
                }
                foreach (XmlNode internalFileDB in internalFileDBs)
                {
                    StringList.Add(internalFileDB.Attributes["Path"].Value);
                }
                String xPath = String.Join(" | ", StringList);

                //select all text not in combined path#
                var Base     = doc.SelectNodes("//*[text()]");
                var toFilter = doc.SelectNodes(xPath);
                var defaults = HexHelper.ExceptNodelists(Base, toFilter);

                //convert that to default type
                ConvertNodeSet(defaults, defaultAttrib);
            }
            //internal filedbs
            foreach (XmlNode n in internalFileDBs)
            {
                var nodes = doc.SelectNodes(n.Attributes["Path"].Value);
                foreach (XmlNode node in nodes)
                {
                    //get internal document
                    var         contentNode = node.SelectSingleNode("./Content");
                    XmlDocument xmldoc      = new XmlDocument();
                    XmlNode     f           = xmldoc.ImportNode(contentNode, true);
                    xmldoc.AppendChild(xmldoc.ImportNode(f, true));

                    //compress the document
                    FileWriter fileWriter = new FileWriter();
                    var        stream     = fileWriter.Export(xmldoc, new MemoryStream());

                    //get this stream to hex
                    node.InnerText = ByteArrayToString(HexHelper.StreamToByteArray(stream));

                    //try to overwrite the bytesize since it's always exported the same way
                    var ByteSize = node.SelectSingleNode("./preceding-sibling::ByteCount");
                    if (ByteSize != null)
                    {
                        long BufferSize = stream.Length;
                        Type type       = typeof(int);
                        ByteSize.InnerText = ByteArrayToString(ConverterFunctions.ConversionRulesExport[type](BufferSize.ToString(), new UnicodeEncoding()));
                    }
                }
            }

            return(doc);
            //doc.Save(Path.ChangeExtension(HexHelper.AddSuffix(docpath, "_e"), "xml"));
        }