Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
edmund-wagner committed Sep 11, 2010
0 parents commit 6f32323
Show file tree
Hide file tree
Showing 90 changed files with 12,653 additions and 0 deletions.
40 changes: 40 additions & 0 deletions license.txt
@@ -0,0 +1,40 @@
****** ***** ****** UnRAR - free utility for RAR archives
** ** ** ** ** ** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
****** ******* ****** License for use and distribution of
** ** ** ** ** ** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
** ** ** ** ** ** FREE portable version
~~~~~~~~~~~~~~~~~~~~~

The source code of UnRAR utility is freeware. This means:

1. All copyrights to RAR and the utility UnRAR are exclusively
owned by the author - Alexander Roshal.

2. The UnRAR sources may be used in any software to handle RAR
archives without limitations free of charge, but cannot be used
to re-create the RAR compression algorithm, which is proprietary.
Distribution of modified UnRAR sources in separate form or as a
part of other software is permitted, provided that it is clearly
stated in the documentation and source comments that the code may
not be used to develop a RAR (WinRAR) compatible archiver.

3. The UnRAR utility may be freely distributed. It is allowed
to distribute UnRAR inside of other software packages.

4. THE RAR ARCHIVER AND THE UnRAR UTILITY ARE DISTRIBUTED "AS IS".
NO WARRANTY OF ANY KIND IS EXPRESSED OR IMPLIED. YOU USE AT
YOUR OWN RISK. THE AUTHOR WILL NOT BE LIABLE FOR DATA LOSS,
DAMAGES, LOSS OF PROFITS OR ANY OTHER KIND OF LOSS WHILE USING
OR MISUSING THIS SOFTWARE.

5. Installing and using the UnRAR utility signifies acceptance of
these terms and conditions of the license.

6. If you don't agree with terms of the license you must remove
UnRAR files from your storage devices and cease to use the
utility.

Thank you for your interest in RAR and UnRAR.


Alexander L. Roshal
9 changes: 9 additions & 0 deletions testutil/.classpath
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry including="**/*.java" kind="src" path="src/main/java"/>
<classpathentry kind="con" path="org.devzuz.q.maven.jdt.core.mavenClasspathContainer"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/unrar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions testutil/.project
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>java-unrar-testutil</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.devzuz.q.maven.jdt.core.mavenIncrementalBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.devzuz.q.maven.jdt.core.mavenNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
7 changes: 7 additions & 0 deletions testutil/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
#Sun Oct 05 03:26:48 CEST 2008
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.5
65 changes: 65 additions & 0 deletions testutil/pom.xml
@@ -0,0 +1,65 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>java-unrar-testutil</groupId>
<artifactId>java-unrar-testutil</artifactId>
<packaging>jar</packaging>
<version>0.1</version>
<name>java-unrar-testutil</name>
<url>http://maven.apache.org</url>
<developers>
<developer>
<id>edmund_wagner</id>
<name>Edmund Wagner</name>
<email>edmund_wagner@users.sourceforge.net</email>
<roles>
<role></role>
</roles>
</developer>
</developers>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<configuration>
<archive>
<manifest>
<mainClass>
de.innosystec.unrar.testutil.JUnRarTestUtil
</mainClass>
<packageName>
de.innosystec.unrar.testutil
</packageName>
<addClasspath>true</addClasspath>
<addExtensions />
<classpathPrefix />
</manifest>
<manifestEntries>
<mode>development</mode>
<url>${pom.url}</url>
</manifestEntries>
<manifestFile>
src/main/resources/META-INF/MANIFEST.MF
</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.innosystec</groupId>
<artifactId>java-unrar</artifactId>
<version>0.3</version>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,166 @@
package de.innosystec.unrar.testutil;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import de.innosystec.unrar.Archive;
import de.innosystec.unrar.exception.RarException;
import de.innosystec.unrar.rarfile.FileHeader;

/**
* extract an archive to the given location
*
* @author edmund wagner
*
*/
public class ExtractArchive {

private static Log logger = LogFactory.getLog(ExtractArchive.class
.getName());

public static void extractArchive(String archive, String destination) {
if (archive == null || destination == null) {
throw new RuntimeException("archive and destination must me set");
}
File arch = new File(archive);
if (!arch.exists()) {
throw new RuntimeException("the archive does not exit: " + archive);
}
File dest = new File(destination);
if (!dest.exists() || !dest.isDirectory()) {
throw new RuntimeException(
"the destination must exist and point to a directory: "
+ destination);
}
extractArchive(arch, dest);
}

public static void main(String[] args) {
if (args.length == 2) {
extractArchive(args[0], args[1]);
} else {
System.out
.println("usage: java -jar extractArchive.jar <thearchive> <the destination directory>");
}
}

public static void extractArchive(File archive, File destination) {
Archive arch = null;
try {
arch = new Archive(archive);
} catch (RarException e) {
logger.error(e);
} catch (IOException e1) {
logger.error(e1);
}
if (arch != null) {
if (arch.isEncrypted()) {
logger.warn("archive is encrypted cannot extreact");
return;
}
FileHeader fh = null;
while (true) {
fh = arch.nextFileHeader();
if (fh == null) {
break;
}
if (fh.isEncrypted()) {
logger.warn("file is encrypted cannot extract: "
+ fh.getFileNameString());
continue;
}
logger.info("extracting: " + fh.getFileNameString());
try {
if (fh.isDirectory()) {
createDirectory(fh, destination);
} else {
File f = createFile(fh, destination);
OutputStream stream = new FileOutputStream(f);
arch.extractFile(fh, stream);
stream.close();
}
} catch (IOException e) {
logger.error("error extracting the file", e);
} catch (RarException e) {
logger.error("error extraction the file", e);
}
}
}
}

private static File createFile(FileHeader fh, File destination) {
File f = null;
String name = null;
if (fh.isFileHeader() && fh.isUnicode()) {
name = fh.getFileNameW();
} else {
name = fh.getFileNameString();
}
f = new File(destination, name);
if (!f.exists()) {
try {
f = makeFile(destination, name);
} catch (IOException e) {
logger.error("error creating the new file: " + f.getName(), e);
}
}
return f;
}

private static File makeFile(File destination, String name)
throws IOException {
String[] dirs = name.split("\\\\");
if (dirs == null) {
return null;
}
String path = "";
int size = dirs.length;
if (size == 1) {
return new File(destination, name);
} else if (size > 1) {
for (int i = 0; i < dirs.length - 1; i++) {
path = path + File.separator + dirs[i];
new File(destination, path).mkdir();
}
path = path + File.separator + dirs[dirs.length - 1];
File f = new File(destination, path);
f.createNewFile();
return f;
} else {
return null;
}
}

private static void createDirectory(FileHeader fh, File destination) {
File f = null;
if (fh.isDirectory() && fh.isUnicode()) {
f = new File(destination, fh.getFileNameW());
if (!f.exists()) {
makeDirectory(destination, fh.getFileNameW());
}
} else if (fh.isDirectory() && !fh.isUnicode()) {
f = new File(destination, fh.getFileNameString());
if (!f.exists()) {
makeDirectory(destination, fh.getFileNameString());
}
}
}

private static void makeDirectory(File destination, String fileName) {
String[] dirs = fileName.split("\\\\");
if (dirs == null) {
return;
}
String path = "";
for (String dir : dirs) {
path = path + File.separator + dir;
new File(destination, path).mkdir();
}

}
}

0 comments on commit 6f32323

Please sign in to comment.