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; }