| 37 | } |
| 38 | |
| 39 | static int zipAddFile(zipFile zf, const char *path, int filename_start, int level, FileProcessParam *param) { |
| 40 | int res; |
| 41 | |
| 42 | // Get file stat |
| 43 | SceIoStat stat; |
| 44 | memset(&stat, 0, sizeof(SceIoStat)); |
| 45 | res = sceIoGetstat(path, &stat); |
| 46 | if (res < 0) |
| 47 | return res; |
| 48 | |
| 49 | // Get file local time |
| 50 | zip_fileinfo zi; |
| 51 | memset(&zi, 0, sizeof(zip_fileinfo)); |
| 52 | convertToZipTime(&stat.st_mtime, &zi.tmz_date); |
| 53 | |
| 54 | // Large file? |
| 55 | int use_zip64 = (stat.st_size >= 0xFFFFFFFF); |
| 56 | |
| 57 | // Open new file in zip |
| 58 | char filename[MAX_PATH_LENGTH]; |
| 59 | strcpy(filename, path+filename_start); |
| 60 | |
| 61 | res = zipOpenNewFileInZip3_64(zf, filename, &zi, |
| 62 | NULL, 0, NULL, 0, NULL, |
| 63 | (level != 0) ? Z_DEFLATED : 0, |
| 64 | level, 0, |
| 65 | -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, |
| 66 | NULL, 0, use_zip64); |
| 67 | |
| 68 | if (res < 0) |
| 69 | return res; |
| 70 | |
| 71 | // Open file to add |
| 72 | SceUID fd = sceIoOpen(path, SCE_O_RDONLY, 0); |
| 73 | if (fd < 0) { |
| 74 | zipCloseFileInZip(zf); |
| 75 | return fd; |
| 76 | } |
| 77 | |
| 78 | // Add file to zip |
| 79 | void *buf = memalign(4096, TRANSFER_SIZE); |
| 80 | |
| 81 | uint64_t seek = 0; |
| 82 | |
| 83 | while (1) { |
| 84 | int read = sceIoRead(fd, buf, TRANSFER_SIZE); |
| 85 | |
| 86 | if (read < 0) { |
| 87 | free(buf); |
| 88 | |
| 89 | sceIoClose(fd); |
| 90 | zipCloseFileInZip(zf); |
| 91 | |
| 92 | return read; |
| 93 | } |
| 94 | |
| 95 | if (read == 0) |
| 96 | break; |
no test coverage detected