print success in the example projects
This commit is contained in:
parent
b8a68d1a08
commit
252fb76ff4
@ -26,115 +26,114 @@
|
||||
|
||||
#pragma mark - Life Cycle
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
[super viewDidLoad];
|
||||
|
||||
_file1.text = @"";
|
||||
_file2.text = @"";
|
||||
_file3.text = @"";
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
}
|
||||
|
||||
#pragma mark - IBAction
|
||||
- (IBAction)zipPressed:(id)sender {
|
||||
NSString *sampleDataPath = [[NSBundle mainBundle].bundleURL
|
||||
URLByAppendingPathComponent:@"Sample Data"
|
||||
isDirectory:YES].path;
|
||||
_zipPath = [self tempZipPath];
|
||||
NSString *password = _passwordField.text;
|
||||
BOOL success = [SSZipArchive createZipFileAtPath:_zipPath
|
||||
withContentsOfDirectory:sampleDataPath
|
||||
withPassword:password.length > 0 ? password : nil];
|
||||
if (success) {
|
||||
_unzipButton.enabled = YES;
|
||||
_zipButton.enabled = NO;
|
||||
} else {
|
||||
NSLog(@"No success");
|
||||
}
|
||||
_resetButton.enabled = YES;
|
||||
NSString *sampleDataPath = [[NSBundle mainBundle].bundleURL
|
||||
URLByAppendingPathComponent:@"Sample Data"
|
||||
isDirectory:YES].path;
|
||||
_zipPath = [self tempZipPath];
|
||||
NSString *password = _passwordField.text;
|
||||
BOOL success = [SSZipArchive createZipFileAtPath:_zipPath
|
||||
withContentsOfDirectory:sampleDataPath
|
||||
withPassword:password.length > 0 ? password : nil];
|
||||
if (success) {
|
||||
NSLog(@"Success zip");
|
||||
_unzipButton.enabled = YES;
|
||||
_zipButton.enabled = NO;
|
||||
} else {
|
||||
NSLog(@"No success zip");
|
||||
}
|
||||
_resetButton.enabled = YES;
|
||||
}
|
||||
|
||||
- (IBAction)unzipPressed:(id)sender {
|
||||
if (!_zipPath) {
|
||||
return;
|
||||
}
|
||||
NSString *unzipPath = [self tempUnzipPath];
|
||||
if (!unzipPath) {
|
||||
return;
|
||||
}
|
||||
NSString *password = _passwordField.text;
|
||||
BOOL success = [SSZipArchive unzipFileAtPath:_zipPath
|
||||
toDestination:unzipPath
|
||||
overwrite:YES
|
||||
password:password.length > 0 ? password : nil
|
||||
error:nil];
|
||||
if (!success) {
|
||||
NSLog(@"No success");
|
||||
return;
|
||||
}
|
||||
NSError *error = nil;
|
||||
NSMutableArray<NSString *> *items = [[[NSFileManager defaultManager]
|
||||
contentsOfDirectoryAtPath:unzipPath
|
||||
error:&error] mutableCopy];
|
||||
if (error) {
|
||||
return;
|
||||
}
|
||||
[items enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
switch (idx) {
|
||||
case 0: {
|
||||
self.file1.text = obj;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
self.file2.text = obj;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
self.file3.text = obj;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
NSLog(@"Went beyond index of assumed files");
|
||||
break;
|
||||
}
|
||||
if (!_zipPath) {
|
||||
return;
|
||||
}
|
||||
}];
|
||||
_unzipButton.enabled = NO;
|
||||
NSString *unzipPath = [self tempUnzipPath];
|
||||
if (!unzipPath) {
|
||||
return;
|
||||
}
|
||||
NSString *password = _passwordField.text;
|
||||
BOOL success = [SSZipArchive unzipFileAtPath:_zipPath
|
||||
toDestination:unzipPath
|
||||
overwrite:YES
|
||||
password:password.length > 0 ? password : nil
|
||||
error:nil];
|
||||
if (success) {
|
||||
NSLog(@"Success unzip");
|
||||
} else {
|
||||
NSLog(@"No success unzip");
|
||||
return;
|
||||
}
|
||||
NSError *error = nil;
|
||||
NSMutableArray<NSString *> *items = [[[NSFileManager defaultManager]
|
||||
contentsOfDirectoryAtPath:unzipPath
|
||||
error:&error] mutableCopy];
|
||||
if (error) {
|
||||
return;
|
||||
}
|
||||
[items enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
switch (idx) {
|
||||
case 0: {
|
||||
self.file1.text = obj;
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
self.file2.text = obj;
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
self.file3.text = obj;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
NSLog(@"Went beyond index of assumed files");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}];
|
||||
_unzipButton.enabled = NO;
|
||||
}
|
||||
|
||||
- (IBAction)resetPressed:(id)sender {
|
||||
_file1.text = @"";
|
||||
_file2.text = @"";
|
||||
_file3.text = @"";
|
||||
_zipButton.enabled = YES;
|
||||
_unzipButton.enabled = NO;
|
||||
_resetButton.enabled = NO;
|
||||
_file1.text = @"";
|
||||
_file2.text = @"";
|
||||
_file3.text = @"";
|
||||
_zipButton.enabled = YES;
|
||||
_unzipButton.enabled = NO;
|
||||
_resetButton.enabled = NO;
|
||||
}
|
||||
|
||||
#pragma mark - Private
|
||||
- (NSString *)tempZipPath {
|
||||
NSString *path = [NSString stringWithFormat:@"%@/\%@.zip",
|
||||
NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0],
|
||||
[NSUUID UUID].UUIDString];
|
||||
return path;
|
||||
NSString *path = [NSString stringWithFormat:@"%@/\%@.zip",
|
||||
NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0],
|
||||
[NSUUID UUID].UUIDString];
|
||||
return path;
|
||||
}
|
||||
|
||||
- (NSString *)tempUnzipPath {
|
||||
NSString *path = [NSString stringWithFormat:@"%@/\%@",
|
||||
NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0],
|
||||
[NSUUID UUID].UUIDString];
|
||||
NSURL *url = [NSURL fileURLWithPath:path];
|
||||
NSError *error = nil;
|
||||
[[NSFileManager defaultManager] createDirectoryAtURL:url
|
||||
withIntermediateDirectories:YES
|
||||
attributes:nil
|
||||
error:&error];
|
||||
if (error) {
|
||||
return nil;
|
||||
}
|
||||
return url.path;
|
||||
NSString *path = [NSString stringWithFormat:@"%@/\%@",
|
||||
NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0],
|
||||
[NSUUID UUID].UUIDString];
|
||||
NSURL *url = [NSURL fileURLWithPath:path];
|
||||
NSError *error = nil;
|
||||
[[NSFileManager defaultManager] createDirectoryAtURL:url
|
||||
withIntermediateDirectories:YES
|
||||
attributes:nil
|
||||
error:&error];
|
||||
if (error) {
|
||||
return nil;
|
||||
}
|
||||
return url.path;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -36,11 +36,6 @@ class ViewController: UIViewController {
|
||||
file3.text = ""
|
||||
}
|
||||
|
||||
override func didReceiveMemoryWarning() {
|
||||
super.didReceiveMemoryWarning()
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
// MARK: IBAction
|
||||
|
||||
@IBAction func zipPressed(_: UIButton) {
|
||||
@ -50,10 +45,11 @@ class ViewController: UIViewController {
|
||||
|
||||
let success = SSZipArchive.createZipFile(atPath: zipPath!, withContentsOfDirectory: sampleDataPath, withPassword: password?.isEmpty == false ? password : nil)
|
||||
if success {
|
||||
print("Success zip")
|
||||
unzipButton.isEnabled = true
|
||||
zipButton.isEnabled = false
|
||||
} else {
|
||||
print("No success")
|
||||
print("No success zip")
|
||||
}
|
||||
resetButton.isEnabled = true
|
||||
}
|
||||
@ -72,8 +68,10 @@ class ViewController: UIViewController {
|
||||
toDestination: unzipPath,
|
||||
overwrite: true,
|
||||
password: password?.isEmpty == false ? password : nil)
|
||||
if success == nil {
|
||||
print("No success")
|
||||
if success != nil {
|
||||
print("Success unzip")
|
||||
} else {
|
||||
print("No success unzip")
|
||||
return
|
||||
}
|
||||
|
||||
@ -127,7 +125,6 @@ class ViewController: UIViewController {
|
||||
} catch {
|
||||
return nil
|
||||
}
|
||||
|
||||
return url.path
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user