This commit is contained in:
Reinhard Pointner 2016-05-16 03:26:26 +08:00
parent 5244a33fac
commit f28800a3a9
4 changed files with 19 additions and 11 deletions

View File

@ -4,6 +4,7 @@ import static java.awt.Font.*;
import static java.util.Arrays.*; import static java.util.Arrays.*;
import static java.util.Collections.*; import static java.util.Collections.*;
import static java.util.regex.Pattern.*; import static java.util.regex.Pattern.*;
import static java.util.stream.Collectors.*;
import static javax.swing.JOptionPane.*; import static javax.swing.JOptionPane.*;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import static net.filebot.Settings.*; import static net.filebot.Settings.*;
@ -37,7 +38,6 @@ import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
@ -446,15 +446,18 @@ class HistoryDialog extends JDialog {
} }
private enum Option { private enum Option {
Revert, ChangeDirectory, Cancel; Revert, ChangeDirectory, Cancel;
@Override @Override
public String toString() { public String toString() {
switch (this) { switch (this) {
case Revert:
return "Revert";
case ChangeDirectory: case ChangeDirectory:
return "Change Directory"; return "Change Directory";
default: default:
return name(); return "Cancel";
} }
} }
} }
@ -529,7 +532,7 @@ class HistoryDialog extends JDialog {
private void revert(File directory, List<Element> elements) { private void revert(File directory, List<Element> elements) {
Map<File, File> renamePlan = getRenameMap(directory); Map<File, File> renamePlan = getRenameMap(directory);
if (isMacSandbox()) { if (isMacSandbox()) {
if (!MacAppUtilities.askUnlockFolders(parent(), Stream.of(renamePlan.keySet(), renamePlan.values()).flatMap(c -> c.stream()).collect(Collectors.toList()))) { if (!MacAppUtilities.askUnlockFolders(parent(), Stream.of(renamePlan.keySet(), renamePlan.values()).flatMap(c -> c.stream()).collect(toList()))) {
return; return;
} }
} }

View File

@ -2,6 +2,7 @@ package net.filebot.ui.rename;
import static java.util.Arrays.*; import static java.util.Arrays.*;
import static java.util.Collections.*; import static java.util.Collections.*;
import static java.util.stream.Collectors.*;
import static javax.swing.JOptionPane.*; import static javax.swing.JOptionPane.*;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import static net.filebot.Settings.*; import static net.filebot.Settings.*;
@ -32,7 +33,6 @@ import java.util.function.BiConsumer;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
@ -202,14 +202,14 @@ class RenameAction extends AbstractAction {
private Map<File, File> checkRenamePlan(List<Entry<File, File>> renamePlan, Window parent) throws IOException { private Map<File, File> checkRenamePlan(List<Entry<File, File>> renamePlan, Window parent) throws IOException {
// ask for user permissions to output paths // ask for user permissions to output paths
if (isMacSandbox()) { if (isMacSandbox()) {
if (!MacAppUtilities.askUnlockFolders(parent, renamePlan.stream().flatMap(e -> Stream.of(e.getKey(), resolve(e.getKey(), e.getValue()))).map(f -> new File(f.getAbsolutePath())).collect(Collectors.toList()))) { if (!MacAppUtilities.askUnlockFolders(parent, renamePlan.stream().flatMap(e -> Stream.of(e.getKey(), resolve(e.getKey(), e.getValue()))).map(f -> new File(f.getAbsolutePath())).collect(toList()))) {
return emptyMap(); return emptyMap();
} }
} }
// build rename map and perform some sanity checks // build rename map and perform some sanity checks
Map<File, File> renameMap = new HashMap<File, File>(); Map<File, File> renameMap = new HashMap<File, File>();
Set<File> destinationSet = new HashSet<File>(); Set<File> destinationFiles = new HashSet<File>();
List<String> issues = new ArrayList<String>(); List<String> issues = new ArrayList<String>();
for (Entry<File, File> mapping : renamePlan) { for (Entry<File, File> mapping : renamePlan) {
@ -220,7 +220,7 @@ class RenameAction extends AbstractAction {
if (renameMap.containsKey(source)) if (renameMap.containsKey(source))
throw new IllegalArgumentException("Duplicate source file: " + source.getPath()); throw new IllegalArgumentException("Duplicate source file: " + source.getPath());
if (destinationSet.contains(destination)) if (destinationFiles.contains(destination))
throw new IllegalArgumentException("Conflict detected: " + mapping.getValue().getPath()); throw new IllegalArgumentException("Conflict detected: " + mapping.getValue().getPath());
if (destination.exists() && !resolve(mapping.getKey(), mapping.getValue()).equals(mapping.getKey())) if (destination.exists() && !resolve(mapping.getKey(), mapping.getValue()).equals(mapping.getKey()))
@ -231,7 +231,7 @@ class RenameAction extends AbstractAction {
// use original mapping values // use original mapping values
renameMap.put(mapping.getKey(), mapping.getValue()); renameMap.put(mapping.getKey(), mapping.getValue());
destinationSet.add(destination); destinationFiles.add(destination);
} catch (Exception e) { } catch (Exception e) {
issues.add(e.getMessage()); issues.add(e.getMessage());
} }

View File

@ -160,7 +160,7 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
if (pathFuture.isDone() && !pathFuture.isCancelled()) { if (pathFuture.isDone() && !pathFuture.isCancelled()) {
File from = renameModel.getMatch(index).getCandidate(); File from = renameModel.getMatch(index).getCandidate();
File to = resolveAbsolutePath(from.getParentFile(), pathFuture.toString(), renameModel.preserveExtension() ? getExtension(from) : null); File to = resolveAbsolutePath(from.getParentFile(), pathFuture.toString(), renameModel.preserveExtension() ? getExtension(from) : null);
if (from.getAbsolutePath().equals(to.getAbsolutePath())) { if (equalsCaseSensitive(from, to)) {
setIcon(ResourceManager.getIcon("dialog.continue")); setIcon(ResourceManager.getIcon("dialog.continue"));
} else if (to.exists() && !to.equals(from)) { } else if (to.exists() && !to.equals(from)) {
setIcon(ResourceManager.getIcon("dialog.cancel")); // take into account that on Windows equals/exists is case-insensitive which we have to work around setIcon(ResourceManager.getIcon("dialog.cancel")); // take into account that on Windows equals/exists is case-insensitive which we have to work around

View File

@ -59,6 +59,11 @@ public final class FileUtilities {
// resolve destination // resolve destination
destination = resolveDestination(source, destination); destination = resolveDestination(source, destination);
// do nothing if source and destination path is the same
if (equalsCaseSensitive(source, destination)) {
return destination;
}
if (source.isDirectory()) { if (source.isDirectory()) {
// move folder // move folder
FileUtils.moveDirectory(source, destination); FileUtils.moveDirectory(source, destination);
@ -67,11 +72,11 @@ public final class FileUtilities {
// on Windows, use ATOMIC_MOVE which allows us to rename files even if only lower/upper-case changes (without ATOMIC_MOVE the operation would be ignored) // on Windows, use ATOMIC_MOVE which allows us to rename files even if only lower/upper-case changes (without ATOMIC_MOVE the operation would be ignored)
// but ATOMIC_MOVE can only work for files on the same drive, if that is not the case there is no point trying move with ATOMIC_MOVE // but ATOMIC_MOVE can only work for files on the same drive, if that is not the case there is no point trying move with ATOMIC_MOVE
if (isWindows() && source.equals(destination) && !equalsCaseSensitive(source, destination)) { if (isWindows() && source.equals(destination)) {
try { try {
return Files.move(source.toPath(), destination.toPath(), StandardCopyOption.ATOMIC_MOVE).toFile(); return Files.move(source.toPath(), destination.toPath(), StandardCopyOption.ATOMIC_MOVE).toFile();
} catch (AtomicMoveNotSupportedException e) { } catch (AtomicMoveNotSupportedException e) {
debug.warning(e.getMessage()); debug.warning(e::toString);
} }
} }