📄 pfwinfolder.cpp
字号:
/////////////////////////////////////////////////////////////////////////////////////////////////////// PowerFish core library// Copyright (C) 1997-2001 Camilla Drefvenborg <elmindreda@home.se>//// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA/////////////////////////////////////////////////////////////////////////////////////////////////////#include <PfBase.h>#include <PfTemplate.h>#include <PfString.h>#include <PfFile.h>#include <PfFolder.h>#include <windows.h>#include <objbase.h>#include <shlobj.h>///////////////////////////////////////////////////////////////////////////////////////////////////const char* PfGetTempPath(void){ // TODO: make thread safe! static char szBuffer[_MAX_PATH + 1]; if (!GetTempPath(sizeof(szBuffer), szBuffer)) return NULL; return szBuffer;}const char* PfGetCurrentPath(void){ // TODO: make thread safe! static char szBuffer[_MAX_PATH + 1]; if (!GetCurrentDirectory(sizeof(szBuffer), szBuffer)) return NULL; return szBuffer;}bool PfSetCurrentPath(const char* szPathName){ PFASSERT(szPathName); if (!SetCurrentDirectory(szPathName)) return false; return true;}bool PfCreateFolder(const char* szPathName){ PFASSERT(szPathName); if (!CreateDirectory(szPathName, NULL)) return false; return true;}bool PfDestroyFolder(const char* szPathName){ PFASSERT(szPathName); if (!RemoveDirectory(szPathName)) return false; return true;}bool PfSearchPathForFiles(const char* szPathName, const char* szPattern, PfFileList& rFiles){ PFASSERT(szPathName); PFASSERT(szPattern); char szSearchPattern[_MAX_PATH + 1]; PfString::FormatS(szSearchPattern, "%s\\%s", szPathName, szPattern); HANDLE hFindFile; WIN32_FIND_DATA wfd; hFindFile = FindFirstFile(szSearchPattern, &wfd); if (hFindFile == INVALID_HANDLE_VALUE) return false; do { PfFileItem* pFileItem = new PfFileItem(); if (!PfGetFileInfo(wfd.cFileName, szPathName, *pFileItem)) { delete pFileItem; pFileItem = NULL; continue; } rFiles.AttachItemFirst(pFileItem); } while (FindNextFile(hFindFile, &wfd)); FindClose(hFindFile); hFindFile = NULL; return true;}bool PfSearchPathForFolders(const char* szPathName, const char* szPattern, PfFolderList& rFolders){ PFASSERT(szPathName); PFASSERT(szPattern); char szSearchPattern[_MAX_PATH + 1]; PfString::FormatS(szSearchPattern, "%s\\%s", szPathName, szPattern); HANDLE hFindFile; WIN32_FIND_DATA wfd; hFindFile = FindFirstFile(szSearchPattern, &wfd); if (hFindFile == INVALID_HANDLE_VALUE) return false; do { PfFolderItem* pFolderItem = new PfFolderItem(); char szFolderPathName[_MAX_PATH + 1]; PfString::FormatS(szFolderPathName, "%s\\%s", szPathName, wfd.cFileName); if (!PfGetFolderInfo(szFolderPathName, *pFolderItem)) { delete pFolderItem; pFolderItem = NULL; continue; } rFolders.AttachItemFirst(pFolderItem); } while (FindNextFile(hFindFile, &wfd)); FindClose(hFindFile); hFindFile = NULL; return true;}bool PfIsFolder(const char* szPathName){ PFASSERT(szPathName); DWORD dwAttributes = GetFileAttributes(szPathName); if (dwAttributes == (DWORD) -1) return false; if (!(dwAttributes & FILE_ATTRIBUTE_DIRECTORY)) return false; return true;}const char* PfRequestUserFolderSelection(void){ // TODO: make thread safe! static char szFolderPath[_MAX_PATH + 1]; if (FAILED(CoInitialize(NULL))) return false; BROWSEINFO bi; bi.hwndOwner = GetActiveWindow(); bi.pidlRoot = NULL; bi.pszDisplayName = szFolderPath; bi.lpszTitle = "Select folder"; bi.ulFlags = BIF_EDITBOX | BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS | BIF_VALIDATE; bi.lpfn = NULL; bi.lParam = NULL; bi.iImage = 0; LPITEMIDLIST pidl = SHBrowseForFolder(&bi); if (!pidl) { CoUninitialize(); return NULL; } BOOL bResult = SHGetPathFromIDList(pidl, szFolderPath); LPMALLOC pMalloc; if (SUCCEEDED(SHGetMalloc(&pMalloc))) { pMalloc->Free(pidl); pidl = NULL; pMalloc->Release(); pMalloc = NULL; } CoUninitialize(); if (bResult) return szFolderPath; else return NULL;}///////////////////////////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -