2 * Extract - Wine-compatible program for extract *.cab files.
4 * Copyright 2007 Etersoft (Lyutin Anatoly)
5 * Copyright 2009 Ilya Shpigor
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/unicode.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(extrac32
);
32 static BOOL force_mode
;
34 static UINT WINAPI
ExtCabCallback(PVOID Context
, UINT Notification
, UINT_PTR Param1
, UINT_PTR Param2
)
36 FILE_IN_CABINET_INFO_W
*pInfo
;
37 FILEPATHS_W
*pFilePaths
;
41 case SPFILENOTIFY_FILEINCABINET
:
42 pInfo
= (FILE_IN_CABINET_INFO_W
*)Param1
;
43 lstrcpyW(pInfo
->FullTargetName
, (LPCWSTR
)Context
);
44 lstrcatW(pInfo
->FullTargetName
, pInfo
->NameInCabinet
);
46 case SPFILENOTIFY_FILEEXTRACTED
:
47 pFilePaths
= (FILEPATHS_W
*)Param1
;
48 WINE_TRACE("Extracted %s\n", wine_dbgstr_w(pFilePaths
->Target
));
54 static void extract(LPCWSTR cabfile
, LPWSTR destdir
)
56 if (!SetupIterateCabinetW(cabfile
, 0, ExtCabCallback
, destdir
))
57 WINE_ERR("Could not extract cab file %s\n", wine_dbgstr_w(cabfile
));
60 static void copy_file(LPCWSTR source
, LPCWSTR destination
)
62 WCHAR destfile
[MAX_PATH
];
64 /* append source filename if destination is a directory */
65 if (PathIsDirectoryW(destination
))
67 PathCombineW(destfile
, destination
, PathFindFileNameW(source
));
68 destination
= destfile
;
71 if (PathFileExistsW(destination
) && !force_mode
)
73 static const WCHAR overwriteMsg
[] = {'O','v','e','r','w','r','i','t','e',' ','"','%','s','"','?',0};
74 static const WCHAR titleMsg
[] = {'E','x','t','r','a','c','t',0};
75 WCHAR msg
[MAX_PATH
+100];
76 snprintfW(msg
, sizeof(msg
)/sizeof(msg
[0]), overwriteMsg
, destination
);
77 if (MessageBoxW(NULL
, msg
, titleMsg
, MB_YESNO
| MB_ICONWARNING
) != IDYES
)
81 WINE_TRACE("copying %s to %s\n", wine_dbgstr_w(source
), wine_dbgstr_w(destination
));
82 CopyFileW(source
, destination
, FALSE
);
85 int PASCAL
wWinMain(HINSTANCE hInstance
, HINSTANCE prev
, LPWSTR cmdline
, int show
)
92 WCHAR backslash
[] = {'\\',0};
93 LPCWSTR cabfile
= NULL
;
96 argv
= CommandLineToArgvW(cmdline
, &argc
);
100 WINE_ERR("Bad command line arguments\n");
104 /* Parse arguments */
105 for(i
= 0; i
< argc
; i
++)
108 if (argv
[i
][0] != '/')
117 /* Get parameters for commands */
118 check
= toupperW( argv
[i
][1] );
122 WINE_FIXME("/A not implemented\n");
128 if ((i
+ 1) >= argc
) return 0;
129 if (!GetFullPathNameW(argv
[++i
], MAX_PATH
, path
, NULL
))
151 if ((i
+ 1) != argc
) return 0;
152 if (!GetFullPathNameW(argv
[i
], MAX_PATH
, path
, NULL
))
157 GetCurrentDirectoryW(MAX_PATH
, path
);
159 lstrcatW(path
, backslash
);
161 /* Execute the specified command */
166 copy_file(cabfile
, path
);
169 /* Extract CAB archive */
170 extract(cabfile
, path
);
174 /* Display CAB archive */
175 WINE_FIXME("/D not implemented\n");