Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
3.5 KiB

  1. #include "inspch.h"
  2. #include "diskspac.h"
  3. #include "util2.h"
  4. void AddTempSpace(DWORD dwDownloadSize, DWORD dwExtractSize, DriveInfo drvinfo[])
  5. {
  6. DWORD uTempDrive = 0xffffffff;
  7. char szRoot[5] = { "A:\\" };
  8. BOOL bEnoughSpaceFound = FALSE;
  9. DWORD dwNeededSize;
  10. while ( szRoot[0] <= 'Z' && !bEnoughSpaceFound)
  11. {
  12. UINT uType;
  13. uType = GetDriveType(szRoot);
  14. // even the drive type is OK, verify the drive has valid connection
  15. //
  16. if ( ( ( uType != DRIVE_RAMDISK) && (uType != DRIVE_FIXED) ) ||
  17. ( GetFileAttributes( szRoot ) == -1) )
  18. {
  19. szRoot[0]++;
  20. continue;
  21. }
  22. // see if this drive is one of our "special drives" and use our own disk space
  23. BOOL bFoundDrive = FALSE;
  24. for(UINT i = 0; i < 3 && !bFoundDrive ; i++)
  25. {
  26. if(szRoot[0] == drvinfo[i].Drive())
  27. {
  28. bFoundDrive = TRUE;
  29. dwNeededSize = dwDownloadSize * drvinfo[i].CompressFactor() / 10 + dwExtractSize;
  30. if(dwNeededSize < drvinfo[i].Free())
  31. {
  32. uTempDrive = i;
  33. bEnoughSpaceFound = TRUE;
  34. }
  35. }
  36. }
  37. // if !bFoundDrive, this is not a special drive, do old check
  38. if(!bFoundDrive)
  39. {
  40. DWORD dwVolFlags, dwCompressFactor;
  41. if(!GetVolumeInformation(szRoot, NULL, 0, NULL, NULL, &dwVolFlags, NULL, 0))
  42. {
  43. szRoot[0]++;
  44. continue;
  45. }
  46. if(dwVolFlags & FS_VOL_IS_COMPRESSED)
  47. dwCompressFactor = 19;
  48. else
  49. dwCompressFactor = 10;
  50. // Decide how much we need if we extract to this drive
  51. dwNeededSize = dwDownloadSize * dwCompressFactor / 10 + dwExtractSize;;
  52. // if this drive has enough bump Req if appropiate
  53. if(IsEnoughSpace(szRoot, dwNeededSize ))
  54. {
  55. bEnoughSpaceFound = TRUE;
  56. }
  57. }
  58. szRoot[0]++;
  59. }
  60. // ok, if we haven't found enough space anywhere, add it to install drive or win drive
  61. if(!bEnoughSpaceFound)
  62. {
  63. if(drvinfo[1].Drive() != 0)
  64. uTempDrive = 1;
  65. else
  66. uTempDrive = 0;
  67. }
  68. if(uTempDrive != 0xffffffff)
  69. {
  70. drvinfo[uTempDrive].UseSpace(dwDownloadSize, TRUE);
  71. drvinfo[uTempDrive].UseSpace(dwExtractSize, FALSE);
  72. // now free up what we used
  73. drvinfo[uTempDrive].FreeSpace(dwDownloadSize, TRUE);
  74. drvinfo[uTempDrive].FreeSpace(dwExtractSize, FALSE);
  75. }
  76. }
  77. DriveInfo::DriveInfo() : m_dwUsed(0), m_dwMaxUsed(0),
  78. m_dwStart(0xffffffff), m_chDrive(0),
  79. m_uCompressFactor(10)
  80. {
  81. }
  82. void DriveInfo::InitDrive(char chDrive)
  83. {
  84. char szPath[5] = { "?:\\" };
  85. DWORD dwVolFlags = 0;
  86. m_chDrive = chDrive;
  87. szPath[0] = chDrive;
  88. m_dwStart = GetSpace(szPath);
  89. GetVolumeInformation(szPath,NULL,0,NULL,NULL, &dwVolFlags,NULL,0);
  90. if(dwVolFlags & FS_VOL_IS_COMPRESSED)
  91. m_uCompressFactor = 19;
  92. else
  93. m_uCompressFactor = 10;
  94. }
  95. void DriveInfo::UseSpace(DWORD dwAmt, BOOL bCompressed)
  96. {
  97. if(bCompressed)
  98. dwAmt = dwAmt * m_uCompressFactor/10;
  99. m_dwUsed += dwAmt;
  100. if(m_dwUsed > m_dwMaxUsed)
  101. m_dwMaxUsed = m_dwUsed;
  102. }
  103. void DriveInfo::FreeSpace(DWORD dwAmt, BOOL bCompressed)
  104. {
  105. if(bCompressed)
  106. dwAmt = dwAmt * m_uCompressFactor/10;
  107. m_dwUsed -= dwAmt;
  108. }