private string openZipEntry( string fileName, ZipLib.Zip.ZipFile zip, ZipLib.Zip.ZipEntry entry, string source) { using (Stream s = zip.GetInputStream(entry)) { byte[] data = new byte[entry.Size]; s.Read(data, 0, data.Length); using (MemoryStream ms = new MemoryStream(data)) { if (intCheckCanOpenFileName(entry.Name)) { openStream(ms, Path.GetExtension(entry.Name).ToUpper(), source, true); } else { Locator.Resolve <IUserMessage>().Error( "Can't open {0}\\{1}!\n\nFile not supported!", fileName, entry.Name); return(string.Empty); } return(string.Format("{0}/{1}", Path.GetFileName(fileName), entry.Name)); } } }
private static Stream GetImageStream(string fileName) { var folderName = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); // override var romsFolderName = Path.Combine(folderName, "roms"); if (Directory.Exists(romsFolderName)) { var romsFileName = Path.Combine(romsFolderName, fileName); if (File.Exists(romsFileName)) { using (var fs = new FileStream(romsFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { return(CreateStream(fs, fs.Length)); } } } var pakFileName = Path.Combine(folderName, "ROMS.PAK"); using (ZipLib.Zip.ZipFile zip = new ZipLib.Zip.ZipFile(pakFileName)) { foreach (ZipLib.Zip.ZipEntry entry in zip) { if (entry.IsFile && entry.CanDecompress && string.Compare(entry.Name, fileName, true) == 0) { using (var s = zip.GetInputStream(entry)) { return(CreateStream(s, entry.Size)); } } } } throw new FileNotFoundException( string.Format( "ROM file not found: {0}", fileName)); }
private void loadMachines() { string folderName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string fileName = Path.Combine(folderName, csMachinesPakFileName); try { if (!File.Exists(fileName)) return; using (ZipLib.Zip.ZipFile zip = new ZipLib.Zip.ZipFile(fileName)) foreach (ZipLib.Zip.ZipEntry entry in zip) if (entry.IsFile && entry.CanDecompress && Path.GetExtension(entry.Name).ToUpper() == ".VMZ") { try { var xml = new XmlDocument(); using (Stream s = zip.GetInputStream(entry)) { xml.Load(s); } var vmNode = xml.SelectSingleNode("/VirtualMachine"); if (vmNode == null) { LogAgent.Warn( "Invalid machine configuration file: {0}\\{1}", csMachinesPakFileName, entry.Name); continue; } string name = Path.GetFileNameWithoutExtension(entry.Name); if (vmNode.Attributes["name"] != null) name = vmNode.Attributes["name"].InnerText; var item = ctxMenuWizard.Items.Add(name); item.Tag = xml; item.Click += new EventHandler(ctxMenuWizardItem_Click); } catch (Exception ex) { LogAgent.Error(ex); } } } catch (Exception ex) { LogAgent.Error(ex); } }
public static Stream GetRomFileStream(string fileName) { string folderName = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); // override string romsFolderName = Path.Combine(folderName, "roms"); if (Directory.Exists(romsFolderName)) { string romsFileName = Path.Combine(romsFolderName, fileName); if (File.Exists(romsFileName)) using (FileStream fs = new FileStream(romsFileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { byte[] fileData = new byte[fs.Length]; fs.Read(fileData, 0, fileData.Length); return new MemoryStream(fileData); } } string pakFileName = Path.Combine(folderName, "Roms.PAK"); using (ZipLib.Zip.ZipFile zip = new ZipLib.Zip.ZipFile(pakFileName)) foreach (ZipLib.Zip.ZipEntry entry in zip) if (entry.IsFile && entry.CanDecompress && string.Compare(entry.Name, fileName, true) == 0) { byte[] fileData = new byte[entry.Size]; using (Stream s = zip.GetInputStream(entry)) s.Read(fileData, 0, fileData.Length); return new MemoryStream(fileData); } throw new FileNotFoundException(string.Format("ROM file not found: {0}", fileName)); }