bool MySetCurrentDirectory(CFSTR path) { #ifndef _UNICODE if (!g_IsNT) { return BOOLToBool(::SetCurrentDirectory(fs2fas(path))); } else #endif { return BOOLToBool(::SetCurrentDirectoryW(fs2us(path))); } }
bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds) { s[0] = '\0'; SYSTEMTIME st; if(!BOOLToBool(FileTimeToSystemTime(&ft, &st))) return false; /* UIntToStringSpec(st.wYear, s, 4); strcat(s, "-"); UIntToStringSpec(st.wMonth, s + strlen(s), 2); strcat(s, "-"); UIntToStringSpec(st.wDay, s + strlen(s), 2); if (includeTime) { strcat(s, " "); UIntToStringSpec(st.wHour, s + strlen(s), 2); strcat(s, ":"); UIntToStringSpec(st.wMinute, s + strlen(s), 2); if (includeSeconds) { strcat(s, ":"); UIntToStringSpec(st.wSecond, s + strlen(s), 2); } } */ sprintf(s, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay); if (includeTime) { sprintf(s + strlen(s), " %02d:%02d", st.wHour, st.wMinute); if (includeSeconds) sprintf(s + strlen(s), ":%02d", st.wSecond); } return true; }
bool CMenu::AppendItem(UINT flags, UINT_PTR newItemID, LPCWSTR newItem) { if (g_IsNT) return BOOLToBool(::AppendMenuW(_menu, flags, newItemID, newItem)); else return AppendItem(flags, newItemID, GetSystemString(newItem)); }
bool CClipboard::Close() { if (!m_Open) return true; m_Open = !BOOLToBool(CloseClipboard()); return !m_Open; }
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 MyGetVolumeInformation( LPCWSTR rootPathName, UString &volumeName, LPDWORD volumeSerialNumber, LPDWORD maximumComponentLength, LPDWORD fileSystemFlags, UString &fileSystemName) { if (g_IsNT) { bool result = BOOLToBool(GetVolumeInformationW( rootPathName, volumeName.GetBuffer(MAX_PATH), MAX_PATH, volumeSerialNumber, maximumComponentLength, fileSystemFlags, fileSystemName.GetBuffer(MAX_PATH), MAX_PATH)); volumeName.ReleaseBuffer(); fileSystemName.ReleaseBuffer(); return result; } AString volumeNameA, fileSystemNameA; bool result = MyGetVolumeInformation(GetSystemString(rootPathName), volumeNameA, volumeSerialNumber, maximumComponentLength, fileSystemFlags,fileSystemNameA); if (result) { volumeName = GetUnicodeString(volumeNameA); fileSystemName = GetUnicodeString(fileSystemNameA); } return result; }
bool CFileBase::Close() { if(!_fileIsOpen) return true; bool result = BOOLToBool(::CloseHandle(_handle)); _fileIsOpen = !result; return result; }
bool CFindFile::Close() { if(!_handleAllocated) return true; bool result = BOOLToBool(::FindClose(_handle)); _handleAllocated = !result; return result; }
bool CFindFile::FindNext(CFileInfo &fileInfo) { WIN32_FIND_DATA fd; bool result = BOOLToBool(::FindNextFile(_handle, &fd)); if (result) ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo); return result; }
bool COutFile::WritePart(const void *data, UInt32 size, UInt32 &processedSize) { if (size > kChunkSizeMax) size = kChunkSizeMax; DWORD processedLoc = 0; bool res = BOOLToBool(::WriteFile(_handle, data, size, &processedLoc, NULL)); processedSize = (UInt32)processedLoc; return res; }
bool CClipboard::Open(HWND wndNewOwner) { #ifdef _WIN32 m_Open = BOOLToBool(::OpenClipboard(wndNewOwner)); #else m_Open = wxTheClipboard->Open(); #endif return m_Open; }
bool CFindChangeNotification::Close() { if(_handle == INVALID_HANDLE_VALUE || _handle == 0) return true; bool result = BOOLToBool(::FindCloseChangeNotification(_handle)); if (result) _handle = INVALID_HANDLE_VALUE; return result; }
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 GetPathFromIDList(LPCITEMIDLIST itemIDList, UString &path) { path.Empty(); SHGetPathFromIDListWP shGetPathFromIDListW = (SHGetPathFromIDListWP) ::GetProcAddress(::GetModuleHandleW(L"shell32.dll"), "SHGetPathFromIDListW"); if (shGetPathFromIDListW == 0) return false; bool result = BOOLToBool(shGetPathFromIDListW(itemIDList, path.GetBuffer(MAX_PATH * 2))); path.ReleaseBuffer(); return result; }
bool CClipboard::Close() { if (!m_Open) return true; #ifdef _WIN32 m_Open = !BOOLToBool(CloseClipboard()); #else wxTheClipboard->Close(); m_Open = false; #endif return !m_Open; }
bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds) { #ifdef _WIN32 s[0] = '\0'; SYSTEMTIME st; if (!BOOLToBool(FileTimeToSystemTime(&ft, &st))) return false; s = UIntToStringSpec(0, st.wYear, s, 4); s = UIntToStringSpec('-', st.wMonth, s, 2); s = UIntToStringSpec('-', st.wDay, s, 2); if (includeTime) { s = UIntToStringSpec(' ', st.wHour, s, 2); s = UIntToStringSpec(':', st.wMinute, s, 2); if (includeSeconds) UIntToStringSpec(':', st.wSecond, s, 2); } /* sprintf(s, "%04d-%02d-%02d", st.wYear, st.wMonth, st.wDay); if (includeTime) { sprintf(s + strlen(s), " %02d:%02d", st.wHour, st.wMinute); if (includeSeconds) sprintf(s + strlen(s), ":%02d", st.wSecond); } */ #else BOOLEAN WINAPI RtlTimeToSecondsSince1970( const LARGE_INTEGER *Time, DWORD *Seconds ); FILETIME filetime; LocalFileTimeToFileTime(&ft, &filetime); LARGE_INTEGER ltime; ltime.QuadPart = filetime.dwHighDateTime; ltime.QuadPart = (ltime.QuadPart << 32) | filetime.dwLowDateTime; DWORD dw; RtlTimeToSecondsSince1970(<ime, &dw ); time_t timep = (time_t)dw; struct tm * date = localtime(&timep); sprintf(s, "%04d-%02d-%02d", date->tm_year+1900, date->tm_mon+1,date->tm_mday); if (includeTime) { sprintf(s + strlen(s), " %02d:%02d", date->tm_hour,date->tm_min); if (includeSeconds) sprintf(s + strlen(s), ":%02d", date->tm_sec); } #endif return true; }
bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds) { s[0] = '\0'; SYSTEMTIME st; if (!BOOLToBool(FileTimeToSystemTime(&ft, &st))) return false; s = UIntToStringSpec(0, st.wYear, s, 4); s = UIntToStringSpec('-', st.wMonth, s, 2); s = UIntToStringSpec('-', st.wDay, s, 2); if (includeTime) { s = UIntToStringSpec(' ', st.wHour, s, 2); s = UIntToStringSpec(':', st.wMinute, s, 2); if (includeSeconds) UIntToStringSpec(':', st.wSecond, s, 2); } return true; }
bool MyGetVolumeInformation( LPCTSTR rootPathName, CSysString &volumeName, LPDWORD volumeSerialNumber, LPDWORD maximumComponentLength, LPDWORD fileSystemFlags, CSysString &fileSystemName) { bool result = BOOLToBool(GetVolumeInformation( rootPathName, volumeName.GetBuffer(MAX_PATH), MAX_PATH, volumeSerialNumber, maximumComponentLength, fileSystemFlags, fileSystemName.GetBuffer(MAX_PATH), MAX_PATH)); volumeName.ReleaseBuffer(); fileSystemName.ReleaseBuffer(); return result; }
bool ConvertFileTimeToString(const FILETIME &ft, char *s, bool includeTime, bool includeSeconds) throw() { SYSTEMTIME st; if (!BOOLToBool(FileTimeToSystemTime(&ft, &st))) { *s = 0; return false; } unsigned val = st.wYear; if (val >= 10000) { *s++ = (char)('0' + val / 10000); val %= 10000; } { s[3] = (char)('0' + val % 10); val /= 10; s[2] = (char)('0' + val % 10); val /= 10; s[1] = (char)('0' + val % 10); s[0] = (char)('0' + val / 10); s += 4; } UINT_TO_STR_2('-', st.wMonth); UINT_TO_STR_2('-', st.wDay); if (includeTime) { UINT_TO_STR_2(' ', st.wHour); UINT_TO_STR_2(':', st.wMinute); if (includeSeconds) { UINT_TO_STR_2(':', st.wSecond); /* *s++ = '.'; unsigned val = st.wMilliseconds; s[2] = (char)('0' + val % 10); val /= 10; s[1] = (char)('0' + val % 10); s[0] = (char)('0' + val / 10); s += 3; */ } } *s = 0; return true; }
bool MyGetDiskFreeSpace(LPCTSTR rootPathName, UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize) { GetDiskFreeSpaceExPointer pGetDiskFreeSpaceEx = (GetDiskFreeSpaceExPointer)GetProcAddress( GetModuleHandle(TEXT("kernel32.dll")), "GetDiskFreeSpaceExA"); bool sizeIsDetected = false; if (pGetDiskFreeSpaceEx) { ULARGE_INTEGER i64FreeBytesToCaller, totalSize2, freeSize2; sizeIsDetected = BOOLToBool(pGetDiskFreeSpaceEx(rootPathName, &i64FreeBytesToCaller, &totalSize2, &freeSize2)); totalSize = totalSize2.QuadPart; freeSize = freeSize2.QuadPart; } DWORD numSectorsPerCluster; DWORD bytesPerSector; DWORD numberOfFreeClusters; DWORD totalNumberOfClusters; if (!::GetDiskFreeSpace(rootPathName, &numSectorsPerCluster, &bytesPerSector, &numberOfFreeClusters, &totalNumberOfClusters)) return false; clusterSize = (UInt64)bytesPerSector * (UInt64)numSectorsPerCluster; if (!sizeIsDetected) { totalSize = clusterSize * (UInt64)totalNumberOfClusters; freeSize = clusterSize * (UInt64)numberOfFreeClusters; } return true; }
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; }
bool ClipboardIsFormatAvailableHDROP() { return BOOLToBool(IsClipboardFormatAvailable(CF_HDROP)); }
bool MyGetOpenFileName(HWND hwnd, LPCWSTR title, LPCWSTR fullFileName, LPCWSTR s, UString &resPath) { const int kBufferSize = MAX_PATH * 2; #ifndef _UNICODE if (!g_IsNT) { CHAR buffer[kBufferSize]; MyStringCopy(buffer, (const char *)GetSystemString(fullFileName)); OPENFILENAME info; info.lStructSize = sizeof(info); info.hwndOwner = hwnd; info.hInstance = 0; const int kFilterBufferSize = MAX_PATH; CHAR filterBuffer[kFilterBufferSize]; CDoubleZeroStringListA doubleZeroStringList; doubleZeroStringList.Add(GetSystemString(s)); doubleZeroStringList.Add("*.*"); doubleZeroStringList.SetForBuffer(filterBuffer); info.lpstrFilter = filterBuffer; info.lpstrCustomFilter = NULL; info.nMaxCustFilter = 0; info.nFilterIndex = 0; info.lpstrFile = buffer; info.nMaxFile = kBufferSize; info.lpstrFileTitle = NULL; info.nMaxFileTitle = 0; info.lpstrInitialDir= NULL; info.lpstrTitle = 0; AString titleA; if (title != 0) { titleA = GetSystemString(title); info.lpstrTitle = titleA; } info.Flags = OFN_EXPLORER | OFN_HIDEREADONLY; info.nFileOffset = 0; info.nFileExtension = 0; info.lpstrDefExt = NULL; info.lCustData = 0; info.lpfnHook = NULL; info.lpTemplateName = NULL; bool res = BOOLToBool(::GetOpenFileNameA(&info)); resPath = GetUnicodeString(buffer); return res; } else #endif { WCHAR buffer[kBufferSize]; MyStringCopy(buffer, fullFileName); OPENFILENAMEW info; info.lStructSize = sizeof(info); info.hwndOwner = hwnd; info.hInstance = 0; const int kFilterBufferSize = MAX_PATH; WCHAR filterBuffer[kFilterBufferSize]; CDoubleZeroStringListW doubleZeroStringList; doubleZeroStringList.Add(s); doubleZeroStringList.Add(L"*.*"); doubleZeroStringList.SetForBuffer(filterBuffer); info.lpstrFilter = filterBuffer; info.lpstrCustomFilter = NULL; info.nMaxCustFilter = 0; info.nFilterIndex = 0; info.lpstrFile = buffer; info.nMaxFile = kBufferSize; info.lpstrFileTitle = NULL; info.nMaxFileTitle = 0; info.lpstrInitialDir= NULL; info.lpstrTitle = title; info.Flags = OFN_EXPLORER | OFN_HIDEREADONLY; info.nFileOffset = 0; info.nFileExtension = 0; info.lpstrDefExt = NULL; info.lCustData = 0; info.lpfnHook = NULL; info.lpTemplateName = NULL; bool res = BOOLToBool(::GetOpenFileNameW(&info)); resPath = buffer; return res; } }
bool CClipboard::Open(HWND wndNewOwner) { m_Open = BOOLToBool(::OpenClipboard(wndNewOwner)); return m_Open; }
static bool GetWorkAreaRect(RECT *rect) { // use another function for multi-monitor. return BOOLToBool(::SystemParametersInfo(SPI_GETWORKAREA, 0, rect, 0)); }
bool CDialog::MoveItem(int id, int x, int y, int width, int height, bool repaint) { return BOOLToBool(::MoveWindow(GetItem(id), x, y, width, height, BoolToBOOL(repaint))); }
bool CStartupInfo::Control(HANDLE pluginHandle, int command, void *param) { return BOOLToBool(m_Data.Control(pluginHandle, command, param)); }
bool COutFile::SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime) { return BOOLToBool(::SetFileTime(_handle, creationTime, lastAccessTime, lastWriteTime)); }
bool COutFile::SetEndOfFile() { return BOOLToBool(::SetEndOfFile(_handle)); }
bool MyGetOpenFileName(HWND hwnd, LPCWSTR title, LPCWSTR initialDir, LPCWSTR filePath, LPCWSTR filterDescription, LPCWSTR filter, UString &resPath #ifdef UNDER_CE , bool openFolder #endif ) { const unsigned kBufSize = MAX_PATH * 2; const unsigned kFilterBufSize = MAX_PATH; if (!filter) filter = L"*.*"; #ifndef _UNICODE if (!g_IsNT) { CHAR buf[kBufSize]; MyStringCopy(buf, (const char *)GetSystemString(filePath)); // OPENFILENAME_NT4A OPENFILENAMEA p; memset(&p, 0, sizeof(p)); p.lStructSize = my_compatib_OPENFILENAMEA_size; p.hwndOwner = hwnd; CHAR filterBuf[kFilterBufSize]; { CDoubleZeroStringListA dz(filterBuf, kFilterBufSize); dz.Add(GetSystemString(filterDescription ? filterDescription : filter)); dz.Add(GetSystemString(filter)); dz.Finish(); p.lpstrFilter = filterBuf; p.nFilterIndex = 1; } p.lpstrFile = buf; p.nMaxFile = kBufSize; CONV_U_To_A(p.lpstrInitialDir, initialDir, initialDirA); CONV_U_To_A(p.lpstrTitle, title, titleA); p.Flags = OFN_EXPLORER | OFN_HIDEREADONLY; bool res = BOOLToBool(::GetOpenFileNameA(&p)); resPath = GetUnicodeString(buf); return res; } else #endif { WCHAR buf[kBufSize]; MyStringCopy(buf, filePath); // OPENFILENAME_NT4W OPENFILENAMEW p; memset(&p, 0, sizeof(p)); p.lStructSize = my_compatib_OPENFILENAMEW_size; p.hwndOwner = hwnd; WCHAR filterBuf[kFilterBufSize]; { CDoubleZeroStringListW dz(filterBuf, kFilterBufSize); dz.Add(filterDescription ? filterDescription : filter); dz.Add(filter); dz.Finish(); p.lpstrFilter = filterBuf; p.nFilterIndex = 1; } p.lpstrFile = buf; p.nMaxFile = kBufSize; p.lpstrInitialDir = initialDir; p.lpstrTitle = title; p.Flags = OFN_EXPLORER | OFN_HIDEREADONLY #ifdef UNDER_CE | (openFolder ? (MY__OFN_PROJECT | MY__OFN_SHOW_ALL) : 0) #endif ; bool res = BOOLToBool(::GetOpenFileNameW(&p)); resPath = buf; return res; } }