1370b324cSopenharmony_ci// Windows/FileSystem.cpp 2370b324cSopenharmony_ci 3370b324cSopenharmony_ci#include "StdAfx.h" 4370b324cSopenharmony_ci 5370b324cSopenharmony_ci#ifndef UNDER_CE 6370b324cSopenharmony_ci 7370b324cSopenharmony_ci#ifndef _UNICODE 8370b324cSopenharmony_ci#include "../Common/StringConvert.h" 9370b324cSopenharmony_ci#endif 10370b324cSopenharmony_ci 11370b324cSopenharmony_ci#include "FileSystem.h" 12370b324cSopenharmony_ci#include "Defs.h" 13370b324cSopenharmony_ci 14370b324cSopenharmony_ci#ifndef _UNICODE 15370b324cSopenharmony_ciextern bool g_IsNT; 16370b324cSopenharmony_ci#endif 17370b324cSopenharmony_ci 18370b324cSopenharmony_cinamespace NWindows { 19370b324cSopenharmony_cinamespace NFile { 20370b324cSopenharmony_cinamespace NSystem { 21370b324cSopenharmony_ci 22370b324cSopenharmony_ci#ifdef _WIN32 23370b324cSopenharmony_ci 24370b324cSopenharmony_cibool MyGetVolumeInformation( 25370b324cSopenharmony_ci CFSTR rootPath, 26370b324cSopenharmony_ci UString &volumeName, 27370b324cSopenharmony_ci LPDWORD volumeSerialNumber, 28370b324cSopenharmony_ci LPDWORD maximumComponentLength, 29370b324cSopenharmony_ci LPDWORD fileSystemFlags, 30370b324cSopenharmony_ci UString &fileSystemName) 31370b324cSopenharmony_ci{ 32370b324cSopenharmony_ci BOOL res; 33370b324cSopenharmony_ci #ifndef _UNICODE 34370b324cSopenharmony_ci if (!g_IsNT) 35370b324cSopenharmony_ci { 36370b324cSopenharmony_ci TCHAR v[MAX_PATH + 2]; v[0] = 0; 37370b324cSopenharmony_ci TCHAR f[MAX_PATH + 2]; f[0] = 0; 38370b324cSopenharmony_ci res = GetVolumeInformation(fs2fas(rootPath), 39370b324cSopenharmony_ci v, MAX_PATH, 40370b324cSopenharmony_ci volumeSerialNumber, maximumComponentLength, fileSystemFlags, 41370b324cSopenharmony_ci f, MAX_PATH); 42370b324cSopenharmony_ci volumeName = MultiByteToUnicodeString(v); 43370b324cSopenharmony_ci fileSystemName = MultiByteToUnicodeString(f); 44370b324cSopenharmony_ci } 45370b324cSopenharmony_ci else 46370b324cSopenharmony_ci #endif 47370b324cSopenharmony_ci { 48370b324cSopenharmony_ci WCHAR v[MAX_PATH + 2]; v[0] = 0; 49370b324cSopenharmony_ci WCHAR f[MAX_PATH + 2]; f[0] = 0; 50370b324cSopenharmony_ci res = GetVolumeInformationW(fs2us(rootPath), 51370b324cSopenharmony_ci v, MAX_PATH, 52370b324cSopenharmony_ci volumeSerialNumber, maximumComponentLength, fileSystemFlags, 53370b324cSopenharmony_ci f, MAX_PATH); 54370b324cSopenharmony_ci volumeName = v; 55370b324cSopenharmony_ci fileSystemName = f; 56370b324cSopenharmony_ci } 57370b324cSopenharmony_ci return BOOLToBool(res); 58370b324cSopenharmony_ci} 59370b324cSopenharmony_ci 60370b324cSopenharmony_ciUINT MyGetDriveType(CFSTR pathName) 61370b324cSopenharmony_ci{ 62370b324cSopenharmony_ci #ifndef _UNICODE 63370b324cSopenharmony_ci if (!g_IsNT) 64370b324cSopenharmony_ci { 65370b324cSopenharmony_ci return GetDriveType(fs2fas(pathName)); 66370b324cSopenharmony_ci } 67370b324cSopenharmony_ci else 68370b324cSopenharmony_ci #endif 69370b324cSopenharmony_ci { 70370b324cSopenharmony_ci return GetDriveTypeW(fs2us(pathName)); 71370b324cSopenharmony_ci } 72370b324cSopenharmony_ci} 73370b324cSopenharmony_ci 74370b324cSopenharmony_citypedef BOOL (WINAPI * Func_GetDiskFreeSpaceExA)( 75370b324cSopenharmony_ci LPCSTR lpDirectoryName, // directory name 76370b324cSopenharmony_ci PULARGE_INTEGER lpFreeBytesAvailable, // bytes available to caller 77370b324cSopenharmony_ci PULARGE_INTEGER lpTotalNumberOfBytes, // bytes on disk 78370b324cSopenharmony_ci PULARGE_INTEGER lpTotalNumberOfFreeBytes // free bytes on disk 79370b324cSopenharmony_ci); 80370b324cSopenharmony_ci 81370b324cSopenharmony_citypedef BOOL (WINAPI * Func_GetDiskFreeSpaceExW)( 82370b324cSopenharmony_ci LPCWSTR lpDirectoryName, // directory name 83370b324cSopenharmony_ci PULARGE_INTEGER lpFreeBytesAvailable, // bytes available to caller 84370b324cSopenharmony_ci PULARGE_INTEGER lpTotalNumberOfBytes, // bytes on disk 85370b324cSopenharmony_ci PULARGE_INTEGER lpTotalNumberOfFreeBytes // free bytes on disk 86370b324cSopenharmony_ci); 87370b324cSopenharmony_ci 88370b324cSopenharmony_cibool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize) 89370b324cSopenharmony_ci{ 90370b324cSopenharmony_ci DWORD numSectorsPerCluster, bytesPerSector, numFreeClusters, numClusters; 91370b324cSopenharmony_ci bool sizeIsDetected = false; 92370b324cSopenharmony_ci #ifndef _UNICODE 93370b324cSopenharmony_ci if (!g_IsNT) 94370b324cSopenharmony_ci { 95370b324cSopenharmony_ci const 96370b324cSopenharmony_ci Func_GetDiskFreeSpaceExA f = Z7_GET_PROC_ADDRESS( 97370b324cSopenharmony_ci Func_GetDiskFreeSpaceExA, GetModuleHandle(TEXT("kernel32.dll")), 98370b324cSopenharmony_ci "GetDiskFreeSpaceExA"); 99370b324cSopenharmony_ci if (f) 100370b324cSopenharmony_ci { 101370b324cSopenharmony_ci ULARGE_INTEGER freeBytesToCaller2, totalSize2, freeSize2; 102370b324cSopenharmony_ci sizeIsDetected = BOOLToBool(f(fs2fas(rootPath), &freeBytesToCaller2, &totalSize2, &freeSize2)); 103370b324cSopenharmony_ci totalSize = totalSize2.QuadPart; 104370b324cSopenharmony_ci freeSize = freeSize2.QuadPart; 105370b324cSopenharmony_ci } 106370b324cSopenharmony_ci if (!::GetDiskFreeSpace(fs2fas(rootPath), &numSectorsPerCluster, &bytesPerSector, &numFreeClusters, &numClusters)) 107370b324cSopenharmony_ci return false; 108370b324cSopenharmony_ci } 109370b324cSopenharmony_ci else 110370b324cSopenharmony_ci #endif 111370b324cSopenharmony_ci { 112370b324cSopenharmony_ci const 113370b324cSopenharmony_ci Func_GetDiskFreeSpaceExW f = Z7_GET_PROC_ADDRESS( 114370b324cSopenharmony_ci Func_GetDiskFreeSpaceExW, GetModuleHandle(TEXT("kernel32.dll")), 115370b324cSopenharmony_ci "GetDiskFreeSpaceExW"); 116370b324cSopenharmony_ci if (f) 117370b324cSopenharmony_ci { 118370b324cSopenharmony_ci ULARGE_INTEGER freeBytesToCaller2, totalSize2, freeSize2; 119370b324cSopenharmony_ci sizeIsDetected = BOOLToBool(f(fs2us(rootPath), &freeBytesToCaller2, &totalSize2, &freeSize2)); 120370b324cSopenharmony_ci totalSize = totalSize2.QuadPart; 121370b324cSopenharmony_ci freeSize = freeSize2.QuadPart; 122370b324cSopenharmony_ci } 123370b324cSopenharmony_ci if (!::GetDiskFreeSpaceW(fs2us(rootPath), &numSectorsPerCluster, &bytesPerSector, &numFreeClusters, &numClusters)) 124370b324cSopenharmony_ci return false; 125370b324cSopenharmony_ci } 126370b324cSopenharmony_ci clusterSize = (UInt64)bytesPerSector * (UInt64)numSectorsPerCluster; 127370b324cSopenharmony_ci if (!sizeIsDetected) 128370b324cSopenharmony_ci { 129370b324cSopenharmony_ci totalSize = clusterSize * (UInt64)numClusters; 130370b324cSopenharmony_ci freeSize = clusterSize * (UInt64)numFreeClusters; 131370b324cSopenharmony_ci } 132370b324cSopenharmony_ci return true; 133370b324cSopenharmony_ci} 134370b324cSopenharmony_ci 135370b324cSopenharmony_ci#endif 136370b324cSopenharmony_ci 137370b324cSopenharmony_ci}}} 138370b324cSopenharmony_ci 139370b324cSopenharmony_ci#endif 140