static void ExtraxctFile(string imagePathFilename, int dirIndex, string asciiCbmFilename, string outPathFilename) { byte[] bamBlock; byte[] dirEntry = null; ArrayList dirEntryList = new ArrayList(); byte[] imageData = DiskImageFile.ReadFile(imagePathFilename); int imageDataType = DiskImageFile.GetImageDataType(imagePathFilename); bamBlock = DOSDisk.ReadBAMBlock(imageData, imageDataType); dirEntryList = DOSDisk.GetDirEntryList(bamBlock, imageData, imageDataType); // by DirIndex if (dirIndex > 0) { dirEntry = (byte[])dirEntryList[dirIndex - 1]; } else { if (asciiCbmFilename.Length > 0) { bool found = false; foreach (byte[] de in dirEntryList) { if (Core.ConvertPETSCII2ASCII(DOSDisk.GetFilename(de)) == asciiCbmFilename) { if (!found) { dirEntry = de; found = true; } else { throw new Exception("Filename is not unique!"); } } } if (!found) { throw new Exception(String.Format("Filename {0} not found!", asciiCbmFilename)); } } else { throw new Exception("No file specified"); } } string filename = (Core.ConvertPETSCII2ASCII(DOSDisk.GetFilename(dirEntry))); if (DOSDisk.GetFileType(dirEntry) == 0) { throw new Exception(String.Format("File {0} is deleted!", filename)); } byte[] fileData = DOSDisk.getFileData(dirEntry, imageData, imageDataType); if (outPathFilename != "") { DiskImageFile.WriteFile(fileData, outPathFilename); } else { DiskImageFile.WriteFile(fileData, filename); } }