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; }
int archiveOpen(char *file) { // Start position of the archive path archive_path_start = strlen(file) + 1; // Close previous zip file first if (uf) unzClose(uf); // Open zip file uf = unzOpen64(file); if (!uf) return -1; // Clear archive list memset(&archive_list, 0, sizeof(FileList)); // Go through all files int res; char name[MAX_PATH_LENGTH]; unz_file_info64 file_info; res = unzGoToFirstFile2(uf, &file_info, name, MAX_PATH_LENGTH, NULL, 0, NULL, 0); if (res < 0) return res; while (res >= 0) { FileListEntry *entry = malloc(sizeof(FileListEntry)); // File info strcpy(entry->name, name); entry->is_folder = 0; entry->name_length = file_info.size_filename; entry->size = file_info.uncompressed_size; entry->size2 = file_info.compressed_size; // Time SceDateTime time; sceRtcSetDosTime(&time, file_info.dosDate); convertLocalTimeToUtc(&time, &time); memcpy(&entry->ctime, &time, sizeof(SceDateTime)); memcpy(&entry->mtime, &time, sizeof(SceDateTime)); memcpy(&entry->atime, &time, sizeof(SceDateTime)); // Get pos unzGetFilePos64(uf, (unz64_file_pos *)&entry->reserved); // Add entry fileListAddEntry(&archive_list, entry, SORT_BY_NAME); // Next res = unzGoToNextFile2(uf, &file_info, name, MAX_PATH_LENGTH, NULL, 0, NULL, 0); } return 0; }
int fileListGetMountPointEntries(FileList *list) { int i; for (i = 0; i < N_MOUNT_POINTS; i++) { if (mount_points[i]) { FileListEntry *entry = malloc(sizeof(FileListEntry)); strcpy(entry->name, mount_points[i]); entry->is_folder = 1; entry->type = FILE_TYPE_UNKNOWN; SceIoStat stat; memset(&stat, 0, sizeof(SceIoStat)); sceIoGetstat(entry->name, &stat); memcpy(&entry->time, (SceRtcTime *)&stat.st_mtime, sizeof(SceRtcTime)); fileListAddEntry(list, entry, SORT_BY_NAME_AND_FOLDER); } } return 0; }
int fileListGetArchiveEntries(FileList *list, char *path, int sort) { int res; if (!uf) return -1; FileListEntry *entry = malloc(sizeof(FileListEntry)); strcpy(entry->name, DIR_UP); entry->name_length = strlen(entry->name); entry->is_folder = 1; entry->type = FILE_TYPE_UNKNOWN; fileListAddEntry(list, entry, sort); char *archive_path = path + archive_path_start; int name_length = strlen(archive_path); FileListEntry *archive_entry = archive_list.head; int i; for (i = 0; i < archive_list.length; i++) { if (archive_entry->name_length >= name_length && strncasecmp(archive_entry->name, archive_path, name_length) == 0) { // Needs a / at end char *p = strchr(archive_entry->name + name_length, '/'); // it's a sub-directory if it has got a slash if (p) *p = '\0'; char name[MAX_PATH_LENGTH]; strcpy(name, archive_entry->name + name_length); if (p) { addEndSlash(name); } if (strlen(name) > 0 && !fileListFindEntry(list, name)) { FileListEntry *entry = malloc(sizeof(FileListEntry)); strcpy(entry->name, archive_entry->name + name_length); if (p) { addEndSlash(entry->name); entry->is_folder = 1; entry->type = FILE_TYPE_UNKNOWN; list->folders++; } else { entry->is_folder = 0; entry->type = getFileType(entry->name); list->files++; } entry->name_length = strlen(entry->name); entry->size = archive_entry->size; entry->size2 = archive_entry->size2; memcpy(&entry->ctime, &archive_entry->ctime, sizeof(SceDateTime)); memcpy(&entry->mtime, &archive_entry->mtime, sizeof(SceDateTime)); memcpy(&entry->atime, &archive_entry->atime, sizeof(SceDateTime)); fileListAddEntry(list, entry, sort); } if (p) *p = '/'; } // Next archive_entry = archive_entry->next; } return 0; }