winefile: Fix the Italian translation.
[wine] / programs / expand / expand.c
1 /*
2  * Copyright 1997 Victor Schneider
3  * Copyright 2002 Alexandre Julliard
4  * Copyright 2007 Hans Leidekker
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #define WIN32_LEAN_AND_MEAN
22
23 #include <stdio.h>
24 #include <string.h>
25 #include <windows.h>
26 #include <lzexpand.h>
27 #include <setupapi.h>
28
29 static UINT CALLBACK extract_callback( PVOID context, UINT notification, UINT_PTR param1, UINT_PTR param2 )
30 {
31     FILE_IN_CABINET_INFO_A *info = (FILE_IN_CABINET_INFO_A *)param1;
32
33     switch (notification)
34     {
35     case SPFILENOTIFY_FILEINCABINET:
36     {
37         LPCSTR targetname = context;
38
39         strcpy( info->FullTargetName, targetname );
40         return FILEOP_DOIT;
41     }
42     default: return NO_ERROR;
43     }
44 }
45
46 int main(int argc, char *argv[])
47 {
48     int ret = 0;
49     char infile[MAX_PATH], outfile[MAX_PATH], actual_name[MAX_PATH];
50     UINT comp;
51
52     if (argc < 3)
53     {
54         fprintf( stderr, "Usage: %s infile outfile\n", argv[0] );
55         return 1;
56     }
57
58     GetFullPathNameA( argv[1], sizeof(infile), infile, NULL );
59     GetFullPathNameA( argv[2], sizeof(outfile), outfile, NULL );
60
61     if (!lstrcmpiA( infile, outfile ))
62     {
63         fprintf( stderr, "%s: can't expand file to itself\n", argv[0] );
64         return 1;
65     }
66     if (!SetupGetFileCompressionInfoExA( infile, actual_name, sizeof(actual_name), NULL, NULL, NULL, &comp ))
67     {
68         fprintf( stderr, "%s: can't open input file %s\n", argv[0], infile );
69         return 1;
70     }
71
72     switch (comp)
73     {
74     case FILE_COMPRESSION_MSZIP:
75     {
76         if (!SetupIterateCabinetA( infile, 0, extract_callback, (PVOID)outfile ))
77         {
78             fprintf( stderr, "%s: cabinet extraction failed\n", argv[0] );
79             return 1;
80         }
81         break;
82     }
83     case FILE_COMPRESSION_WINLZA:
84     {
85         INT hin, hout;
86         OFSTRUCT ofin, ofout;
87         LONG error;
88
89         if ((hin = LZOpenFile( infile, &ofin, OF_READ )) < 0)
90         {
91             fprintf( stderr, "%s: can't open input file %s\n", argv[0], infile );
92             return 1;
93         }
94         if ((hout = LZOpenFile( outfile, &ofout, OF_CREATE | OF_WRITE )) < 0)
95         {
96             LZClose( hin );
97             fprintf( stderr, "%s: can't open output file %s\n", argv[0], outfile );
98             return 1;
99         }
100         error = LZCopy( hin, hout );
101
102         LZClose( hin );
103         LZClose( hout );
104
105         if (error < 0)
106         {
107             fprintf( stderr, "%s: LZCopy failed, error is %d\n", argv[0], error );
108             return 1;
109         }
110         break;
111     }
112     default:
113     {
114         if (!CopyFileA( infile, outfile, FALSE ))
115         {
116             fprintf( stderr, "%s: CopyFileA failed\n", argv[0] );
117             return 1;
118         }
119         break;
120     }
121     }
122     return ret;
123 }