~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/programs/expand/expand.c

Version: ~ [ wine-1.5.30 ] ~ [ wine-1.5.29 ] ~ [ wine-1.5.28 ] ~ [ wine-1.5.27 ] ~ [ wine-1.5.26 ] ~ [ wine-1.5.25 ] ~ [ wine-1.5.24 ] ~ [ wine-1.5.23 ] ~ [ wine-1.5.22 ] ~ [ wine-1.5.21 ] ~ [ wine-1.5.20 ] ~ [ wine-1.5.19 ] ~ [ wine-1.5.18 ] ~ [ wine-1.5.17 ] ~ [ wine-1.5.16 ] ~ [ wine-1.5.15 ] ~ [ wine-1.5.14 ] ~ [ wine-1.5.13 ] ~ [ wine-1.5.12 ] ~ [ wine-1.5.11 ] ~ [ wine-1.5.10 ] ~ [ wine-1.5.9 ] ~ [ wine-1.5.8 ] ~ [ wine-1.5.7 ] ~ [ wine-1.4.1 ] ~ [ wine-1.5.6 ] ~ [ wine-1.5.5 ] ~ [ wine-1.5.4 ] ~ [ wine-1.5.3 ] ~ [ wine-1.5.2 ] ~ [ wine-1.5.1 ] ~ [ wine-1.5.0 ] ~ [ wine-1.4 ] ~ [ wine-1.4-rc6 ] ~ [ wine-1.4-rc5 ] ~ [ wine-1.4-rc4 ] ~ [ wine-1.4-rc3 ] ~ [ wine-1.4-rc2 ] ~ [ wine-1.4-rc1 ] ~ [ wine-1.3.37 ] ~ [ wine-1.3.36 ] ~ [ wine-1.3.35 ] ~ [ wine-1.3.34 ] ~ [ wine-1.3.33 ] ~ [ wine-1.3.32 ] ~ [ wine-1.3.31 ] ~ [ wine-1.3.30 ] ~ [ wine-1.3.29 ] ~ [ wine-1.3.28 ] ~ [ wine-1.3.27 ] ~ [ wine-1.3.26 ] ~ [ wine-1.3.25 ] ~ [ wine-1.3.24 ] ~ [ wine-1.3.23 ] ~ [ wine-1.3.22 ] ~ [ wine-1.3.21 ] ~ [ wine-1.3.20 ] ~ [ wine-1.3.19 ] ~ [ wine-1.3.18 ] ~ [ wine-1.2.3 ] ~ [ wine-1.3.17 ] ~ [ wine-1.3.16 ] ~ [ wine-1.3.15 ] ~ [ wine-1.3.14 ] ~ [ wine-1.3.13 ] ~ [ wine-1.3.12 ] ~ [ wine-1.3.11 ] ~ [ wine-1.3.10 ] ~ [ wine-1.3.9 ] ~ [ wine-1.2.2 ] ~ [ wine-1.3.8 ] ~ [ wine-1.3.7 ] ~ [ wine-1.3.6 ] ~ [ wine-1.3.5 ] ~ [ wine-1.2.1 ] ~ [ wine-1.3.4 ] ~ [ wine-1.3.3 ] ~ [ wine-1.3.2 ] ~ [ wine-1.3.1 ] ~ [ wine-1.3.0 ] ~ [ wine-1.2 ] ~ [ wine-1.2-rc7 ] ~ [ wine-1.2-rc6 ] ~ [ wine-1.2-rc5 ] ~ [ wine-1.2-rc4 ] ~ [ wine-1.2-rc3 ] ~ [ wine-1.2-rc2 ] ~ [ wine-1.2-rc1 ] ~ [ wine-1.1.44 ] ~ [ wine-1.1.43 ] ~ [ wine-1.1.42 ] ~ [ wine-1.1.41 ] ~ [ wine-1.1.40 ] ~ [ wine-1.1.39 ] ~ [ wine-1.1.38 ] ~ [ wine-1.1.37 ] ~ [ wine-1.1.36 ] ~ [ wine-1.1.35 ] ~ [ wine-1.1.34 ] ~ [ wine-1.1.33 ] ~ [ wine-1.1.32 ] ~ [ wine-1.1.31 ] ~ [ wine-1.1.30 ] ~ [ wine-1.1.29 ] ~ [ wine-1.1.28 ] ~ [ wine-1.1.27 ] ~ [ wine-1.1.26 ] ~ [ wine-1.1.25 ] ~ [ wine-1.1.24 ] ~ [ wine-1.1.23 ] ~ [ wine-1.1.22 ] ~ [ wine-1.1.21 ] ~ [ wine-1.1.20 ] ~ [ wine-1.1.19 ] ~ [ wine-1.1.18 ] ~ [ wine-1.1.17 ] ~ [ wine-1.1.16 ] ~ [ wine-1.1.15 ] ~ [ wine-1.1.14 ] ~ [ wine-1.1.13 ] ~ [ wine-1.1.12 ] ~ [ wine-1.1.11 ] ~ [ wine-1.1.10 ] ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~

  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 set_outfile( 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     char buffer[MAX_PATH];
 33     char* basename;
 34 
 35     switch (notification)
 36     {
 37     case SPFILENOTIFY_FILEINCABINET:
 38     {
 39         LPSTR outfile = context;
 40         if (outfile[0] != 0)
 41         {
 42             SetLastError( ERROR_NOT_SUPPORTED );
 43             return FILEOP_ABORT;
 44         }
 45         GetFullPathNameA( info->NameInCabinet, sizeof(buffer), buffer, &basename );
 46         strcpy( outfile, basename );
 47         return FILEOP_SKIP;
 48     }
 49     default: return NO_ERROR;
 50     }
 51 }
 52 
 53 static UINT CALLBACK extract_callback( PVOID context, UINT notification, UINT_PTR param1, UINT_PTR param2 )
 54 {
 55     FILE_IN_CABINET_INFO_A *info = (FILE_IN_CABINET_INFO_A *)param1;
 56 
 57     switch (notification)
 58     {
 59     case SPFILENOTIFY_FILEINCABINET:
 60     {
 61         LPCSTR targetname = context;
 62 
 63         strcpy( info->FullTargetName, targetname );
 64         return FILEOP_DOIT;
 65     }
 66     default: return NO_ERROR;
 67     }
 68 }
 69 
 70 static BOOL option_equal(LPCSTR str1, LPCSTR str2)
 71 {
 72     if (str1[0] != '/' && str1[0] != '-')
 73         return FALSE;
 74     return !lstrcmpA( str1 + 1, str2 );
 75 }
 76 
 77 int main(int argc, char *argv[])
 78 {
 79     int ret = 0;
 80     char infile[MAX_PATH], outfile[MAX_PATH], actual_name[MAX_PATH];
 81     char outfile_basename[MAX_PATH], *basename_index;
 82     UINT comp;
 83 
 84     if (argc < 3)
 85     {
 86         fprintf( stderr, "Usage:\n" );
 87         fprintf( stderr, "\t%s infile outfile\n", argv[0] );
 88         fprintf( stderr, "\t%s /r infile \n", argv[0] );
 89         return 1;
 90     }
 91 
 92     if (argc == 3 && (option_equal(argv[1], "R") || option_equal(argv[1], "r")))
 93         GetFullPathNameA( argv[2], sizeof(infile), infile, NULL );
 94     else
 95         GetFullPathNameA( argv[1], sizeof(infile), infile, NULL );
 96 
 97     if (!SetupGetFileCompressionInfoExA( infile, actual_name, sizeof(actual_name), NULL, NULL, NULL, &comp ))
 98     {
 99         fprintf( stderr, "%s: can't open input file %s\n", argv[0], infile );
100         return 1;
101     }
102 
103     if (argc == 3 && (option_equal(argv[1], "R") || option_equal(argv[1], "r")))
104     {
105         switch (comp)
106         {
107         case FILE_COMPRESSION_MSZIP:
108         {
109             outfile_basename[0] = 0;
110             if (!SetupIterateCabinetA( infile, 0, set_outfile, outfile_basename ))
111             {
112                 fprintf( stderr, "%s: can't determine original name\n", argv[0] );
113                 return 1;
114             }
115             GetFullPathNameA( infile, sizeof(outfile), outfile, &basename_index );
116             *basename_index = 0;
117             strcat( outfile, outfile_basename );
118             break;
119         }
120         case FILE_COMPRESSION_WINLZA:
121         {
122             GetExpandedNameA( infile, outfile_basename );
123             break;
124         }
125         default:
126         {
127             fprintf( stderr, "%s: can't determine original\n", argv[0] );
128             return 1;
129         }
130         }
131     }
132     else
133         GetFullPathNameA( argv[2], sizeof(outfile), outfile, NULL );
134 
135     if (!lstrcmpiA( infile, outfile ))
136     {
137         fprintf( stderr, "%s: can't expand file to itself\n", argv[0] );
138         return 1;
139     }
140 
141     switch (comp)
142     {
143     case FILE_COMPRESSION_MSZIP:
144     {
145         if (!SetupIterateCabinetA( infile, 0, extract_callback, outfile ))
146         {
147             fprintf( stderr, "%s: cabinet extraction failed\n", argv[0] );
148             return 1;
149         }
150         break;
151     }
152     case FILE_COMPRESSION_WINLZA:
153     {
154         INT hin, hout;
155         OFSTRUCT ofin, ofout;
156         LONG error;
157 
158         if ((hin = LZOpenFileA( infile, &ofin, OF_READ )) < 0)
159         {
160             fprintf( stderr, "%s: can't open input file %s\n", argv[0], infile );
161             return 1;
162         }
163         if ((hout = LZOpenFileA( outfile, &ofout, OF_CREATE | OF_WRITE )) < 0)
164         {
165             LZClose( hin );
166             fprintf( stderr, "%s: can't open output file %s\n", argv[0], outfile );
167             return 1;
168         }
169         error = LZCopy( hin, hout );
170 
171         LZClose( hin );
172         LZClose( hout );
173 
174         if (error < 0)
175         {
176             fprintf( stderr, "%s: LZCopy failed, error is %d\n", argv[0], error );
177             return 1;
178         }
179         break;
180     }
181     default:
182     {
183         if (!CopyFileA( infile, outfile, FALSE ))
184         {
185             fprintf( stderr, "%s: CopyFileA failed\n", argv[0] );
186             return 1;
187         }
188         break;
189     }
190     }
191     return ret;
192 }
193 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.