push 0f15bbd80d260bbd8adf052e820484a405c49375
[wine/hacks.git] / programs / expand / expand.c
blob6022fe2de98118e337cb2a1e99e87b26cd8309e4
1 /*
2 * Copyright 1997 Victor Schneider
3 * Copyright 2002 Alexandre Julliard
4 * Copyright 2007 Hans Leidekker
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define WIN32_LEAN_AND_MEAN
23 #include <stdio.h>
24 #include <string.h>
25 #include <windows.h>
26 #include <lzexpand.h>
27 #include <setupapi.h>
29 static UINT CALLBACK extract_callback( PVOID context, UINT notification, UINT_PTR param1, UINT_PTR param2 )
31 FILE_IN_CABINET_INFO_A *info = (FILE_IN_CABINET_INFO_A *)param1;
33 switch (notification)
35 case SPFILENOTIFY_FILEINCABINET:
37 LPCSTR targetname = context;
39 strcpy( info->FullTargetName, targetname );
40 return FILEOP_DOIT;
42 default: return NO_ERROR;
46 int main(int argc, char *argv[])
48 int ret = 0;
49 char infile[MAX_PATH], outfile[MAX_PATH], actual_name[MAX_PATH];
50 UINT comp;
52 if (argc < 3)
54 fprintf( stderr, "Usage: %s infile outfile\n", argv[0] );
55 return 1;
58 GetFullPathNameA( argv[1], sizeof(infile), infile, NULL );
59 GetFullPathNameA( argv[2], sizeof(outfile), outfile, NULL );
61 if (!lstrcmpiA( infile, outfile ))
63 fprintf( stderr, "%s: can't expand file to itself\n", argv[0] );
64 return 1;
66 if (!SetupGetFileCompressionInfoExA( infile, actual_name, sizeof(actual_name), NULL, NULL, NULL, &comp ))
68 fprintf( stderr, "%s: can't open input file %s\n", argv[0], infile );
69 return 1;
72 switch (comp)
74 case FILE_COMPRESSION_MSZIP:
76 if (!SetupIterateCabinetA( infile, 0, extract_callback, (PVOID)outfile ))
78 fprintf( stderr, "%s: cabinet extraction failed\n", argv[0] );
79 return 1;
81 break;
83 case FILE_COMPRESSION_WINLZA:
85 INT hin, hout;
86 OFSTRUCT ofin, ofout;
87 LONG error;
89 if ((hin = LZOpenFile( infile, &ofin, OF_READ )) < 0)
91 fprintf( stderr, "%s: can't open input file %s\n", argv[0], infile );
92 return 1;
94 if ((hout = LZOpenFile( outfile, &ofout, OF_CREATE | OF_WRITE )) < 0)
96 LZClose( hin );
97 fprintf( stderr, "%s: can't open output file %s\n", argv[0], outfile );
98 return 1;
100 error = LZCopy( hin, hout );
102 LZClose( hin );
103 LZClose( hout );
105 if (error < 0)
107 fprintf( stderr, "%s: LZCopy failed, error is %d\n", argv[0], error );
108 return 1;
110 break;
112 default:
114 if (!CopyFileA( infile, outfile, FALSE ))
116 fprintf( stderr, "%s: CopyFileA failed\n", argv[0] );
117 return 1;
119 break;
122 return ret;