Пример #1
0
        public override Score ReadScore()
        {
            // at first we need to load the binary file system
            // from the GPX container
            var fileSystem = new GpxFileSystem();
            fileSystem.FileFilter = s => s == GpxFileSystem.ScoreGpif;
            fileSystem.Load(_data);

            // convert data to string
            var data = fileSystem.Files[0].Data;
            var xml = Std.ToString(data);

            // lets set the fileSystem to null, maybe the garbage collector will come along
            // and kick the fileSystem binary data before we finish parsing
            fileSystem.Files = null;
            fileSystem = null;

            // the score.gpif file within this filesystem stores
            // the score information as XML we need to parse.
            var parser = new GpxParser();
            parser.ParseXml(xml);

            parser.Score.Finish();

            return parser.Score;
        }
Пример #2
0
        public override Score ReadScore()
        {
            // at first we need to load the binary file system
            // from the GPX container
            var fileSystem = new GpxFileSystem();

            fileSystem.FileFilter = s => s == GpxFileSystem.ScoreGpif;
            fileSystem.Load(_data);

            // convert data to string
            var data = fileSystem.Files[0].Data;
            var xml  = Std.ToString(data);

            // lets set the fileSystem to null, maybe the garbage collector will come along
            // and kick the fileSystem binary data before we finish parsing
            fileSystem.Files = null;
            fileSystem       = null;

            // the score.gpif file within this filesystem stores
            // the score information as XML we need to parse.
            var parser = new GpxParser();

            parser.ParseXml(xml);

            parser.Score.Finish();

            return(parser.Score);
        }
Пример #3
0
        public override Score ReadScore()
        {
            // at first we need to load the binary file system
            // from the GPX container
            Logger.Info(Name, "Loading GPX filesystem");
            var fileSystem = new GpxFileSystem();

            fileSystem.FileFilter = s => s.EndsWith(GpxFileSystem.ScoreGpif) || s.EndsWith(GpxFileSystem.BinaryStylesheet);
            fileSystem.Load(Data);
            Logger.Info(Name, "GPX filesystem loaded");

            string xml = null;

            byte[] binaryStylesheet = null;
            foreach (var entry in fileSystem.Files)
            {
                switch (entry.FileName)
                {
                case GpxFileSystem.ScoreGpif:
                    xml = Platform.Platform.ToString(entry.Data, GetSetting("encoding", "utf-8"));
                    break;

                case GpxFileSystem.BinaryStylesheet:
                    binaryStylesheet = entry.Data;
                    break;
                }
            }

            // lets set the fileSystem to null, maybe the garbage collector will come along
            // and kick the fileSystem binary data before we finish parsing
            fileSystem.Files = null;
            fileSystem       = null;

            // the score.gpif file within this filesystem stores
            // the score information as XML we need to parse.
            Logger.Info(Name, "Start Parsing score.gpif");
            var parser = new GpifParser();

            parser.ParseXml(xml, Settings);
            Logger.Info(Name, "score.gpif parsed");

            var score = parser.Score;

            if (binaryStylesheet != null)
            {
                Logger.Info(Name, "Start Parsing BinaryStylesheet");
                var stylesheetParser = new BinaryStylesheetParser();
                stylesheetParser.Parse(binaryStylesheet);
                if (stylesheetParser.Stylesheet != null)
                {
                    stylesheetParser.Stylesheet.Apply(score);
                }
                Logger.Info(Name, "BinaryStylesheet parsed");
            }

            return(score);
        }
Пример #4
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Usage GpxExtractor Mode PathToGpx");
                Console.WriteLine("Mode can be extract or decompress");
                return;
            }

            var gpxFs = new GpxFileSystem();
            var dir = Path.Combine(Path.GetDirectoryName(args[1]), Path.GetFileNameWithoutExtension(args[1]));
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            var mode = args[0];
            switch (mode)
            {
                case "extract":

                    gpxFs.Load(ByteBuffer.FromBuffer(File.ReadAllBytes(args[1])));

                    foreach (var file in gpxFs.Files)
                    {
                        Console.WriteLine("Extracting {0}", file.FileName);
                        File.WriteAllBytes(Path.Combine(dir, file.FileName), file.Data);
                    }

                    break;
                case "decompress":

                    var src = new BitReader(ByteBuffer.FromBuffer(File.ReadAllBytes(args[1])));

                    var header = gpxFs.ReadHeader(src);
                    Console.WriteLine("Found Header: {0}", header);

                    if (header != GpxFileSystem.HeaderBcFz)
                    {
                        Console.WriteLine("The requested file is no compressed gpx");
                        return;
                    }

                    var decompressed = gpxFs.Decompress(src);
                    File.WriteAllBytes(Path.Combine(dir, "Decompressed.gpx"), decompressed);
                    break;
            }
        }
Пример #5
0
        public void TestFileSystemCompressed()
        {
            GpxFileSystem fileSystem = new GpxFileSystem();
            fileSystem.Load(new StreamWrapper(new MemoryStream(Load("GuitarPro6/Compressed.gpx"))));

            string[] names = {"score.gpif", "misc.xml", "BinaryStylesheet", "PartConfiguration", "LayoutConfiguration"};
            int[] sizes = {8488, 130, 12204, 20, 12};

            for (int i = 0; i < fileSystem.Files.Count; i++)
            {
                var file = fileSystem.Files[i];
                Console.WriteLine("{0} - {1}", file.FileName, file.FileSize);
                Assert.AreEqual(names[i], file.FileName);
                Assert.AreEqual(sizes[i], file.FileSize);
            }
        }