Ejemplo n.º 1
0
        public IVisualPinballManager SetTableScript(string path, string tableScript)
        {
            _logger.Info("Saving table script to {0}", path);

            var cf      = new CompoundFile(path, CFSUpdateMode.Update, CFSConfiguration.Default);
            var storage = cf.RootStorage.GetStorage("GameStg");

            // 1. verify that we can do it
            _logger.Info("Checking checksum capabilities...");
            var computedChecksum = ComputeChecksum(cf);
            var storedChecksum   = ReadChecksum(storage);

            if (!computedChecksum.SequenceEqual(storedChecksum))
            {
                throw new FormatException("Could not recompute checksum.");
            }
            _logger.Info("Checkum looks good, computed the same as found in file.");
            _logger.Info("Checking BIFF capabilities...");
            var gameData = new BiffSerializer(storage.GetStream("GameData").GetData());
            var parsers  = new Dictionary <string, BiffSerializer.IBiffTagSerializer> {
                { "CODE", new BiffSerializer.SimpleSerializer() }
            };

            gameData.Deserialize(parsers);
            if (!gameData.CheckConsistency())
            {
                throw new FormatException("Could not re-serialize BIFF data.");
            }
            _logger.Info("Un- and re-serialized BIFF data and got the same result. We're good to go!");

            try {
                // 2. update table script
                _logger.Info("Updating CODE data in BIFF stream...");
                gameData.SetString("CODE", tableScript);
                storage.GetStream("GameData").SetData(gameData.Serialize());
                cf.Commit();
                cf.Close();

                // 3. update hash
                cf      = new CompoundFile(path, CFSUpdateMode.Update, CFSConfiguration.Default);
                storage = cf.RootStorage.GetStorage("GameStg");
                var hash = ComputeChecksum(cf);
                _logger.Info("Setting new checksum {0}...", BitConverter.ToString(hash));
                storage.GetStream("MAC").SetData(hash);
                cf.Commit();
                cf.Close();
                _logger.Info("Done!");
            } catch (CFItemNotFound e) {
                _logger.Error(e, "Error patching file!");
                _crashManager.Report(e, "vpt");
            }

            return(this);
        }
Ejemplo n.º 2
0
        public IVisualPinballManager SetTableScript(string path, string tableScript)
        {
            _logger.Info("Saving table script to {0}", path);

            var cf = new CompoundFile(path, CFSUpdateMode.Update, CFSConfiguration.Default);
            var storage = cf.RootStorage.GetStorage("GameStg");

            // 1. verify that we can do it
            _logger.Info("Checking checksum capabilities...");
            var computedChecksum = ComputeChecksum(cf);
            var storedChecksum = ReadChecksum(storage);
            if (!computedChecksum.SequenceEqual(storedChecksum)) {
                throw new FormatException("Could not recompute checksum.");
            }
            _logger.Info("Checkum looks good, computed the same as found in file.");
            _logger.Info("Checking BIFF capabilities...");
            var gameData = new BiffSerializer(storage.GetStream("GameData").GetData());
            var parsers = new Dictionary<string, BiffSerializer.IBiffTagSerializer> {
                    { "CODE", new BiffSerializer.SimpleSerializer() }
            };
            gameData.Deserialize(parsers);
            if (!gameData.CheckConsistency()) {
                throw new FormatException("Could not re-serialize BIFF data.");
            }
            _logger.Info("Un- and re-serialized BIFF data and got the same result. We're good to go!");

            try {

                // 2. update table script
                _logger.Info("Updating CODE data in BIFF stream...");
                gameData.SetString("CODE", tableScript);
                storage.GetStream("GameData").SetData(gameData.Serialize());
                cf.Commit();
                cf.Close();

                // 3. update hash
                cf = new CompoundFile(path, CFSUpdateMode.Update, CFSConfiguration.Default);
                storage = cf.RootStorage.GetStorage("GameStg");
                var hash = ComputeChecksum(cf);
                _logger.Info("Setting new checksum {0}...", BitConverter.ToString(hash));
                storage.GetStream("MAC").SetData(hash);
                cf.Commit();
                cf.Close();
                _logger.Info("Done!");

            } catch (CFItemNotFound e) {
                _logger.Error(e, "Error patching file!");
                _crashManager.Report(e, "vpt");
            }

            return this;
        }