char *find_file(char *pattern, char *path) { static struct dirent file; int fd, i, found, len1, len2; memset(&dir, 0, sizeof(dir)); fd = sceIoDopen(path); found = 0; len1 = strlen(pattern); while (!found) { if (sceIoDread(fd, &dir) <= 0) break; len2 = strlen(dir.d_name); for (i = 0; i < len2; i++) { if (strnicmp(&dir.d_name[i], pattern, len1) == 0) { strcpy(file.name, dir.d_name); found = 1; break; } } } sceIoDclose(fd); return found ? file.name : NULL; }
/* Returns number of files successfully read; negative number if error */ int pl_file_get_file_list(pl_file_list *list, const char *path, const char **filter) { SceUID fd = sceIoDopen(path); if (fd < 0) return -1; SceIoDirent dir; memset(&dir, 0, sizeof(dir)); pl_file *file, *last = NULL; list->files = NULL; const char **pext; int loop; int count = 0; while (sceIoDread(fd, &dir) > 0) { if (filter && !(SCE_S_ISDIR(dir.d_stat.st_mode))) { /* Loop through the list of allowed extensions and compare */ for (pext = filter, loop = 1; *pext; pext++) { if (pl_file_is_of_type(dir.d_name, *pext)) { loop = 0; break; } } if (loop) continue; } /* Create a new file entry */ if (!(file = (pl_file*)malloc(sizeof(pl_file)))) { pl_file_destroy_file_list(list); return -1; } file->name = strdup(dir.d_name); file->next = NULL; file->attrs = (SCE_S_ISDIR(dir.d_stat.st_mode)) ? PL_FILE_DIRECTORY : 0; /* Update preceding element */ if (last) last->next = file; else list->files = file; last = file; count++; } sceIoDclose(fd); /* Sort the files by name */ sort_file_list(list, count); return count; }
void delete_files(const char *dirname, const char *pattern) { int fd, i, len1, len2; char path[MAX_PATH]; memset(&dir, 0, sizeof(dir)); sprintf(path, "%s%s", launchDir, dirname); fd = sceIoDopen(path); len1 = strlen(pattern); while (1) { if (sceIoDread(fd, &dir) <= 0) break; len2 = strlen(dir.d_name); for (i = 0; i < len2; i++) { if (strnicmp(&dir.d_name[i], pattern, len1) == 0) { char path2[MAX_PATH]; sprintf(path2, "%s/%s", path, dir.d_name); sceIoRemove(path2); } } } sceIoDclose(fd); }
void find_state_file(UINT8 *slot) { int fd, len; char path[MAX_PATH], pattern[16]; memset(&dir, 0, sizeof(dir)); sprintf(path, "%sstate", launchDir); sprintf(pattern, "%s.sv", game_name); len = strlen(pattern); fd = sceIoDopen(path); while (sceIoDread(fd, &dir) > 0) { if (strnicmp(dir.d_name, pattern, len) == 0) { int number = dir.d_name[len] - '0'; if (number >= 0 && number <= 9) slot[number] = 1; } } sceIoDclose(fd); }
static void cmd_CWD_func(ClientInfo *client) { char cmd_path[PATH_MAX]; char path[PATH_MAX]; SceUID pd; int n = sscanf(client->recv_buffer, "%*s %[^\r\n\t]", cmd_path); if (n < 1) { client_send_ctrl_msg(client, "500 Syntax error, command unrecognized.\n"); } else { if (cmd_path[0] != '/') { /* Change dir relative to current dir */ sprintf(path, "%s%s", client->cur_path, cmd_path); } else { sprintf(path, "%s%s", FTP_DEFAULT_PREFIX, cmd_path); } /* If there isn't "/" at the end, add it */ if (path[strlen(path) - 1] != '/') { strcat(path, "/"); } /* Check if the path exists */ pd = sceIoDopen(path); if (pd < 0) { client_send_ctrl_msg(client, "550 Invalid directory.\n"); return; } sceIoDclose(pd); strcpy(client->cur_path, path); client_send_ctrl_msg(client, "250 Requested file action okay, completed.\n"); } }
int has_directories(const char *base, const char *path) { SceIoDirent dir; char buffer[256]; int ret = 0; SceUID fd; sce_paf_private_snprintf(buffer, 256, "%s/%s", base, path); kprintf("checking %s\n", buffer); fd = sceIoDopen(buffer); if(fd >= 0) { sce_paf_private_memset(&dir, 0, sizeof(SceIoDirent)); while(sceIoDread(fd, &dir) > 0) { if (FIO_S_ISDIR(dir.d_stat.st_mode) && dir.d_name[0] != '.') { ret = 1; break; } } sceIoDclose(fd); } else { ret = -1; } return ret; }
extern u32 copy_dir(const char *src, const char *dest, t_copy_cb cb, t_copy_overwritecb ocb, void *data) { int dl = sceIoDopen(src); u32 result = 0; SceIoDirent sid; if (dl < 0) { if (cb != NULL) cb(src, dest, false, data); return 0; } sceIoMkdir(dest, 0777); memset(&sid, 0, sizeof(SceIoDirent)); while (sceIoDread(dl, &sid)) { char copysrc[260], copydest[260]; if (sid.d_name[0] == '.') continue; SPRINTF_S(copysrc, "%s/%s", src, sid.d_name); SPRINTF_S(copydest, "%s/%s", dest, sid.d_name); if (FIO_S_ISDIR(sid.d_stat.st_mode)) { result += copy_dir(copysrc, copydest, cb, ocb, data); continue; } if (copy_file(copysrc, copydest, cb, ocb, data)) ++result; memset(&sid, 0, sizeof(SceIoDirent)); } sceIoDclose(dl); return result; }
struct RDIR *retro_opendir(const char *name) { #if defined(_WIN32) char path_buf[1024]; #endif struct RDIR *rdir = (struct RDIR*)calloc(1, sizeof(*rdir)); if (!rdir) return NULL; #if defined(_WIN32) path_buf[0] = '\0'; snprintf(path_buf, sizeof(path_buf), "%s\\*", name); rdir->directory = FindFirstFile(path_buf, &rdir->entry); #elif defined(VITA) || defined(PSP) rdir->directory = sceIoDopen(name); #elif defined(_3DS) rdir->directory = (name && *name)? opendir(name) : NULL; rdir->entry = NULL; #elif defined(__CELLOS_LV2__) rdir->error = cellFsOpendir(name, &rdir->directory); #else rdir->directory = opendir(name); rdir->entry = NULL; #endif return rdir; }
static int testIoDread(const char *path) { SceIoDirent ent; SceUID uid; int r, trial; printf("sceIoDopen(\"%s\")...", path); uid = sceIoDopen(path); if (uid < 0) { printf("error: 0x%08X\n", uid); return uid; } puts("OK\n"); trial = 0; do { trial++; printf("sceIoDread (trial: %d)...", trial); r = sceIoDread(uid, &ent); if (r < 0) printf("error: 0x%08X\n", r); else puts("OK\n"); } while (r > 0); puts("sceIoDclose..."); r = sceIoDclose(uid); if (r) printf("error: 0x%08X\n", r); else puts("OK\n"); return 0; }
void RemoveDir(const char* oldPath) { char *fullOldPath; SceIoDirent oneDir; int oDir = sceIoDopen(oldPath); if (oDir < 0){ return; } while (1){ memset(&oneDir, 0, sizeof(SceIoDirent)); if (sceIoDread(oDir, &oneDir) <= 0) break; if (!strcmp(oneDir.d_name, ".") || !strcmp(oneDir.d_name, "..")) continue; if (oldPath[strlen(oldPath)-1] != '/'){ fullOldPath = (char *)calloc(strlen(oldPath)+strlen(oneDir.d_name)+2,sizeof(char)); sprintf(fullOldPath,"%s/%s",oldPath,oneDir.d_name); } else { fullOldPath = (char *)calloc(strlen(oldPath)+strlen(oneDir.d_name)+1,sizeof(char)); sprintf(fullOldPath,"%s%s",oldPath,oneDir.d_name); } if (FIO_S_ISDIR(oneDir.d_stat.st_mode)){ RemoveDir(fullOldPath); } else if(FIO_S_ISREG(oneDir.d_stat.st_mode)){ sceIoRemove(fullOldPath); } free(fullOldPath); } sceIoDclose(oDir); sceIoRmdir(oldPath); }
void runTest() { int dfd = sceIoDopen("ms0:/tmp/"); if (dfd <= 0) { pspDebugScreenPrintf("sceIoDopen = 0x%08X\n", dfd); return; } SceIoDirent dir; u8 buffer[1044]; while (1) { memset(&dir, 0, sizeof(dir)); memset(buffer, 0, sizeof(buffer)); ((u32 *) buffer)[0] = sizeof(buffer); dir.d_private = buffer; int result = sceIoDread(dfd, &dir); pspDebugScreenPrintf("sceIoDread = 0x%08X\n", result); if (result <= 0) { break; } int i; for (i = 0; i < sizeof(buffer); i++) { if (buffer[i] != 0) { pspDebugScreenPrintf("[%2d] = 0x%02X('%c') ", i, buffer[i], buffer[i]); } } pspDebugScreenPrintf("\n"); } sceIoDclose(dfd); }
void getSubFiles(char* pDir, CStringList& pOut, CString* search) { SceUID dir; if ((dir = sceIoDopen(pDir)) <= 0) return; SceIoDirent ent; SceIoStat statx; while (sceIoDread(dir, &ent) > 0) { CString fullName = CString() << pDir << ent.d_name; sceIoGetstat(fullName.text(), &statx); if (!(statx.st_mode & S_IFDIR)) { if (search != 0) { CString s( *search ); CString m( ent.d_name ); s.replaceAll( "%", "*" ); s << ".txt"; if (m.match( s.text()) == false) continue; } pOut.add( ent.d_name ); } } sceIoDclose(dir); }
extern u32 utils_del_dir(const char *dir) { u32 count = 0; int dl = sceIoDopen(dir); SceIoDirent sid; if (dl < 0) return count; memset(&sid, 0, sizeof(SceIoDirent)); while (sceIoDread(dl, &sid)) { char compPath[260]; if (sid.d_name[0] == '.') continue; SPRINTF_S(compPath, "%s/%s", dir, sid.d_name); if (FIO_S_ISDIR(sid.d_stat.st_mode)) { if (utils_del_dir(compPath)) { count++; } continue; } if (utils_del_file(compPath)) { count++; } memset(&sid, 0, sizeof(SceIoDirent)); } sceIoDclose(dl); sceIoRmdir(dir); return count; }
static int get_fontlist(FontList *list, char *path) { SceIoDirent dir; int result = 0, dfd; char fullpath[256]; memset(&dir, 0, sizeof(dir)); dfd = sceIoDopen(path); if(dfd < 0) { return dfd; } while (sceIoDread(dfd, &dir) > 0) { const char *p; p = strrchr(dir.d_name, '.'); if(p == NULL) p = dir.d_name; if(0 == stricmp(p, ".bin") || 0 == stricmp(p, ".pf") || 0 == stricmp(p, ".fnt") || 0 == stricmp(p, ".tlf")) { sprintf(fullpath, "%s/%s", path, dir.d_name); fontlist_add(list, fullpath); } } sceIoDclose(dfd); return result; }
int findfirst(const signed char *pathname, struct ffblk *ffblk, int attrib) { signed char *match=strdup(pathname); unsigned int i; if(match[0]=='*') match++; for(i=0;i<strlen(match);i++) { if(match[i]>='a' && match[i]<='z') match[i]^=32; } dirsize=0; printf("Looking for '%s' (%s)\n",match,pathname); int fd = sceIoDopen(path); SceIoDirent entry; while (sceIoDread(fd, &entry) > 0) { if(strcasestr(entry.d_name,match)==0 && wildcard(entry.d_name,match)==0) continue; if(dirsize==0) { dirfname=(signed char **)calloc(sizeof(signed char *),64); } else if((dirsize%64)==0) { dirfname=(signed char **)realloc(dirfname,sizeof(signed char *)*(dirsize+64)); } dirfname[dirsize++]=strdup(entry.d_name); } sceIoDclose(fd); printf("Got %d matches\n",dirsize); if (dirsize>0) { dirpos=1; strcpy(ffblk->ff_name,dirfname[dirsize-1]); return 0; } return 1; }
int FileManager::OpenDir(const char* path) { dirStatus = 1; dirId = sceIoDopen(path); sceIoDread(dirId, &dirent); sceIoDread(dirId, &dirent); return dirId; }
SceUID hook_sceIoDopen(const char *dirname) { sceKernelCheckCallback(); char tmpPath[MAX_PATH_LENGTH]; char *tmp=TranslateVFS(tmpPath, dirname); return sceIoDopen(tmp); }
SceUID hook_sceIoDopen(const char *dirname) { state_machine_checkState(); char tmpPath[MAX_PATH_LENGTH]; char *tmp=TranslateVFS(tmpPath, dirname); return sceIoDopen(tmp); }
int removePath(char *path, uint32_t *value, uint32_t max, void (* SetProgress)(uint32_t value, uint32_t max)) { SceUID dfd = sceIoDopen(path); if (dfd >= 0) { int res = 0; do { SceIoDirent dir; memset(&dir, 0, sizeof(SceIoDirent)); res = sceIoDread(dfd, &dir); if (res > 0) { if (strcmp(dir.d_name, ".") == 0 || strcmp(dir.d_name, "..") == 0) continue; char *new_path = malloc(strlen(path) + strlen(dir.d_name) + 2); snprintf(new_path, MAX_PATH_LENGTH, "%s/%s", path, dir.d_name); if (SCE_S_ISDIR(dir.d_stat.st_mode)) { removePath(new_path, value, max, SetProgress); } else { sceIoRemove(new_path); if (value) (*value)++; if (SetProgress) SetProgress(value ? *value : 0, max); } free(new_path); } } while (res > 0); sceIoDclose(dfd); int ret = sceIoRmdir(path); if (ret < 0) return ret; if (value) (*value)++; if (SetProgress) SetProgress(value ? *value : 0, max); } else { int ret = sceIoRemove(path); if (ret < 0) return ret; if (value) (*value)++; if (SetProgress) SetProgress(value ? *value : 0, max); } return 0; }
int randomCtf( char * theme ) { int dfd = sceIoDopen( "ms0:/PSP/THEME" ); if ( dfd < 0 ) return -1; int th_count = 0; SceIoDirent ent; memset( &ent, 0, sizeof( SceIoDirent ) ); while ( sceIoDread( dfd, &ent ) > 0 ) { if ( !( ent.d_stat.st_attr & FIO_SO_IFDIR ) && ent.d_name[0] != '.' && cmpistr( ent.d_name, "random.ctf" ) && endwithistr( ent.d_name, ".ctf" ) ) { th_count ++; } log( "name %s %d\n", ent.d_name, th_count ); memset( &ent, 0, sizeof( SceIoDirent ) ); } sceIoDclose( dfd ); if ( th_count <= 0 ) return -1; if ( th_count > 1 ) { time_t tm = sceKernelLibcTime( NULL ); th_count = tm % th_count; } else th_count = 0; dfd = sceIoDopen( "ms0:/PSP/THEME" ); memset( &ent, 0, sizeof( SceIoDirent ) ); while ( sceIoDread( dfd, &ent ) > 0 ) { log( "name %s %d\n", ent.d_name, th_count ); if ( !( ent.d_stat.st_attr & FIO_SO_IFDIR ) && ent.d_name[0] != '.' && cmpistr( ent.d_name, "random.ctf" ) && endwithistr( ent.d_name, "ctf" ) ) { if ( th_count == 0 ) { sprintf( theme, "/PSP/THEME/%s", ent.d_name ); break; } else th_count --; } memset( &ent, 0, sizeof( SceIoDirent ) ); } sceIoDclose( dfd ); return 0; }
void openSettingsMenu() { settings_menu.status = SETTINGS_MENU_OPENING; settings_menu.entry_sel = 0; settings_menu.option_sel = 0; // Get current theme if (theme_name) free(theme_name); readConfig("ux0:VitaShell/theme/theme.txt", theme_entries, sizeof(theme_entries) / sizeof(ConfigEntry)); // Get theme index in main tab int theme_index = -1; int i; for (i = 0; i < (sizeof(main_settings) / sizeof(SettingsMenuOption)); i++) { if (main_settings[i].name == VITASHELL_SETTINGS_THEME) { theme_index = i; break; } } // Find all themes if (theme_index >= 0) { SceUID dfd = sceIoDopen("ux0:VitaShell/theme"); if (dfd >= 0) { theme_count = 0; theme = 0; int res = 0; do { SceIoDirent dir; memset(&dir, 0, sizeof(SceIoDirent)); res = sceIoDread(dfd, &dir); if (res > 0) { if (SCE_S_ISDIR(dir.d_stat.st_mode)) { if (theme_name && strcasecmp(dir.d_name, theme_name) == 0) theme = theme_count; strncpy(theme_options[theme_count], dir.d_name, MAX_THEME_LENGTH); theme_count++; } } } while (res > 0 && theme_count < MAX_THEMES); sceIoDclose(dfd); main_settings[theme_index].options = theme_options; main_settings[theme_index].n_options = theme_count; main_settings[theme_index].value = &theme; } } changed = 0; }
extern void conf_load() { //memset(&config, 0, sizeof(config)); config.skey = PSP_CTRL_NOTE; config.ssskey = PSP_CTRL_VOLDOWN + PSP_CTRL_SELECT; config.bg_color = 0xb0c0c0c0; config.txtrowbytes = 54; config.jpg_quality = 90; config.suspend_skey = PSP_CTRL_RIGHT|PSP_CTRL_LEFT |PSP_ANA_RIGHT|PSP_CTRL_LTRIGGER; config.standby_skey = PSP_CTRL_RIGHT|PSP_CTRL_LEFT |PSP_ANA_RIGHT|PSP_CTRL_LTRIGGER; config.savekey = PSP_CTRL_RIGHT|PSP_CTRL_LEFT |PSP_ANA_RIGHT|PSP_CTRL_LTRIGGER; config.loadkey = PSP_CTRL_RIGHT|PSP_CTRL_LEFT |PSP_ANA_RIGHT|PSP_CTRL_LTRIGGER; //memset(&keyset, 0, sizeof(keyset)); memset(keyset.turbo_key_interval, 2, 12); int i; for(i=0;i<16;i++){ //keyset.keymap_skey[i] = turbo_key_tab[i]; //keyset.keymap_table[i] = turbo_key_tab[i]; keyset.stick_table[i] = turbo_key_tab[i]; keyset.stick_skey[i] = PSP_CTRL_UP|PSP_CTRL_DOWN|PSP_ANA_RIGHT|PSP_ANA_LEFT; } for(i=0;i<12;i++){ keyset.turbo_skey[i] = PSP_CTRL_UP|PSP_CTRL_DOWN|PSP_ANA_RIGHT|PSP_ANA_LEFT; } int j; for(i=0;i<MAX_KEYLIST;i++) { //memset((u8 *)&g_keylist[i], 0, sizeof(t_keylist_table)); g_keylist[i].idx = -1; g_keylist[i].reversekey = PSP_CTRL_RTRIGGER; //g_keylist[i].count = 0; //g_keylist[i].lastkey_stamp = 0; for(j=0;j<MAX_KEYSET;j++) { //g_keylist[i].list[j].btn = 0; //g_keylist[i].list[j].x = 127; //g_keylist[i].list[j].y = 127; g_keylist[i].list[j].stamp = 7; } } int dl = sceIoDopen(TAB_DIR); if(dl < 0) TAB_DIR[16]=0; else sceIoDclose(dl); int fd = sceIoOpen(CONFIG_DIR, PSP_O_RDONLY, 0777); if(fd >= 0) { sceIoRead(fd, &config, sizeof(config)); } sceIoClose(fd); }
bool PSPFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { DEBUG_ENTER_FUNC(); assert(_isDirectory); //TODO: honor the hidden flag bool ret = true; if (PowerMan.beginCriticalSection() == PowerManager::Blocked) PSP_DEBUG_PRINT_FUNC("Suspended\n"); // Make sure to block in case of suspend PSP_DEBUG_PRINT_FUNC("Current path[%s]\n", _path.c_str()); int dfd = sceIoDopen(_path.c_str()); if (dfd > 0) { SceIoDirent dir; memset(&dir, 0, sizeof(dir)); while (sceIoDread(dfd, &dir) > 0) { // Skip 'invisible files if (dir.d_name[0] == '.') continue; PSPFilesystemNode entry; entry._isValid = true; entry._displayName = dir.d_name; Common::String newPath(_path); if (newPath.lastChar() != '/') newPath += '/'; newPath += dir.d_name; entry._path = newPath; entry._isDirectory = dir.d_stat.st_attr & FIO_SO_IFDIR; PSP_DEBUG_PRINT_FUNC("Child[%s], %s\n", entry._path.c_str(), entry._isDirectory ? "dir" : "file"); // Honor the chosen mode if ((mode == Common::FSNode::kListFilesOnly && entry._isDirectory) || (mode == Common::FSNode::kListDirectoriesOnly && !entry._isDirectory)) continue; myList.push_back(new PSPFilesystemNode(entry)); } sceIoDclose(dfd); ret = true; } else { // dfd <= 0 ret = false; } PowerMan.endCriticalSection(); return ret; }
int FileManager::DirExists(const char* path) { SceUID dir = sceIoDopen(path); if (dir >= 0){ sceIoDclose(dir); return 1; } else { return -1; } }
bool MFFileNative_FindFirst(MFFind *pFind, const char *pSearchPattern, MFFindData *pFindData) { SceIoDirent findData; int findStatus; // separate path and search pattern.. char *pPath = (char*)MFStr("%s/%s%s", gPSPSystemPath, (char*)pFind->pMount->pFilesysData, pSearchPattern); const char *pPattern = pPath; char *pLast = MFString_RChr(pPath, '/'); if(pLast) { *pLast = 0; pPattern = pLast + 1; } else { // find pattern refers to current directory.. pPath = "."; } // open the directory SceUID hFind = sceIoDopen(pPath); if(hFind < 0) { MFDebug_Warn(2, MFStr("Couldnt open directory '%s' with search pattern '%s'", pPath, pPattern)); return false; } findStatus = sceIoDread(hFind, &findData); MFDebug_Assert(findStatus >= 0, "Error reading directory."); if(findStatus == 0) return false; pFindData->attributes = (FIO_SO_ISDIR(findData.d_stat.st_attr) ? MFFA_Directory : 0) | (FIO_SO_ISLNK(findData.d_stat.st_attr) ? MFFA_SymLink : 0); pFindData->fileSize = (uint64)findData.d_stat.st_size; MFString_Copy((char*)pFindData->pFilename, findData.d_name); MFString_CopyCat(pFindData->pSystemPath, (char*)pFind->pMount->pFilesysData, pSearchPattern); pLast = MFString_RChr(pFindData->pSystemPath, '/'); if(pLast) pLast[1] = 0; else pFindData->pSystemPath[0] = 0; pFind->pFilesystemData = (void*)hFind; return true; }
int getPathInfo(char *path, uint32_t *size, uint32_t *folders, uint32_t *files) { SceUID dfd = sceIoDopen(path); if (dfd >= 0) { int res = 0; do { SceIoDirent dir; memset(&dir, 0, sizeof(SceIoDirent)); res = sceIoDread(dfd, &dir); if (res > 0) { if (strcmp(dir.d_name, ".") == 0 || strcmp(dir.d_name, "..") == 0) continue; char *new_path = malloc(strlen(path) + strlen(dir.d_name) + 2); snprintf(new_path, MAX_PATH_LENGTH, "%s/%s", path, dir.d_name); if (SCE_S_ISDIR(dir.d_stat.st_mode)) { getPathInfo(new_path, size, folders, files); } else { if (size) (*size) += dir.d_stat.st_size; if (files) (*files)++; } free(new_path); } } while (res > 0); sceIoDclose(dfd); if (folders) (*folders)++; } else { if (size) { SceIoStat stat; memset(&stat, 0, sizeof(SceIoStat)); int res = sceIoGetstat(path, &stat); if (res < 0) return res; (*size) += stat.st_size; } if (files) (*files)++; } return 0; }
/* ================ CheckForPak ================ */ bool CheckForMod(char* dir) { int dd = sceIoDopen(dir); SceIoDirent entry; int res; bool ret = false; while ((res = sceIoDread(dd, &entry)) > 0 && (!ret)) if ( strstr(strtolower(entry.d_name),".pak") != NULL || !strcmp(strtolower(entry.d_name), "progs.dat") ) ret = true; // Enable checks for progs.dat only mods sceIoDclose(dd); return ret; }
int main(int argc, char **argv) { int result; int directory; SceIoDirent directoryEntry; directory = sceIoDopen("disc0:/PSP_GAME"); do { result = sceIoDread(directory, &directoryEntry); printf("%d : '%s'\n", result, directoryEntry.d_name); } while(result > 0); return 0; }
int fileListGetDirectoryEntries(FileList *list, char *path) { SceUID dfd = sceIoDopen(path); if (dfd < 0) return dfd; FileListEntry *entry = malloc(sizeof(FileListEntry)); strcpy(entry->name, DIR_UP); entry->is_folder = 1; entry->type = FILE_TYPE_UNKNOWN; fileListAddEntry(list, entry, SORT_BY_NAME_AND_FOLDER); int res = 0; do { SceIoDirent dir; memset(&dir, 0, sizeof(SceIoDirent)); res = sceIoDread(dfd, &dir); if (res > 0) { if (strcmp(dir.d_name, ".") == 0 || strcmp(dir.d_name, "..") == 0) continue; FileListEntry *entry = malloc(sizeof(FileListEntry)); strcpy(entry->name, dir.d_name); entry->is_folder = SCE_S_ISDIR(dir.d_stat.st_mode); if (entry->is_folder) { addEndSlash(entry->name); entry->type = FILE_TYPE_UNKNOWN; } else { /* char file[MAX_PATH_LENGTH]; snprintf(file, MAX_PATH_LENGTH, "%s%s", path, entry->name); entry->type = getFileType(file); */ entry->type = FILE_TYPE_UNKNOWN; } memcpy(&entry->time, (SceRtcTime *)&dir.d_stat.st_mtime, sizeof(SceRtcTime)); entry->size = dir.d_stat.st_size; fileListAddEntry(list, entry, SORT_BY_NAME_AND_FOLDER); } } while (res > 0); sceIoDclose(dfd); return 0; }
static void addmedialistpath(char *path) { int dirid; int retval; int x; int found; SceIoDirent *direntt; if ((dirid = sceIoDopen(path)) > 0) { // Opened ok retval = 1; //direntt = (SceIoDirent *)malloc(sizeof(SceIoDirent)); direntt = (SceIoDirent *) & direnta; while ((retval > 0) && (files_infonum < MAX_FILE_NUM)) { retval = sceIoDread(dirid, direntt); if (retval > 0) { sceKernelDcacheWritebackAll(); if ((direntt->d_stat.st_attr & 0x10) == 0x10) { // directory if (direntt->d_name[0] != '.') { char *pathname = (char *) malloc(200); sprintf(pathname, "%s%s/", path, direntt->d_name); addmedialistpath(pathname); //free(pathname); // dont free, as used in files } } // else if (((direntt->d_stat.st_attr & 0x20) == 0x20) && (direntt->d_name[0] != 0)) { // File else if (direntt->d_name[0] != 0) { // File // Only add files of types known to codecs loaded // Now check against the codecs known to us found = 0; for (x = 0; x < codecnum; x++) { char *ptr = stubs[x].extension; while (*ptr != 0) { if (strncasecmp(&direntt->d_name[strlen(direntt->d_name) - 3], ptr, 3) == 0) found = 1; ptr += 4; } } if (found == 1) { files_info[files_infonum].filename = (char *) malloc(200); memcpy(files_info[files_infonum].filename, direntt->d_name, 200); files_info[files_infonum].pathname = path; files_infonum++; } // if found } // if d_name } // if retval //free(direntt); } // while sceIoDclose(dirid); } // if }