2002-03-10 00:29:33 +01:00
|
|
|
/*
|
|
|
|
* Copyright 1997 Victor Schneider
|
2002-05-20 21:18:16 +02:00
|
|
|
* Copyright 2002 Alexandre Julliard
|
2007-04-25 20:50:13 +02:00
|
|
|
* Copyright 2007 Hans Leidekker
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*/
|
|
|
|
|
2006-01-16 20:41:34 +01:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
|
1997-08-04 18:34:36 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <lzexpand.h>
|
2007-04-25 20:50:13 +02:00
|
|
|
#include <setupapi.h>
|
|
|
|
|
2008-08-21 10:18:00 +02:00
|
|
|
static UINT CALLBACK set_outfile( PVOID context, UINT notification, UINT_PTR param1, UINT_PTR param2 )
|
|
|
|
{
|
|
|
|
FILE_IN_CABINET_INFO_A *info = (FILE_IN_CABINET_INFO_A *)param1;
|
|
|
|
char buffer[MAX_PATH];
|
|
|
|
char* basename;
|
|
|
|
|
|
|
|
switch (notification)
|
|
|
|
{
|
|
|
|
case SPFILENOTIFY_FILEINCABINET:
|
|
|
|
{
|
|
|
|
LPSTR outfile = context;
|
|
|
|
if (outfile[0] != 0)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_SUPPORTED );
|
|
|
|
return FILEOP_ABORT;
|
|
|
|
}
|
|
|
|
GetFullPathNameA( info->NameInCabinet, sizeof(buffer), buffer, &basename );
|
|
|
|
strcpy( outfile, basename );
|
|
|
|
return FILEOP_SKIP;
|
|
|
|
}
|
|
|
|
default: return NO_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-25 20:50:13 +02:00
|
|
|
static UINT CALLBACK extract_callback( PVOID context, UINT notification, UINT_PTR param1, UINT_PTR param2 )
|
|
|
|
{
|
|
|
|
FILE_IN_CABINET_INFO_A *info = (FILE_IN_CABINET_INFO_A *)param1;
|
|
|
|
|
|
|
|
switch (notification)
|
|
|
|
{
|
|
|
|
case SPFILENOTIFY_FILEINCABINET:
|
|
|
|
{
|
|
|
|
LPCSTR targetname = context;
|
|
|
|
|
|
|
|
strcpy( info->FullTargetName, targetname );
|
|
|
|
return FILEOP_DOIT;
|
|
|
|
}
|
|
|
|
default: return NO_ERROR;
|
|
|
|
}
|
|
|
|
}
|
1997-08-04 18:34:36 +02:00
|
|
|
|
2008-08-21 10:18:00 +02:00
|
|
|
static BOOL option_equal(LPCSTR str1, LPCSTR str2)
|
|
|
|
{
|
|
|
|
if (str1[0] != '/' && str1[0] != '-')
|
|
|
|
return FALSE;
|
|
|
|
return !lstrcmpA( str1 + 1, str2 );
|
|
|
|
}
|
|
|
|
|
2002-05-20 21:18:16 +02:00
|
|
|
int main(int argc, char *argv[])
|
1997-08-04 18:34:36 +02:00
|
|
|
{
|
2007-04-25 20:50:13 +02:00
|
|
|
int ret = 0;
|
|
|
|
char infile[MAX_PATH], outfile[MAX_PATH], actual_name[MAX_PATH];
|
2008-08-21 10:18:00 +02:00
|
|
|
char outfile_basename[MAX_PATH], *basename_index;
|
2007-04-25 20:50:13 +02:00
|
|
|
UINT comp;
|
|
|
|
|
|
|
|
if (argc < 3)
|
|
|
|
{
|
2008-08-21 10:18:00 +02:00
|
|
|
fprintf( stderr, "Usage:\n" );
|
|
|
|
fprintf( stderr, "\t%s infile outfile\n", argv[0] );
|
2009-03-08 23:48:03 +01:00
|
|
|
fprintf( stderr, "\t%s /r infile\n", argv[0] );
|
2007-04-25 20:50:13 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-08-21 10:18:00 +02:00
|
|
|
if (argc == 3 && (option_equal(argv[1], "R") || option_equal(argv[1], "r")))
|
|
|
|
GetFullPathNameA( argv[2], sizeof(infile), infile, NULL );
|
|
|
|
else
|
|
|
|
GetFullPathNameA( argv[1], sizeof(infile), infile, NULL );
|
2007-04-25 20:50:13 +02:00
|
|
|
|
2008-08-21 10:18:00 +02:00
|
|
|
if (!SetupGetFileCompressionInfoExA( infile, actual_name, sizeof(actual_name), NULL, NULL, NULL, &comp ))
|
2007-04-25 20:50:13 +02:00
|
|
|
{
|
2008-08-21 10:18:00 +02:00
|
|
|
fprintf( stderr, "%s: can't open input file %s\n", argv[0], infile );
|
2007-04-25 20:50:13 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2008-08-21 10:18:00 +02:00
|
|
|
|
|
|
|
if (argc == 3 && (option_equal(argv[1], "R") || option_equal(argv[1], "r")))
|
2007-04-25 20:50:13 +02:00
|
|
|
{
|
2008-08-21 10:18:00 +02:00
|
|
|
switch (comp)
|
|
|
|
{
|
|
|
|
case FILE_COMPRESSION_MSZIP:
|
|
|
|
{
|
|
|
|
outfile_basename[0] = 0;
|
2009-01-29 11:15:10 +01:00
|
|
|
if (!SetupIterateCabinetA( infile, 0, set_outfile, outfile_basename ))
|
2008-08-21 10:18:00 +02:00
|
|
|
{
|
|
|
|
fprintf( stderr, "%s: can't determine original name\n", argv[0] );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
GetFullPathNameA( infile, sizeof(outfile), outfile, &basename_index );
|
|
|
|
*basename_index = 0;
|
|
|
|
strcat( outfile, outfile_basename );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FILE_COMPRESSION_WINLZA:
|
|
|
|
{
|
|
|
|
GetExpandedNameA( infile, outfile_basename );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
fprintf( stderr, "%s: can't determine original\n", argv[0] );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
GetFullPathNameA( argv[2], sizeof(outfile), outfile, NULL );
|
|
|
|
|
|
|
|
if (!lstrcmpiA( infile, outfile ))
|
|
|
|
{
|
|
|
|
fprintf( stderr, "%s: can't expand file to itself\n", argv[0] );
|
2007-04-25 20:50:13 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (comp)
|
|
|
|
{
|
|
|
|
case FILE_COMPRESSION_MSZIP:
|
|
|
|
{
|
2009-01-29 11:15:10 +01:00
|
|
|
if (!SetupIterateCabinetA( infile, 0, extract_callback, outfile ))
|
2007-04-25 20:50:13 +02:00
|
|
|
{
|
|
|
|
fprintf( stderr, "%s: cabinet extraction failed\n", argv[0] );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FILE_COMPRESSION_WINLZA:
|
|
|
|
{
|
|
|
|
INT hin, hout;
|
|
|
|
OFSTRUCT ofin, ofout;
|
|
|
|
LONG error;
|
|
|
|
|
2008-09-03 11:30:44 +02:00
|
|
|
if ((hin = LZOpenFileA( infile, &ofin, OF_READ )) < 0)
|
2007-04-25 20:50:13 +02:00
|
|
|
{
|
|
|
|
fprintf( stderr, "%s: can't open input file %s\n", argv[0], infile );
|
|
|
|
return 1;
|
|
|
|
}
|
2008-09-03 11:30:44 +02:00
|
|
|
if ((hout = LZOpenFileA( outfile, &ofout, OF_CREATE | OF_WRITE )) < 0)
|
2007-04-25 20:50:13 +02:00
|
|
|
{
|
|
|
|
LZClose( hin );
|
|
|
|
fprintf( stderr, "%s: can't open output file %s\n", argv[0], outfile );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
error = LZCopy( hin, hout );
|
|
|
|
|
|
|
|
LZClose( hin );
|
|
|
|
LZClose( hout );
|
|
|
|
|
|
|
|
if (error < 0)
|
|
|
|
{
|
|
|
|
fprintf( stderr, "%s: LZCopy failed, error is %d\n", argv[0], error );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
if (!CopyFileA( infile, outfile, FALSE ))
|
|
|
|
{
|
|
|
|
fprintf( stderr, "%s: CopyFileA failed\n", argv[0] );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
1997-08-04 18:34:36 +02:00
|
|
|
}
|