|
This is patch to bug #1032 titled "Incorrect amount of available disk
space displayed for large disks"
I tested the patch on WindowsNT with disks larger
than 2GBytes.
I tested the patch on Windows95 OS release 2 but I
simulated large disk with debugger
I simulated Windows95 OS release 1 with the
debugger.
It should work OK.
Gilles Saint-Denis
|
Index: abi/src/ask/lib/win/ask_lib_Win32.c
===================================================================
RCS file: /cvsroot/abi/src/ask/lib/win/ask_lib_Win32.c,v
retrieving revision 1.11
diff -u -r1.11 ask_lib_Win32.c
--- abi/src/ask/lib/win/ask_lib_Win32.c 2000/09/27 13:47:03 1.11
+++ abi/src/ask/lib/win/ask_lib_Win32.c 2000/11/03 00:17:00
@@ -160,11 +160,7 @@
{
char szBuf[256];
char* p;
- DWORD iSectorsPerCluster;
- DWORD iBytesPerSector;
- DWORD iNumberOfFreeClusters;
- DWORD iTotalNumberOfClusters;
- DWORD iBytes;
+ long iBytesLow, iBytesHigh;
int iResult;
if (g_pSet_BrowseDir->pszDirName &&g_pSet_BrowseDir->pszDirName[0])
@@ -187,17 +183,10 @@
p++;
*p = 0;
- iResult = GetDiskFreeSpace(szBuf,
- &iSectorsPerCluster,
- &iBytesPerSector,
- &iNumberOfFreeClusters,
- &iTotalNumberOfClusters);
+ iResult = ASK_getDiskFreeSpace(szBuf, &iBytesHigh, &iBytesLow);
- iBytes = (iResult != 0 ? iNumberOfFreeClusters : 0)
- * iSectorsPerCluster * iBytesPerSector;
-
// and set it into the static text display
- ASK_convertBytesToString(iBytes, szBuf);
+ ASK_convert64BitsToString(iBytesHigh, iBytesLow, szBuf);
SetWindowText(g_hwndStatic_DiskSpace, szBuf);
if(iResult == 0)
Index: abi/src/ask/lib/win/ask_lib_Win32_small.c
===================================================================
RCS file: /cvsroot/abi/src/ask/lib/win/ask_lib_Win32_small.c,v
retrieving revision 1.1
diff -u -r1.1 ask_lib_Win32_small.c
--- abi/src/ask/lib/win/ask_lib_Win32_small.c 1999/05/11 21:47:41 1.1
+++ abi/src/ask/lib/win/ask_lib_Win32_small.c 2000/11/03 00:17:01
@@ -25,12 +25,49 @@
#include <sys/utime.h>
#include "ask.h"
+#include "ut_assert.h"
-long ASK_getDiskFreeSpace(const char* pszDir)
+typedef BOOL (WINAPI *PF_GETDISKFREE)(LPCTSTR, PULARGE_INTEGER, PULARGE_INTEGER,
+PULARGE_INTEGER);
+
+int ASK_getDiskFreeSpace(const char* pszDir, long *HighPart, long *LowPart)
{
- // TODO GetDiskFreeSpaceEx()
+ int iResult;
+ PF_GETDISKFREE pGetDiskFreeSpaceEx = NULL;
+
+ HMODULE hModule = GetModuleHandle("kernel32.dll");
+ UT_ASSERT(hModule);
+ pGetDiskFreeSpaceEx = (PF_GETDISKFREE)GetProcAddress (hModule,
+ "GetDiskFreeSpaceExA");
+
+ if(pGetDiskFreeSpaceEx)
+ {
+ ULARGE_INTEGER iFreeBytesAvailableToCaller;
+ ULARGE_INTEGER iTotalNumberOfBytes;
+ ULARGE_INTEGER iTotalNumberOfFreeBytes;
+
+ iResult = pGetDiskFreeSpaceEx(pszDir, &iFreeBytesAvailableToCaller,
+ &iTotalNumberOfBytes, &iTotalNumberOfFreeBytes);
+ *HighPart = iResult != 0 ? iFreeBytesAvailableToCaller.HighPart : 0;
+ *LowPart = iResult != 0 ? iFreeBytesAvailableToCaller.LowPart : 0;
+ }
+ else
+ {
+ DWORD iSectorsPerCluster;
+ DWORD iBytesPerSector;
+ DWORD iNumberOfFreeClusters;
+ DWORD iTotalNumberOfClusters;
+
+ iResult = GetDiskFreeSpace(pszDir,
+ &iSectorsPerCluster,
+ &iBytesPerSector,
+ &iNumberOfFreeClusters,
+ &iTotalNumberOfClusters);
- return 0;
+ *HighPart = 0;
+ *LowPart = (iResult != 0 ? iNumberOfFreeClusters : 0)
+ * iSectorsPerCluster * iBytesPerSector;
+ }
+ return iResult;
}
unsigned int ASK_getFileModTime(const char* pszFileName)
Index: abi/src/ask/lib/xp/ask.h
===================================================================
RCS file: /cvsroot/abi/src/ask/lib/xp/ask.h,v
retrieving revision 1.3
diff -u -r1.3 ask.h
--- abi/src/ask/lib/xp/ask.h 2000/09/27 13:47:04 1.3
+++ abi/src/ask/lib/xp/ask.h 2000/11/03 00:17:02
@@ -82,6 +82,7 @@
long ASK_getFileSetTotalSizeInBytesToCopy(ASK_FileSet* pFileSet);
long ASK_getFileSetTotalFilesToCopy(ASK_FileSet* pFileSet);
void ASK_convertBytesToString(long n, char* pszStrings);
+void ASK_convert64BitsToString(long high, long low, char* pszStrings);
int ASK_isFileNewer(char* pszFileName, unsigned int iModTime);
/*
@@ -94,7 +95,7 @@
void ASK_setFileModTime(const char* pszFileName, unsigned int iModTime);
unsigned int ASK_getFileAttributes(const char* pszFileName);
void ASK_setFileAttributes(const char* pszFileName, unsigned int iAttributes);
-long ASK_getDiskFreeSpace(const char* pszDir);
+int ASK_getDiskFreeSpace(const char* pszDir, long *HighPart, long *LowPart);
void ASK_fixSlashes(char* pszPath);
int ASK_isDirectory(char* pszFile);
int ASK_fileExists(char* pszFile);
Index: abi/src/ask/lib/xp/ask_lib.c
===================================================================
RCS file: /cvsroot/abi/src/ask/lib/xp/ask_lib.c,v
retrieving revision 1.4
diff -u -r1.4 ask_lib.c
--- abi/src/ask/lib/xp/ask_lib.c 2000/09/27 13:47:04 1.4
+++ abi/src/ask/lib/xp/ask_lib.c 2000/11/03 00:17:03
@@ -276,6 +276,23 @@
sprintf(pszStrings, "%4.1f MB", n / (1024 * 1024.0));
}
+void ASK_convert64BitsToString(long high, long low, char* pszStrings)
+{
+ unsigned long iMegaByte = low;
+ iMegaByte /= (1024 * 1024);
+
+ if (high || iMegaByte >= 1024)
+ {
+ iMegaByte |= high << 12;
+ sprintf(pszStrings, "%5.2f GB", iMegaByte / 1024.0);
+ }
+ else
+ {
+ ASK_convertBytesToString(low, pszStrings);
+ }
+ return;
+}
+
int ASK_isFileNewer(char* pszFileName, unsigned int iModTime)
{
if(ASK_fileExists(pszFileName))
