TitleList *getUpdateCIAs() { Handle dir, CIAFile; FS_DirectoryEntry ent; int ret; int ciafiles; TitleList *updateCIAs; char ciaPath[9 + 16 + 4 + 1]; // /updates/ + 16 hex digits + .cia + \0 LOG_INFO("getUpdateCIAs"); // Run through first and count .cia files. dir = openDirectory(CIAS_PATH); if(dir == 0) { LOG_ERROR("getUpdateCIAs: Failed to open SDMC:" CIAS_PATH ".\n"); printf("Failed to open SDMC:" CIAS_PATH ".\n"); goto error0; } ciafiles = 0; for(;;) { ret = getNextFile(dir, &ent); if(ret < 1) { if(ret == -1) { LOG_ERROR("getUpdateCIAs: Error reading directory."); printf("Error reading directory.\n"); goto error2; } break; } simpleUTF16toASCII((char *)(ent.name)); if(isCIAName((char *)(ent.name)) == 1) { ciafiles++; } } closeDirectory(dir); LOG_VERBOSE("Found %d files.", ciafiles); updateCIAs = initTitleList(ciafiles, 0); // Run through a second time and add CIA info. dir = openDirectory(CIAS_PATH); if(dir == 0) { LOG_ERROR("getUpdateCIAs: Failed to open SDMC:" CIAS_PATH ".\n"); printf("Failed to open SDMC:" CIAS_PATH ".\n"); goto error1; } ciafiles = 0; for(;;) { ret = getNextFile(dir, &ent); if(ret < 1) { if(ret == -1) { LOG_ERROR("getUpdateCIAs: Error reading directory."); printf("Error reading directory.\n"); goto error2; } break; } simpleUTF16toASCII((char *)(ent.name)); if(isCIAName((char *)(ent.name)) == 1) { snprintf(ciaPath, 9 + 16 + 4 + 1, CIAS_PATH "%s", ent.name); CIAFile = openFileHandle(ciaPath, FS_OPEN_READ); if(CIAFile == 0) { LOG_ERROR("getUpdateCIAs: Failed to open %s for read.\n", ciaPath); printf("Failed to open %s for read.\n", ciaPath); goto error2; } if(R_FAILED(AM_GetCiaFileInfo(MEDIATYPE_NAND, updateCIAs->title[ciafiles], CIAFile))) { LOG_ERROR("getUpdateCIAs: Failed to get information on %s.\n", ciaPath); printf("Failed to get information on %s.\n", ciaPath); goto error3; } closeFileHandle(CIAFile); ciafiles++; LOG_VERBOSE("getUpdateCIAs: Added %s.", (char *)(ent.name)); } } closeDirectory(dir); LOG_INFO("getUpdateCIAs: Got CIAs from SD card."); return(updateCIAs); error3: closeFileHandle(CIAFile); error2: closeDirectory(dir); error1: freeTitleList(updateCIAs); error0: LOG_ERROR("getUpdateCIAs: Failed to get CIAs from SD card."); return(NULL); }
/**************************************************************************** * This function will read the contents of a directory and store the * * contents in the folder structure. The ext parameter works as a filter * * to read in only certain file extension types. After reading the * * directory, the function will sort the contents. * ****************************************************************************/ int readDirectory(char *ext, int media) { int ret = 1; iox_dirent_t directory; int size; char folderName[255]; unsigned int numToc, index; char *extcmp; folder.fIndex = 0; struct TocEntry cdDirectory[255]; size = strlen(ext); switch (media) { case 0: { while (ret > 0) { ret = fileXioDread(folder.iDir, &directory); if (ret > 0) { if (FIO_S_ISDIR(directory.stat.mode)) //is a directory { strcpy(folder.object[folder.fIndex].name, ""); strcat(folder.object[folder.fIndex].name, "/"); strcat(folder.object[folder.fIndex].name, directory.name); folder.object[folder.fIndex].type = 0; folder.object[folder.fIndex].count = folder.fIndex; folder.fIndex++; } else if (FIO_S_ISREG(directory.stat.mode)) //is a file { if (size > ret) size = 0; extcmp = &directory.name[ret-size]; if (strcasecmp(extcmp, ext) == 0) { strcpy(folder.object[folder.fIndex].name, directory.name); folder.object[folder.fIndex].type = 1; folder.object[folder.fIndex].count = folder.fIndex; folder.fIndex++; } } } } folder.fMax = folder.fIndex; folder.fIndex = 0; sortFolder(); for (ret = 0; ret < folder.fMax; ret++) { if (folder.object[ret].type == 0) { strcpy(folderName, &folder.object[ret].name[1]); strcpy(folder.object[ret].name, folderName); } } closeDirectory(MODE_HDD); return folder.fMax; } case 1: { numToc = CDVD_GetDir(&folder.directory[5], NULL, CDVD_GET_FILES_AND_DIRS, cdDirectory, 254, NULL); CDVD_Stop(); #define CD_S_ISDIR(x) x & 2 #define CD_S_ISFILE(x) !CD_S_ISDIR(x) for (index=0; index<numToc; index++) { if (CD_S_ISDIR(cdDirectory[index].fileProperties)) //is a folder { strcpy(folder.object[folder.fIndex].name, ""); strcat(folder.object[folder.fIndex].name, "/"); strcat(folder.object[folder.fIndex].name, cdDirectory[index].filename); folder.object[folder.fIndex].type = 0; folder.object[folder.fIndex].count = folder.fIndex; folder.fIndex++; } else { ret = strlen(cdDirectory[index].filename); if (size > ret) size = 0; extcmp = &cdDirectory[index].filename[ret-size]; if (strcasecmp(extcmp, ext) == 0) { strcpy(folder.object[folder.fIndex].name, cdDirectory[index].filename); folder.object[folder.fIndex].type = 1; folder.object[folder.fIndex].count = folder.fIndex; folder.fIndex++; } } } folder.fMax = folder.fIndex; folder.fIndex = 0; sortFolder(); for (ret = 0; ret < folder.fMax; ret++) { if (folder.object[ret].type == 0) { strcpy(folderName, &folder.object[ret].name[1]); strcpy(folder.object[ret].name, folderName); } } return folder.fMax; } } return 0; }