Exemplo n.º 1
0
        public override void LaunchEditor(FileSystem fs, File file)
        {
            var data = file.GetData();

            var ms            = new MemoryStream(data);
            var hyperTextFile = new HyperTextFile();

            try
            {
                hyperTextFile.Open(ms);
            }
            finally
            {
                ms.Close();
            }

            if (hyperTextFile.EmbeddedTextureFile != null)
            {
                ShowForm(file, hyperTextFile.EmbeddedTextureFile);
            }
            else
            {
                MessageBox.Show("There are no embedded textures in the selected HyperText file to edit.", "Edit",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Exemplo n.º 2
0
        public Control GetView(File file)
        {
            var data = file.GetData();

            var ms            = new MemoryStream(data);
            var hyperTextFile = new HyperTextFile();

            try
            {
                hyperTextFile.Open(ms);
            }
            finally
            {
                ms.Close();
            }

            StringWriter sw = new StringWriter();

            hyperTextFile.WriteHTML(sw);

            // Create a temporary folder
            string tempPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            string htmlPath = Path.Combine(tempPath, "exported.html");

            Directory.CreateDirectory(tempPath);
            System.IO.File.WriteAllText(htmlPath, sw.ToString());

            if (hyperTextFile.EmbeddedTextureFile != null)
            {
                foreach (var texture in hyperTextFile.EmbeddedTextureFile)
                {
                    string imagePath = Path.Combine(tempPath, texture.Name + ".png");

                    string directory = Path.GetDirectoryName(imagePath);
                    if (!Directory.Exists(directory))
                    {
                        Directory.CreateDirectory(directory);
                    }

                    Image image = texture.Decode();
                    image.Save(imagePath, ImageFormat.Png);
                }
            }

            WebBrowser browser = new WebBrowser();

            browser.AllowNavigation     = false;
            browser.AllowWebBrowserDrop = false;
            //_browser.WebBrowserShortcutsEnabled = false;
            //_browser.IsWebBrowserContextMenuEnabled = false;

            //browser.DocumentText = sw.ToString();
            browser.Navigate(htmlPath);

            browser.Disposed += delegate
            {
                Directory.Delete(tempPath, true);

                if (hyperTextFile.EmbeddedTextureFile != null)
                {
                    hyperTextFile.EmbeddedTextureFile.Dispose();
                }
            };

            return(browser);
        }