* extract support via Apache Commons VFS2 (and junrar file provider)
This commit is contained in:
parent
b62b719700
commit
ea70a23ed0
|
@ -27,5 +27,8 @@
|
||||||
<classpathentry kind="lib" path="lib/ivy/jar/slf4j-jdk14.jar"/>
|
<classpathentry kind="lib" path="lib/ivy/jar/slf4j-jdk14.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/ivy/jar/hamcrest-core.jar"/>
|
<classpathentry kind="lib" path="lib/ivy/jar/hamcrest-core.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/jars/ObjCBridge.jar"/>
|
<classpathentry kind="lib" path="lib/jars/ObjCBridge.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/ivy/jar/junrar.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/ivy/jar/commons-vfs2.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/ivy/jar/commons-logging.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
12
build.xml
12
build.xml
|
@ -168,6 +168,18 @@
|
||||||
<include name="com/sun/jna/**" />
|
<include name="com/sun/jna/**" />
|
||||||
</zipfileset>
|
</zipfileset>
|
||||||
|
|
||||||
|
<zipfileset src="${dir.lib}/jars/commons-vfs2.jar">
|
||||||
|
<include name="org/apache/commons/vfs2/**" />
|
||||||
|
</zipfileset>
|
||||||
|
|
||||||
|
<zipfileset src="${dir.lib}/jars/commons-logging.jar">
|
||||||
|
<include name="org/apache/commons/logging/**" />
|
||||||
|
</zipfileset>
|
||||||
|
|
||||||
|
<zipfileset src="${dir.lib}/jars/junrar.jar">
|
||||||
|
<include name="com/github/junrar/**" />
|
||||||
|
</zipfileset>
|
||||||
|
|
||||||
<!-- include classes and native libraries -->
|
<!-- include classes and native libraries -->
|
||||||
<zipfileset src="${dir.lib}/ivy/jar/jna.jar">
|
<zipfileset src="${dir.lib}/ivy/jar/jna.jar">
|
||||||
<include name="com/sun/jna/**" />
|
<include name="com/sun/jna/**" />
|
||||||
|
|
1
ivy.xml
1
ivy.xml
|
@ -19,6 +19,7 @@
|
||||||
<dependency org="net.java.dev.glazedlists" name="glazedlists_java15" rev="1.9.1" />
|
<dependency org="net.java.dev.glazedlists" name="glazedlists_java15" rev="1.9.1" />
|
||||||
<dependency org="com.miglayout" name="miglayout-swing" rev="4.2" />
|
<dependency org="com.miglayout" name="miglayout-swing" rev="4.2" />
|
||||||
<dependency org="com.fifesoft" name="rsyntaxtextarea" rev="2.5.3" />
|
<dependency org="com.fifesoft" name="rsyntaxtextarea" rev="2.5.3" />
|
||||||
|
<dependency org="com.github.junrar" name="junrar" rev="0.7" />
|
||||||
|
|
||||||
<!-- FileBot Scripting -->
|
<!-- FileBot Scripting -->
|
||||||
<dependency org="org.apache.ant" name="ant" rev="1.9.4" />
|
<dependency org="org.apache.ant" name="ant" rev="1.9.4" />
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
<providers>
|
||||||
|
<provider class-name="com.github.junrar.vfs2.provider.rar.RARFileProvider">
|
||||||
|
<scheme name="rar" />
|
||||||
|
</provider>
|
||||||
|
<extension-map extension="rar" scheme="rar" />
|
||||||
|
<mime-type-map mime-type="application/rar" scheme="rar" />
|
||||||
|
</providers>
|
|
@ -145,6 +145,7 @@ public class Main {
|
||||||
System.setProperty("http.agent", String.format("%s %s", getApplicationName(), getApplicationVersion()));
|
System.setProperty("http.agent", String.format("%s %s", getApplicationName(), getApplicationVersion()));
|
||||||
System.setProperty("swing.crossplatformlaf", "javax.swing.plaf.nimbus.NimbusLookAndFeel");
|
System.setProperty("swing.crossplatformlaf", "javax.swing.plaf.nimbus.NimbusLookAndFeel");
|
||||||
System.setProperty("grape.root", new File(getApplicationFolder(), "grape").getAbsolutePath());
|
System.setProperty("grape.root", new File(getApplicationFolder(), "grape").getAbsolutePath());
|
||||||
|
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
|
||||||
|
|
||||||
if (args.unixfs) {
|
if (args.unixfs) {
|
||||||
System.setProperty("unixfs", "true");
|
System.setProperty("unixfs", "true");
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
package net.filebot.archive;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileFilter;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.filebot.vfs.FileInfo;
|
||||||
|
import net.filebot.vfs.SimpleFileInfo;
|
||||||
|
|
||||||
|
import org.apache.commons.vfs2.AllFileSelector;
|
||||||
|
import org.apache.commons.vfs2.FileObject;
|
||||||
|
import org.apache.commons.vfs2.FileSelectInfo;
|
||||||
|
import org.apache.commons.vfs2.FileSelector;
|
||||||
|
import org.apache.commons.vfs2.FileSystemManager;
|
||||||
|
import org.apache.commons.vfs2.FileType;
|
||||||
|
import org.apache.commons.vfs2.VFS;
|
||||||
|
|
||||||
|
public class ApacheVFS implements ArchiveExtractor, Closeable {
|
||||||
|
|
||||||
|
private static final FileSelector ALL_FILES = new AllFileSelector();
|
||||||
|
|
||||||
|
private final FileSystemManager fsm;
|
||||||
|
private final FileObject archive;
|
||||||
|
|
||||||
|
public ApacheVFS(File file) throws Exception {
|
||||||
|
if (!file.exists()) {
|
||||||
|
throw new FileNotFoundException(file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.fsm = VFS.getManager();
|
||||||
|
this.archive = fsm.createFileSystem(fsm.toFileObject(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<FileInfo> listFiles() throws Exception {
|
||||||
|
List<FileInfo> paths = new ArrayList<FileInfo>();
|
||||||
|
for (FileObject it : archive.findFiles(ALL_FILES)) {
|
||||||
|
if (it.getType() == FileType.FILE) {
|
||||||
|
// ignore leading / slash
|
||||||
|
paths.add(new SimpleFileInfo(it.getName().getPathDecoded().substring(1), it.getContent().getSize()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return paths;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void extract(File outputDir) throws Exception {
|
||||||
|
extract(outputDir, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void extract(File outputDir, FileFilter filter) throws Exception {
|
||||||
|
fsm.toFileObject(outputDir).copyFrom(archive, filter == null ? ALL_FILES : new FileFilterSelector(filter));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
archive.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class FileFilterSelector implements FileSelector {
|
||||||
|
|
||||||
|
private final FileFilter filter;
|
||||||
|
|
||||||
|
public FileFilterSelector(FileFilter filter) {
|
||||||
|
this.filter = filter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean traverseDescendents(FileSelectInfo it) throws Exception {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean includeFile(FileSelectInfo it) throws Exception {
|
||||||
|
// ignore leading / slash
|
||||||
|
return filter.accept(new File(it.getFile().getName().getPathDecoded().substring(1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ import net.filebot.vfs.FileInfo;
|
||||||
public class Archive implements Closeable {
|
public class Archive implements Closeable {
|
||||||
|
|
||||||
public static enum Extractor {
|
public static enum Extractor {
|
||||||
SevenZipNativeBindings, SevenZipExecutable;
|
SevenZipNativeBindings, SevenZipExecutable, ApacheVFS;
|
||||||
|
|
||||||
public ArchiveExtractor newInstance(File archive) throws Exception {
|
public ArchiveExtractor newInstance(File archive) throws Exception {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
|
@ -27,6 +27,8 @@ public class Archive implements Closeable {
|
||||||
return new SevenZipNativeBindings(archive);
|
return new SevenZipNativeBindings(archive);
|
||||||
case SevenZipExecutable:
|
case SevenZipExecutable:
|
||||||
return new SevenZipExecutable(archive);
|
return new SevenZipExecutable(archive);
|
||||||
|
case ApacheVFS:
|
||||||
|
return new ApacheVFS(archive);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue