Ejemplo n.º 1
0
        private void extractSelectedFilesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            foreach (ListViewItem item in mainListView.SelectedItems)
            {
                try
                {
                    BarnFile bf = item.Tag as BarnFile;

                    int index = bf.Index;

                    if (bf.Extension == "BMP" && convertBitmapsToolStripMenuItem.Checked)
                    {
                        byte[]    data = BarnManager.ExtractData(bf.Index);
                        GK3Bitmap bmp  = new GK3Bitmap(data);

                        bmp.Save(BarnManager.ExtractPath + bf.Name);
                        bmp.Dispose();
                    }
                    else
                    {
                        BarnManager.Extract(index);
                    }
                }
                catch (System.IO.FileNotFoundException)
                {
                    // FileNotFoundException most likely means the barn the file
                    // is in could not be found.

                    string filename = BarnManager.GetFileName((int)item.Tag);

                    DialogResult result = MessageBox.Show("Unable to extract " + filename + Environment.NewLine
                                                          + "Continue extracting the rest of the files?", "Error extracting file",
                                                          MessageBoxButtons.YesNo, MessageBoxIcon.Error);

                    if (result == DialogResult.No)
                    {
                        break;
                    }
                }
            }

            Cursor.Current = Cursors.Default;
        }
Ejemplo n.º 2
0
        private void previewFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in mainListView.SelectedItems)
            {
                try
                {
                    BarnFile bf = item.Tag as BarnFile;

                    if (isPreviewSupported(bf.Extension))
                    {
                        // get the name of a temporary file we can use
                        string filename = System.IO.Path.GetTempPath() +
                                          System.IO.Path.DirectorySeparatorChar +
                                          bf.Name + "." + getPreviewExtension(bf.Extension);

                        byte[] data    = BarnManager.ExtractData(bf.Index);
                        bool   success = true;

                        // if it's a bitmap then convert it
                        if (bf.Extension == "BMP")
                        {
                            GK3Bitmap bmp = new GK3Bitmap(data);
                            bmp.Save(filename);
                        }
                        else if (bf.Extension == "SHP")
                        {
                            success = writeSheepPreview(filename, data);
                        }
                        else if (bf.Extension == "MOD" ||
                                 bf.Extension == "BSP")
                        {
                            // we're using the viewer, which can look directly inside
                            // this barn, so no need to extract anything
                        }
                        else
                        {
                            System.IO.FileStream fs = new System.IO.FileStream(filename, System.IO.FileMode.Create);
                            fs.Write(data, 0, data.Length);
                            fs.Close();
                        }

                        if (success)
                        {
                            if (bf.Extension == "MOD" ||
                                bf.Extension == "BSP")
                            {
                                // BSP and MOD are special cases. Windows most likely won't have
                                // a file type association with the viewer, so we
                                // have to crank it up manually
                                string viewerPath;
                                if (string.IsNullOrEmpty(Settings.Default.PathToViewer))
                                {
                                    viewerPath = "GK3Viewer.exe";
                                }
                                else if (Settings.Default.PathToViewer.EndsWith(".EXE", StringComparison.OrdinalIgnoreCase))
                                {
                                    viewerPath = Settings.Default.PathToViewer;
                                }
                                else
                                {
                                    viewerPath = Settings.Default.PathToViewer + System.IO.Path.DirectorySeparatorChar + "GK3Viewer.exe";
                                }

                                string args = string.Empty;
                                if (bf.Extension == "MOD")
                                {
                                    args = "-b " + _currentBarnName + " -mod " + bf.Name;
                                }
                                else if (bf.Extension == "BSP")
                                {
                                    args = "-b " + _currentBarnName + " -bsp " + bf.Name;
                                }

                                try
                                {
                                    System.Diagnostics.Process.Start(viewerPath, args);
                                }
                                catch
                                {
                                    MessageBox.Show("Unable to start the Viewer.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                            else
                            {
                                System.Diagnostics.Process.Start(filename);

                                // add the file to the list of files to delete when the browser closes
                                _temporaryFiles.Add(filename);
                            }
                        }
                    }
                }
                catch (System.IO.FileNotFoundException)
                {
                }
            }
        }