/// <summary> /// Expand all files contained in the specified CAB archive. /// </summary> /// <param name="destinationFolder">Where the extracted files will go. /// Folder heirarchy in the CAB will be created relative to this location. /// If null, current working directory is used.</param> /// <param name="fullPathToCabinet">Full path to the archive you want to decompress.</param> public void Expand(string destinationFolder, string fullPathToCabinet) { #if NETFX_CORE //Debug.Assert(!String.IsNullOrEmpty(destinationFolder)); //Debug.Assert(destinationFolder.Contains(":"), "destinationFolder needs to be full path."); //Debug.Assert(fullPathToCabinet.Contains(":"), "fullPathToCabinet needs to be full path."); #else // if destination folder is null, use current working folder if (destinationFolder == null) { destinationFolder = Assembly.GetExecutingAssembly().Location; } destinationFolder = Path.GetFullPath(destinationFolder); #endif // Ensure the path ends with a backslash. if (!destinationFolder.EndsWith("" + Cabinet.DirectorySeparatorChar)) { destinationFolder = destinationFolder + Cabinet.DirectorySeparatorChar; } #if !NETFX_CORE // Create the folder if necessary if (!Directory.Exists(destinationFolder)) { Directory.CreateDirectory(destinationFolder); } fullPathToCabinet = Path.GetFullPath(fullPathToCabinet); #endif // Separate path and filename information, since this is // how cabinet.dll wants it. string filename = Path.GetFileName(fullPathToCabinet); string folder = Path.GetDirectoryName(fullPathToCabinet); // Ensure folder ends with a backslash if (!folder.EndsWith("" + Cabinet.DirectorySeparatorChar)) { folder = folder + Cabinet.DirectorySeparatorChar; } // Store this for use later. this.destinationFolder = destinationFolder; // cabinet.dll, I call upon your power... Extract these files! bool success = Cabinet.FDICopy( hfdi, filename, folder, 0, FdiNotifyDelegate, IntPtr.Zero, IntPtr.Zero); if (!success) { throw new Exception("Failed to expand cabinet: " + fullPathToCabinet + " with error : " + erf.erfOper.ToString()); } }