* Extract API changes to include FileSize
This commit is contained in:
parent
dea0a1fb83
commit
66a6278611
|
@ -1,7 +1,5 @@
|
|||
|
||||
package net.sourceforge.filebot.archive;
|
||||
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
|
@ -23,15 +21,15 @@ import net.sf.sevenzipjbinding.ISevenZipInArchive;
|
|||
import net.sf.sevenzipjbinding.PropID;
|
||||
import net.sf.sevenzipjbinding.SevenZipException;
|
||||
import net.sourceforge.filebot.MediaTypes;
|
||||
import net.sourceforge.filebot.vfs.FileInfo;
|
||||
import net.sourceforge.filebot.vfs.SimpleFileInfo;
|
||||
import net.sourceforge.tuned.FileUtilities.ExtensionFileFilter;
|
||||
|
||||
|
||||
public class Archive implements Closeable {
|
||||
|
||||
private ISevenZipInArchive inArchive;
|
||||
private ArchiveOpenVolumeCallback openVolume;
|
||||
|
||||
|
||||
public Archive(File file) throws Exception {
|
||||
// initialize 7-Zip-JBinding
|
||||
if (!file.exists()) {
|
||||
|
@ -52,12 +50,10 @@ public class Archive implements Closeable {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public int itemCount() throws SevenZipException {
|
||||
return inArchive.getNumberOfItems();
|
||||
}
|
||||
|
||||
|
||||
public Map<PropID, Object> getItem(int index) throws SevenZipException {
|
||||
Map<PropID, Object> item = new EnumMap<PropID, Object>(PropID.class);
|
||||
|
||||
|
@ -71,16 +67,16 @@ public class Archive implements Closeable {
|
|||
return item;
|
||||
}
|
||||
|
||||
|
||||
public List<File> listFiles() throws SevenZipException {
|
||||
List<File> paths = new ArrayList<File>();
|
||||
public List<FileInfo> listFiles() throws SevenZipException {
|
||||
List<FileInfo> paths = new ArrayList<FileInfo>();
|
||||
|
||||
for (int i = 0; i < inArchive.getNumberOfItems(); i++) {
|
||||
boolean isFolder = (Boolean) inArchive.getProperty(i, PropID.IS_FOLDER);
|
||||
if (!isFolder) {
|
||||
String path = (String) inArchive.getProperty(i, PropID.PATH);
|
||||
Long length = (Long) inArchive.getProperty(i, PropID.SIZE);
|
||||
if (path != null) {
|
||||
paths.add(new File(path));
|
||||
paths.add(new SimpleFileInfo(path, length != null ? length : -1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,12 +84,10 @@ public class Archive implements Closeable {
|
|||
return paths;
|
||||
}
|
||||
|
||||
|
||||
public void extract(ExtractOutProvider outputMapper) throws SevenZipException {
|
||||
inArchive.extract(null, false, new ExtractCallback(inArchive, outputMapper));
|
||||
}
|
||||
|
||||
|
||||
public void extract(ExtractOutProvider outputMapper, FileFilter filter) throws SevenZipException {
|
||||
List<Integer> selection = new ArrayList<Integer>();
|
||||
|
||||
|
@ -114,7 +108,6 @@ public class Archive implements Closeable {
|
|||
inArchive.extract(indices, false, new ExtractCallback(inArchive, outputMapper));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
try {
|
||||
|
@ -126,7 +119,6 @@ public class Archive implements Closeable {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static Set<String> getArchiveTypes() {
|
||||
Set<String> extensions = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
|
@ -143,7 +135,6 @@ public class Archive implements Closeable {
|
|||
|
||||
private static final Pattern multiPartIndex = Pattern.compile("[.][0-9]{3}+$");
|
||||
|
||||
|
||||
public static boolean hasMultiPartIndex(File file) {
|
||||
return multiPartIndex.matcher(file.getName()).find();
|
||||
}
|
||||
|
@ -153,7 +144,6 @@ public class Archive implements Closeable {
|
|||
private Pattern volume = Pattern.compile("[.]r[0-9]+$|[.]part[0-9]+|[.][0-9]+$", Pattern.CASE_INSENSITIVE);
|
||||
private FileFilter archives = new ExtensionFileFilter(getArchiveTypes());
|
||||
|
||||
|
||||
@Override
|
||||
public boolean accept(File path) {
|
||||
if (!archives.accept(path) && !hasMultiPartIndex(path)) {
|
||||
|
|
|
@ -58,6 +58,7 @@ import net.sourceforge.filebot.similarity.SimilarityComparator;
|
|||
import net.sourceforge.filebot.similarity.SimilarityMetric;
|
||||
import net.sourceforge.filebot.subtitle.SubtitleFormat;
|
||||
import net.sourceforge.filebot.subtitle.SubtitleNaming;
|
||||
import net.sourceforge.filebot.vfs.FileInfo;
|
||||
import net.sourceforge.filebot.vfs.MemoryFile;
|
||||
import net.sourceforge.filebot.web.AudioTrack;
|
||||
import net.sourceforge.filebot.web.Episode;
|
||||
|
@ -1085,8 +1086,8 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||
final FileMapper outputMapper = new FileMapper(outputFolder, false);
|
||||
|
||||
final List<File> outputMapping = new ArrayList<File>();
|
||||
for (File entry : archive.listFiles()) {
|
||||
outputMapping.add(outputMapper.getOutputFile(entry));
|
||||
for (FileInfo entry : archive.listFiles()) {
|
||||
outputMapping.add(outputMapper.getOutputFile(new File(entry.getPath())));
|
||||
}
|
||||
|
||||
final Set<File> selection = new TreeSet<File>();
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
|
||||
package net.sourceforge.filebot.cli;
|
||||
|
||||
|
||||
public enum ConflictAction {
|
||||
|
||||
OVERRIDE,
|
||||
SKIP,
|
||||
FAIL;
|
||||
SKIP, OVERRIDE, FAIL, AUTO;
|
||||
|
||||
public static ConflictAction forName(String action) {
|
||||
for (ConflictAction it : values()) {
|
||||
|
|
|
@ -53,6 +53,7 @@ import net.sourceforge.filebot.similarity.SequenceMatchSimilarity;
|
|||
import net.sourceforge.filebot.similarity.SeriesNameMatcher;
|
||||
import net.sourceforge.filebot.similarity.SimilarityComparator;
|
||||
import net.sourceforge.filebot.similarity.SimilarityMetric;
|
||||
import net.sourceforge.filebot.vfs.FileInfo;
|
||||
import net.sourceforge.filebot.web.Date;
|
||||
import net.sourceforge.filebot.web.Episode;
|
||||
import net.sourceforge.filebot.web.Movie;
|
||||
|
@ -95,8 +96,8 @@ public class MediaDetection {
|
|||
FileFilter diskFolderEntryFilter = releaseInfo.getDiskFolderEntryFilter();
|
||||
Archive iso = new Archive(file);
|
||||
try {
|
||||
for (File path : iso.listFiles()) {
|
||||
for (File entry : listPath(path)) {
|
||||
for (FileInfo it : iso.listFiles()) {
|
||||
for (File entry : listPath(new File(it.getPath()))) {
|
||||
if (diskFolderEntryFilter.accept(entry)) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
package net.sourceforge.filebot.ui.analyze;
|
||||
|
||||
|
||||
import static net.sourceforge.filebot.ui.NotificationLogging.*;
|
||||
import static net.sourceforge.tuned.ExceptionUtilities.*;
|
||||
import static net.sourceforge.tuned.FileUtilities.*;
|
||||
|
@ -38,6 +36,8 @@ import net.sourceforge.filebot.ResourceManager;
|
|||
import net.sourceforge.filebot.archive.Archive;
|
||||
import net.sourceforge.filebot.archive.FileMapper;
|
||||
import net.sourceforge.filebot.ui.analyze.FileTree.FolderNode;
|
||||
import net.sourceforge.filebot.vfs.FileInfo;
|
||||
import net.sourceforge.tuned.FileUtilities;
|
||||
import net.sourceforge.tuned.ui.GradientStyle;
|
||||
import net.sourceforge.tuned.ui.LoadingOverlayPane;
|
||||
import net.sourceforge.tuned.ui.ProgressDialog;
|
||||
|
@ -45,12 +45,10 @@ import net.sourceforge.tuned.ui.ProgressDialog.Cancellable;
|
|||
import net.sourceforge.tuned.ui.SwingWorkerPropertyChangeAdapter;
|
||||
import net.sourceforge.tuned.ui.notification.SeparatorBorder;
|
||||
|
||||
|
||||
class ExtractTool extends Tool<TableModel> {
|
||||
|
||||
private JTable table = new JTable(new ArchiveEntryModel());
|
||||
|
||||
|
||||
public ExtractTool() {
|
||||
super("Archives");
|
||||
|
||||
|
@ -69,13 +67,11 @@ class ExtractTool extends Tool<TableModel> {
|
|||
add(new JButton(extractAction), "gap top rel, gap bottom unrel");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void setModel(TableModel model) {
|
||||
table.setModel(model);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected TableModel createModelInBackground(FolderNode sourceModel) throws InterruptedException {
|
||||
List<ArchiveEntry> entries = new ArrayList<ArchiveEntry>();
|
||||
|
@ -88,7 +84,7 @@ class ExtractTool extends Tool<TableModel> {
|
|||
if (Archive.VOLUME_ONE_FILTER.accept(file)) {
|
||||
Archive archive = new Archive(file);
|
||||
try {
|
||||
for (File it : archive.listFiles()) {
|
||||
for (FileInfo it : archive.listFiles()) {
|
||||
entries.add(new ArchiveEntry(file, it));
|
||||
}
|
||||
} finally {
|
||||
|
@ -112,7 +108,6 @@ class ExtractTool extends Tool<TableModel> {
|
|||
return new ArchiveEntryModel(entries);
|
||||
}
|
||||
|
||||
|
||||
private Action extractAction = new AbstractAction("Extract All", ResourceManager.getIcon("package.extract")) {
|
||||
|
||||
@Override
|
||||
|
@ -150,7 +145,6 @@ class ExtractTool extends Tool<TableModel> {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void done(PropertyChangeEvent evt) {
|
||||
dialog.close();
|
||||
|
@ -162,35 +156,29 @@ class ExtractTool extends Tool<TableModel> {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
private static class ArchiveEntry {
|
||||
|
||||
public final File archive;
|
||||
public final File entry;
|
||||
public final FileInfo entry;
|
||||
|
||||
|
||||
public ArchiveEntry(File archive, File entry) {
|
||||
public ArchiveEntry(File archive, FileInfo entry) {
|
||||
this.archive = archive;
|
||||
this.entry = entry;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class ArchiveEntryModel extends AbstractTableModel {
|
||||
|
||||
private final ArchiveEntry[] data;
|
||||
|
||||
|
||||
public ArchiveEntryModel() {
|
||||
this.data = new ArchiveEntry[0];
|
||||
}
|
||||
|
||||
|
||||
public ArchiveEntryModel(Collection<ArchiveEntry> data) {
|
||||
this.data = data.toArray(new ArchiveEntry[data.size()]);
|
||||
}
|
||||
|
||||
|
||||
public List<File> getArchiveList() {
|
||||
Set<File> archives = new LinkedHashSet<File>();
|
||||
for (ArchiveEntry it : data) {
|
||||
|
@ -199,19 +187,16 @@ class ExtractTool extends Tool<TableModel> {
|
|||
return new ArrayList<File>(archives);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return data.length;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getColumnName(int column) {
|
||||
switch (column) {
|
||||
|
@ -219,11 +204,12 @@ class ExtractTool extends Tool<TableModel> {
|
|||
return "File";
|
||||
case 1:
|
||||
return "Path";
|
||||
case 2:
|
||||
return "Size";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int row, int column) {
|
||||
switch (column) {
|
||||
|
@ -231,28 +217,28 @@ class ExtractTool extends Tool<TableModel> {
|
|||
return data[row].entry.getName();
|
||||
case 1:
|
||||
File root = new File(data[row].archive.getName());
|
||||
File prefix = data[row].entry.getParentFile();
|
||||
File prefix = new File(data[row].entry.getPath()).getParentFile();
|
||||
File path = (prefix == null) ? root : new File(root, prefix.getPath());
|
||||
return normalizePathSeparators(path.getPath());
|
||||
case 2:
|
||||
return FileUtilities.formatSize(data[row].entry.getLength());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected static class ExtractJob extends SwingWorker<Void, Void> implements Cancellable {
|
||||
|
||||
private final File[] archives;
|
||||
private final File outputRoot;
|
||||
|
||||
|
||||
public ExtractJob(Collection<File> archives, File outputRoot) {
|
||||
this.archives = archives.toArray(new File[archives.size()]);
|
||||
this.outputRoot = outputRoot;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Void doInBackground() throws Exception {
|
||||
for (File it : archives) {
|
||||
|
@ -279,7 +265,6 @@ class ExtractTool extends Tool<TableModel> {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean cancel() {
|
||||
return cancel(true);
|
||||
|
|
Loading…
Reference in New Issue