Esempio n. 1
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
                );
        }