std::vector<PSPFileInfo> DirectoryFileSystem::GetDirListing(std::string path) { std::vector<PSPFileInfo> myVector; #ifdef _WIN32_NO_MINGW WIN32_FIND_DATA findData; HANDLE hFind; std::string w32path = GetLocalPath(path) + "\\*.*"; hFind = FindFirstFile(ConvertUTF8ToWString(w32path).c_str(), &findData); if (hFind == INVALID_HANDLE_VALUE) { return myVector; //the empty list } while (true) { PSPFileInfo entry; if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) entry.type = FILETYPE_DIRECTORY; else entry.type = FILETYPE_NORMAL; // TODO: Make this more correct? entry.access = entry.type == FILETYPE_NORMAL ? 0666 : 0777; // TODO: is this just for .. or all subdirectories? Need to add a directory to the test // to find out. Also why so different than the old test results? if (!wcscmp(findData.cFileName, L"..") ) entry.size = 4096; else entry.size = findData.nFileSizeLow | ((u64)findData.nFileSizeHigh<<32); entry.name = ConvertWStringToUTF8(findData.cFileName); tmFromFiletime(entry.atime, findData.ftLastAccessTime); tmFromFiletime(entry.ctime, findData.ftCreationTime); tmFromFiletime(entry.mtime, findData.ftLastWriteTime); myVector.push_back(entry); int retval = FindNextFile(hFind, &findData); if (!retval) break; } FindClose(hFind); #else dirent *dirp; std::string localPath = GetLocalPath(path); DIR *dp = opendir(localPath.c_str()); #if HOST_IS_CASE_SENSITIVE if(dp == NULL && FixPathCase(basePath,path, FPC_FILE_MUST_EXIST)) { // May have failed due to case sensitivity, try again localPath = GetLocalPath(path); dp = opendir(localPath.c_str()); } #endif if (dp == NULL) { ERROR_LOG(FILESYS,"Error opening directory %s\n",path.c_str()); return myVector; } while ((dirp = readdir(dp)) != NULL) { PSPFileInfo entry; struct stat s; std::string fullName = GetLocalPath(path) + "/"+dirp->d_name; stat(fullName.c_str(), &s); if (S_ISDIR(s.st_mode)) entry.type = FILETYPE_DIRECTORY; else entry.type = FILETYPE_NORMAL; entry.access = s.st_mode & 0x1FF; entry.name = dirp->d_name; entry.size = s.st_size; localtime_r((time_t*)&s.st_atime,&entry.atime); localtime_r((time_t*)&s.st_ctime,&entry.ctime); localtime_r((time_t*)&s.st_mtime,&entry.mtime); myVector.push_back(entry); } closedir(dp); #endif return myVector; }
std::vector<PSPFileInfo> VirtualDiscFileSystem::GetDirListing(std::string path) { std::vector<PSPFileInfo> myVector; #ifdef _WIN32 WIN32_FIND_DATA findData; HANDLE hFind; // TODO: Handler files that are virtual might not be listed. std::string w32path = GetLocalPath(path) + "\\*.*"; hFind = FindFirstFile(ConvertUTF8ToWString(w32path).c_str(), &findData); if (hFind == INVALID_HANDLE_VALUE) { return myVector; //the empty list } for (BOOL retval = 1; retval; retval = FindNextFile(hFind, &findData)) { if (!wcscmp(findData.cFileName, L"..") || !wcscmp(findData.cFileName, L".")) { continue; } PSPFileInfo entry; if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { entry.type = FILETYPE_DIRECTORY; } else { entry.type = FILETYPE_NORMAL; } entry.access = FILEACCESS_READ; entry.size = findData.nFileSizeLow | ((u64)findData.nFileSizeHigh<<32); entry.name = ConvertWStringToUTF8(findData.cFileName); tmFromFiletime(entry.atime, findData.ftLastAccessTime); tmFromFiletime(entry.ctime, findData.ftCreationTime); tmFromFiletime(entry.mtime, findData.ftLastWriteTime); entry.isOnSectorSystem = true; std::string fullRelativePath = path + "/" + entry.name; int fileIndex = getFileListIndex(fullRelativePath); if (fileIndex != -1) entry.startSector = fileList[fileIndex].firstBlock; myVector.push_back(entry); } FindClose(hFind); #else dirent *dirp; std::string localPath = GetLocalPath(path); DIR *dp = opendir(localPath.c_str()); #if HOST_IS_CASE_SENSITIVE if(dp == NULL && FixPathCase(basePath,path, FPC_FILE_MUST_EXIST)) { // May have failed due to case sensitivity, try again localPath = GetLocalPath(path); dp = opendir(localPath.c_str()); } #endif if (dp == NULL) { ERROR_LOG(FILESYS,"Error opening directory %s\n", path.c_str()); return myVector; } while ((dirp = readdir(dp)) != NULL) { if (!strcmp(dirp->d_name, "..") || !strcmp(dirp->d_name, ".")) { continue; } PSPFileInfo entry; struct stat s; std::string fullName = GetLocalPath(path) + "/"+dirp->d_name; stat(fullName.c_str(), &s); if (S_ISDIR(s.st_mode)) entry.type = FILETYPE_DIRECTORY; else entry.type = FILETYPE_NORMAL; entry.access = s.st_mode & 0x1FF; entry.name = dirp->d_name; entry.size = s.st_size; localtime_r((time_t*)&s.st_atime,&entry.atime); localtime_r((time_t*)&s.st_ctime,&entry.ctime); localtime_r((time_t*)&s.st_mtime,&entry.mtime); entry.isOnSectorSystem = true; std::string fullRelativePath = path + "/" + entry.name; int fileIndex = getFileListIndex(fullRelativePath); if (fileIndex != -1) entry.startSector = fileList[fileIndex].firstBlock; myVector.push_back(entry); } closedir(dp); #endif return myVector; }