1
0
mirror of https://github.com/opa334/TrollStore.git synced 2025-07-06 16:28:45 +08:00

Create TSStreamingInstaller.m

This commit is contained in:
a1109471307 2025-07-03 18:08:34 +08:00 committed by GitHub
parent 1a85ac7247
commit cf150dd451
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,61 @@
#import "TSStreamingInstaller.h"
#import "minizip/unzip.h"
#define CHUNK_SIZE 16384
@implementation TSStreamingInstaller {
unzFile _zipFile;
BOOL _cancelled;
}
- (BOOL)installToDestination:(NSString *)destPath {
// ZIP
_zipFile = unzOpen64([self.ipaPath UTF8String]);
if (!_zipFile) return NO;
// ZIP
unz_global_info64 globalInfo;
unzGetGlobalInfo64(_zipFile, &globalInfo);
for (int i = 0; i < globalInfo.number_entry; i++) {
if (_cancelled) break;
//
unz_file_info64 fileInfo;
char filename[256];
unzGetCurrentFileInfo64(_zipFile, &fileInfo, filename, sizeof(filename), NULL, 0, NULL, 0);
NSString *fullPath = [destPath stringByAppendingPathComponent:[NSString stringWithUTF8String:filename]];
if (filename[strlen(filename)-1] == '/') {
//
[[NSFileManager defaultManager] createDirectoryAtPath:fullPath withIntermediateDirectories:YES attributes:nil error:nil];
} else {
//
FILE *fp = fopen([fullPath UTF8String], "wb");
unzOpenCurrentFile(_zipFile);
void *buffer = malloc(CHUNK_SIZE);
while (true) {
int bytes = unzReadCurrentFile(_zipFile, buffer, CHUNK_SIZE);
if (bytes <= 0) break;
fwrite(buffer, 1, bytes, fp);
}
fclose(fp);
free(buffer);
unzCloseCurrentFile(_zipFile);
}
//
float progress = (float)(i+1) / (float)globalInfo.number_entry;
if (self.progressHandler) self.progressHandler(progress);
unzGoToNextFile(_zipFile);
}
unzClose(_zipFile);
return !_cancelled;
}
@end