mirror of
https://github.com/zydeco/minivmac4ios.git
synced 2024-11-26 00:49:20 +00:00
support disk image creation on iOS 7 (fo realz)
This commit is contained in:
parent
20a99c5a88
commit
b2194bfcc5
@ -424,37 +424,58 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Creating Disk Image", nil) message:@"\n\n\n" preferredStyle:UIAlertControllerStyleAlert];
|
UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
|
||||||
[self presentViewController:alertController animated:true completion:^{
|
activityIndicatorView.color = [UIColor blackColor];
|
||||||
UIView *alertView = alertController.view;
|
if ([UIAlertController class]) {
|
||||||
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
|
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Creating Disk Image", nil) message:@"\n\n\n" preferredStyle:UIAlertControllerStyleAlert];
|
||||||
activityView.color = [UIColor blackColor];
|
[self presentViewController:alertController animated:true completion:^{
|
||||||
activityView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
|
UIView *alertView = alertController.view;
|
||||||
activityView.center = CGPointMake(alertView.bounds.size.width / 2.0, alertView.bounds.size.height / 2.0 + 32.0);
|
activityIndicatorView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
|
||||||
[alertView addSubview:activityView];
|
activityIndicatorView.center = CGPointMake(alertView.bounds.size.width / 2.0, alertView.bounds.size.height / 2.0 + 32.0);
|
||||||
[activityView startAnimating];
|
[alertView addSubview:activityIndicatorView];
|
||||||
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
|
[activityIndicatorView startAnimating];
|
||||||
int error = 0;
|
[self _writeNewDiskImage:fd size:size activityIndicator:activityIndicatorView progressAlert:alertController];
|
||||||
if (ftruncate(fd, size)) {
|
}];
|
||||||
error = errno;
|
} else {
|
||||||
}
|
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Creating Disk Image", nil) message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
|
||||||
close(fd);
|
[alertView addSubview:activityIndicatorView];
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
[activityIndicatorView startAnimating];
|
||||||
[activityView stopAnimating];
|
[alertView setValue:activityIndicatorView forKey:@"accessoryView"];
|
||||||
|
[alertView show];
|
||||||
|
[self _writeNewDiskImage:fd size:size activityIndicator:activityIndicatorView progressAlert:alertView];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)_writeNewDiskImage:(int)fd size:(off_t)size activityIndicator:(UIActivityIndicatorView*)activityIndicatorView progressAlert:(id)progressAlert {
|
||||||
|
long queue = NSFoundationVersionNumber >= NSFoundationVersionNumber_iOS_8_0 ? QOS_CLASS_USER_INITIATED : DISPATCH_QUEUE_PRIORITY_HIGH;
|
||||||
|
dispatch_async(dispatch_get_global_queue(queue, 0), ^{
|
||||||
|
int error = 0;
|
||||||
|
if (ftruncate(fd, size)) {
|
||||||
|
error = errno;
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[activityIndicatorView stopAnimating];
|
||||||
|
if ([progressAlert isKindOfClass:[UIAlertController class]]) {
|
||||||
[self dismissViewControllerAnimated:YES completion:^{
|
[self dismissViewControllerAnimated:YES completion:^{
|
||||||
if (error) {
|
if (error) {
|
||||||
[[AppDelegate sharedInstance] showAlertWithTitle:NSLocalizedString(@"Could not create disk image", nil) message:[[NSString alloc] initWithUTF8String:strerror(error)]];
|
[[AppDelegate sharedInstance] showAlertWithTitle:NSLocalizedString(@"Could not create disk image", nil) message:[[NSString alloc] initWithUTF8String:strerror(error)]];
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
[self.tableView beginUpdates];
|
} else if ([progressAlert isKindOfClass:[UIAlertView class]]) {
|
||||||
[self loadDirectoryContents];
|
UIAlertView *alert = progressAlert;
|
||||||
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
|
[alert dismissWithClickedButtonIndex:0 animated:NO];
|
||||||
[self.tableView endUpdates];
|
if (error) {
|
||||||
});
|
[[AppDelegate sharedInstance] showAlertWithTitle:NSLocalizedString(@"Could not create disk image", nil) message:[[NSString alloc] initWithUTF8String:strerror(error)]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[self.tableView beginUpdates];
|
||||||
|
[self loadDirectoryContents];
|
||||||
|
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
|
||||||
|
[self.tableView endUpdates];
|
||||||
});
|
});
|
||||||
}];
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Text Field Delegate
|
#pragma mark - Text Field Delegate
|
||||||
|
|
||||||
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
|
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
|
||||||
|
Loading…
Reference in New Issue
Block a user