protected override void SaveAndClose(EditorForm form, TextureFile textureFile, File file)
        {
            using (new WaitCursor(form))
            {
                var resourceFile = new ResourceFile();
                using (var ms = new MemoryStream(file.GetData()))
                {
                    resourceFile.Read(ms);
                }

                var msSystem = new MemoryStream(resourceFile.SystemMemData);
                var msGraphics = new MemoryStream(resourceFile.GraphicsMemData);

                try
                {
                    textureFile.Save(msSystem, msGraphics);
                }
                finally
                {
                    msSystem.Close();
                    msGraphics.Close();
                }

                using (var resMS = new MemoryStream())
                {
                    resourceFile.Write(resMS);
                    file.SetData(resMS.ToArray());
                }
            }

            form.Close();

        }
Example #2
0
        public void Open(Stream stream)
        {
            var res = new ResourceFile();
            res.Read(stream);

            if (res.Type != ResourceType.Generic)
            {
                throw new Exception("Not a supported file type.");
            }

            var systemMemory = new MemoryStream(res.SystemMemData);
            var graphicsMemory = new MemoryStream(res.GraphicsMemData);

            Data = new HtmlDocument();

            // Read System Memory
            
            var systemMemoryBR = new BinaryReader(systemMemory);

            Data.Read(systemMemoryBR);

            // Read Graphics Memory

            var graphicsMemoryBR = new BinaryReader(graphicsMemory);

            Data.ReadData(graphicsMemoryBR);

            // Read Embedded Resource Files

            Data.ReadEmbeddedResources(systemMemory, graphicsMemory);

            systemMemory.Close();
            graphicsMemory.Close();

        }
Example #3
0
        private void btnOpenResource_Click(object sender, EventArgs e)
        {
            var filename = OpenFileForRead("Open Resource...", null);
            if (filename != null)
            {
                var res = new ResourceFile();
                var fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
                try
                {
                    res.Read(fs);

                    _resourceFile = res;
                    _filename = filename;

                    UpdateUI();
                }
                catch ( Exception exception )
                {
                    MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    fs.Close();
                }
            }
        }
Example #4
0
        public void Open(Stream stream)
        {
            var res = new ResourceFile();
            res.Read(stream);

            if (res.Type != ResourceType.Texture)
            {
                throw new Exception("Not a valid texture resource.");
            }

            // Read

            var systemMem = new MemoryStream(res.SystemMemData);
            var graphicsMem = new MemoryStream(res.GraphicsMemData);

            Open(systemMem, graphicsMem);

            systemMem.Close();
            graphicsMem.Close();

            // Save the resource file for later
            _resourceFile = res;
        }