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_NO_STATUS
31 static int myprintf(const char* format
, ...)
39 len
= vsnprintf(tmp
, sizeof(tmp
), format
, va
);
41 WriteFile(GetStdHandle(STD_ERROR_HANDLE
), tmp
, len
, &w
, NULL
);
46 static UINT CALLBACK
set_outfile( PVOID context
, UINT notification
, UINT_PTR param1
, UINT_PTR param2
)
48 FILE_IN_CABINET_INFO_A
*info
= (FILE_IN_CABINET_INFO_A
*)param1
;
49 char buffer
[MAX_PATH
];
54 case SPFILENOTIFY_FILEINCABINET
:
56 LPSTR outfile
= context
;
59 SetLastError( ERROR_NOT_SUPPORTED
);
62 GetFullPathNameA( info
->NameInCabinet
, sizeof(buffer
), buffer
, &basename
);
63 strcpy( outfile
, basename
);
66 default: return NO_ERROR
;
70 static UINT CALLBACK
extract_callback( PVOID context
, UINT notification
, UINT_PTR param1
, UINT_PTR param2
)
72 FILE_IN_CABINET_INFO_A
*info
= (FILE_IN_CABINET_INFO_A
*)param1
;
76 case SPFILENOTIFY_FILEINCABINET
:
78 LPCSTR targetname
= context
;
80 strcpy( info
->FullTargetName
, targetname
);
83 default: return NO_ERROR
;
87 static BOOL
option_equal(LPCSTR str1
, LPCSTR str2
)
89 if (str1
[0] != '/' && str1
[0] != '-')
91 return !lstrcmpA( str1
+ 1, str2
);
94 int main(int argc
, char *argv
[])
97 char infile
[MAX_PATH
], outfile
[MAX_PATH
], actual_name
[MAX_PATH
];
98 char outfile_basename
[MAX_PATH
], *basename_index
;
103 myprintf( "Usage:\n" );
104 myprintf( "\t%s infile outfile\n", argv
[0] );
105 myprintf( "\t%s /r infile\n", argv
[0] );
109 if (argc
== 3 && (option_equal(argv
[1], "R") || option_equal(argv
[1], "r")))
110 GetFullPathNameA( argv
[2], sizeof(infile
), infile
, NULL
);
112 GetFullPathNameA( argv
[1], sizeof(infile
), infile
, NULL
);
114 if (!SetupGetFileCompressionInfoExA( infile
, actual_name
, sizeof(actual_name
), NULL
, NULL
, NULL
, &comp
))
116 myprintf( "%s: can't open input file %s\n", argv
[0], infile
);
120 if (argc
== 3 && (option_equal(argv
[1], "R") || option_equal(argv
[1], "r")))
124 case FILE_COMPRESSION_MSZIP
:
125 outfile_basename
[0] = 0;
126 if (!SetupIterateCabinetA( infile
, 0, set_outfile
, outfile_basename
))
128 myprintf( "%s: can't determine original name\n", argv
[0] );
131 GetFullPathNameA( infile
, sizeof(outfile
), outfile
, &basename_index
);
133 strcat( outfile
, outfile_basename
);
135 case FILE_COMPRESSION_WINLZA
:
136 GetExpandedNameA( infile
, outfile_basename
);
139 myprintf( "%s: can't determine original\n", argv
[0] );
144 GetFullPathNameA( argv
[2], sizeof(outfile
), outfile
, NULL
);
146 if (!lstrcmpiA( infile
, outfile
))
148 myprintf( "%s: can't expand file to itself\n", argv
[0] );
154 case FILE_COMPRESSION_MSZIP
:
155 if (!SetupIterateCabinetA( infile
, 0, extract_callback
, outfile
))
157 myprintf( "%s: cabinet extraction failed\n", argv
[0] );
161 case FILE_COMPRESSION_WINLZA
:
164 OFSTRUCT ofin
, ofout
;
167 if ((hin
= LZOpenFileA( infile
, &ofin
, OF_READ
)) < 0)
169 myprintf( "%s: can't open input file %s\n", argv
[0], infile
);
172 if ((hout
= LZOpenFileA( outfile
, &ofout
, OF_CREATE
| OF_WRITE
)) < 0)
175 myprintf( "%s: can't open output file %s\n", argv
[0], outfile
);
178 error
= LZCopy( hin
, hout
);
185 myprintf( "%s: LZCopy failed, error is %d\n", argv
[0], error
);
191 if (!CopyFileA( infile
, outfile
, FALSE
))
193 myprintf( "%s: CopyFileA failed\n", argv
[0] );