strmbase: Separate BaseFilter destructor from Release.
[wine.git] / dlls / setupapi / diskspace.c
blob1ca45f969132d84940bc2037eba51c6d42720ca2
1 /*
2 * SetupAPI DiskSpace functions
4 * Copyright 2004 CodeWeavers (Aric Stewart)
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wingdi.h"
26 #include "winuser.h"
27 #include "winnls.h"
28 #include "winreg.h"
29 #include "setupapi.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
34 typedef struct {
35 WCHAR lpzName[20];
36 LONGLONG dwFreeSpace;
37 LONGLONG dwWantedSpace;
38 } DRIVE_ENTRY, *LPDRIVE_ENTRY;
40 typedef struct {
41 DWORD dwDriveCount;
42 DRIVE_ENTRY Drives[26];
43 } DISKSPACELIST, *LPDISKSPACELIST;
46 /***********************************************************************
47 * SetupCreateDiskSpaceListW (SETUPAPI.@)
49 HDSKSPC WINAPI SetupCreateDiskSpaceListW(PVOID Reserved1, DWORD Reserved2, UINT Flags)
51 WCHAR drives[255];
52 DWORD rc;
53 WCHAR *ptr;
54 LPDISKSPACELIST list=NULL;
56 TRACE("(%p, %u, 0x%08x)\n", Reserved1, Reserved2, Flags);
58 if (Reserved1 || Reserved2 || Flags & ~SPDSL_IGNORE_DISK)
60 SetLastError(ERROR_INVALID_PARAMETER);
61 return NULL;
64 rc = GetLogicalDriveStringsW(255,drives);
66 if (rc == 0)
67 return NULL;
69 list = HeapAlloc(GetProcessHeap(),0,sizeof(DISKSPACELIST));
71 list->dwDriveCount = 0;
73 ptr = drives;
75 while (*ptr)
77 DWORD type = GetDriveTypeW(ptr);
78 if (type == DRIVE_FIXED)
80 DWORD clusters;
81 DWORD sectors;
82 DWORD bytes;
83 DWORD total;
84 lstrcpyW(list->Drives[list->dwDriveCount].lpzName,ptr);
85 GetDiskFreeSpaceW(ptr,&sectors,&bytes,&clusters,&total);
86 list->Drives[list->dwDriveCount].dwFreeSpace = clusters * sectors *
87 bytes;
88 list->Drives[list->dwDriveCount].dwWantedSpace = 0;
89 list->dwDriveCount++;
91 ptr += lstrlenW(ptr) + 1;
93 return list;
97 /***********************************************************************
98 * SetupCreateDiskSpaceListA (SETUPAPI.@)
100 HDSKSPC WINAPI SetupCreateDiskSpaceListA(PVOID Reserved1, DWORD Reserved2, UINT Flags)
102 return SetupCreateDiskSpaceListW( Reserved1, Reserved2, Flags );
105 /***********************************************************************
106 * SetupDuplicateDiskSpaceListW (SETUPAPI.@)
108 HDSKSPC WINAPI SetupDuplicateDiskSpaceListW(HDSKSPC DiskSpace, PVOID Reserved1, DWORD Reserved2, UINT Flags)
110 DISKSPACELIST *list_copy, *list_original = DiskSpace;
112 if (Reserved1 || Reserved2 || Flags)
114 SetLastError(ERROR_INVALID_PARAMETER);
115 return NULL;
118 if (!DiskSpace)
120 SetLastError(ERROR_INVALID_HANDLE);
121 return NULL;
124 list_copy = HeapAlloc(GetProcessHeap(), 0, sizeof(DISKSPACELIST));
125 if (!list_copy)
127 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
128 return NULL;
131 *list_copy = *list_original;
133 return list_copy;
136 /***********************************************************************
137 * SetupDuplicateDiskSpaceListA (SETUPAPI.@)
139 HDSKSPC WINAPI SetupDuplicateDiskSpaceListA(HDSKSPC DiskSpace, PVOID Reserved1, DWORD Reserved2, UINT Flags)
141 return SetupDuplicateDiskSpaceListW(DiskSpace, Reserved1, Reserved2, Flags);
144 /***********************************************************************
145 * SetupAddInstallSectionToDiskSpaceListA (SETUPAPI.@)
147 BOOL WINAPI SetupAddInstallSectionToDiskSpaceListA(HDSKSPC DiskSpace,
148 HINF InfHandle, HINF LayoutInfHandle,
149 LPCSTR SectionName, PVOID Reserved1, UINT Reserved2)
151 FIXME ("Stub\n");
152 return TRUE;
155 /***********************************************************************
156 * SetupQuerySpaceRequiredOnDriveW (SETUPAPI.@)
158 BOOL WINAPI SetupQuerySpaceRequiredOnDriveW(HDSKSPC DiskSpace,
159 LPCWSTR DriveSpec, LONGLONG *SpaceRequired,
160 PVOID Reserved1, UINT Reserved2)
162 WCHAR *driveW;
163 unsigned int i;
164 LPDISKSPACELIST list = DiskSpace;
165 BOOL rc = FALSE;
166 static const WCHAR bkslsh[]= {'\\',0};
168 if (!DiskSpace)
170 SetLastError(ERROR_INVALID_HANDLE);
171 return FALSE;
174 if (!DriveSpec)
176 SetLastError(ERROR_INVALID_PARAMETER);
177 return FALSE;
180 driveW = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(DriveSpec) + 2) * sizeof(WCHAR));
181 if (!driveW)
183 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
184 return FALSE;
187 lstrcpyW(driveW,DriveSpec);
188 lstrcatW(driveW,bkslsh);
190 TRACE("Looking for drive %s\n",debugstr_w(driveW));
192 for (i = 0; i < list->dwDriveCount; i++)
194 TRACE("checking drive %s\n",debugstr_w(list->Drives[i].lpzName));
195 if (lstrcmpW(driveW,list->Drives[i].lpzName)==0)
197 rc = TRUE;
198 *SpaceRequired = list->Drives[i].dwWantedSpace;
199 break;
203 HeapFree(GetProcessHeap(), 0, driveW);
205 if (!rc) SetLastError(ERROR_INVALID_DRIVE);
206 return rc;
209 /***********************************************************************
210 * SetupQuerySpaceRequiredOnDriveA (SETUPAPI.@)
212 BOOL WINAPI SetupQuerySpaceRequiredOnDriveA(HDSKSPC DiskSpace,
213 LPCSTR DriveSpec, LONGLONG *SpaceRequired,
214 PVOID Reserved1, UINT Reserved2)
216 DWORD len;
217 LPWSTR DriveSpecW;
218 BOOL ret;
220 /* The parameter validation checks are in a different order from the
221 * Unicode variant of SetupQuerySpaceRequiredOnDrive. */
222 if (!DriveSpec)
224 SetLastError(ERROR_INVALID_PARAMETER);
225 return FALSE;
228 if (!DiskSpace)
230 SetLastError(ERROR_INVALID_HANDLE);
231 return FALSE;
234 len = MultiByteToWideChar(CP_ACP, 0, DriveSpec, -1, NULL, 0);
236 DriveSpecW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
237 if (!DriveSpecW)
239 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
240 return FALSE;
243 MultiByteToWideChar(CP_ACP, 0, DriveSpec, -1, DriveSpecW, len);
245 ret = SetupQuerySpaceRequiredOnDriveW(DiskSpace, DriveSpecW, SpaceRequired,
246 Reserved1, Reserved2);
248 HeapFree(GetProcessHeap(), 0, DriveSpecW);
250 return ret;
253 /***********************************************************************
254 * SetupDestroyDiskSpaceList (SETUPAPI.@)
256 BOOL WINAPI SetupDestroyDiskSpaceList(HDSKSPC DiskSpace)
258 LPDISKSPACELIST list = DiskSpace;
259 HeapFree(GetProcessHeap(),0,list);
260 return TRUE;
263 /***********************************************************************
264 * SetupAddToDiskSpaceListA (SETUPAPI.@)
266 BOOL WINAPI SetupAddToDiskSpaceListA(HDSKSPC diskspace, PCSTR targetfile,
267 LONGLONG filesize, UINT operation,
268 PVOID reserved1, UINT reserved2)
270 FIXME(": stub\n");
271 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
272 return FALSE;
275 /***********************************************************************
276 * SetupAddToDiskSpaceListW (SETUPAPI.@)
278 BOOL WINAPI SetupAddToDiskSpaceListW(HDSKSPC diskspace, PCWSTR targetfile,
279 LONGLONG filesize, UINT operation,
280 PVOID reserved1, UINT reserved2)
282 FIXME(": stub\n");
283 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
284 return FALSE;