iOS: add unpack error handling
parent
7059d450f2
commit
a77442c97f
|
@ -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)
|
||||
|
|
|
@ -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];
|
||||
|
|
Binary file not shown.
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue