Exemplo n.º 1
0
static char *get_filename(const char **extensions) {
	static char result[16];
	Menu *filemenu;
	char *namebuf;
	char cwd[1024];
	unsigned long p_num, dummy;
	GPDIRENTRY gpentry;
	GPFILEATTR gpentry_attr;
	int selected;
	unsigned int i, j;

	fs_chdir(".");
	do {
		fs_getcwd(cwd, sizeof(cwd));
		GpDirEnumNum(cwd, &p_num);
		filemenu = malloc((p_num+1) * sizeof(Menu));
		if (filemenu == NULL)
			return NULL;
		namebuf = malloc(p_num * 16);
		if (namebuf == NULL) {
			free(filemenu);
			return NULL;
		}
		for (i = 0, j = 0; i < p_num; i++) {
			GpDirEnumList(cwd, i, 1, &gpentry, &dummy);
			if (strcmp(gpentry.name, ".") == 0)
				continue;
			GpFileAttr(gpentry.name, &gpentry_attr);
			if ((gpentry_attr.attr & 16) || valid_extension(gpentry.name, extensions)) {
				memcpy(namebuf + j * 16, gpentry.name, 16);
				filemenu[j].label = namebuf + j * 16;
				filemenu[j].default_opt = NULL;
				filemenu[j].cur_opt = gpentry_attr.attr;
				filemenu[j].num_opts = 0;
				filemenu[j].select_callback = NULL;
				filemenu[j].modify_callback = NULL;
				j++;
			}
		}
		filemenu[j].label = NULL;
		qsort(filemenu, j, sizeof(Menu), dirsort);
		selected = show_menu(filemenu, 1, 1, 38, 18);
		if (selected >= 0) {
			if (filemenu[selected].cur_opt & 16) {
				fs_chdir(filemenu[selected].label);
				selected = 0;
			} else {
				memcpy(result, filemenu[selected].label, 16);
				selected = -2;
			}
		}
		free(namebuf);
		free(filemenu);
	} while (selected >= 0);
	if (selected == -2)
		return result;
	return NULL;
}
Exemplo n.º 2
0
bool GP32FilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const {
	assert(_isDirectory);

	GPDIRENTRY dirEntry;
	GPFILEATTR attr;

	GP32FilesystemNode entry;

	uint32 read;

	if (mode == FilesystemNode::kListAll)
		LP("listDir(kListAll)");
	else
		LP("listDir(kListDirectoriesOnly)");

	int startIdx = 0; // current file
	String listDir(_path);
	//listDir += "/";
	while (GpDirEnumList(listDir.c_str(), startIdx++, 1, &dirEntry, &read)  == SM_OK) {
		if (dirEntry.name[0] == '.')
			continue;
		entry._displayName = dirEntry.name;
		entry._path = _path;
		entry._path += dirEntry.name;

		GpFileAttr(entry._path.c_str(), &attr);
		entry._isDirectory = attr.attr & (1 << 4);

		// Honor the chosen mode
		if ((mode == FilesystemNode::kListFilesOnly && entry._isDirectory) ||
			(mode == FilesystemNode::kListDirectoriesOnly && !entry._isDirectory))
			continue;

		if (entry._isDirectory)
			entry._path += "\\";
		myList.push_back(new GP32FilesystemNode(entry));
	}

	BP("Dir... %s", listDir.c_str());

	return true;
}