Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenextrac32.c
Go to the documentation of this file.
00001 /* 00002 * Extract - Wine-compatible program for extract *.cab files. 00003 * 00004 * Copyright 2007 Etersoft (Lyutin Anatoly) 00005 * Copyright 2009 Ilya Shpigor 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00020 */ 00021 00022 #include <windows.h> 00023 #include <shellapi.h> 00024 #include <setupapi.h> 00025 #include <shlwapi.h> 00026 00027 #include "wine/unicode.h" 00028 #include "wine/debug.h" 00029 00030 WINE_DEFAULT_DEBUG_CHANNEL(extrac32); 00031 00032 static BOOL force_mode; 00033 00034 static UINT WINAPI ExtCabCallback(PVOID Context, UINT Notification, UINT_PTR Param1, UINT_PTR Param2) 00035 { 00036 FILE_IN_CABINET_INFO_W *pInfo; 00037 FILEPATHS_W *pFilePaths; 00038 00039 switch(Notification) 00040 { 00041 case SPFILENOTIFY_FILEINCABINET: 00042 pInfo = (FILE_IN_CABINET_INFO_W*)Param1; 00043 lstrcpyW(pInfo->FullTargetName, (LPCWSTR)Context); 00044 lstrcatW(pInfo->FullTargetName, pInfo->NameInCabinet); 00045 return FILEOP_DOIT; 00046 case SPFILENOTIFY_FILEEXTRACTED: 00047 pFilePaths = (FILEPATHS_W*)Param1; 00048 WINE_TRACE("Extracted %s\n", wine_dbgstr_w(pFilePaths->Target)); 00049 return NO_ERROR; 00050 } 00051 return NO_ERROR; 00052 } 00053 00054 static void extract(LPCWSTR cabfile, LPWSTR destdir) 00055 { 00056 if (!SetupIterateCabinetW(cabfile, 0, ExtCabCallback, destdir)) 00057 WINE_ERR("Could not extract cab file %s\n", wine_dbgstr_w(cabfile)); 00058 } 00059 00060 static void copy_file(LPCWSTR source, LPCWSTR destination) 00061 { 00062 WCHAR destfile[MAX_PATH]; 00063 00064 /* append source filename if destination is a directory */ 00065 if (PathIsDirectoryW(destination)) 00066 { 00067 PathCombineW(destfile, destination, PathFindFileNameW(source)); 00068 destination = destfile; 00069 } 00070 00071 if (PathFileExistsW(destination) && !force_mode) 00072 { 00073 static const WCHAR overwriteMsg[] = {'O','v','e','r','w','r','i','t','e',' ','"','%','s','"','?',0}; 00074 static const WCHAR titleMsg[] = {'E','x','t','r','a','c','t',0}; 00075 WCHAR msg[MAX_PATH+100]; 00076 snprintfW(msg, sizeof(msg)/sizeof(msg[0]), overwriteMsg, destination); 00077 if (MessageBoxW(NULL, msg, titleMsg, MB_YESNO | MB_ICONWARNING) != IDYES) 00078 return; 00079 } 00080 00081 WINE_TRACE("copying %s to %s\n", wine_dbgstr_w(source), wine_dbgstr_w(destination)); 00082 CopyFileW(source, destination, FALSE); 00083 } 00084 00085 int PASCAL wWinMain(HINSTANCE hInstance, HINSTANCE prev, LPWSTR cmdline, int show) 00086 { 00087 LPWSTR *argv; 00088 int argc; 00089 int i; 00090 WCHAR check, cmd = 0; 00091 WCHAR path[MAX_PATH]; 00092 WCHAR backslash[] = {'\\',0}; 00093 LPCWSTR cabfile = NULL; 00094 00095 path[0] = 0; 00096 argv = CommandLineToArgvW(cmdline, &argc); 00097 00098 if(!argv) 00099 { 00100 WINE_ERR("Bad command line arguments\n"); 00101 return 0; 00102 } 00103 00104 /* Parse arguments */ 00105 for(i = 0; i < argc; i++) 00106 { 00107 /* Get cabfile */ 00108 if (argv[i][0] != '/') 00109 { 00110 if (!cabfile) 00111 { 00112 cabfile = argv[i]; 00113 continue; 00114 } else 00115 break; 00116 } 00117 /* Get parameters for commands */ 00118 check = toupperW( argv[i][1] ); 00119 switch(check) 00120 { 00121 case 'A': 00122 WINE_FIXME("/A not implemented\n"); 00123 break; 00124 case 'Y': 00125 force_mode = TRUE; 00126 break; 00127 case 'L': 00128 if ((i + 1) >= argc) return 0; 00129 if (!GetFullPathNameW(argv[++i], MAX_PATH, path, NULL)) 00130 return 0; 00131 break; 00132 case 'C': 00133 if (cmd) return 0; 00134 cmd = check; 00135 break; 00136 case 'E': 00137 case 'D': 00138 if (cmd) return 0; 00139 cmd = check; 00140 break; 00141 default: 00142 return 0; 00143 } 00144 } 00145 00146 if (!cabfile) 00147 return 0; 00148 00149 if (cmd == 'C') 00150 { 00151 if ((i + 1) != argc) return 0; 00152 if (!GetFullPathNameW(argv[i], MAX_PATH, path, NULL)) 00153 return 0; 00154 } 00155 00156 if (!path[0]) 00157 GetCurrentDirectoryW(MAX_PATH, path); 00158 00159 lstrcatW(path, backslash); 00160 00161 /* Execute the specified command */ 00162 switch(cmd) 00163 { 00164 case 'C': 00165 /* Copy file */ 00166 copy_file(cabfile, path); 00167 break; 00168 case 'E': 00169 /* Extract CAB archive */ 00170 extract(cabfile, path); 00171 break; 00172 case 0: 00173 case 'D': 00174 /* Display CAB archive */ 00175 WINE_FIXME("/D not implemented\n"); 00176 break; 00177 } 00178 return 0; 00179 } Generated on Sat May 26 2012 04:15:37 for ReactOS by
1.7.6.1
|