/*! Change current working directory * * @param[in,out] r newlib reentrancy struct * @param[in] name Path to new working directory * * @returns 0 for success * @returns -1 for error */ static int sdmc_chdir(struct _reent *r, const char *name) { Handle fd; Result rc; const char *pathptr = NULL; pathptr = sdmc_fixpath(name); if(pathptr==NULL) { r->_errno=EINVAL; return -1; } rc = FSUSER_OpenDirectory(NULL, &fd, sdmcArchive, FS_makePath(PATH_CHAR, pathptr)); if(rc == 0) { FSDIR_Close(fd); strncpy(__cwd,pathptr,PATH_MAX); } else { r->_errno=EINVAL; return -1; } return 0; }
void NES_LOADROMLIST() { Handle romHandle; FS_dirent dirStruct; FS_path dirPath = FS_makePath(PATH_CHAR, "/3DNES/ROMS"); // init SDMC archive sdmcArchive = (FS_archive){0x9, (FS_path){PATH_EMPTY, 1, (u8*)""}}; FSUSER_OpenArchive(NULL, &sdmcArchive); FSUSER_OpenDirectory(NULL, &romHandle, sdmcArchive, dirPath); // Get number of files in directory fileSystem.totalFiles = 0 while(1) { u32 dataRead = 0; FSDIR_Read(romHandle, &dataRead, 1, &dirStruct); if(dataRead == 0) break; fileSystem.totalFiles++; } fileSystem.fileList = linearAlloc(MAX_FILENAME_SIZE * fileSystem.totalFiles); FSUSER_OpenDirectory(NULL, &romHandle, sdmcArchive, dirPath); fileSystem.totalFiles = 0; while(1) { u32 dataRead = 0; FSDIR_Read(romHandle, &dataRead, 1, &dirStruct); if(dataRead == 0) break; unicodeToChar(&fileSystem.fileList[MAX_FILENAME_SIZE * fileSystem.totalFiles), dirStruct.name); fileSystem.totalFiles++; } FSDIR_Close(romHandle); }
Directory::Directory(FS_Archive archive, const std::u16string& root) { load = false; err = 0; Handle handle; list.clear(); err = FSUSER_OpenDirectory(&handle, archive, fsMakePath(PATH_UTF16, root.c_str())); if (R_FAILED(err)) { return; } u32 result = 0; do { FS_DirectoryEntry item; err = FSDIR_Read(handle, &result, 1, &item); if (result == 1) { list.push_back(item); } } while(result); err = FSDIR_Close(handle); if (R_FAILED(err)) { list.clear(); return; } load = true; }
static void _vd3dRewind(struct VDir* vd) { struct VDir3DS* vd3d = (struct VDir3DS*) vd; FSDIR_Close(vd3d->handle); // TODO: Use UTF-16 FS_Path newPath = fsMakePath(PATH_ASCII, vd3d->path); FSUSER_OpenDirectory(&vd3d->handle, sdmcArchive, newPath); }
static bool _vd3dClose(struct VDir* vd) { struct VDir3DS* vd3d = (struct VDir3DS*) vd; FSDIR_Close(vd3d->handle); free(vd3d->path); free(vd3d); return true; }
void scanHomebrewDirectory(menu_s* m, char* path) { if(!path)return; Handle dirHandle; FS_path dirPath=FS_makePath(PATH_CHAR, path); FSUSER_OpenDirectory(NULL, &dirHandle, sdmcArchive, dirPath); static char fullPath[1024]; u32 entriesRead; do { static FS_dirent entry; memset(&entry,0,sizeof(FS_dirent)); entriesRead=0; FSDIR_Read(dirHandle, &entriesRead, 1, &entry); if(entriesRead) { strncpy(fullPath, path, 1024); int n=strlen(fullPath); unicodeToChar(&fullPath[n], entry.name, 1024-n); if(entry.isDirectory) //directories { addDirectoryToMenu(m, fullPath); }else{ //stray executables n=strlen(fullPath); if(n>5 && !strcmp(".3dsx", &fullPath[n-5]))addFileToMenu(m, fullPath); } } }while(entriesRead); FSDIR_Close(dirHandle); }
static void _vd3dRewind(struct VDir* vd) { struct VDir3DS* vd3d = (struct VDir3DS*) vd; FSDIR_Close(vd3d->handle); uint16_t utf16Path[PATH_MAX + 1]; ssize_t units = utf8_to_utf16(utf16Path, (const uint8_t*) vd3d->path, PATH_MAX); utf16Path[units] = 0; FS_Path newPath = fsMakePath(PATH_UTF16, utf16Path); FSUSER_OpenDirectory(&vd3d->handle, sdmcArchive, newPath); }
void dumpTicket(void) { Result res = 0; Handle nandDir; u32 entryCount; FS_dirent dirent; printf("Opening NAND...\n"); res = FSUSER_OpenArchive(NULL, &nandArchive); if(res != 0) { printf("%sError opening NAND!\n%.8lX%s\n", TEXT_RED, res, TEXT_RESET); return; } printf("Opening /...\n"); nandPath.data = (u8 *)nandPathString; nandPath.size = (wcslen(nandPathString) + 1) * 2; res = FSUSER_OpenDirectory(NULL, &nandDir, nandArchive, nandPath); if(res != 0) { printf("%sError opening /!\n%.8lX%s\n", TEXT_RED, res, TEXT_RESET); return; } printf("Reading...\n"); for(;;) { res = FSDIR_Read(nandDir, &entryCount, 1, &dirent); if(res != 0) { printf("%sError reading dir!\n%.8lX%s\n", TEXT_RED, res, TEXT_RESET); return; } if(entryCount == 0) { break; } utf16_to_utf8(utf8, dirent.name, 0x106); printf("/%s\n", utf8); } printf("Closing /...\n"); res = FSDIR_Close(nandDir); if(res != 0) { printf("%sError closing /!\n%.8lX%s\n", TEXT_RED, res, TEXT_RESET); return; } printf("Closing NAND...\n"); res = FSUSER_CloseArchive(NULL, &nandArchive); if(res != 0) { printf("%sError closing NAND!\n%.8lX%s\n", TEXT_RED, res, TEXT_RESET); return; } }
//same thing as contructor. can be used to reinit dirList too void dirList::reassign(const std::u16string p) { entry.clear(); FSUSER_OpenDirectory(&d, a, fsMakePath(PATH_UTF16, p.data())); u32 read = 0; do { FS_DirectoryEntry getEnt; FSDIR_Read(d, &read, 1, &getEnt); entry.push_back(getEnt); }while(read > 0); FSDIR_Close(d); }
/*! Close an open directory * * @param[in,out] r newlib reentrancy struct * @param[in] dirState Pointer to open directory state * * @returns 0 for success * @returns -1 for error */ static int sdmc_dirclose(struct _reent *r, DIR_ITER *dirState) { Result rc; /* get pointer to our data */ sdmc_dir_t *dir = (sdmc_dir_t*)(dirState->dirStruct); /* close the directory */ rc = FSDIR_Close(dir->fd); if(rc == 0) return 0; r->_errno = rc; return -1; }
void scanHomebrewDirectory(menu_s* m, char* path) { if(!path)return; Handle dirHandle; FS_path dirPath=FS_makePath(PATH_CHAR, path); FSUSER_OpenDirectory(&dirHandle, sdmcArchive, dirPath); static char fullPath[1024][1024]; u32 entriesRead; int totalentries = 0; do { static FS_dirent entry; memset(&entry,0,sizeof(FS_dirent)); entriesRead=0; FSDIR_Read(dirHandle, &entriesRead, 1, &entry); if(entriesRead) { strncpy(fullPath[totalentries], path, 1024); int n=strlen(fullPath[totalentries]); unicodeToChar(&fullPath[totalentries][n], entry.name, 1024-n); if(entry.isDirectory) //directories { //addDirectoryToMenu(m, fullPath[totalentries]); totalentries++; }else{ //stray executables n=strlen(fullPath[totalentries]); if(n>5 && !strcmp(".3dsx", &fullPath[totalentries][n-5])){ //addFileToMenu(m, fullPath[totalentries]); totalentries++; } if(n>4 && !strcmp(".xml", &fullPath[totalentries][n-4])) { //addFileToMenu(m, fullPath[totalentries]); totalentries++; } } } }while(entriesRead); FSDIR_Close(dirHandle); bool sortAlpha = getConfigBoolForKey("sortAlpha", false, configTypeMain); addMenuEntries(fullPath, totalentries, strlen(path), m, sortAlpha); updateMenuIconPositions(m); }
void dumpFolder(char *path, u32 lowpath_id, char *dumpfolder, u8 *filebuffer, size_t bufsize) { Handle extdata_dir; Result ret = FSUSER_OpenDirectory(NULL, &extdata_dir, extdata_archive, FS_makePath(PATH_CHAR, path)); if (ret!=0) { printf("could not open dir\n"); gfxFlushBuffers(); gfxSwapBuffers(); return; } char dirname[0x120]; sprintf(dirname, "%s/%08x%s", dumpfolder, (unsigned int) lowpath_id, path); mkdir(dirname, 0777); FS_dirent dirStruct; char fileName[0x106] = ""; int cont = 0; while(1) { u32 dataRead = 0; FSDIR_Read(extdata_dir, &dataRead, 1, &dirStruct); if(dataRead == 0) break; unicodeToChar(fileName, dirStruct.name); printf("name: %s%s%s\n", path, fileName, dirStruct.isDirectory ? " (DIRECTORY)" : ""); gfxFlushBuffers(); gfxSwapBuffers(); cont++; if (dirStruct.isDirectory) { char newpath[0x120]; sprintf(newpath, "%s%s/", path, fileName); dumpFolder(newpath, lowpath_id, dumpfolder, filebuffer, bufsize); } else { char file_inpath[0x120]; char file_outpath[0x120]; char file_display_path[0x120]; sprintf(file_inpath, "%s%s", path, fileName); sprintf(file_outpath, "%s/%08x%s%s", dumpfolder, (unsigned int) lowpath_id, path, fileName); sprintf(file_display_path, "%08x%s%s", (unsigned int) lowpath_id, path, fileName); archive_copyfile(Extdata_Archive, SDArchive, file_inpath, file_outpath, filebuffer, 0, bufsize, file_display_path); } } printf("total files in 0x%08x%s: %d\n", (unsigned int) lowpath_id, path, (unsigned int) cont); gfxFlushBuffers(); gfxSwapBuffers(); FSDIR_Close(extdata_dir); }
static Result action_paste_files_make_dst_directory(void* data, u32 index) { paste_files_data* pasteData = (paste_files_data*) data; Result res = 0; u32 attributes = ((file_info*) ((list_item*) linked_list_get(&pasteData->contents, index))->data)->attributes; char dstPath[FILE_PATH_MAX]; action_paste_files_get_dst_path(pasteData, index, dstPath); FS_Path* fsPath = util_make_path_utf8(dstPath); if(fsPath != NULL) { Handle dirHandle = 0; if(R_SUCCEEDED(FSUSER_OpenDirectory(&dirHandle, pasteData->target->archive, *fsPath))) { FSDIR_Close(dirHandle); } else { res = FSUSER_CreateDirectory(pasteData->target->archive, *fsPath, attributes); } util_free_path_utf8(fsPath); } else { res = R_FBI_OUT_OF_MEMORY; } if(R_SUCCEEDED(res)) { char parentPath[FILE_PATH_MAX]; util_get_parent_path(parentPath, dstPath, FILE_PATH_MAX); char baseDstPath[FILE_PATH_MAX]; if(pasteData->target->attributes & FS_ATTRIBUTE_DIRECTORY) { strncpy(baseDstPath, pasteData->target->path, FILE_PATH_MAX); } else { util_get_parent_path(baseDstPath, pasteData->target->path, FILE_PATH_MAX); } if(strncmp(parentPath, baseDstPath, FILE_PATH_MAX) == 0) { list_item* dstItem = NULL; if(R_SUCCEEDED(res) && R_SUCCEEDED(task_create_file_item(&dstItem, pasteData->target->archive, dstPath, attributes))) { linked_list_add(pasteData->items, dstItem); } } } return res; }
void get_config_path() { if(strlen(config_base_path) == 0) { sdmcArchive = (FS_Archive){ARCHIVE_SDMC, (FS_Path){PATH_EMPTY, 1, (u8*)""}}; FSUSER_OpenArchive(&sdmcArchive); sprintf(config_base_path, "/lynx"); FS_Path dirPath = (FS_Path){PATH_ASCII, strlen(config_base_path)+1, (u8*)config_base_path}; FSUSER_OpenDirectory(&dirHandle, sdmcArchive, dirPath); if(!dirHandle) sprintf(config_base_path, "/"); //!! FSDIR_Close(dirHandle); sprintf(config_roms_path, "%s/%s", config_base_path, "Roms"); sprintf(config_bios_path, "%s/%s", config_base_path, "Bios"); sprintf(config_skin_path, "%s/%s", config_base_path, "Skin"); sprintf(config_save_path, "%s/%s", config_base_path, "Save"); } }
dirList::dirList(FS_Archive arch, const std::u16string p) { //keep archive data a = arch; //save path path = p; //open path given by p FSUSER_OpenDirectory(&d, a, fsMakePath(PATH_UTF16, p.data())); //loop until we stop reading anymore entries u32 read = 0; do { FS_DirectoryEntry getEnt; FSDIR_Read(d, &read, 1, &getEnt); entry.push_back(getEnt); }while(read > 0); FSDIR_Close(d); }
directoryContents * contentsOfDirectoryAtPath(char * path, bool dirsOnly) { directoryContents * contents = malloc(sizeof(directoryContents)); int numPaths = 0; Handle dirHandle; FS_path dirPath=FS_makePath(PATH_CHAR, path); FSUSER_OpenDirectory(&dirHandle, sdmcArchive, dirPath); u32 entriesRead; do { static FS_dirent entry; memset(&entry,0,sizeof(FS_dirent)); entriesRead=0; FSDIR_Read(dirHandle, &entriesRead, 1, &entry); if(entriesRead) { if(!dirsOnly || (dirsOnly && entry.isDirectory)) { char fullPath[1024]; strncpy(fullPath, path, 1024); int n=strlen(path); unicodeToChar(&fullPath[n], entry.name, 1024-n); strcpy(contents->paths[numPaths], fullPath); numPaths++; } } }while(entriesRead); FSDIR_Close(dirHandle); // qsort(contents->paths, numPaths, 1024, compareStrings); contents->numPaths = numPaths; return contents; }
void closeDirectory(Handle dir) { LOG_VERBOSE("closeDirectory"); FSDIR_Close(dir); }
static void task_populate_files_thread(void* arg) { populate_files_data* data = (populate_files_data*) arg; Result res = 0; list_item* baseItem = NULL; if(R_SUCCEEDED(res = task_create_file_item(&baseItem, data->archive, data->path))) { file_info* baseInfo = (file_info*) baseItem->data; if(baseInfo->attributes & FS_ATTRIBUTE_DIRECTORY) { strncpy(baseItem->name, "<current directory>", LIST_ITEM_NAME_MAX); } else { strncpy(baseItem->name, "<current file>", LIST_ITEM_NAME_MAX); } linked_list queue; linked_list_init(&queue); linked_list_add(&queue, baseItem); bool quit = false; while(!quit && R_SUCCEEDED(res) && linked_list_size(&queue) > 0) { u32 tail = linked_list_size(&queue) - 1; list_item* currItem = (list_item*) linked_list_get(&queue, tail); file_info* curr = (file_info*) currItem->data; linked_list_remove_at(&queue, tail); if(data->includeBase || currItem != baseItem) { linked_list_add(data->items, currItem); } if(curr->attributes & FS_ATTRIBUTE_DIRECTORY) { FS_Path* fsPath = util_make_path_utf8(curr->path); if(fsPath != NULL) { Handle dirHandle = 0; if(R_SUCCEEDED(res = FSUSER_OpenDirectory(&dirHandle, curr->archive, *fsPath))) { u32 entryCount = 0; FS_DirectoryEntry* entries = (FS_DirectoryEntry*) calloc(MAX_FILES, sizeof(FS_DirectoryEntry)); if(entries != NULL) { if(R_SUCCEEDED(res = FSDIR_Read(dirHandle, &entryCount, MAX_FILES, entries)) && entryCount > 0) { qsort(entries, entryCount, sizeof(FS_DirectoryEntry), task_populate_files_compare_directory_entries); for(u32 i = 0; i < entryCount && R_SUCCEEDED(res); i++) { svcWaitSynchronization(task_get_pause_event(), U64_MAX); if(task_is_quit_all() || svcWaitSynchronization(data->cancelEvent, 0) == 0) { quit = true; break; } char name[FILE_NAME_MAX] = {'\0'}; utf16_to_utf8((uint8_t*) name, entries[i].name, FILE_NAME_MAX - 1); if(data->filter == NULL || data->filter(data->filterData, name, entries[i].attributes)) { char path[FILE_PATH_MAX] = {'\0'}; snprintf(path, FILE_PATH_MAX, "%s%s", curr->path, name); list_item* item = NULL; if(R_SUCCEEDED(res = task_create_file_item(&item, curr->archive, path))) { if(data->recursive && (((file_info*) item->data)->attributes & FS_ATTRIBUTE_DIRECTORY)) { linked_list_add(&queue, item); } else { linked_list_add(data->items, item); } } } } } free(entries); } else { res = R_FBI_OUT_OF_MEMORY; } FSDIR_Close(dirHandle); } util_free_path_utf8(fsPath); } else { res = R_FBI_OUT_OF_MEMORY; } } } if(!data->includeBase) { task_free_file(baseItem); } } svcCloseHandle(data->cancelEvent); data->result = res; data->finished = true; }
int load_file(char **wildcards, char *result, bool startup) { Handle dirHandle; FS_DirectoryEntry entry; char current_dir_name[MAX__PATH]; char prev_dir_name[MAX__PATH]; char current_dir_short[81]; u32 current_dir_length; u32 total_filenames_allocated; u32 total_dirnames_allocated; char **file_list; char **dir_list; u32 num_files; u32 num_dirs; char *file_name; u32 file_name_length; u32 ext_pos = -1; s32 return_value = 1; u32 current_file_selection; u32 current_file_scroll_value; u32 current_dir_selection; u32 current_dir_scroll_value; u32 current_file_in_scroll; u32 current_dir_in_scroll; u32 current_file_number, current_dir_number; u32 current_column = 0; u32 repeat; u32 i; strcpy(current_dir_name, config_roms_path); strcpy(prev_dir_name, current_dir_name); while(return_value == 1) { current_file_selection = 0; current_file_scroll_value = 0; current_dir_selection = 0; current_dir_scroll_value = 0; current_file_in_scroll = 0; current_dir_in_scroll = 0; total_filenames_allocated = 32; total_dirnames_allocated = 32; file_list = (char **)malloc(sizeof(char *) * 32); dir_list = (char **)malloc(sizeof(char *) * 32); memset(file_list, 0, sizeof(char *) * 32); memset(dir_list, 0, sizeof(char *) * 32); num_files = 0; num_dirs = 0; file_name= (char*) malloc(0x105); FS_Path dirPath = (FS_Path){PATH_ASCII, strlen(current_dir_name)+1, (u8*)current_dir_name}; FSUSER_OpenDirectory(&dirHandle, sdmcArchive, dirPath); // DEBUG printf("Current directory: %s\n", current_dir_name); u32 nread = 0; do { if(dirHandle) FSDIR_Read(dirHandle, &nread, 1, &entry); if(nread) { //(current_file) { strncpy_u2a(file_name, entry.name, 0x105); //utf-16 to ascii function yoinked from blargSNES file_name_length = strlen(file_name); if(((file_name[0] != '.') || (file_name[1] == '.'))) { //if(S_ISDIR(file_info.st_mode)) { //!!!!!!!! if(entry.attributes & FS_ATTRIBUTE_DIRECTORY) { if((strcmp(file_name, "filer") != 0) && (strcmp(file_name, "Nintendo 3DS") != 0) && (strcmp(file_name, "private") != 0)) { dir_list[num_dirs] = (char *)malloc(file_name_length + 1); strcpy(dir_list[num_dirs], file_name); num_dirs++; } } else { // Must match one of the wildcards, also ignore the . if(file_name_length >= 4) { if(file_name[file_name_length - 4] == '.') ext_pos = file_name_length - 4; else if(file_name[file_name_length - 3] == '.') ext_pos = file_name_length - 3; else ext_pos = 0; for(i = 0; wildcards[i] != NULL; i++) { if(!strcasecmp((file_name + ext_pos), wildcards[i])) { file_list[num_files] = (char *)malloc(file_name_length + 1); strcpy(file_list[num_files], file_name); num_files++; break; } } } } } if(num_files == total_filenames_allocated) { file_list = (char **)realloc(file_list, sizeof(char *) * total_filenames_allocated * 2); memset(file_list + total_filenames_allocated, 0, sizeof(char *) * total_filenames_allocated); total_filenames_allocated *= 2; } if(num_dirs == total_dirnames_allocated) { dir_list = (char **)realloc(dir_list, sizeof(char *) * total_dirnames_allocated * 2); memset(dir_list + total_dirnames_allocated, 0, sizeof(char *) * total_dirnames_allocated); total_dirnames_allocated *= 2; } } } while(nread); qsort((void *)file_list, num_files, sizeof(char *), sort_function); qsort((void *)dir_list, num_dirs, sizeof(char *), sort_function); FSDIR_Close(dirHandle); current_dir_length = strlen(current_dir_name); if(current_dir_length > 80) { memcpy(current_dir_short, "...", 3); memcpy(current_dir_short + 3, current_dir_name + current_dir_length - 77, 77); current_dir_short[80] = 0; } else { memcpy(current_dir_short, current_dir_name, current_dir_length + 1); } repeat = 1; if(num_files == 0) current_column = 1; if(num_dirs == 0) current_column = 0; char print_buffer[81]; while(repeat) { sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); //!! sftd_draw_text(font, 0, 4, COLOR_ACTIVE_ITEM, 10, current_dir_short); const char strMsg[] = "[A] Select Rom [X] Run BIOS [Y] Dir up [B] Back"; guitextwidth = sftd_get_text_width(font, 10, strMsg); sftd_draw_text(font, (320 - guitextwidth) / 2, 225, COLOR_HELP_TEXT, 10, strMsg); for(i = 0, current_file_number = i + current_file_scroll_value; i < FILE_LIST_ROWS; i++, current_file_number++) { if(current_file_number < num_files) { strncpy(print_buffer,file_list[current_file_number], 30); //38); print_buffer[30] = 0; //38] = 0; if((current_file_number == current_file_selection) && (current_column == 0)) { sftd_draw_text(font, FILE_LIST_POSITION, ((i + 2) * 10), COLOR_ACTIVE_ITEM, 10, print_buffer); } else { sftd_draw_text(font, FILE_LIST_POSITION, ((i + 2) * 10), COLOR_INACTIVE_ITEM, 10, print_buffer); } } } for(i = 0, current_dir_number = i + current_dir_scroll_value; i < FILE_LIST_ROWS; i++, current_dir_number++) { if(current_dir_number < num_dirs) { strncpy(print_buffer,dir_list[current_dir_number], 8); //13); print_buffer[9] = 0; //14] = 0; if((current_dir_number == current_dir_selection) && (current_column == 1)) { sftd_draw_text(font, DIR_LIST_POSITION, ((i + 2) * 10), COLOR_ACTIVE_ITEM, 10, print_buffer); } else { sftd_draw_text(font, DIR_LIST_POSITION, ((i + 2) * 10), COLOR_INACTIVE_ITEM, 10, print_buffer); } } } // Catch input // change to read key state later if (aptGetStatus() == APP_PREPARE_SLEEPMODE) { aptSignalReadyForSleep(); aptWaitStatusEvent(); } else if (aptGetStatus() == APP_SUSPENDING) { aptReturnToMenu(); } hidScanInput(); u32 keydown = hidKeysDown(); if (keydown & KEY_A) { if(current_column == 1) { if(num_dirs != 0) { repeat = 0; strcpy(prev_dir_name, current_dir_name); if (strlen(current_dir_name)>1) strcat(current_dir_name, "/"); strcat(current_dir_name, dir_list[current_dir_selection]); } } else { if(num_files != 0) { repeat = 0; return_value = 0; //strcpy(result, file_list[current_file_selection]); sprintf(result, "%s/%s", current_dir_name, file_list[current_file_selection]); break; } } } if (keydown & KEY_Y) { repeat = 0; char* findpath = strrchr(current_dir_name,'/'); if(findpath > current_dir_name) findpath[0] = '\0'; else findpath[1] = '\0'; } if (keydown & KEY_B ) { return_value = -1; repeat = 0; break; } if (keydown & KEY_X ) { return_value = 1; repeat = 0; break; } if (keydown & KEY_UP) { if(current_column == 0) { if(current_file_selection) { current_file_selection--; if(current_file_in_scroll == 0) { //clear_screen(COLOR_BG); current_file_scroll_value--; } else { current_file_in_scroll--; } } } else { if(current_dir_selection) { current_dir_selection--; if(current_dir_in_scroll == 0) { //clear_screen(COLOR_BG); current_dir_scroll_value--; } else { current_dir_in_scroll--; } } } } if (keydown & KEY_DOWN) { if(current_column == 0) { if(current_file_selection < (num_files - 1)) { current_file_selection++; if(current_file_in_scroll == (FILE_LIST_ROWS - 1)) { //clear_screen(COLOR_BG); current_file_scroll_value++; } else { current_file_in_scroll++; } } } else { if(current_dir_selection < (num_dirs - 1)) { current_dir_selection++; if(current_dir_in_scroll == (FILE_LIST_ROWS - 1)) { //clear_screen(COLOR_BG); current_dir_scroll_value++; } else { current_dir_in_scroll++; } } } } if (keydown & KEY_L) { if(current_column == 0) { if(current_file_selection>FILE_LIST_ROWS) { current_file_selection-=FILE_LIST_ROWS; current_file_scroll_value -= FILE_LIST_ROWS; if (current_file_in_scroll>current_file_selection){ //clear_screen(COLOR_BG); current_file_scroll_value=0; current_file_in_scroll=current_file_selection; } } else { current_file_selection=0; current_file_scroll_value=0; current_file_in_scroll=0; } } else { if(current_dir_selection) { current_dir_selection--; if(current_dir_in_scroll == 0) { //clear_screen(COLOR_BG); current_dir_scroll_value--; } else { current_dir_in_scroll--; } } } } if (keydown & KEY_R) { if(current_column == 0) { if(current_file_selection < (num_files - 1 - FILE_LIST_ROWS)) { current_file_selection+=FILE_LIST_ROWS; current_file_scroll_value+=FILE_LIST_ROWS; if (current_file_scroll_value>(num_files - FILE_LIST_ROWS)){ //clear_screen(COLOR_BG); current_file_scroll_value=num_files - FILE_LIST_ROWS; current_file_in_scroll= FILE_LIST_ROWS - (num_files - current_file_selection); } //clear_screen(COLOR_BG); } else { current_file_selection = num_files - 1; current_file_in_scroll = (num_files<=FILE_LIST_ROWS - 1)?num_files:FILE_LIST_ROWS - 1; current_file_scroll_value = (num_files > FILE_LIST_ROWS)?num_files - FILE_LIST_ROWS:0; } } else { if(current_dir_selection < (num_dirs - 1)) { current_dir_selection++; if(current_dir_in_scroll == (FILE_LIST_ROWS - 1)) { //clear_screen(COLOR_BG); current_dir_scroll_value++; } else { current_dir_in_scroll++; } } } } if (keydown & KEY_LEFT) { if(current_column == 1) { if(num_files != 0) current_column = 0; } } if (keydown & KEY_RIGHT) { if(current_column == 0) { if(num_dirs != 0) current_column = 1; } } sf2d_end_frame(); gui_DrawTopScreen(); sf2d_swapbuffers(); } // free pointers for(i = 0; i < num_files; i++) free(file_list[i]); free(file_list); for(i = 0; i < num_dirs; i++) free(dir_list[i]); free(dir_list); free(file_name); } return return_value; }