4

I have an installer for VB6 application and I need to decompress the files individually with c#. All files end with an underscore, eg image.jp_. I saw with 7ZIP program that files are compressed with MSZIP compression mode, but I can not decompress.

EDIT

My solution

How to create a CAB (cabinet) file using C#

based on the use of WiX, I use as explained in the link the DLL:

Microsoft.Deployment.Compression.dll
Microsoft.Deployment.Compression.Cab.dll

and then instead of using the CAB file, I put my file image.jp_ and it worked perfectly. Thank you all for trash me the question, and Charly, I love to say thanks

CabInfo cab = new CabInfo(@"C:\test\image.jp_");
cab.Unpack(@"C:\test\");

thanks

andres descalzo
  • 14,451
  • 12
  • 60
  • 105
  • 1
    How do you have 7,000 reputation and not know what is and isn't allowed? – Cole Johnson Oct 14 '13 at 22:27
  • 1
    @ColeJohnson that's your reason to lower the score, you're quite wrong – andres descalzo Oct 14 '13 at 22:29
  • 1
    Perhaps Andres has experience in another area. He could be an expert Java programmer on Linux, for example. Be careful not to judge the querent. – neontapir Oct 14 '13 at 22:30
  • 1
    No. I'm downvoting because your question is asking for code. Which isn't allowed. In addition, they are _my_ votes. Meaning I can downvote how I please. – Cole Johnson Oct 14 '13 at 22:31
  • @neontapir I'm referring to the fact that this is off topic. If you have 7k reputation, you should know what is on topic or not. – Cole Johnson Oct 14 '13 at 22:31
  • 2
    I disagree, I don't think he's asking for a full-baked solution, but rather an approach. At least I can interpret his question either way. It doesn't appear trivial to me either. I'm not sure how you'd programmatically decompress a Microsoft Cabinet file using .NET, short of calling cabarc.exe manually. – neontapir Oct 14 '13 at 22:40
  • 1
    @neontapir Thanks for your answer, it was helpful to find my solution – andres descalzo Oct 15 '13 at 02:29
  • @andresdescalzo Please post your solution as an answer instead of editing your question. – user247702 Oct 15 '13 at 13:06
  • @Stijn Ok, now I upload my solution. thanks – andres descalzo Oct 15 '13 at 13:37

3 Answers3

12

There's lots of piquant history behind this question. A long, long time ago in a galaxy far away, Microsoft got caught with their hands in the cookie jar. Back when they were still a small company making a living out of selling DOS licenses. A company called Stac Electronics figured out a way to make DOS work better. Lots of opportunity, disk drives were still very slow and processors were getting faster.

Stac came up with a DOS utility that compressed files automatically, without DOS being aware that this happened. Compressing them before they got written to the disk and decompressing them when they got read. DOS only ever saw the uncompressed version of the file. Very popular at the time, it made disk access an easy x2 faster.

So Microsoft went "good idea! We can do that too". And made their own version of it called DoubleSpace and released it to the world in DOS version 6.0. Stac wasn't thrilled, instant death to their reason for being and sued Microsoft. And won. $120 million dollars. That hurt. A lot. It was the equivalent of adding a surcharge of $5.50 to every copy of DOS having been sold already and Microsoft back then was already really heavy into making sure every PC came with DOS preinstalled by making the price attractive.

Microsoft had a very hard time recovering from that, compression was a dirty word in the company for a very, very long time. Very visible in the .NET framework for example, support for .zip archives has always been missing until just recently.

Long story short, they came up with their own compression scheme, one that didn't violate anybody's patents. Not much left, it sucked heavily. Which is what you ran into, MSZIP is not the appropriate label for it. You'll have to run a program called expand.exe to decompress the file, available on every Windows version. Type "expand /?" for help. Ask more questions about it at superuser.com

Hans Passant
  • 873,011
  • 131
  • 1,552
  • 2,371
  • +1, but I'm pretty sure it happened in *this* galaxy. – dreamlax Oct 15 '13 at 00:58
  • 1
    **tl;dr:** You'll have to run a program called expand.exe to decompress the file, available on every Windows version. – Robert Harvey Oct 15 '13 at 02:14
  • 3
    Immediately preceding "made their own version of it called DoubleSpace," Microsoft was in discussion with Stac to license Stac's utility. During this discussion, Microsoft examined Stac's code. It's not surprising that Stac sued. – Brian Oct 15 '13 at 16:49
1

One possibility would be to import the cabinet.dll or SetupApi.DLL library and use extern calls to invoke methods on it. This article discusses the approach.

You'll need prototypes like these:

[DllImport("setupapi.dll")]
internal static extern IntPtr SetupDiGetClassDevsEx(IntPtr ClassGuid, 
[MarshalAs(UnmanagedType.LPStr)]String enumerator, 
IntPtr hwndParent, Int32 Flags, IntPtr DeviceInfoSet, 
[MarshalAs(UnmanagedType.LPStr)]String MachineName, IntPtr Reserved);

[DllImport("setupapi.dll")]
internal static extern Int32 SetupDiDestroyDeviceInfoList(IntPtr DeviceInfoSet);

The article doesn't talk about MSZIP deflation specifically, though.

Another possibility might be to use the 7Z SDK, as mentioned in this SO question.

Community
  • 1
  • 1
neontapir
  • 4,450
  • 3
  • 35
  • 51
0

(at the request of @Stijn)

My solution

How to create a CAB (cabinet) file using C#

based on the use of WiX, I use as explained in the link the DLL:

Microsoft.Deployment.Compression.dll Microsoft.Deployment.Compression.Cab.dll

and then instead of using the CAB file, I put my file image.jp_ and it worked perfectly. Thank you all for trash me the question.

CabInfo cab = new CabInfo(@"C:\test\image.jp_");
cab.Unpack(@"C:\test\");

in my case I find very simple to do, I already had installed the WiX for another project but you can download and install very simply.

Then you just have to go to the installation folder or find these DLL and copy for use in our application.

all other solutions "ZIP" or "GZip" or libraries based on this, does not work. if anyone has another solution for. NET 4.0 will be very welcome

thanks

andres descalzo
  • 14,451
  • 12
  • 60
  • 105