int fileListGetEntries(FileList *list, char *path) { if (isInArchive()) { return fileListGetArchiveEntries(list, path); } if (strcmp(path, HOME_PATH) == 0) { return fileListGetMountPointEntries(list); } return fileListGetDirectoryEntries(list, path); }
int getArchivePathInfo(char *path, uint64_t *size, uint32_t *folders, uint32_t *files) { if (!uf) return -1; SceIoStat stat; memset(&stat, 0, sizeof(SceIoStat)); if (archiveFileGetstat(path, &stat) < 0) { FileList list; memset(&list, 0, sizeof(FileList)); fileListGetArchiveEntries(&list, path, SORT_NONE); FileListEntry *entry = list.head->next; // Ignore .. int i; for (i = 0; i < list.length - 1; i++) { char *new_path = malloc(strlen(path) + strlen(entry->name) + 2); snprintf(new_path, MAX_PATH_LENGTH, "%s%s", path, entry->name); getArchivePathInfo(new_path, size, folders, files); free(new_path); entry = entry->next; } if (folders) (*folders)++; fileListEmpty(&list); } else { if (size) (*size) += stat.st_size; if (files) (*files)++; } return 0; }
int extractArchivePath(char *src, char *dst, FileProcessParam *param) { if (!uf) return -1; SceIoStat stat; memset(&stat, 0, sizeof(SceIoStat)); if (archiveFileGetstat(src, &stat) < 0) { FileList list; memset(&list, 0, sizeof(FileList)); fileListGetArchiveEntries(&list, src, SORT_NONE); int ret = sceIoMkdir(dst, 0777); if (ret < 0 && ret != SCE_ERROR_ERRNO_EEXIST) { fileListEmpty(&list); return ret; } if (param) { if (param->value) (*param->value) += DIRECTORY_SIZE; if (param->SetProgress) param->SetProgress(param->value ? *param->value : 0, param->max); if (param->cancelHandler && param->cancelHandler()) { fileListEmpty(&list); return 0; } } FileListEntry *entry = list.head->next; // Ignore .. int i; for (i = 0; i < list.length - 1; i++) { char *src_path = malloc(strlen(src) + strlen(entry->name) + 2); snprintf(src_path, MAX_PATH_LENGTH, "%s%s", src, entry->name); char *dst_path = malloc(strlen(dst) + strlen(entry->name) + 2); snprintf(dst_path, MAX_PATH_LENGTH, "%s%s", dst, entry->name); int ret = extractArchivePath(src_path, dst_path, param); free(dst_path); free(src_path); if (ret <= 0) { fileListEmpty(&list); return ret; } entry = entry->next; } fileListEmpty(&list); } else { SceUID fdsrc = archiveFileOpen(src, SCE_O_RDONLY, 0); if (fdsrc < 0) return fdsrc; SceUID fddst = sceIoOpen(dst, SCE_O_WRONLY | SCE_O_CREAT | SCE_O_TRUNC, 0777); if (fddst < 0) { archiveFileClose(fdsrc); return fddst; } void *buf = malloc(TRANSFER_SIZE); uint64_t seek = 0; while (1) { int read = archiveFileRead(fdsrc, buf, TRANSFER_SIZE); if (read < 0) { free(buf); sceIoClose(fddst); archiveFileClose(fdsrc); return read; } if (read == 0) break; int written = sceIoWrite(fddst, buf, read); if (written == SCE_ERROR_ERRNO_ENODEV) { fddst = sceIoOpen(dst, SCE_O_WRONLY | SCE_O_CREAT, 0777); if (fddst >= 0) { sceIoLseek(fddst, seek, SCE_SEEK_SET); written = sceIoWrite(fddst, buf, read); } } if (written < 0) { free(buf); sceIoClose(fddst); archiveFileClose(fdsrc); return written; } seek += written; if (param) { if (param->value) (*param->value) += read; if (param->SetProgress) param->SetProgress(param->value ? *param->value : 0, param->max); if (param->cancelHandler && param->cancelHandler()) { free(buf); sceIoClose(fddst); archiveFileClose(fdsrc); return 0; } } } free(buf); sceIoClose(fddst); archiveFileClose(fdsrc); } return 1; }