Hello, I am developing self-update system for native environments (android and ios). I tried some node library for downloading but no luck. Is there a way to download zip file and extract to resources folder ?
THIS IS FOR COCOS2DX ANDROID & iOS
I’ve had to download and extract a zip on cocos2dx and I did the with the following:
For downloading use the code explained here: How to download zip file from url and save it on writable directory with cocos2d-x v3.11
For extraction you will need to use some libraries for native code:
iOS - objective C (https://github.com/ZipArchive/ZipArchive)
- (void)unzip:(NSObject *)parametersObject {
NSString *zipPath = @((FileUtils::getInstance()->getWritablePath() + "theFile.zip").c_str());
NSString *destPath = @((FileUtils::getInstance()->getWritablePath()).c_str());
// Unzip on a new thread
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[SSZipArchive unzipFileAtPath:zipPath toDestination:destPath overwrite:false password:nil error:nil];
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"File extracted correctly");
// Delete de .zip file
[[NSFileManager defaultManager] removeItemAtPath: zipPath error: nil];
});
});
}
Android - Java (https://github.com/zeroturnaround/zt-zip)
private void unZip() {
Log.d("", “Start unzip, zip located at: " + Cocos2dxHelper.getCocos2dxWritablePath() + “/theFile.zip”);
String targetPath = Cocos2dxHelper.getCocos2dxWritablePath() + “/theFile.zip”;
String destinationPath = Cocos2dxHelper.getCocos2dxWritablePath();
ZipUtil.unpack(new File(targetPath), new File(destinationPath));
Log.d(”", “Unzipped!”);
new File(targetPath).delete();
}