bool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo) { if (!Close()) return false; if (g_IsNT) { WIN32_FIND_DATAW fd; _handle = ::FindFirstFileW(wildcard, &fd); #ifdef WIN_LONG_PATH if (_handle == INVALID_HANDLE_VALUE) { UString longPath; if (GetLongPath(wildcard, longPath)) _handle = ::FindFirstFileW(longPath, &fd); } #endif if (_handle != INVALID_HANDLE_VALUE) ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo); } else { WIN32_FIND_DATAA fd; _handle = ::FindFirstFileA(UnicodeStringToMultiByte(wildcard, GetCurrentCodePage()), &fd); if (_handle != INVALID_HANDLE_VALUE) ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo); } return (_handle != INVALID_HANDLE_VALUE); }
HANDLE CFindChangeNotification::FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter) { if (g_IsNT) return (_handle = ::FindFirstChangeNotificationW(pathName, BoolToBOOL(watchSubtree), notifyFilter)); return FindFirst(UnicodeStringToMultiByte(pathName, GetCurrentCodePage()), watchSubtree, notifyFilter); }
static void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfoW &fi) { fi.Attrib = fd.dwFileAttributes; fi.CTime = fd.ftCreationTime; fi.ATime = fd.ftLastAccessTime; fi.MTime = fd.ftLastWriteTime; fi.Size = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow; fi.Name = GetUnicodeString(fd.cFileName, GetCurrentCodePage()); #ifndef _WIN32_WCE fi.ReparseTag = fd.dwReserved0; #else fi.ObjectID = fd.dwOID; #endif }
HANDLE CFindChangeNotification::FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter) { if (!g_IsNT) return FindFirst(UnicodeStringToMultiByte(pathName, GetCurrentCodePage()), watchSubtree, notifyFilter); _handle = ::FindFirstChangeNotificationW(pathName, BoolToBOOL(watchSubtree), notifyFilter); #ifdef WIN_LONG_PATH if (!IsHandleAllocated()) { UString longPath; if (GetLongPath(pathName, longPath)) _handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter); } #endif return _handle; }
bool MyGetModuleFileName(HMODULE hModule, UString &result) { result.Empty(); if (g_IsNT) { wchar_t fullPath[MAX_PATH + 2]; DWORD size = ::GetModuleFileNameW(hModule, fullPath, MAX_PATH + 1); if (size <= MAX_PATH && size != 0) { result = fullPath; return true; } return false; } CSysString resultSys; if (!MyGetModuleFileName(hModule, resultSys)) return false; result = MultiByteToUnicodeString(resultSys, GetCurrentCodePage()); return true; }
bool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo) { Close(); if (g_IsNT) { WIN32_FIND_DATAW findData; _handle = ::FindFirstFileW(wildcard, &findData); if (_handleAllocated = (_handle != INVALID_HANDLE_VALUE)) ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo); } else { WIN32_FIND_DATAA findData; _handle = ::FindFirstFileA(UnicodeStringToMultiByte(wildcard, GetCurrentCodePage()), &findData); if (_handleAllocated = (_handle != INVALID_HANDLE_VALUE)) ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo); } return _handleAllocated; }
CSysString GetSysPath(LPCWSTR sysPath) { return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }
FString us2fs(const wchar_t *s) { return UnicodeStringToMultiByte(s, GetCurrentCodePage()); }
UString fs2us(const FString &s) { return MultiByteToUnicodeString((AString)s, GetCurrentCodePage()); }
FString fas2fs(const AString &s) { return MultiByteToUnicodeString(s, GetCurrentCodePage()); }
AString fs2fas(CFSTR s) { return UnicodeStringToMultiByte(s, GetCurrentCodePage()); }
static void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfoW &fi) { WIN_FD_TO_MY_FI(fi, fd); fi.Name = GetUnicodeString(fd.cFileName, GetCurrentCodePage()); }