diff options
| author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2024-05-14 00:00:00 +0000 |
|---|---|---|
| committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2024-05-15 23:55:04 +0500 |
| commit | fc662341e6f85da78ada0e443f6116b978f79f22 (patch) | |
| tree | 1be1cc402a7a9cbc18d4eeea6b141354c2d559e3 /CPP/Windows/FileSystem.cpp | |
| parent | 5b39dc76f1bc82f941d5c800ab9f34407a06b53a (diff) | |
| download | 7zip-fc662341e6f85da78ada0e443f6116b978f79f22.tar.gz 7zip-fc662341e6f85da78ada0e443f6116b978f79f22.tar.bz2 7zip-fc662341e6f85da78ada0e443f6116b978f79f22.zip | |
24.0524.05
Diffstat (limited to 'CPP/Windows/FileSystem.cpp')
| -rw-r--r-- | CPP/Windows/FileSystem.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/CPP/Windows/FileSystem.cpp b/CPP/Windows/FileSystem.cpp index 6a262d9..d11f02e 100644 --- a/CPP/Windows/FileSystem.cpp +++ b/CPP/Windows/FileSystem.cpp | |||
| @@ -71,6 +71,12 @@ UINT MyGetDriveType(CFSTR pathName) | |||
| 71 | } | 71 | } |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | #if !defined(Z7_WIN32_WINNT_MIN) || Z7_WIN32_WINNT_MIN < 0x0400 | ||
| 75 | // GetDiskFreeSpaceEx requires Windows95-OSR2, NT4 | ||
| 76 | #define Z7_USE_DYN_GetDiskFreeSpaceEx | ||
| 77 | #endif | ||
| 78 | |||
| 79 | #ifdef Z7_USE_DYN_GetDiskFreeSpaceEx | ||
| 74 | typedef BOOL (WINAPI * Func_GetDiskFreeSpaceExA)( | 80 | typedef BOOL (WINAPI * Func_GetDiskFreeSpaceExA)( |
| 75 | LPCSTR lpDirectoryName, // directory name | 81 | LPCSTR lpDirectoryName, // directory name |
| 76 | PULARGE_INTEGER lpFreeBytesAvailable, // bytes available to caller | 82 | PULARGE_INTEGER lpFreeBytesAvailable, // bytes available to caller |
| @@ -84,6 +90,7 @@ typedef BOOL (WINAPI * Func_GetDiskFreeSpaceExW)( | |||
| 84 | PULARGE_INTEGER lpTotalNumberOfBytes, // bytes on disk | 90 | PULARGE_INTEGER lpTotalNumberOfBytes, // bytes on disk |
| 85 | PULARGE_INTEGER lpTotalNumberOfFreeBytes // free bytes on disk | 91 | PULARGE_INTEGER lpTotalNumberOfFreeBytes // free bytes on disk |
| 86 | ); | 92 | ); |
| 93 | #endif | ||
| 87 | 94 | ||
| 88 | bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize) | 95 | bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize) |
| 89 | { | 96 | { |
| @@ -92,14 +99,22 @@ bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize, | |||
| 92 | #ifndef _UNICODE | 99 | #ifndef _UNICODE |
| 93 | if (!g_IsNT) | 100 | if (!g_IsNT) |
| 94 | { | 101 | { |
| 102 | #ifdef Z7_USE_DYN_GetDiskFreeSpaceEx | ||
| 95 | const | 103 | const |
| 96 | Func_GetDiskFreeSpaceExA f = Z7_GET_PROC_ADDRESS( | 104 | Func_GetDiskFreeSpaceExA f = Z7_GET_PROC_ADDRESS( |
| 97 | Func_GetDiskFreeSpaceExA, GetModuleHandle(TEXT("kernel32.dll")), | 105 | Func_GetDiskFreeSpaceExA, GetModuleHandle(TEXT("kernel32.dll")), |
| 98 | "GetDiskFreeSpaceExA"); | 106 | "GetDiskFreeSpaceExA"); |
| 99 | if (f) | 107 | if (f) |
| 108 | #endif | ||
| 100 | { | 109 | { |
| 101 | ULARGE_INTEGER freeBytesToCaller2, totalSize2, freeSize2; | 110 | ULARGE_INTEGER freeBytesToCaller2, totalSize2, freeSize2; |
| 102 | sizeIsDetected = BOOLToBool(f(fs2fas(rootPath), &freeBytesToCaller2, &totalSize2, &freeSize2)); | 111 | sizeIsDetected = BOOLToBool( |
| 112 | #ifdef Z7_USE_DYN_GetDiskFreeSpaceEx | ||
| 113 | f | ||
| 114 | #else | ||
| 115 | GetDiskFreeSpaceExA | ||
| 116 | #endif | ||
| 117 | (fs2fas(rootPath), &freeBytesToCaller2, &totalSize2, &freeSize2)); | ||
| 103 | totalSize = totalSize2.QuadPart; | 118 | totalSize = totalSize2.QuadPart; |
| 104 | freeSize = freeSize2.QuadPart; | 119 | freeSize = freeSize2.QuadPart; |
| 105 | } | 120 | } |
| @@ -109,14 +124,22 @@ bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize, | |||
| 109 | else | 124 | else |
| 110 | #endif | 125 | #endif |
| 111 | { | 126 | { |
| 127 | #ifdef Z7_USE_DYN_GetDiskFreeSpaceEx | ||
| 112 | const | 128 | const |
| 113 | Func_GetDiskFreeSpaceExW f = Z7_GET_PROC_ADDRESS( | 129 | Func_GetDiskFreeSpaceExW f = Z7_GET_PROC_ADDRESS( |
| 114 | Func_GetDiskFreeSpaceExW, GetModuleHandle(TEXT("kernel32.dll")), | 130 | Func_GetDiskFreeSpaceExW, GetModuleHandle(TEXT("kernel32.dll")), |
| 115 | "GetDiskFreeSpaceExW"); | 131 | "GetDiskFreeSpaceExW"); |
| 116 | if (f) | 132 | if (f) |
| 133 | #endif | ||
| 117 | { | 134 | { |
| 118 | ULARGE_INTEGER freeBytesToCaller2, totalSize2, freeSize2; | 135 | ULARGE_INTEGER freeBytesToCaller2, totalSize2, freeSize2; |
| 119 | sizeIsDetected = BOOLToBool(f(fs2us(rootPath), &freeBytesToCaller2, &totalSize2, &freeSize2)); | 136 | sizeIsDetected = BOOLToBool( |
| 137 | #ifdef Z7_USE_DYN_GetDiskFreeSpaceEx | ||
| 138 | f | ||
| 139 | #else | ||
| 140 | GetDiskFreeSpaceExW | ||
| 141 | #endif | ||
| 142 | (fs2us(rootPath), &freeBytesToCaller2, &totalSize2, &freeSize2)); | ||
| 120 | totalSize = totalSize2.QuadPart; | 143 | totalSize = totalSize2.QuadPart; |
| 121 | freeSize = freeSize2.QuadPart; | 144 | freeSize = freeSize2.QuadPart; |
| 122 | } | 145 | } |
