- port cabextract to wine
[wine/dcerpc.git] / dlls / cabinet / cabinet_main.c
blob6a4a5ae53b6e7b867d174b578be2e6c1f2c025df
1 /*
2 * cabinet.dll main
4 * Copyright 2002 Patrik Stridvall
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winerror.h"
27 #include <assert.h>
29 #define NO_SHLWAPI_REG
30 #include "shlwapi.h"
31 #undef NO_SHLWAPI_REG
33 #include <string.h>
35 #include "cabinet.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(cabinet);
41 /***********************************************************************
42 * DllGetVersion (CABINET.2)
44 * Retrieves version information of the 'CABINET.DLL'
46 * PARAMS
47 * pdvi [O] pointer to version information structure.
49 * RETURNS
50 * Success: S_OK
51 * Failure: E_INVALIDARG
53 * NOTES
54 * Supposedly returns version from IE6SP1RP1
56 HRESULT WINAPI CABINET_DllGetVersion (DLLVERSIONINFO *pdvi)
58 WARN("hmmm... not right version number \"5.1.1106.1\"?\n");
60 if (pdvi->cbSize != sizeof(DLLVERSIONINFO)) return E_INVALIDARG;
62 pdvi->dwMajorVersion = 5;
63 pdvi->dwMinorVersion = 1;
64 pdvi->dwBuildNumber = 1106;
65 pdvi->dwPlatformID = 1;
67 return S_OK;
70 /***********************************************************************
71 * Extract (CABINET.3)
73 * Apparently an undocumented function, presumably to extract a CAB file
74 * to somewhere...
76 * PARAMS
77 * unknown [IO] unknown pointer
78 * what [I] char* describing what to uncompress, I guess.
80 * RETURNS
81 * Success: S_OK
82 * Failure: E_OUTOFMEMORY (?)
84 HRESULT WINAPI Extract(DWORD unknown, LPCSTR what)
86 LPCSTR whatx;
87 LPSTR dir, dirx, lastoption, x;
88 BOOL updatelastoption;
90 TRACE("(unknown == %0lx, what == %s)\n", unknown, debugstr_a(what));
92 dir = LocalAlloc(LPTR, strlen(what));
93 if (!dir) return E_OUTOFMEMORY;
95 /* copy the filename up to the last pathsep to construct the dirname */
96 whatx = what;
97 dirx = dir;
98 lastoption = NULL;
99 while (*whatx) {
100 if ((*whatx == '\\') || (*whatx == '/')) {
101 /* unless all chars between *dirx and lastoption are pathsep's, we
102 remember our location in dir as lastoption */
103 if (lastoption) {
104 updatelastoption = FALSE;
105 for (x = lastoption; x < dirx; x++)
106 if ((*dirx != '\\') && (*dirx != '/')) {
107 updatelastoption = TRUE;
108 break;
110 if (updatelastoption) lastoption = dirx;
111 } else
112 lastoption = dirx;
114 *dirx++ = *whatx++;
117 if (!lastoption) {
118 /* FIXME: I guess use the cwd or something? */
119 assert(FALSE);
120 } else {
121 *lastoption = '\0';
124 TRACE("extracting to dir: %s\n", debugstr_a(dir));
126 /* FIXME: what to do on failure? */
127 if (!process_cabinet(what, dir, FALSE, FALSE))
128 return E_OUTOFMEMORY;
130 LocalFree(dir);
132 return S_OK;