Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
0415896
Added support for volume check
aonez Jan 9, 2017
9196576
Improved detection of new format volume name scheme
aonez Jan 10, 2017
2b143c1
Fixed nullable result
aonez Feb 5, 2017
1061278
Excluded this branch from Travis, since it's only meant as a demo for…
abbeycode Feb 4, 2017
124e167
Added tests, headers, and stubs for multi-volume archives (PR #38)
abbeycode Feb 9, 2017
c054bfe
Adapted to multivolume branch
aonez Aug 17, 2017
8d3e7b0
Silenced two warnings caused by an update to unpack30.cpp (Issue #43)
abbeycode Jun 21, 2017
c0fd271
Ignoring analyzer issues for Unrar library files (Issue #43)
abbeycode Jun 22, 2017
061c2f3
Replaced simulator ID with name, since duplicate simulators have been…
abbeycode Jun 22, 2017
949a7fa
Switched from Travis-After-All to the officially supported Build Stag…
abbeycode Aug 8, 2017
2e8dd20
Added release note [ci skip]
abbeycode Aug 10, 2017
1feda29
Unexcluded multivolume branch from Travis
abbeycode Aug 17, 2017
0a8591b
Rebased to multivolume branch
aonez Aug 18, 2017
ed799b3
Trying with .travis.yml from master
aonez Aug 18, 2017
f74850c
Revert "Trying with .travis.yml from master"
aonez Aug 18, 2017
27eb8b2
Was at master, merging branch…
aonez Aug 19, 2017
1f8a963
Implementing hasMultipleVolumes
aonez Aug 19, 2017
b1b86a1
Implementing isVolume methods
aonez Aug 19, 2017
9d5e717
Implementing listVolumePaths
aonez Aug 19, 2017
8586292
Improved firstVolumePath
aonez Aug 19, 2017
9ce9134
Fixed wrong scape
aonez Aug 19, 2017
844377e
Something that must be corrected
aonez Aug 19, 2017
4a585be
Second dummy try…
aonez Aug 19, 2017
fa3139f
Removed isVolume
aonez Aug 19, 2017
9a26401
Removed fileURL overloads
aonez Aug 19, 2017
071d0bc
Unnecessary __block flag removed
aonez Aug 19, 2017
5f96585
Using NSMutableSet to get unique paths faster
aonez Aug 19, 2017
b447aec
Printing hasMultipleVolumes error
aonez Aug 19, 2017
50700ac
Opening first volume to list parts if needed
aonez Aug 19, 2017
97a24bc
Comparing unordered volume lists
aonez Aug 19, 2017
0f0e6ac
isVolume method removed
aonez Aug 19, 2017
e3c7718
Removing extra space
aonez Aug 19, 2017
83683a1
Added macros for unified logging and activity tracing, and switched t…
abbeycode Aug 8, 2017
dcaf9c9
Added localization script, empty strings file, and wiring for resourc…
abbeycode Sep 6, 2017
0f23417
Added support for NSProgress with cancellation to extraction methods,…
abbeycode Sep 18, 2017
0060bc1
Added NSProgress+cancellation support to a couple more methods for wh…
abbeycode Sep 18, 2017
560a631
Implemented NSProgressReporting protocol to make conformance more app…
abbeycode Sep 20, 2017
9587b99
Added more details to extractFiles progress reporting, along with som…
abbeycode Sep 21, 2017
99ff47c
Added progress reporting to performOnData, and additional documentati…
abbeycode Sep 21, 2017
b8b0baa
Whoops. Committed header changes for progress property
abbeycode Sep 23, 2017
9786f81
Fixed documentation
abbeycode Sep 23, 2017
3c4d1d2
Added reporting of URKFileInfo objects to progress reporting for extr…
abbeycode Sep 23, 2017
65ffbba
Deprecated methods that take a progress block argument, and created v…
abbeycode Sep 23, 2017
2144a1e
Fixed documentation
abbeycode Sep 24, 2017
ec31928
Moved ProgressReportingTests.m into place in the project
abbeycode Sep 24, 2017
660b9b1
Updated documentation
abbeycode Sep 24, 2017
5784477
Removed SWIFT_VERSION overrides, and specified 4.0 at the project level
abbeycode Sep 28, 2017
09c21db
Fixed merge error
abbeycode Sep 28, 2017
ce1717e
Excluded this branch from Travis, since it's only meant as a demo for…
abbeycode Feb 4, 2017
b090e89
Added tests, headers, and stubs for multi-volume archives (PR #38)
abbeycode Feb 9, 2017
13effa0
Adapted to multivolume branch
aonez Aug 17, 2017
602bb90
Updated to RAR lib v5.5.5 (Issue #43)
abbeycode Jun 21, 2017
df360db
Updated Travis build to Xcode 8.3
abbeycode Jun 21, 2017
3753993
Added release notes for 2.8.1 (Issue #43)
abbeycode Jun 22, 2017
d102983
Rebased to multivolume branch
aonez Aug 18, 2017
61ac50b
Was at master, merging branch…
aonez Aug 19, 2017
b3b05ad
Implementing isVolume methods
aonez Aug 19, 2017
53311f2
isVolume method removed
aonez Aug 19, 2017
614f35f
Removing extra space
aonez Aug 19, 2017
0f89b94
Rebase to @abbeycode multivolume branch
Sep 29, 2017
e83d7af
Fillet multivolume methods
Sep 29, 2017
7043e0d
Using new error method
Sep 29, 2017
8364d76
Using NSMutableOrderedSet for sorted array
Sep 29, 2017
8f4992e
Fixed bad travis config
Sep 29, 2017
e5d4743
Added newline break
Sep 29, 2017
41a6107
Removed unnecessary parenthesis
Sep 29, 2017
8231542
Checking first part on archive init
Sep 29, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Classes/URKArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,16 +289,20 @@ extern NSString *URKErrorDomain;
/**
* Gets the path of the first volume in a multi-volume archive, or the only volume in a single-volume one
*
* @param filePath A path to the archive file
*
* @return Returns the path, or nil if there was an error
*/
- (nullable NSString *)firstVolumePath;
- (NSString *)firstVolumePath:(NSString *)filePath;

/**
* Gets the URL of the first volume in a multi-volume archive, or the only volume in a single-volume one
*
* @param fileURL The URL of the archive file
*
* @return Returns the URL, or nil if there was an error
*/
- (nullable NSURL *)firstVolumeURL;
- (NSURL *)firstVolumeURL:(NSURL *)fileURL;
Copy link
Contributor Author

@aonez aonez Sep 29, 2017

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 passed fileURL.


/**
* Lists the paths of volumes in a single- or multi-volume archive
Expand Down
82 changes: 72 additions & 10 deletions Classes/URKArchive.mm
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ - (instancetype)initWithFile:(NSURL *)fileURL password:(NSString*)password error
if (error) {
*error = nil;
}


fileURL = [self firstVolumeURL:fileURL];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added it before (!fileURL) check and [self init], let me know if you think there's a better place


URKLogDebug("Initializing private fields");

NSError *bookmarkError = nil;
Expand Down Expand Up @@ -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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No extra parenthesis 👍

}


Expand Down Expand Up @@ -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 {
Copy link
Contributor Author

@aonez aonez Sep 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the contents to the NSURL method because init uses NSURL

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few thoughts on this.

  1. Since we're working with regular expressions in the firstVolume... method, it makes sense for it to use a path. Let it be true to itself
  2. I think it would be clearer if firstVolumePath were a class method that takes a path, since it isn't using any internal state of the class
  3. It only needs to be private. We can get rid of the public firstVolumeURL and firstPathURL instance methods, since all instances are going to represent the first volume. Basically, it will always be true that firstVolumeURL == fileURL


if (![path length]) {
return nil;
URKLogDebug("Checking if the archive is part of a volume...");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added URKLogDebug trough all the process


__block NSString *volumePath = fileURL.path;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be a __block variable, since it's not modified from inside a block. Also, once we refactor to a single class method (+[URKArchive firstVolumePath:]), it'll be the input argument.

NSTextCheckingResult * match;

if (volumePath.length)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invert this if and exit early. If volumePath is empty, log an error and return nil. That way we un-nest everything below, and you don't need to check for match twice. You can simplify the rest of the method's conditions.

{
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);
Copy link
Contributor Author

@aonez aonez Sep 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just skip, do not return nil. URKLogInfo, this will get to the final user?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, all logging is for the dev to see, not the user.

Copy link
Owner

@abbeycode abbeycode Sep 29, 2017

Choose a reason for hiding this comment

The 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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Way cleaner 😃

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NSMutableOrderedSet class doesn't sort members as they're added. You're better off using a regular NSMutableSet and sorting it when you convert to an array.


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
Expand Down