iOS: add unpack error handling

master
Maksim 2020-06-11 16:46:09 +02:00
parent 7059d450f2
commit a77442c97f
4 changed files with 23 additions and 7 deletions

View File

@ -1,5 +1,6 @@
import Foundation
import SSZipArchive
import Bugsnag
private enum Constants {
static let percentProgressIndex: Int = 0
@ -31,7 +32,7 @@ final class ZipManager: NSObject {
private var assets: [Asset] = [.init(name: "assets", path: .library, versioned: true),
.init(name: "worlds", path: .documents, versioned: false)]
@objc func runProcess(_ progress: @escaping (_ percent: Int) -> Void) {
@objc func runProcess(_ progress: @escaping (_ percent: Int) -> Void, _ errorBlock: @escaping (Error) -> Void) {
let versionRuntime = VersionManager.parseVersion()
for (index, asset) in assets.enumerated() {
@ -48,17 +49,17 @@ final class ZipManager: NSObject {
}
#endif
unzipFile(at: zippath, to: asset.destinationPath, vRuntime: versionRuntime) { (percent) in
unzipFile(at: zippath, to: asset.destinationPath, vRuntime: versionRuntime, { (percent) in
if index == Constants.percentProgressIndex {
progress(percent)
}
}
}, errorBlock)
}
}
}
private extension ZipManager {
func unzipFile(at path: String, to destination: String, vRuntime: UInt32, _ block: @escaping (_ percent: Int) -> Void) {
func unzipFile(at path: String, to destination: String, vRuntime: UInt32, _ block: @escaping (_ percent: Int) -> Void, _ errorBlock :@escaping (Error) -> Void) {
let fileManager = FileManager.default
let files = (try? fileManager.contentsOfDirectory(atPath: destination)) ?? []
@ -74,7 +75,12 @@ private extension ZipManager {
block(progress * 100 / total)
}) { (path, success, error) in
block(100)
if let error = error {
Bugsnag.notifyError(error)
errorBlock(error)
} else {
block(100)
}
}
VersionManager.writeVersion(withPath: destination, ver: vRuntime)

11
build/iOS/MultiCraft/MultiCraft/ioswrap.m Executable file → Normal file
View File

@ -62,6 +62,17 @@ void ioswrap_assets()
[manager runProcess:^(NSInteger progress) {
[progressVC updateProgress:progress];
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, YES);
} :^(NSError * error) {
UIAlertController *vc = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Unexpected issue, please restart the game!", nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Close game", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
exit(0);
}];
[vc addAction:cancel];
[window.rootViewController presentViewController:vc animated:NO completion:nil];
while (true)
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, YES);
}];
[progressVC dismissView];

View File

@ -16,9 +16,8 @@ end
target 'MultiCraft' do
source 'https://cdn.cocoapods.org/'
source 'https://github.com/MoNTE48/VorbisOgg-Specs.git'
pod 'Bugsnag', '5.23.1'
pod 'Bugsnag', '5.23.3'
pod 'leveldb-library'
pod 'libvorbis'
pod 'LuaJITPod', :git => 'https://github.com/MoNTE48/LuaJITPod'