bool IsFilenameOnFATVolume(const wchar_t *pszFilename) { VDStringW rootPath(VDFileGetRootPath(pszFilename)); if (VDIsWindowsNT()) { DWORD dwMaxComponentLength; DWORD dwFSFlags; wchar_t szFilesystem[MAX_PATH]; if (!GetVolumeInformationW(rootPath.c_str(), NULL, 0, // Volume name buffer NULL, // Serial number buffer &dwMaxComponentLength, &dwFSFlags, szFilesystem, MAX_PATH)) return false; return !_wcsnicmp(szFilesystem, L"FAT", 3); } else { DWORD dwMaxComponentLength; DWORD dwFSFlags; char szFilesystem[MAX_PATH]; if (!GetVolumeInformationA(VDTextWToA(rootPath).c_str(), NULL, 0, // Volume name buffer NULL, // Serial number buffer &dwMaxComponentLength, &dwFSFlags, szFilesystem, sizeof szFilesystem)) return false; return !_strnicmp(szFilesystem, "FAT", 3); } }
sint64 VDGetDiskFreeSpace(const wchar_t *path) { typedef BOOL (WINAPI *tpGetDiskFreeSpaceExA)(LPCSTR lpDirectoryName, PULARGE_INTEGER lpFreeBytesAvailable, PULARGE_INTEGER lpTotalNumberOfBytes, PULARGE_INTEGER lpTotalNumberOfFreeBytes); typedef BOOL (WINAPI *tpGetDiskFreeSpaceExW)(LPCWSTR lpDirectoryName, PULARGE_INTEGER lpFreeBytesAvailable, PULARGE_INTEGER lpTotalNumberOfBytes, PULARGE_INTEGER lpTotalNumberOfFreeBytes); static bool sbChecked = false; static tpGetDiskFreeSpaceExA spGetDiskFreeSpaceExA; static tpGetDiskFreeSpaceExW spGetDiskFreeSpaceExW; if (!sbChecked) { HMODULE hmodKernel = GetModuleHandle("kernel32.dll"); spGetDiskFreeSpaceExA = (tpGetDiskFreeSpaceExA)GetProcAddress(hmodKernel, "GetDiskFreeSpaceExA"); spGetDiskFreeSpaceExW = (tpGetDiskFreeSpaceExW)GetProcAddress(hmodKernel, "GetDiskFreeSpaceExW"); sbChecked = true; } if (spGetDiskFreeSpaceExA) { BOOL success; uint64 freeClient, totalBytes, totalFreeBytes; VDStringW directoryName(path); if (!directoryName.empty()) { wchar_t c = directoryName[directoryName.length()-1]; if (c != L'/' && c != L'\\') directoryName += L'\\'; } if ((LONG)GetVersion() < 0) success = spGetDiskFreeSpaceExA(VDTextWToA(directoryName).c_str(), (PULARGE_INTEGER)&freeClient, (PULARGE_INTEGER)&totalBytes, (PULARGE_INTEGER)&totalFreeBytes); else success = spGetDiskFreeSpaceExW(directoryName.c_str(), (PULARGE_INTEGER)&freeClient, (PULARGE_INTEGER)&totalBytes, (PULARGE_INTEGER)&totalFreeBytes); return success ? (sint64)freeClient : -1; } else { DWORD sectorsPerCluster, bytesPerSector, freeClusters, totalClusters; BOOL success; VDStringW rootPath(VDFileGetRootPath(path)); if ((LONG)GetVersion() < 0) success = GetDiskFreeSpaceA(rootPath.empty() ? NULL : VDTextWToA(rootPath).c_str(), §orsPerCluster, &bytesPerSector, &freeClusters, &totalClusters); else success = GetDiskFreeSpaceW(rootPath.empty() ? NULL : rootPath.c_str(), §orsPerCluster, &bytesPerSector, &freeClusters, &totalClusters); return success ? (sint64)((uint64)sectorsPerCluster * bytesPerSector * freeClusters) : -1; } }