예제 #1
0
void TocManager::readDir(const char *path, TocNode **node, int level) {
	if (level <= 2) { // we don't scan deeper than that
		iox_dirent_t dirent;
		int fd = fio.dopen(path);
		if (fd >= 0) {
			while (fio.dread(fd, &dirent) > 0)
				if (dirent.name[0] != '.') { // skip '.' and '..'
					*node = new TocNode;
					(*node)->sub = (*node)->next = NULL;

					(*node)->nameLen = strlen(dirent.name);
					memcpy((*node)->name, dirent.name, (*node)->nameLen + 1);

					if (dirent.stat.mode & FIO_S_IFDIR) { // directory
						(*node)->isDir = true;
						char nextPath[256];
						sprintf(nextPath, "%s%s/", path, dirent.name);
						readDir(nextPath, &((*node)->sub), level + 1);
					} else
						(*node)->isDir = false;
					node = &((*node)->next);
				}
			fio.dclose(fd);
		} else
			printf("Can't open path: %s\n", path);
	}
}
예제 #2
0
파일: ps2-fs.cpp 프로젝트: 0xf1sh/scummvm
bool Ps2FilesystemNode::getChildren(AbstractFSList &list, ListMode mode, bool hidden) const {
	//TODO: honor the hidden flag

	// dbg_printf("getChildren\n");

	if (!_isDirectory)
		return false;

	if (_isRoot) {
		if (g_systemPs2->cdPresent())
			list.push_back(new Ps2FilesystemNode("cdfs:"));

		if (g_systemPs2->hddPresent())
			list.push_back(new Ps2FilesystemNode("pfs0:"));

		if (g_systemPs2->usbMassPresent())
			list.push_back(new Ps2FilesystemNode("mass:"));

		if (g_systemPs2->netPresent())
			list.push_back(new Ps2FilesystemNode("host:"));

		if (g_systemPs2->mcPresent())
			list.push_back(new Ps2FilesystemNode("mc0:"));

		return true;
	} else {
		int fd;

		if (_path == "pfs0:")
			fd = fio.dopen("pfs0:/");
		else
			fd = fio.dopen(_path.c_str());

		// dbg_printf("dopen = %d\n", fd);

		if (fd >= 0) {
			iox_dirent_t dirent;
			Ps2FilesystemNode dirEntry;
			int dreadRes;
			while ((dreadRes = fio.dread(fd, &dirent)) > 0) {

				if (dirent.name[0] == '.')
					continue; // ignore '.' and '..'

				if ( (mode == Common::FSNode::kListAll) ||

					((mode == Common::FSNode::kListDirectoriesOnly) &&
					 (dirent.stat.mode & FIO_S_IFDIR)) ||

				    ((mode == Common::FSNode::kListFilesOnly) &&
					 !(dirent.stat.mode & FIO_S_IFDIR)) ) {

					dirEntry._isHere = true;
					dirEntry._isDirectory = (bool)(dirent.stat.mode & FIO_S_IFDIR);
					dirEntry._isRoot = false;

					dirEntry._path = _path;
					dirEntry._path += dirent.name;
					if (dirEntry._isDirectory && dirEntry._path.lastChar() != '/')
						dirEntry._path += '/';
					dirEntry._displayName = dirent.name;

					dirEntry._verified = true;

					list.push_back(new Ps2FilesystemNode(&dirEntry));
				}
			}
			fio.dclose(fd);
			return true;
		}
	}
	return false;
}