Beispiel #1
0
        public TextViewer(ArchiveEntry entry)
        {
            InitializeComponent();

            this.Text  = entry.FileName;
            this.Entry = entry;

            using (var sr = new StreamReader(entry.GetDataStream()))
            {
                textEditorControl1.Text = sr.ReadToEnd();
            }

            textEditorControl1.SetHighlighting(this.DetectHighlighting(entry.FileName));

            splitContainer1.Panel2Collapsed = true;
        }
Beispiel #2
0
        private void LoadImage(ArchiveEntry entry)
        {
            var stream = entry.GetDataStream();

            if (Path.GetExtension(entry.FileName) == ".dds")
            {
                var dds = new DDSImage(stream);
                this.DDSImage       = dds;
                this.ImageSize      = new Size(dds.BitmapImage.Width, dds.BitmapImage.Height);
                this.ImageBox.Image = dds.BitmapImage;
            }
            else
            {
                var bitmap = new Bitmap(stream);
                this.ImageSize      = new Size(bitmap.Width, bitmap.Height);
                this.ImageBox.Image = bitmap;
            }
        }
Beispiel #3
0
        public static void PreviewTexture(IWin32Window owner, ArchiveEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentException("Parameter 'entry' can't be null.", nameof(entry));
            }

            string fileName  = entry.FileName;
            var    extension = Path.GetExtension(entry.LowerPath);

            switch (extension)
            {
            case ".dds":
            case ".bmp":
            case ".png":
            case ".jpg":
                if ((entry as BA2TextureEntry)?.IsFormatSupported() == false)
                {
                    MessageBox.Show(owner, "Unsupported DDS texture.");
                    return;
                }

                if (!Settings.Default.BuiltInPreviewing.Contains(extension))
                {
                    goto default;
                }

                if (entry is BA2GNFEntry)
                {
                    if (Settings.Default.ReplaceGNFExt)
                    {
                        fileName = Path.GetFileNameWithoutExtension(fileName) + ".gnf";
                    }

                    goto default;
                }

                try
                {
                    DDSViewer.Show(owner, entry.FileName, entry.GetDataStream());
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                    goto default;
                }
                break;

            case ".txt":
            case ".bat":
            case ".xml":
            case ".lst":
            case ".psc":
            case ".json":
                if (!Settings.Default.BuiltInPreviewing.Contains(extension))
                {
                    // Don't launch .bat files, just to be safe
                    if (extension == ".bat")
                    {
                        MessageBox.Show(owner,
                                        "Can only preview batch scripts with built-in text viewer, you can enable it in Options.",
                                        "Error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Warning);
                        break;
                    }

                    goto default;
                }

                new TextViewer(entry).Show(owner);
                break;

            default:
                string dest = Program.CreateTempDirectory();
                string file = Path.Combine(dest, fileName);
                entry.Extract(dest, false, fileName);

                try
                {
                    Process.Start(new ProcessStartInfo(file));
                }
                catch (Win32Exception ex)
                {
                    if (ex.NativeErrorCode == (int)SystemErrorCodes.ERROR_NO_ASSOCIATION)
                    {
                        ShellExecute.OpenWith(file);
                    }
                    else if (ex.NativeErrorCode != (int)SystemErrorCodes.ERROR_CANCELLED)
                    {
                        MessageBox.Show(owner, ex.Message, "Preview Error");
                    }
                }
                break;
            }
        }