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; }
void mnuFile_Extract_Clicked(object o, EventArgs args) { TreePath[] paths; TreeModel model; paths = mainListBox.Selection.GetSelectedRows(out model); foreach (TreePath path in paths) { TreeIter itr; if (model.GetIter(out itr, path) == true) { uint index = (uint)model.GetValue(itr, 0); Console.Write("Extracting... "); BarnManager.Extract(index); Console.WriteLine("Done!"); } } }
void mnuFile_Open_Clicked(object o, EventArgs args) { FileChooserDialog chooser = new FileChooserDialog("Open", this, FileChooserAction.Open); chooser.LocalOnly = true; chooser.AddButton(Stock.Cancel, ResponseType.Cancel); chooser.AddButton(Stock.Open, ResponseType.Ok); FileFilter brnfilter = new FileFilter(); FileFilter allfilter = new FileFilter(); brnfilter.Name = "Barn files"; brnfilter.AddPattern("*.brn"); allfilter.Name = "All files"; allfilter.AddPattern("*.*"); chooser.AddFilter(brnfilter); chooser.AddFilter(allfilter); int response = chooser.Run(); if ((ResponseType)response == ResponseType.Ok) { try { BarnManager.OpenBarn(chooser.Uri.Replace("file://", "")); List <BarnFile> files = BarnManager.GetFiles(); Console.WriteLine("Starting..."); mainListStore.Clear(); foreach (BarnFile file in files) { mainListStore.AppendValues(file.Index, file.Name, file.InternalSize, BarnManager.MapExtensionToType(file.Extension), file.Barn, file.Compression.ToString()); } Console.WriteLine("There are " + files.Count + " files!"); } catch (System.IO.FileNotFoundException) { displayOkErrorMessageBox("Unable to open " + chooser.Uri + " because it could not be found."); } catch (System.IO.DirectoryNotFoundException) { displayOkErrorMessageBox("Unable to open " + chooser.Uri + " because part of the path could not be found."); } catch (BarnLib.BarnException) { displayOkErrorMessageBox("Unable to open " + chooser.Uri + " because it is not a valid Barn file."); } } chooser.Destroy(); }
private void openFile(string filename) { _currentBarnName = filename; BarnManager.OpenBarn(filename); List <BarnFile> files = BarnManager.GetFiles(); mainListView.SuspendLayout(); foreach (BarnFile file in files) { string iconKey = ""; if (file.Extension == "WAV") { iconKey = "audio"; } else if (file.Extension == "EXE") { iconKey = "executable"; } else if (file.Extension == "BMP") { iconKey = "image"; } else if (file.Extension == "TXT") { iconKey = "text"; } else if (file.Extension == "HTML" || file.Extension == "HTM") { iconKey = "html"; } else if (file.Extension == "MUL" || file.Extension == "MOD" || file.Extension == "BSP" || file.Extension == "ACT") { iconKey = "binary"; } else if (file.Extension == "YAK" || file.Extension == "ANM" || file.Extension == "NVC" || file.Extension == "SIF" || file.Extension == "STK" || file.Extension == "GAS" || file.Extension == "SCN") { iconKey = "script"; } else if (file.Extension == "FON") { iconKey = "font"; } else if (file.Extension == "CUR") { iconKey = "cursor"; } string compression; if (file.Compression == BarnLib.Compression.None) { compression = Strings.CompressionNone; } else { compression = file.Compression.ToString(); } ListViewItem item = new ListViewItem(new string[] { file.Name, file.InternalSize.ToString(), BarnManager.MapExtensionToType(file.Extension), file.Barn, compression }, iconKey); item.Tag = file; mainListView.Items.Add(item); } mainListView.ResumeLayout(); // enable the menu items extractSelectedFilesToolStripMenuItem.Enabled = true; // TODO: uncomment the following lines once previewing and stuff is implemented previewFileToolStripMenuItem.Enabled = true; //extractAllBitmapsToolStripMenuItem.Enabled = true; //extractAllDocsToolStripMenuItem.Enabled = true; //extractAllHtmlFilesToolStripMenuItem.Enabled = true; //extractAllWavsToolStripMenuItem.Enabled = true; }
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) { } } }