mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-23 16:28:51 -05:00
Refactor net.filebot.Archive.extractor
This commit is contained in:
parent
c7f5fe9364
commit
42ae55f9da
@ -11,7 +11,6 @@ import java.util.prefs.BackingStoreException;
|
|||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
import net.filebot.UserFiles.FileChooser;
|
import net.filebot.UserFiles.FileChooser;
|
||||||
import net.filebot.archive.Archive.Extractor;
|
|
||||||
import net.filebot.cli.ArgumentBean;
|
import net.filebot.cli.ArgumentBean;
|
||||||
import net.filebot.util.PreferencesList;
|
import net.filebot.util.PreferencesList;
|
||||||
import net.filebot.util.PreferencesMap;
|
import net.filebot.util.PreferencesMap;
|
||||||
@ -126,10 +125,6 @@ public final class Settings {
|
|||||||
return FileChooser.valueOf(System.getProperty("net.filebot.UserFiles.fileChooser", "Swing"));
|
return FileChooser.valueOf(System.getProperty("net.filebot.UserFiles.fileChooser", "Swing"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Extractor getPreferredArchiveExtractor() {
|
|
||||||
return Extractor.valueOf(System.getProperty("net.filebot.Archive.extractor", "SevenZipNativeBindings"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getPreferredThreadPoolSize() {
|
public static int getPreferredThreadPoolSize() {
|
||||||
try {
|
try {
|
||||||
String threadPool = System.getProperty("threadPool");
|
String threadPool = System.getProperty("threadPool");
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package net.filebot.archive;
|
package net.filebot.archive;
|
||||||
|
|
||||||
|
import static java.util.Arrays.*;
|
||||||
|
import static net.filebot.MediaTypes.*;
|
||||||
import static net.filebot.util.StringUtilities.*;
|
import static net.filebot.util.StringUtilities.*;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
@ -7,19 +9,26 @@ import java.io.File;
|
|||||||
import java.io.FileFilter;
|
import java.io.FileFilter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.apache.commons.vfs2.FileSystemException;
|
||||||
|
import org.apache.commons.vfs2.VFS;
|
||||||
|
|
||||||
import net.filebot.MediaTypes;
|
|
||||||
import net.filebot.Settings;
|
|
||||||
import net.filebot.util.FileUtilities.ExtensionFileFilter;
|
import net.filebot.util.FileUtilities.ExtensionFileFilter;
|
||||||
|
import net.filebot.util.SystemProperty;
|
||||||
import net.filebot.vfs.FileInfo;
|
import net.filebot.vfs.FileInfo;
|
||||||
|
import net.sf.sevenzipjbinding.ArchiveFormat;
|
||||||
|
|
||||||
public class Archive implements Closeable {
|
public class Archive implements Closeable {
|
||||||
|
|
||||||
|
public static Extractor getExtractor() {
|
||||||
|
return SystemProperty.of("net.filebot.Archive.extractor", Extractor::valueOf, Extractor.SevenZipNativeBindings).get();
|
||||||
|
}
|
||||||
|
|
||||||
public static enum Extractor {
|
public static enum Extractor {
|
||||||
|
|
||||||
SevenZipNativeBindings, SevenZipExecutable, ApacheVFS;
|
SevenZipNativeBindings, SevenZipExecutable, ApacheVFS;
|
||||||
|
|
||||||
public ArchiveExtractor newInstance(File archive) throws Exception {
|
public ArchiveExtractor newInstance(File archive) throws Exception {
|
||||||
@ -28,15 +37,28 @@ 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:
|
default:
|
||||||
return new ApacheVFS(archive);
|
return new ApacheVFS(archive);
|
||||||
}
|
}
|
||||||
return null;
|
}
|
||||||
|
|
||||||
|
public String[] getSupportedTypes() {
|
||||||
|
switch (this) {
|
||||||
|
case SevenZipNativeBindings:
|
||||||
|
case SevenZipExecutable:
|
||||||
|
return stream(ArchiveFormat.values()).map(ArchiveFormat::getMethodName).toArray(String[]::new);
|
||||||
|
default:
|
||||||
|
try {
|
||||||
|
return VFS.getManager().getSchemes();
|
||||||
|
} catch (FileSystemException e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Archive open(File archive) throws Exception {
|
public static Archive open(File archive) throws Exception {
|
||||||
return new Archive(Settings.getPreferredArchiveExtractor().newInstance(archive));
|
return new Archive(getExtractor().newInstance(archive));
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ArchiveExtractor extractor;
|
private final ArchiveExtractor extractor;
|
||||||
@ -64,16 +86,8 @@ public class Archive implements Closeable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Set<String> getArchiveTypes() {
|
public static String[] getArchiveTypes() {
|
||||||
Set<String> extensions = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
return Stream.of(ARCHIVE_FILES.extensions(), Extractor.SevenZipNativeBindings.getSupportedTypes()).flatMap(Stream::of).distinct().toArray(String[]::new);
|
||||||
|
|
||||||
// application data
|
|
||||||
extensions.addAll(MediaTypes.getDefault().getExtensionList("archive"));
|
|
||||||
|
|
||||||
// formats provided by the library
|
|
||||||
extensions.addAll(SevenZipNativeBindings.getArchiveTypes());
|
|
||||||
|
|
||||||
return extensions;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Pattern multiPartIndex = Pattern.compile("[.][0-9]{3}$");
|
private static final Pattern multiPartIndex = Pattern.compile("[.][0-9]{3}$");
|
||||||
|
@ -12,7 +12,6 @@ import java.util.Map;
|
|||||||
|
|
||||||
import net.filebot.vfs.FileInfo;
|
import net.filebot.vfs.FileInfo;
|
||||||
import net.filebot.vfs.SimpleFileInfo;
|
import net.filebot.vfs.SimpleFileInfo;
|
||||||
import net.sf.sevenzipjbinding.ArchiveFormat;
|
|
||||||
import net.sf.sevenzipjbinding.IInArchive;
|
import net.sf.sevenzipjbinding.IInArchive;
|
||||||
import net.sf.sevenzipjbinding.PropID;
|
import net.sf.sevenzipjbinding.PropID;
|
||||||
import net.sf.sevenzipjbinding.SevenZipException;
|
import net.sf.sevenzipjbinding.SevenZipException;
|
||||||
@ -119,15 +118,4 @@ public class SevenZipNativeBindings implements ArchiveExtractor, Closeable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getArchiveTypes() {
|
|
||||||
List<String> extensions = new ArrayList<String>();
|
|
||||||
|
|
||||||
// formats provided by the library
|
|
||||||
for (ArchiveFormat it : ArchiveFormat.values()) {
|
|
||||||
extensions.add(it.getMethodName());
|
|
||||||
}
|
|
||||||
|
|
||||||
return extensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ public class ScriptShellMethods {
|
|||||||
try {
|
try {
|
||||||
return MediaDetection.isVideoDiskFile(self);
|
return MediaDetection.isVideoDiskFile(self);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
debug.log(Level.WARNING, format("Failed to read disk image: %s: %s", self, e));
|
debug.log(Level.WARNING, "Failed to read disk image: " + e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user