WriteToFile() public method

public WriteToFile ( string file ) : void
file string
return void
        public static void Run(string mapPath, string ROMpath, int offset, int? mapPointerOffset, 
            bool insertMapChange, int? mapChangePointerOffset)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(mapPath);

            Map map = new Map(doc);

            if (map.TileWidth != 16 || map.TileHeight != 16)
            {
                throw new Exception("Tilesize is not 16x16");
            }

            var tileChanges = new Dictionary<int, Tuple<Rectangle, TileLayer>>(map.Layers.Count);

            int mainLayerIndex = HandleLayers(map, tileChanges);

            //byte[] ROMData = File.ReadAllBytes(ROMpath);

            //MemoryStream stream = new MemoryStream(ROMData);
            ChangeStream stream = new ChangeStream();

            InsertMap(offset, mapPointerOffset, insertMapChange, mapChangePointerOffset,
                map, tileChanges, mainLayerIndex, stream);

            stream.WriteToFile(ROMpath);
            //File.WriteAllBytes(ROMpath, ROMData);
        }
Exemplo n.º 2
0
        public static void Assemble(string inputFile, string outputFile, string languageName, ILog messageLog)
        {
            TextReader reader;
            bool close;
            if (inputFile != null)
            {
                reader = File.OpenText(inputFile);
                close = true;
            }
            else
            {
                reader = Console.In;
                close = false;
            }

            EACodeLanguage language = languages[languageName];

            if (outputFile != null)
            {
                if (File.Exists(outputFile))
                {
                    if (File.GetAttributes(outputFile).HasFlag(FileAttributes.ReadOnly))
                    {
                        messageLog.AddError("outputFile is read-only.");
                        goto end;
                    }
                }

                var cache = new ChangeStream();
                using (BinaryWriter writer = new BinaryWriter(cache))
                {
                    Assemble(language, reader, writer, messageLog);
                    if (messageLog.ErrorCount == 0)
                    {
                        using (Stream stream = File.OpenWrite(outputFile))
                        {
                            cache.WriteToFile(stream);
                        }
                    }
                }
            }
            else
            {
                messageLog.AddError("outputFile needs to be specified for assembly.");
            }
            end:

            if (close)
                reader.Close();
        }