Skip to content

Commit

Permalink
Made Extract Large Files work in the example app, documented the exam…
Browse files Browse the repository at this point in the history
…ple app in the readme, and added the arm64 rar binaries for use in scripts and unit tests
  • Loading branch information
abbeycode committed Aug 1, 2022
1 parent 74a35d6 commit 0ddf3e4
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 28 deletions.
45 changes: 23 additions & 22 deletions Example/Classes/UnrarExampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,40 +154,39 @@ - (void)updateExtractionStep:(NSString *)message {

- (void)updateProgress:(float)progress {
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self.extractionProgressView setProgress:progress animated:YES];
[self.extractionProgressView setProgress:progress animated:progress > 0];
}];
}

- (NSURL *)createLargeArchive {
[self reportError:@""];
[self updateExtractionStep:@"Creating large text file…"];

[self updateProgress:0];

NSURL *largeFile = [self randomTextFileOfLength:100000000];

if (!largeFile) {
[self reportError:@"Failed to create large text file"];
return nil;
}

[self updateProgress:0];

[self updateExtractionStep:@"Compressing large text file…"];

// Create archive
NSURL *archiveURL = self.largeArchiveURL;

if (![archiveURL checkResourceIsReachableAndReturnError:nil]) {
[self updateExtractionStep:@"Creating large text file…"];

[self updateProgress:0];

NSURL *largeFile = [self randomTextFileOfLength:100000000];

if (!largeFile) {
[self reportError:@"Failed to create large text file"];
return nil;
}

[self updateProgress:0];

[self updateExtractionStep:@"No archive"];
[self reportError:
@"The large archive has not been created yet. A Terminal command "
"has been copied to the clipboard. Press ⌘C to copy it out "
"of the Simulator. From a prompt at the UnrarKit/Example "
"directory, paste it and run"];
"has been copied to the clipboard. Press ⌘V to paste it into a "
"prompt in the UnrarKit source directory, paste it and run. Then "
"click the button again"];

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = largeFile.path;
pasteboard.string = [NSString stringWithFormat:@"./Example/makeLargeArchive.sh \"%@\"", largeFile.path];

return nil;
}
Expand All @@ -214,9 +213,11 @@ - (NSURL *)randomTextFileOfLength:(NSUInteger)numberOfCharacters {
for (NSUInteger i = 0; i < numberOfCharacters; i++) {
uint32_t charIndex = arc4random_uniform((uint32_t)letterCount);
[randomString appendFormat:@"%C", [letters characterAtIndex:charIndex]];

float progress = i / (float)numberOfCharacters;
[self updateProgress:progress];

if (i % 100 == 0) {
float progress = i / (float)numberOfCharacters;
[self updateProgress:progress];
}
}

NSError *error = nil;
Expand Down
15 changes: 12 additions & 3 deletions Example/makeLargeArchive.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#!/bin/bash


export UNCOMPRESSED_FILE="$1"
export ARCHIVE_NAME="`dirname $1`/large-archive.rar"
UNCOMPRESSED_FILE="$1"
ARCHIVE_NAME="`dirname $1`/large-archive.rar"

"../Tests/Test Data/bin/rar" a -ep ${ARCHIVE_NAME} ${UNCOMPRESSED_FILE}
ARCH="`uname -m`"

if [[ $ARCH -eq "arm64" ]];
then
RAR="Tests/Test Data/bin/arm/rar"
else
RAR="Tests/Test Data/bin/x64/rar"
fi

"$RAR" a -ep "${ARCHIVE_NAME}" "${UNCOMPRESSED_FILE}"
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ Using either method above, you can call `[progress cancel]` to stop the operatio
To open in Xcode, use the [UnrarKit.xcworkspace](UnrarKit.xcworkspace) file, which includes the other projects.
## The example app
Included in the source repo is a project named "UnrarExample", that builds as part of the main solution. It's only ever verified to run in the simulator, but if you provide Team info, it should probably also run on-device.
For large file extraction, the tool uses the `rar` executable. You may need to right-click and open it in Finder to get through Gatekeeper the first time you do so.
# Documentation
Full documentation for the project is available on [CocoaDocs](http://cocoadocs.org/docsets/UnrarKit).
Expand Down
File renamed without changes.
Binary file added Tests/Test Data/bin/arm/rar
Binary file not shown.
127 changes: 127 additions & 0 deletions Tests/Test Data/bin/x64/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
END USER LICENSE AGREEMENT

The following agreement regarding RAR (and its Windows version - WinRAR)
archiver - referred to as "software" - is made between win.rar GmbH -
referred to as "licensor" - and anyone who is installing, accessing
or in any other way using the software - referred to as "user".

1. The author and holder of the copyright of the software is
Alexander L. Roshal. The licensor and as such issuer of the license
and bearer of the worldwide exclusive usage rights including the rights
to reproduce, distribute and make the software available to the public
in any form is win.rar GmbH, Marienstr. 12, 10117 Berlin, Germany.

2. The software is distributed as try before you buy. This means that
anyone may use the software during a test period of a maximum of 40 days
at no charge. Following this test period, the user must purchase
a license to continue using the software.

3. The software's trial version may be freely distributed, with exceptions
noted below, provided the distribution package is not modified in any way.

a. Nobody may distribute separate parts of the package, with the exception
of the UnRAR components, without written permission.

b. The software's unlicensed trial version may not be distributed
inside of any other software package without written permission.
The software must remain in the original unmodified installation
file for download without any barrier and conditions to the user
such as collecting fees for the download or making the download
conditional on the user giving his contact data.

c. The unmodified installation file of WinRAR must be provided pure
and unpaired. Any bundling is interdicted. In particular the use
of any install or download software which is providing any kind
of download bundles is prohibited unless granted by win.rar GmbH
in written form.

d. Hacks/cracks, keys or key generators may not be included, pointed to
or referred to by the distributor of the trial version.

e. In case of violation of the precedent conditions the allowance
lapses immediately and automatically.

4. The trial version of the software can display a registration reminder
dialog. Depending on the software version and configuration such dialog
can contain either a predefined text and links loaded locally
or a web page loaded from the internet. Such web page can contain
licensing instructions or other materials according to the licensor's
choice, including advertisement. When opening a web page, the software
transfers only those parameters which are technically required
by HTTP protocol to successfully open a web page in a browser.

5. The software is distributed "as is". No warranty of any kind is expressed
or implied. You use at your own risk. Neither the author, the licensor
nor the agents of the licensor will be liable for data loss, damages,
loss of profits or any other kind of loss while using or misusing
this software.

6. There are 2 basic types of licenses issued for the software. These are:

a. A single computer usage license. The user purchases one license to
use the software on one computer.

Home users may use their single computer usage license on all
computers and mobile devices (USB drive, external hard drive, etc.)
which are property of the license owner.

Business users require one license per computer or mobile device
on which the software is installed.

b. A multiple usage license. The user purchases a number of usage
licenses for use, by the purchaser or the purchaser's employees
on the same number of computers.

In a network (server/client) environment the user must purchase
a license copy for each separate client (workstation) on which
the software is installed, used or accessed. A separate license copy
for each client (workstation) is needed regardless of whether
the clients (workstations) will use the software simultaneously
or at different times. If for example you wish to have 9 different
clients (workstations) in your network with access to RAR,
you must purchase 9 license copies.

A user who purchased a license, is granted a non-exclusive right to use
the software on as many computers as defined by the licensing terms above
according to the number of licenses purchased, for any legal purpose.

7. There are no additional license fees, apart from the cost of the license,
associated with the creation and distribution of RAR archives,
volumes, self-extracting archives or self-extracting volumes.
Owners of a license may use their copies of the software to produce
archives and self-extracting archives and to distribute those archives
free of any additional royalties.

8. The licensed software may not be rented or leased but may be permanently
transferred, in its entirety, if the recipient agrees to the terms of
this license.

9. To buy a license, please read the file order.htm provided with
the software for details.

10. You may not use, copy, emulate, clone, rent, lease, sell, modify,
decompile, disassemble, otherwise reverse engineer, or transfer
the licensed software, or any subset of the licensed software,
except as provided for in this agreement. Any such unauthorized use
shall result in immediate and automatic termination of this license
and may result in criminal and/or civil prosecution.

Neither RAR binary code, WinRAR binary code, UnRAR source
or UnRAR binary code may be used or reverse engineered to re-create
the RAR compression algorithm, which is proprietary, without written
permission.

The software may be using components developed and/or copyrighted
by third parties. Please read "Acknowledgments" help file topic
for WinRAR or acknow.txt text file for other RAR versions for details.

11. This License Agreement is construed solely and exclusively under
German law. If you are a merchant, the courts at the registered office
of win.rar GmbH in Berlin/Germany shall have exclusive jurisdiction
for any and all disputes arising in connection with this License
Agreement or its validity.

12. Installing and using the software signifies acceptance of these terms
and conditions of the license. If you do not agree with the terms of this
license, you must remove all software files from your storage devices
and cease to use the software.
File renamed without changes.
14 changes: 12 additions & 2 deletions Tests/URKArchiveTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "URKArchiveTestCase.h"
#import "UnrarKit_Tests-Swift.h"

#import <zlib.h>

Expand Down Expand Up @@ -40,7 +41,8 @@ - (void)setUp
@"Test File A.txt",
@"Test File B.jpg",
@"Test File C.m4a",
@"bin/rar"];
@"bin/arm/rar",
@"bin/x64/rar"];

NSArray *unicodeFiles = @[@"Ⓣest Ⓐrchive.rar",
@"Test File Ⓐ.txt",
Expand Down Expand Up @@ -273,9 +275,17 @@ - (NSURL *)archiveWithFiles:(NSArray *)fileURLs name:(NSString *)archiveName arg
archiveFileName = [uniqueString stringByAppendingPathExtension:@"rar"];
}

NSString *binPath;

if ([self.machineHardwareName isEqualTo:@"arm64"]) {
binPath = @"Test Data/bin/arm";
} else {
binPath = @"Test Data/bin/x64";
}

NSURL *rarExec = [[NSBundle bundleForClass:[self class]] URLForResource:@"rar"
withExtension:nil
subdirectory:@"Test Data/bin"];
subdirectory:binPath];
NSURL *archiveURL = [self.tempDirectory URLByAppendingPathComponent:archiveFileName];

NSMutableArray *rarArguments = [NSMutableArray arrayWithArray:@[@"a", @"-ep", archiveURL.path]];
Expand Down
21 changes: 21 additions & 0 deletions Tests/URKArchiveTestCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// URKArchiveTestCase.swift
// UnrarKit Tests
//
// Created by Dov Frankel on 8/1/22.
//

import Foundation

@objc public extension URKArchiveTestCase {

var machineHardwareName: String? {
var sysinfo = utsname()
guard uname(&sysinfo) == EXIT_SUCCESS else { return nil }

let data = Data(bytes: &sysinfo.machine, count: Int(_SYS_NAMELEN))
guard let identifier = String(bytes: data, encoding: .ascii) else { return nil }
return identifier.trimmingCharacters(in: .controlCharacters)
}

}
5 changes: 5 additions & 0 deletions Tests/UnrarKit Tests-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

#import "URKArchiveTestCase.h"
13 changes: 12 additions & 1 deletion UnrarKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
7AC29ACD1F83DB0400DA4DE6 /* dll.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 96853F1A18DB722E00B5651B /* dll.hpp */; settings = {ATTRIBUTES = (Public, ); }; };
7AC29ACE1F83DB1000DA4DE6 /* raros.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 96853F4E18DB722E00B5651B /* raros.hpp */; settings = {ATTRIBUTES = (Public, ); }; };
7AC29AD01F850A6A00DA4DE6 /* UnrarKitMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = 96BF58BA1F3A487100BC24E1 /* UnrarKitMacros.h */; settings = {ATTRIBUTES = (Public, ); }; };
7AD4ED212898463D00A664B7 /* URKArchiveTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AD4ED202898463D00A664B7 /* URKArchiveTestCase.swift */; };
7ADC7A091F8831BC00023C2E /* CheckDataTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 7ADC7A081F8831BC00023C2E /* CheckDataTests.m */; };
964C8AC718D28EE000AD7321 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 964C8AC518D28EE000AD7321 /* InfoPlist.strings */; };
9660D7AF1A3F4FF90059AC1E /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 9660D7AE1A3F4FF90059AC1E /* libz.dylib */; };
Expand Down Expand Up @@ -184,6 +185,8 @@
7A7820D92338F09500E106F8 /* PerformOnDataTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PerformOnDataTests.m; sourceTree = "<group>"; };
7A7820DB2338F38E00E106F8 /* ExtractBufferedDataTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ExtractBufferedDataTests.m; sourceTree = "<group>"; };
7AC29A5D1F83C08200DA4DE6 /* libunrar.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libunrar.a; sourceTree = BUILT_PRODUCTS_DIR; };
7AD4ED1F2898463C00A664B7 /* UnrarKit Tests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UnrarKit Tests-Bridging-Header.h"; sourceTree = "<group>"; };
7AD4ED202898463D00A664B7 /* URKArchiveTestCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URKArchiveTestCase.swift; sourceTree = "<group>"; };
7ADC7A081F8831BC00023C2E /* CheckDataTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CheckDataTests.m; sourceTree = "<group>"; };
96370FB319ED8A8200DAF8F1 /* blake2s_sse.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = blake2s_sse.cpp; sourceTree = "<group>"; };
96370FB419ED8A8200DAF8F1 /* blake2s.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = blake2s.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -459,6 +462,7 @@
964C8AD018D28F1600AD7321 /* Test Data */,
964547D01B384F7D00202B28 /* URKArchiveTestCase.h */,
964547D11B384F7D00202B28 /* URKArchiveTestCase.m */,
7AD4ED202898463D00A664B7 /* URKArchiveTestCase.swift */,
964C8AC818D28EE000AD7321 /* URKArchiveTests.m */,
7ADC7A081F8831BC00023C2E /* CheckDataTests.m */,
7A7820DB2338F38E00E106F8 /* ExtractBufferedDataTests.m */,
Expand All @@ -483,6 +487,7 @@
964C8AC318D28EE000AD7321 /* Supporting Files */ = {
isa = PBXGroup;
children = (
7AD4ED1F2898463C00A664B7 /* UnrarKit Tests-Bridging-Header.h */,
964C8AC418D28EE000AD7321 /* UnrarKit Tests-Info.plist */,
964C8AC518D28EE000AD7321 /* InfoPlist.strings */,
);
Expand Down Expand Up @@ -829,7 +834,7 @@
ProvisioningStyle = Automatic;
};
964C8ABA18D28EE000AD7321 = {
LastSwiftMigration = 0820;
LastSwiftMigration = 1340;
TestTargetID = 96853EDA18DB71CD00B5651B;
};
96EA535A1B3CB04300F79DC6 = {
Expand Down Expand Up @@ -967,6 +972,7 @@
7A267F6E1F713B970004EAA6 /* ProgressReportingTests.m in Sources */,
9699FA8A1B3D9B6F00B6D373 /* URKArchiveTestCase.m in Sources */,
7A61604C2334263F00B26887 /* ExtractDataTests.m in Sources */,
7AD4ED212898463D00A664B7 /* URKArchiveTestCase.swift in Sources */,
96A043E01E4D232F00BD7013 /* HasMultipleVolumesTests.m in Sources */,
9699FA8D1B3D9B6F00B6D373 /* ListFilenamesTests.m in Sources */,
7A66082B20B4BE2000FE68D6 /* IterateFileInfoTests.m in Sources */,
Expand Down Expand Up @@ -1281,6 +1287,9 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.abbey-code.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnrarKit Tests-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = xctest;
};
Expand Down Expand Up @@ -1310,6 +1319,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.abbey-code.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "Tests/UnrarKit Tests-Bridging-Header.h";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUNDLE_LOADER)";
WRAPPER_EXTENSION = xctest;
};
Expand Down

0 comments on commit 0ddf3e4

Please sign in to comment.