diskspace.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <stdarg.h>
  21. #include "windef.h"
  22. #include "winbase.h"
  23. #include "wingdi.h"
  24. #include "winuser.h"
  25. #include "winnls.h"
  26. #include "winreg.h"
  27. #include "setupapi.h"
  28. #include "wine/debug.h"
  29. WINE_DEFAULT_DEBUG_CHANNEL(setupapi);
  30. typedef struct {
  31. WCHAR lpzName[20];
  32. LONGLONG dwFreeSpace;
  33. LONGLONG dwWantedSpace;
  34. } DRIVE_ENTRY, *LPDRIVE_ENTRY;
  35. typedef struct {
  36. DWORD dwDriveCount;
  37. DRIVE_ENTRY Drives[26];
  38. } DISKSPACELIST, *LPDISKSPACELIST;
  39. /***********************************************************************
  40. * SetupCreateDiskSpaceListW (SETUPAPI.@)
  41. */
  42. HDSKSPC WINAPI SetupCreateDiskSpaceListW(PVOID Reserved1, DWORD Reserved2, UINT Flags)
  43. {
  44. WCHAR drives[255];
  45. DWORD rc;
  46. WCHAR *ptr;
  47. LPDISKSPACELIST list=NULL;
  48. rc = GetLogicalDriveStringsW(255,drives);
  49. if (rc == 0)
  50. return NULL;
  51. list = (LPDISKSPACELIST)HeapAlloc(GetProcessHeap(),0,sizeof(DISKSPACELIST));
  52. list->dwDriveCount = 0;
  53. ptr = drives;
  54. while (*ptr)
  55. {
  56. DWORD type = GetDriveTypeW(ptr);
  57. DWORD len;
  58. if (type == DRIVE_FIXED)
  59. {
  60. DWORD clusters;
  61. DWORD sectors;
  62. DWORD bytes;
  63. DWORD total;
  64. lstrcpyW(list->Drives[list->dwDriveCount].lpzName,ptr);
  65. GetDiskFreeSpaceW(ptr,&sectors,&bytes,&clusters,&total);
  66. list->Drives[list->dwDriveCount].dwFreeSpace = clusters * sectors *
  67. bytes;
  68. list->Drives[list->dwDriveCount].dwWantedSpace = 0;
  69. list->dwDriveCount++;
  70. }
  71. len = lstrlenW(ptr);
  72. len++;
  73. ptr+=sizeof(WCHAR)*len;
  74. }
  75. return (HANDLE)list;
  76. }
  77. /***********************************************************************
  78. * SetupCreateDiskSpaceListA (SETUPAPI.@)
  79. */
  80. HDSKSPC WINAPI SetupCreateDiskSpaceListA(PVOID Reserved1, DWORD Reserved2, UINT Flags)
  81. {
  82. return SetupCreateDiskSpaceListW( Reserved1, Reserved2, Flags );
  83. }
  84. /***********************************************************************
  85. * SetupAddInstallSectionToDiskSpaceListA (SETUPAPI.@)
  86. */
  87. BOOL WINAPI SetupAddInstallSectionToDiskSpaceListA(HDSKSPC DiskSpace,
  88. HINF InfHandle, HINF LayoutInfHandle,
  89. LPSTR SectionName, PVOID Reserved1, UINT Reserved2)
  90. {
  91. FIXME ("Stub\n");
  92. return TRUE;
  93. }
  94. /***********************************************************************
  95. * SetupQuerySpaceRequiredOnDriveA (SETUPAPI.@)
  96. */
  97. BOOL WINAPI SetupQuerySpaceRequiredOnDriveA(HDSKSPC DiskSpace,
  98. LPSTR DriveSpec, LONGLONG* SpaceRequired,
  99. PVOID Reserved1, UINT Reserved2)
  100. {
  101. WCHAR driveW[20];
  102. unsigned int i;
  103. LPDISKSPACELIST list = (LPDISKSPACELIST)DiskSpace;
  104. BOOL rc = FALSE;
  105. static const WCHAR bkslsh[]= {'\\',0};
  106. MultiByteToWideChar(CP_ACP,0,DriveSpec,-1,driveW,20);
  107. lstrcatW(driveW,bkslsh);
  108. TRACE("Looking for drive %s\n",debugstr_w(driveW));
  109. for (i = 0; i < list->dwDriveCount; i++)
  110. {
  111. TRACE("checking drive %s\n",debugstr_w(list->Drives[i].lpzName));
  112. if (lstrcmpW(driveW,list->Drives[i].lpzName)==0)
  113. {
  114. rc = TRUE;
  115. *SpaceRequired = list->Drives[i].dwWantedSpace;
  116. break;
  117. }
  118. }
  119. return rc;
  120. }
  121. /***********************************************************************
  122. * SetupDestroyDiskSpaceList (SETUPAPI.@)
  123. */
  124. BOOL WINAPI SetupDestroyDiskSpaceList(HDSKSPC DiskSpace)
  125. {
  126. LPDISKSPACELIST list = (LPDISKSPACELIST)DiskSpace;
  127. HeapFree(GetProcessHeap(),0,list);
  128. return TRUE;
  129. }