source: other-projects/gs2-export-cdrom-installer/trunk/DiskSpace.cpp

Last change on this file was 22919, checked in by ak19, 14 years ago

Dr Bainbridge got gssetup.exe (for the export to cdrom installer) to work again for a later version of Visual Studio: now it works with Visual Studio 9 and does not use STLPort anymore. Changed .rc reference to including afxres.h to windows.h in vcinstall.rc, and there were changes to dereferencing File elements in an STL iterator (in fileCopier.cpp). Also needed to change references to unsigned double to double since the former seems to no longer be supported in later versions of Vis Studio.

  • Property svn:keywords set to Author Date Id Revision
File size: 2.0 KB
Line 
1#include <windows.h>
2
3#include "DiskSpace.h"
4
5typedef BOOL (* diskEx) (LPCTSTR root, PULARGE_INTEGER a, PULARGE_INTEGER B, PULARGE_INTEGER C);
6
7DiskSpace::DiskSpace(const char *rootName)
8{
9 char rootPath[128];
10 DWORD totalClusters;
11 OSVERSIONINFO osVerInfo;
12
13 // copy the rootname to our own path
14 strcpy(rootPath, rootName);
15
16 // get some guide to the os version
17 osVerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
18 GetVersionEx(&osVerInfo);
19
20 // if get disk free space fails then note fatal initialisation error
21 if (!GetDiskFreeSpace(rootName, &sectorsPerCluster, &bytesPerSector,
22 &freeClusters, &totalClusters))
23 { this->initialised = FALSE;
24 return;
25 }
26
27 // call the advanced form of getDiskSpace if we have access to it; this
28 // will cope with 2Gb+ partitions correctly
29 if (osVerInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS &&
30 LOWORD(osVerInfo.dwBuildNumber) > 1000 ||
31 TRUE)
32 { HMODULE module;
33 FARPROC proc;
34 ULARGE_INTEGER freeBytes, freeToCaller, totalBytes;
35
36 module = LoadLibrary("KERNEL32.DLL");
37 proc = GetProcAddress(module, "GetDiskFreeSpaceEx");
38 if (proc == NULL)
39 { this->initialised = TRUE;
40 return;
41 }
42 (* ((diskEx) proc))(rootPath, &freeBytes, &freeToCaller, &totalBytes);
43 // Get free clusters - use the ULARGE_INTEGER variables to get the
44 // result and avoid overflow problems
45 //freeBytes = freeBytes / sectorsPerCluster; //(sectorsPerCluster * bytesPerSector);
46 //freeClusters = totalBytes;
47 }
48 this->initialised = TRUE;
49 return;
50}
51
52BOOL DiskSpace::initialisedOk()
53{ return this->initialised;
54}
55
56double DiskSpace::totalFreeSpace()
57{ return this->freeClusters * (((double) (this->sectorsPerCluster * this->bytesPerSector)) / (double) (1024));
58}
59
60int DiskSpace::fileClusters(int fileSize)
61{ int sectors, clusters;
62
63 sectors = (fileSize + this->bytesPerSector - 1) / this->bytesPerSector;
64 clusters = (sectors + this->sectorsPerCluster - 1) / this->sectorsPerCluster;
65 return clusters;
66}
67
68int DiskSpace::fileSpace(int fileSize)
69{ return this->fileClusters(fileSize) * this->bytesPerSector * this->sectorsPerCluster;
70}
71
Note: See TracBrowser for help on using the repository browser.