public static string[] GetFiles(CabinetOpenCabHandler openCabHandler, CabinetCloseCabHandler closeCabHandler, object openCabContext, bool autoChain) { using (CabExtractor cabInstance = new CabExtractor()) { cabInstance.openCabHandler = openCabHandler; cabInstance.closeCabHandler = closeCabHandler; cabInstance.openCabContext = openCabContext; cabInstance.nextCabinetName = ""; cabInstance.listFiles = new ArrayList(); for (short iCab = 0; (autoChain || iCab == 0) && cabInstance.nextCabinetName != null; iCab++) { cabInstance.cabNumbers[""] = iCab; cabInstance.Process(); } #if !CABMINIMAL string[] fileNames = new string[cabInstance.listFiles.Count]; for (int i = 0; i < cabInstance.listFiles.Count; i++) { fileNames[i] = ((CabinetFileInfo)cabInstance.listFiles[i]).Name; } return(fileNames); #else return((string[])cabInstance.listFiles.ToArray(typeof(string))); #endif } }
public static void Extract(CabinetOpenCabHandler openCabHandler, CabinetCloseCabHandler closeCabHandler, object openCabContext, bool autoChain, CabinetExtractOpenFileHandler openFileHandler, CabinetExtractCloseFileHandler closeFileHandler, object openFileContext, CabinetFilterFileHandler filterFileHandler, object filterContext, CabinetStatusCallback statusCallback, object statusContext) #endif // !CABMINIMAL { using (CabExtractor cabInstance = new CabExtractor()) { cabInstance.openCabHandler = openCabHandler; cabInstance.closeCabHandler = closeCabHandler; cabInstance.openCabContext = openCabContext; cabInstance.openFileHandler = openFileHandler; cabInstance.closeFileHandler = closeFileHandler; cabInstance.openFileContext = openFileContext; cabInstance.filterFileHandler = filterFileHandler; cabInstance.filterFileContext = filterContext; cabInstance.fdiNotifyHandler = new FDI.PFNNOTIFY(cabInstance.CabExtractNotify); cabInstance.nextCabinetName = ""; #if !CABMINIMAL cabInstance.statusCallback = statusCallback; cabInstance.statusContext = statusContext; if (statusCallback != null) { CabinetFileInfo[] files = Cabinet.GetFiles(openCabHandler, closeCabHandler, openCabContext, autoChain, filterFileHandler, filterContext); cabInstance.status.totalFiles = files.Length; cabInstance.status.totalFileBytes = 0; int prevFolder = -1, prevCabinet = -1; for (int i = 0; i < files.Length; i++) { cabInstance.status.totalFileBytes += files[i].Length; if (files[i].CabinetFolderNumber != prevFolder) // Assumes the results of GetFiles are grouped by folders { prevFolder = files[i].CabinetFolderNumber; cabInstance.status.totalFolders++; } if (files[i].CabinetNumber != prevCabinet) { prevCabinet = files[i].CabinetNumber; cabInstance.status.totalCabinets++; } } } #endif // !CABMINIMAL for (short iCab = 0; (autoChain || iCab == 0) && cabInstance.nextCabinetName != null; iCab++) { cabInstance.cabNumbers[""] = iCab; cabInstance.Process(); } } }
/// <summary> /// Reads a single file from a cabinet or cabinet chain. /// </summary> /// <param name="openCabHandler">Callback for opening cabinet streams.</param> /// <param name="closeCabHandler">Callback for closing cabinet streams. This may be null, in which /// case the stream's <see cref="Stream.Close"/> method will be called.</param> /// <param name="openCabContext">User context object that will be passed to the /// <paramref name="openCabHandler"/> and <paramref name="closeCabHandler"/>.</param> /// <param name="autoChain">True to automatically process multiple cabinets in a chain. If false, the /// aggregate list of files may still be obtained by getting the file list from each cab individually.</param> /// <param name="name">Name of the file within the cabinet (not the external file path).</param> /// <returns>A stream for reading the extracted file, or null if the file does not exist in the cabinet.</returns> /// <exception cref="CabinetExtractException">The stream is not a cabinet file or the cabinet file is corrupt.</exception> /// <remarks>This method may fail if the file size is greater than available memory.</remarks> public static Stream Extract(CabinetOpenCabHandler openCabHandler, CabinetCloseCabHandler closeCabHandler, object openCabContext, bool autoChain, string name) { object[] openFileContext = new object[1]; Cabinet.Extract(openCabHandler, closeCabHandler, openCabContext, autoChain, new CabinetExtractOpenFileHandler(Cabinet.ExtractBytesOpenFileHandler), null, openFileContext, new CabinetFilterFileHandler(Cabinet.ExtractBytesFilterFileHandler), name #if !CABMINIMAL , null, null #endif // !CABMINIMAL ); MemoryStream extractStream = (MemoryStream)openFileContext[0]; if (extractStream != null) { extractStream.Position = 0; } return(extractStream); }
internal static CabinetFileInfo[] GetFiles(CabinetOpenCabHandler openCabHandler, CabinetCloseCabHandler closeCabHandler, object openCabContext, bool autoChain, CabinetFilterFileHandler filterFileHandler, object filterContext) { using (CabExtractor cabInstance = new CabExtractor()) { cabInstance.filterFileHandler = filterFileHandler; cabInstance.filterFileContext = filterContext; cabInstance.openCabHandler = openCabHandler; cabInstance.closeCabHandler = closeCabHandler; cabInstance.openCabContext = openCabContext; cabInstance.nextCabinetName = ""; cabInstance.listFiles = new ArrayList(); for (short iCab = 0; (autoChain || iCab == 0) && cabInstance.nextCabinetName != null; iCab++) { cabInstance.cabNumbers[""] = iCab; cabInstance.Process(); } return((CabinetFileInfo[])cabInstance.listFiles.ToArray(typeof(CabinetFileInfo))); } }
public static void Create(CabinetNameHandler nameHandler, object nameContext, long maxCabSize, long maxFolderSize, CabinetOpenCabHandler openCabHandler, CabinetCloseCabHandler closeCabHandler, object openCabContext, string[][] foldersAndFiles, CabinetCompressionLevel compLevel, CabinetCreateOpenFileHandler openFileHandler, CabinetCreateCloseFileHandler closeFileHandler, object openFileContext, CabinetStatusCallback statusCallback, object statusContext) #endif // !CABMINIMAL { using (CabCreator cabInstance = new CabCreator(maxCabSize, maxFolderSize)) { cabInstance.nameHandler = nameHandler; cabInstance.nameContext = nameContext; cabInstance.openCabHandler = openCabHandler; cabInstance.closeCabHandler = closeCabHandler; cabInstance.openCabContext = openCabContext; cabInstance.openFileHandler = openFileHandler; cabInstance.closeFileHandler = closeFileHandler; cabInstance.openFileContext = openFileContext; #if !CABMINIMAL cabInstance.statusCallback = statusCallback; cabInstance.statusContext = statusContext; if (cabInstance.statusCallback != null) { cabInstance.status.totalFolders = (short)foldersAndFiles.Length; for (int iFolder = 0; iFolder < foldersAndFiles.Length; iFolder++) { string[] files = foldersAndFiles[iFolder]; for (int iFile = 0; iFile < files.Length; iFile++) { FileAttributes attributes; DateTime lastWriteTime; Stream fileStream = openFileHandler(files[iFile], out attributes, out lastWriteTime, openFileContext); if (fileStream != null) { cabInstance.status.totalFileBytes += fileStream.Length; cabInstance.status.totalFiles++; } closeFileHandler(files[iFile], fileStream, openFileContext); } } } #endif // !CABMINIMAL for (int iFolder = 0; iFolder < foldersAndFiles.Length; iFolder++) { string[] files = foldersAndFiles[iFolder]; for (int iFile = 0; iFile < files.Length; iFile++) { FileAttributes attributes; DateTime lastWriteTime; Stream fileStream = openFileHandler(files[iFile], out attributes, out lastWriteTime, openFileContext); if (fileStream != null) { #if !CABMINIMAL if (cabInstance.statusCallback != null) { if (cabInstance.status.currentFolderTotalBytes > 0) { cabInstance.status.currentFolderBytesProcessed = cabInstance.status.currentFolderTotalBytes; cabInstance.status.statusType = CabinetStatusType.FinishFolder; cabInstance.statusCallback(cabInstance.status, cabInstance.statusContext); cabInstance.status.currentFolderBytesProcessed = cabInstance.status.currentFolderTotalBytes = 0; if (!(iFolder == 0 && iFile == 0)) { cabInstance.status.currentFolderNumber++; if (cabInstance.status.totalFolders <= cabInstance.status.currentFolderNumber) { cabInstance.status.totalFolders = (short)(cabInstance.status.currentFolderNumber + 1); } } } } #endif // !CABMINIMAL cabInstance.status.currentFileName = files[iFile]; if (!(iFolder == 0 && iFile == 0)) { cabInstance.status.currentFileNumber++; } #if !CABMINIMAL if (cabInstance.statusCallback != null) { cabInstance.status.currentFileTotalBytes = fileStream.Length; cabInstance.status.currentFileBytesProcessed = 0; cabInstance.status.statusType = CabinetStatusType.StartFile; cabInstance.statusCallback(cabInstance.status, cabInstance.statusContext); } #endif // !CABMINIMAL cabInstance.AddFile(files[iFile], fileStream, attributes, lastWriteTime, false, compLevel); } } cabInstance.FlushFolder(); } cabInstance.FlushCabinet(); } }
public static void Create(CabinetNameHandler nameHandler, object nameContext, long maxCabSize, long maxFolderSize, CabinetOpenCabHandler openCabHandler, CabinetCloseCabHandler closeCabHandler, object openCabContext, string[][] foldersAndFiles, CabinetCompressionLevel compLevel, CabinetCreateOpenFileHandler openFileHandler, CabinetCreateCloseFileHandler closeFileHandler, object openFileContext)
public static void Extract(CabinetOpenCabHandler openCabHandler, CabinetCloseCabHandler closeCabHandler, object openCabContext, bool autoChain, CabinetExtractOpenFileHandler openFileHandler, CabinetExtractCloseFileHandler closeFileHandler, object openFileContext, CabinetFilterFileHandler filterFileHandler, object filterContext)