setupapi: Create proper AMD64 fake dlls on 64-bit.
[wine] / dlls / setupapi / diskspace.c
1 /*
2  * SetupAPI DiskSpace functions
3  *
4  * Copyright 2004 CodeWeavers (Aric Stewart)
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 #include <stdarg.h>
22
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"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
33
34 typedef struct {
35     WCHAR   lpzName[20];
36     LONGLONG dwFreeSpace;
37     LONGLONG dwWantedSpace;
38 } DRIVE_ENTRY, *LPDRIVE_ENTRY;
39
40 typedef struct {
41     DWORD   dwDriveCount;
42     DRIVE_ENTRY Drives[26];
43 } DISKSPACELIST, *LPDISKSPACELIST;
44
45
46 /***********************************************************************
47  *              SetupCreateDiskSpaceListW  (SETUPAPI.@)
48  */
49 HDSKSPC WINAPI SetupCreateDiskSpaceListW(PVOID Reserved1, DWORD Reserved2, UINT Flags)
50 {
51     WCHAR drives[255];
52     DWORD rc;
53     WCHAR *ptr;
54     LPDISKSPACELIST list=NULL;
55
56     rc = GetLogicalDriveStringsW(255,drives);
57
58     if (rc == 0)
59         return NULL;
60
61     list = HeapAlloc(GetProcessHeap(),0,sizeof(DISKSPACELIST));
62
63     list->dwDriveCount = 0;
64     
65     ptr = drives;
66     
67     while (*ptr)
68     {
69         DWORD type = GetDriveTypeW(ptr);
70         if (type == DRIVE_FIXED)
71         {
72             DWORD clusters;
73             DWORD sectors;
74             DWORD bytes;
75             DWORD total;
76             lstrcpyW(list->Drives[list->dwDriveCount].lpzName,ptr);
77             GetDiskFreeSpaceW(ptr,&sectors,&bytes,&clusters,&total);
78             list->Drives[list->dwDriveCount].dwFreeSpace = clusters * sectors *
79                                                            bytes;
80             list->Drives[list->dwDriveCount].dwWantedSpace = 0;
81             list->dwDriveCount++;
82         }
83        ptr += lstrlenW(ptr) + 1;
84     }
85     return list;
86 }
87
88
89 /***********************************************************************
90  *              SetupCreateDiskSpaceListA  (SETUPAPI.@)
91  */
92 HDSKSPC WINAPI SetupCreateDiskSpaceListA(PVOID Reserved1, DWORD Reserved2, UINT Flags)
93 {
94     return SetupCreateDiskSpaceListW( Reserved1, Reserved2, Flags );
95 }
96
97
98 /***********************************************************************
99  *              SetupAddInstallSectionToDiskSpaceListA  (SETUPAPI.@)
100  */
101 BOOL WINAPI SetupAddInstallSectionToDiskSpaceListA(HDSKSPC DiskSpace, 
102                         HINF InfHandle, HINF LayoutInfHandle, 
103                         LPCSTR SectionName, PVOID Reserved1, UINT Reserved2)
104 {
105     FIXME ("Stub\n");
106     return TRUE;
107 }
108
109 /***********************************************************************
110 *               SetupQuerySpaceRequiredOnDriveA  (SETUPAPI.@)
111 */
112 BOOL WINAPI SetupQuerySpaceRequiredOnDriveA(HDSKSPC DiskSpace, 
113                         LPCSTR DriveSpec, LONGLONG* SpaceRequired, 
114                         PVOID Reserved1, UINT Reserved2)
115 {
116     WCHAR driveW[20];
117     unsigned int i;
118     LPDISKSPACELIST list = DiskSpace;
119     BOOL rc = FALSE;
120     static const WCHAR bkslsh[]= {'\\',0};
121
122     MultiByteToWideChar(CP_ACP,0,DriveSpec,-1,driveW,20);
123
124     lstrcatW(driveW,bkslsh);
125
126     TRACE("Looking for drive %s\n",debugstr_w(driveW));
127  
128     for (i = 0; i < list->dwDriveCount; i++)
129     {
130         TRACE("checking drive %s\n",debugstr_w(list->Drives[i].lpzName));
131         if (lstrcmpW(driveW,list->Drives[i].lpzName)==0)
132         {
133             rc = TRUE;
134             *SpaceRequired = list->Drives[i].dwWantedSpace;
135             break;
136         }
137     }
138
139     return rc;
140 }
141
142 /***********************************************************************
143 *               SetupDestroyDiskSpaceList  (SETUPAPI.@)
144 */
145 BOOL WINAPI SetupDestroyDiskSpaceList(HDSKSPC DiskSpace)
146 {
147     LPDISKSPACELIST list = DiskSpace;
148     HeapFree(GetProcessHeap(),0,list);
149     return TRUE; 
150 }