-
Notifications
You must be signed in to change notification settings - Fork 101
Added checks for volume files #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0415896
9196576
2b143c1
1061278
124e167
c054bfe
8d3e7b0
c0fd271
061c2f3
949a7fa
2e8dd20
1feda29
0a8591b
ed799b3
f74850c
27eb8b2
1f8a963
b1b86a1
9d5e717
8586292
9ce9134
844377e
4a585be
fa3139f
9a26401
071d0bc
5f96585
b447aec
50700ac
97a24bc
0f0e6ac
e3c7718
83683a1
dcaf9c9
0f23417
0060bc1
560a631
9587b99
99ff47c
b8b0baa
9786f81
3c4d1d2
65ffbba
2144a1e
ec31928
660b9b1
5784477
09c21db
ce1717e
b090e89
13effa0
602bb90
df360db
3753993
d102983
61ac50b
b3b05ad
53311f2
614f35f
0f89b94
e83d7af
7043e0d
8364d76
8f4992e
e5d4743
41a6107
8231542
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,7 +134,9 @@ - (instancetype)initWithFile:(NSURL *)fileURL password:(NSString*)password error | |
| if (error) { | ||
| *error = nil; | ||
| } | ||
|
|
||
|
|
||
| fileURL = [self firstVolumeURL:fileURL]; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just added it before |
||
|
|
||
| URKLogDebug("Initializing private fields"); | ||
|
|
||
| NSError *bookmarkError = nil; | ||
|
|
@@ -255,7 +257,15 @@ - (NSNumber *)compressedSize | |
|
|
||
| - (BOOL)hasMultipleVolumes | ||
| { | ||
| return NO; | ||
| NSError *listError = nil; | ||
| NSArray<NSURL*> *volumeURLs = [self listVolumeURLs:&listError]; | ||
|
|
||
| if (!volumeURLs) { | ||
| NSLog(@"Error getting file volumes list: %@", listError); | ||
| return false; | ||
| } | ||
|
|
||
| return volumeURLs.count > 1; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No extra parenthesis 👍 |
||
| } | ||
|
|
||
|
|
||
|
|
@@ -385,23 +395,75 @@ + (BOOL)urlIsARAR:(NSURL *)fileURL | |
| return [NSArray arrayWithArray:fileInfos]; | ||
| } | ||
|
|
||
| - (nullable NSString *)firstVolumePath { | ||
| return @""; | ||
| - (NSString *)firstVolumePath:(NSString *)filePath { | ||
| NSURL *fileURL = [self firstVolumeURL:[NSURL fileURLWithPath:filePath]]; | ||
|
|
||
| return fileURL.path; | ||
| } | ||
|
|
||
| - (nullable NSURL *)firstVolumeURL { | ||
| NSString *path = [self firstVolumePath]; | ||
| - (NSURL *)firstVolumeURL:(NSURL *)fileURL { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed the contents to the
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a few thoughts on this.
|
||
|
|
||
| if (![path length]) { | ||
| return nil; | ||
| URKLogDebug("Checking if the archive is part of a volume..."); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
|
|
||
| __block NSString *volumePath = fileURL.path; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't need to be a |
||
| NSTextCheckingResult * match; | ||
|
|
||
| if (volumePath.length) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Invert this |
||
| { | ||
| NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(.part)([0-9]+)(.rar)$" options:NSRegularExpressionCaseInsensitive error:nil]; | ||
| match = [regex firstMatchInString:volumePath options:0 range:NSMakeRange(0, volumePath.length)]; | ||
| if (match) | ||
| { | ||
| URKLogDebug("The archive part of a volume"); | ||
|
|
||
| int rangeLength = 10; | ||
| NSString * leadingZeros = @""; | ||
| while (rangeLength < match.range.length) | ||
| { | ||
| rangeLength++; | ||
| leadingZeros = [leadingZeros stringByAppendingString:@"0"]; | ||
| } | ||
| NSString * regexTemplate = [NSString stringWithFormat:@"$1%@1$3", leadingZeros]; | ||
| volumePath = [regex stringByReplacingMatchesInString:volumePath options:0 range:NSMakeRange(0, volumePath.length) withTemplate:regexTemplate]; | ||
| } | ||
| else { | ||
| // After rXX, rar uses r-z and symbols like {}|~... so accepting anything but a number | ||
| regex = [NSRegularExpression regularExpressionWithPattern:@"(\\.[^0-9])([0-9]+)$" options:NSRegularExpressionCaseInsensitive error:nil]; | ||
| match = [regex firstMatchInString:volumePath options:0 range:NSMakeRange(0, volumePath.length)]; | ||
| if (match) { | ||
| URKLogDebug("The archive is part of a legacy volume"); | ||
| volumePath = [[volumePath stringByDeletingPathExtension] stringByAppendingPathExtension:@"rar"]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return [NSURL fileURLWithPath:path]; | ||
| if (match) { | ||
| if ([[NSFileManager defaultManager] fileExistsAtPath:volumePath]) { | ||
| URKLogDebug("First volume part %@ found. Using as the main archive", volumePath); | ||
| return [NSURL fileURLWithPath:volumePath]; | ||
| } | ||
| else | ||
| URKLogInfo("First volume part %@ not found. Skipping first volume selection", volumePath); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just skip, do not return nil.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, all logging is for the dev to see, not the user.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, look at the README for logging suggestions. This should probably be Debug level |
||
| } | ||
|
|
||
| return fileURL; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If no match, always return the passed fileURL |
||
| } | ||
|
|
||
| - (nullable NSArray<NSString*> *)listVolumePaths:(NSError **)error | ||
| { | ||
| return @[]; | ||
| NSMutableOrderedSet<NSString*> *volumePaths = [NSMutableOrderedSet new]; | ||
|
|
||
| NSArray<URKFileInfo*> *listFileInfo = [self listFileInfo:error]; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Way cleaner 😃
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
|
||
| if (listFileInfo == nil) { | ||
| return nil; | ||
| } | ||
|
|
||
| for (URKFileInfo* info in listFileInfo) { | ||
| [volumePaths addObject:info.archiveName]; | ||
| } | ||
|
|
||
| return [NSArray arrayWithArray:volumePaths.array]; | ||
| } | ||
|
|
||
| - (nullable NSArray<NSURL*> *)listVolumeURLs:(NSError **)error | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those will be not nullable, since they will be called after a
(!fileURL)check. If no first part, they will return the passedfileURL.