bool MyGetVolumeInformation( CFSTR rootPath, UString &volumeName, LPDWORD volumeSerialNumber, LPDWORD maximumComponentLength, LPDWORD fileSystemFlags, UString &fileSystemName) { BOOL res; #ifndef _UNICODE if (!g_IsNT) { TCHAR v[MAX_PATH + 2]; v[0] = 0; TCHAR f[MAX_PATH + 2]; f[0] = 0; res = GetVolumeInformation(fs2fas(rootPath), v, MAX_PATH, volumeSerialNumber, maximumComponentLength, fileSystemFlags, f, MAX_PATH); volumeName = MultiByteToUnicodeString(v); fileSystemName = MultiByteToUnicodeString(f); } else #endif { WCHAR v[MAX_PATH + 2]; v[0] = 0; WCHAR f[MAX_PATH + 2]; f[0] = 0; res = GetVolumeInformationW(fs2us(rootPath), v, MAX_PATH, volumeSerialNumber, maximumComponentLength, fileSystemFlags, f, MAX_PATH); volumeName = v; fileSystemName = f; } return BOOLToBool(res); }
bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize) { DWORD numSectorsPerCluster, bytesPerSector, numFreeClusters, numClusters; bool sizeIsDetected = false; #ifndef _UNICODE if (!g_IsNT) { GetDiskFreeSpaceExA_Pointer pGetDiskFreeSpaceEx = (GetDiskFreeSpaceExA_Pointer)GetProcAddress( GetModuleHandle(TEXT("kernel32.dll")), "GetDiskFreeSpaceExA"); if (pGetDiskFreeSpaceEx) { ULARGE_INTEGER freeBytesToCaller2, totalSize2, freeSize2; sizeIsDetected = BOOLToBool(pGetDiskFreeSpaceEx(fs2fas(rootPath), &freeBytesToCaller2, &totalSize2, &freeSize2)); totalSize = totalSize2.QuadPart; freeSize = freeSize2.QuadPart; } if (!::GetDiskFreeSpace(fs2fas(rootPath), &numSectorsPerCluster, &bytesPerSector, &numFreeClusters, &numClusters)) return false; } else #endif { GetDiskFreeSpaceExW_Pointer pGetDiskFreeSpaceEx = (GetDiskFreeSpaceExW_Pointer)GetProcAddress( GetModuleHandle(TEXT("kernel32.dll")), "GetDiskFreeSpaceExW"); if (pGetDiskFreeSpaceEx) { ULARGE_INTEGER freeBytesToCaller2, totalSize2, freeSize2; sizeIsDetected = BOOLToBool(pGetDiskFreeSpaceEx(fs2us(rootPath), &freeBytesToCaller2, &totalSize2, &freeSize2)); totalSize = totalSize2.QuadPart; freeSize = freeSize2.QuadPart; } if (!::GetDiskFreeSpaceW(fs2us(rootPath), &numSectorsPerCluster, &bytesPerSector, &numFreeClusters, &numClusters)) return false; } clusterSize = (UInt64)bytesPerSector * (UInt64)numSectorsPerCluster; if (!sizeIsDetected) { totalSize = clusterSize * (UInt64)numClusters; freeSize = clusterSize * (UInt64)numFreeClusters; } return true; }
bool MySetCurrentDirectory(CFSTR path) { #ifndef _UNICODE if (!g_IsNT) { return BOOLToBool(::SetCurrentDirectory(fs2fas(path))); } else #endif { return BOOLToBool(::SetCurrentDirectoryW(fs2us(path))); } }
UINT MyGetDriveType(CFSTR pathName) { #ifndef _UNICODE if (!g_IsNT) { return GetDriveType(fs2fas(pathName)); } else #endif { return GetDriveTypeW(fs2us(pathName)); } }
bool CLibrary::Load(CFSTR path) throw() { if (!Free()) return false; #ifndef _UNICODE if (!g_IsNT) { _module = ::LoadLibrary(fs2fas(path)); } else #endif { _module = ::LoadLibraryW(fs2us(path)); } return (_module != NULL); }
bool CLibrary::LoadEx(CFSTR path, DWORD flags) throw() { if (!Free()) return false; #ifndef _UNICODE if (!g_IsNT) { _module = ::LoadLibraryEx(fs2fas(path), NULL, flags); } else #endif { _module = ::LoadLibraryExW(fs2us(path), NULL, flags); } return (_module != NULL); }
bool MyGetFullPathName(CFSTR fileName, FString &resFullPath) { resFullPath.Empty(); #ifndef _UNICODE if (!g_IsNT) { TCHAR s[MAX_PATH + 2]; s[0] = 0; LPTSTR fileNamePointer = 0; DWORD needLength = ::GetFullPathName(fs2fas(fileName), MAX_PATH + 1, s, &fileNamePointer); if (needLength == 0 || needLength > MAX_PATH) return false; resFullPath = fas2fs(s); return true; } else #endif { LPWSTR fileNamePointer = 0; WCHAR s[MAX_PATH + 2]; s[0] = 0; DWORD needLength = ::GetFullPathNameW(fs2us(fileName), MAX_PATH + 1, s, &fileNamePointer); if (needLength == 0) return false; if (needLength <= MAX_PATH) { resFullPath = us2fs(s); return true; } #ifdef WIN_LONG_PATH needLength++; UString temp; LPWSTR buffer = temp.GetBuffer(needLength + 1); buffer[0] = 0; DWORD needLength2 = ::GetFullPathNameW(fs2us(fileName), needLength, buffer, &fileNamePointer); temp.ReleaseBuffer(); if (needLength2 > 0 && needLength2 <= needLength) { resFullPath = us2fs(temp); AddTrailingDots(fileName, resFullPath); return true; } #endif return false; } }
DWORD_PTR GetRealIconIndex(CFSTR path, DWORD attrib, int &iconIndex) { #ifndef _UNICODE if (!g_IsNT) { SHFILEINFO shellInfo; DWORD_PTR res = ::SHGetFileInfo(fs2fas(path), FILE_ATTRIBUTE_NORMAL | attrib, &shellInfo, sizeof(shellInfo), SHGFI_USEFILEATTRIBUTES | SHGFI_SYSICONINDEX); iconIndex = shellInfo.iIcon; return res; } else #endif { SHFILEINFOW shellInfo; DWORD_PTR res = ::MySHGetFileInfoW(fs2us(path), FILE_ATTRIBUTE_NORMAL | attrib, &shellInfo, sizeof(shellInfo), SHGFI_USEFILEATTRIBUTES | SHGFI_SYSICONINDEX); iconIndex = shellInfo.iIcon; return res; } }
bool DeleteFileAlways(CFSTR name) { if (!MySetFileAttributes(name, 0)) return false; #ifndef _UNICODE if (!g_IsNT) { if (::DeleteFile(fs2fas(name))) return true; } else #endif { if (::DeleteFileW(fs2us(name))) return true; #ifdef WIN_LONG_PATH UString longPath; if (GetLongPath(name, longPath)) return BOOLToBool(::DeleteFileW(longPath)); #endif } return false; }