Пример #1
0
        private void menuItemView_Click(object sender, EventArgs e)
        {
            if (!isLoaded())
            {
                return;
            }

            if (lvFiles.SelectedItems.Count == 0)
            {
                return;
            }

            ArchiveEntry ent = m_Archive.getByName(Path.GetFileNameWithoutExtension(lvFiles.SelectedItems[0].Text));

            if (ent == null)
            {
                return;
            }

            ent.extractTo(Path.GetTempPath());

            string file = String.Format("{0}\\{1}{2}", Path.GetTempPath(), ent.getName(), ent.getExtension());

            Process p = Process.Start(file);

            if (p != null)
            {
                p.WaitForExit();
            }

            File.Delete(file);
        }
Пример #2
0
        public void ExtractItem(ListViewItem Item, string Destination)
        {
            if (Item == null || String.IsNullOrWhiteSpace(Destination))
            {
                return;
            }

            ArchiveEntry ent = m_Archive.getByName(Path.GetFileNameWithoutExtension(Item.Text));

            if (ent != null)
            {
                ent.extractTo(Destination);
                SetStatus(String.Format("Extracted {0} to {1}", Item.Text, Destination));
            }
        }
Пример #3
0
        private void lvFiles_ItemDrag(object sender, ItemDragEventArgs e)
        {
            List <string> selection = new List <string>();

            foreach (ListViewItem item in lvFiles.SelectedItems)
            {
                ArchiveEntry ent = m_Archive.getByName(Path.GetFileNameWithoutExtension(item.Text));

                if (ent == null)
                {
                    return;
                }
                ent.extractTo(Path.GetTempPath());

                string file = String.Format("{0}\\{1}{2}", Path.GetTempPath(), ent.getName(), ent.getExtension());
                selection.Add(file);
            }

            DataObject data = new DataObject(DataFormats.FileDrop, selection.ToArray());

            DoDragDrop(data, DragDropEffects.Move);
        }
Пример #4
0
        private void lvFiles_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lvFiles.SelectedItems.Count <= 0)
            {
                pbPreview.Width    = 0;
                pbPreview.Visible  = false;
                rtbPreview.Width   = 0;
                rtbPreview.Visible = false;
                splitContainer.SplitterDistance = this.Width;

                lbSelection.Text = String.Empty;

                return;
            }

            if (File.Exists(currentMeshFile))
            {
                File.Delete(currentMeshFile);
            }

            if (File.Exists(currentMeshFile + ".mtl"))
            {
                File.Delete(currentMeshFile + ".mtl");
            }

            if (glControl != null)
            {
                if (glControl.GLrender != null)
                {
                    glControl.GLrender.ClearAllObjects();
                    glControl.GLrender.GLControlInstance.Dispose();
                }
                glControl.Dispose();
            }

            ListViewItem Item = lvFiles.SelectedItems[0];

            lbSelection.Text = String.Format("Sel {0}", Item.Index + 1);

            ImageListIndex indx = FileType.GetImageIndex(Path.GetExtension(Item.Text));

            if (indx == ImageListIndex.Image)
            {
                pbPreview.Width    = 399;
                pbPreview.Visible  = true;
                rtbPreview.Width   = 0;
                rtbPreview.Visible = false;
                pnlPreview.Visible = false;

                ArchiveEntry ent = m_Archive.getByName(Path.GetFileNameWithoutExtension(Item.Text));
                Image        img = null;

                using (MemoryStream ms = new MemoryStream(ent.getData()))
                {
                    try
                    {
                        if (Path.GetExtension(Item.Text) == ".tga")
                        {
                            TargaImage tgaImg = new TargaImage(ms);
                            img = tgaImg.Image;
                        }
                        else
                        {
                            img = Image.FromStream(ms);
                        }
                    }
                    catch
                    { }
                }

                if (img != null)
                {
                    pbPreview.Image    = img;
                    pbPreview.Width    = img.Width;
                    pbPreview.Location = new Point(pbPreview.Location.X, (this.Height / 2) - (img.Height / 2) - 20);
                    splitContainer.SplitterDistance = Math.Max(this.Width - img.Width - 20, 200);
                }
            }
            else if (indx == ImageListIndex.Text)
            {
                pbPreview.Width    = 0;
                pbPreview.Visible  = false;
                rtbPreview.Width   = 500;
                rtbPreview.Visible = true;
                pnlPreview.Visible = false;
                splitContainer.SplitterDistance = this.Width - 500;

                rtbPreview.Text = "";

                ArchiveEntry ent = m_Archive.getByName(Path.GetFileNameWithoutExtension(Item.Text));
                if (ent != null)
                {
                    rtbPreview.Text = Encoding.Default.GetString(ent.getData());
                }
            }
            else if (indx == ImageListIndex.Mesh)
            {
                pnlPreview.Visible = true;
                splitContainer.SplitterDistance = this.Width - 500;

                glControl        = new OGLControl();
                glControl.Parent = pnlPreview;
                glControl.Dock   = DockStyle.Fill;
                glContext        = new OpenGLContext(glControl);
                glControl.GLrender.PrimitiveTypes = OpenTK.Graphics.OpenGL.PrimitiveType.Triangles;
                glControl.GLrender.Camera.ZNear   = 0.01f;
                glControl.GLrender.Camera.ZFar    = float.MaxValue;

                string tempFile = Path.GetTempFileName();
                currentMeshFile = Path.ChangeExtension(Path.GetTempFileName(), "obj");
                ArchiveEntry ent = m_Archive.getByName(Path.GetFileNameWithoutExtension(Item.Text));
                ent.extractTo(tempFile, true);

                using (AssimpContext context = new AssimpContext())
                {
                    Scene mesh = context.ImportFile(tempFile);
                    context.ExportFile(mesh, currentMeshFile, "obj");
                }
                File.Delete(tempFile);

                Model model = new Model(currentMeshFile);

                glControl.GLrender.AddModel(model);
                glControl.GLrender.SelectedModelIndex = 0;
            }
            else
            {
                pbPreview.Width    = 0;
                pbPreview.Visible  = false;
                rtbPreview.Width   = 0;
                rtbPreview.Visible = false;
                pnlPreview.Visible = false;
            }
        }