mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-17 23:05:03 -05:00
* [Windows] allow renaming of files where just the upper/lower case is different
This commit is contained in:
parent
c75b376140
commit
3ed58bda08
@ -303,7 +303,7 @@ class RenameAction extends AbstractAction {
|
||||
// rename file, throw exception on failure
|
||||
File source = mapping.getKey();
|
||||
File destination = resolveDestination(mapping.getKey(), mapping.getValue(), false);
|
||||
if (!source.equals(destination)) {
|
||||
if (!source.getAbsolutePath().equals(destination.getAbsolutePath())) {
|
||||
action.rename(source, destination);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
|
||||
package net.sourceforge.filebot.ui.rename;
|
||||
|
||||
|
||||
import static net.sourceforge.filebot.similarity.EpisodeMetrics.*;
|
||||
import static net.sourceforge.tuned.FileUtilities.*;
|
||||
import static net.sourceforge.tuned.ui.TunedUtilities.*;
|
||||
@ -34,7 +32,6 @@ import net.sourceforge.tuned.FileUtilities;
|
||||
import net.sourceforge.tuned.ui.DefaultFancyListCellRenderer;
|
||||
import net.sourceforge.tuned.ui.GradientStyle;
|
||||
|
||||
|
||||
class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||
|
||||
private RenameModel renameModel;
|
||||
@ -50,7 +47,6 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||
private Color pathRainbowBeginColor = new Color(0xCC3300);
|
||||
private Color pathRainbowEndColor = new Color(0x008080);
|
||||
|
||||
|
||||
public RenameListCellRenderer(RenameModel renameModel) {
|
||||
super(new Insets(4, 7, 4, 7));
|
||||
|
||||
@ -61,7 +57,6 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||
this.add(typeRenderer, "gap rel:push, hidemode 3");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void configureListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
super.configureListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
@ -124,12 +119,12 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||
}
|
||||
|
||||
switch (formattedFuture.getState()) {
|
||||
case PENDING:
|
||||
setIcon(ResourceManager.getIcon("worker.pending"));
|
||||
break;
|
||||
case STARTED:
|
||||
setIcon(ResourceManager.getIcon("worker.started"));
|
||||
break;
|
||||
case PENDING:
|
||||
setIcon(ResourceManager.getIcon("worker.pending"));
|
||||
break;
|
||||
case STARTED:
|
||||
setIcon(ResourceManager.getIcon("worker.started"));
|
||||
break;
|
||||
}
|
||||
|
||||
if (renameModel.hasComplement(index)) {
|
||||
@ -154,22 +149,20 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||
if (pathFuture.isDone() && !pathFuture.isCancelled()) {
|
||||
File from = renameModel.getMatch(index).getCandidate();
|
||||
File to = resolveAbsolutePath(from.getParentFile(), pathFuture.toString(), renameModel.preserveExtension() ? getExtension(from) : null);
|
||||
if (from.equals(to)) {
|
||||
if (from.getAbsolutePath().equals(to.getAbsolutePath())) {
|
||||
setIcon(ResourceManager.getIcon("dialog.continue"));
|
||||
} else if (to.exists()) {
|
||||
setIcon(ResourceManager.getIcon("dialog.cancel"));
|
||||
} 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected String formatPath(File file) {
|
||||
return normalizePathSeparators(file.getPath());
|
||||
}
|
||||
|
||||
|
||||
protected String colorizePath(File file, boolean hasExtension) {
|
||||
List<File> path = listPath(file);
|
||||
StringBuilder html = new StringBuilder(512);
|
||||
@ -196,21 +189,15 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||
return html.append("</nobr></html>").toString();
|
||||
}
|
||||
|
||||
|
||||
protected File resolveAbsolutePath(File targetDir, String path, String extension) {
|
||||
File f = new File(extension == null || extension.isEmpty() ? path : String.format("%s.%s", path, extension));
|
||||
if (!f.isAbsolute()) {
|
||||
f = new File(targetDir, f.getPath()); // resolve path against target folder
|
||||
}
|
||||
|
||||
try {
|
||||
return f.getCanonicalFile();
|
||||
} catch (Exception e) {
|
||||
return f.getAbsoluteFile();
|
||||
}
|
||||
return f.getAbsoluteFile();
|
||||
}
|
||||
|
||||
|
||||
protected float getMatchProbablity(Match<Object, File> match) {
|
||||
if (match.getValue() instanceof Episode) {
|
||||
float f = verificationMetric().getSimilarity(match.getValue(), match.getCandidate());
|
||||
@ -226,7 +213,6 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||
return 1; // assume match is OK
|
||||
}
|
||||
|
||||
|
||||
protected String getType(File file) {
|
||||
if (file.isDirectory()) {
|
||||
return "Folder";
|
||||
@ -241,7 +227,6 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||
return "File";
|
||||
}
|
||||
|
||||
|
||||
private static class TypeRenderer extends DefaultListCellRenderer {
|
||||
|
||||
private final Insets margin = new Insets(0, 10, 0, 0);
|
||||
@ -253,7 +238,6 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||
|
||||
private float alpha = 1.0f;
|
||||
|
||||
|
||||
public TypeRenderer() {
|
||||
setOpaque(false);
|
||||
setForeground(new Color(0x141414));
|
||||
@ -261,7 +245,6 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||
setBorder(new CompoundBorder(new EmptyBorder(margin), new EmptyBorder(padding)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
@ -282,7 +265,6 @@ class RenameListCellRenderer extends DefaultFancyListCellRenderer {
|
||||
g2d.drawString(getText(), (float) (shape.getCenterX() - textBounds.getX() - (textBounds.getWidth() / 2f)), (float) (shape.getCenterY() - textBounds.getY() - (textBounds.getHeight() / 2)));
|
||||
}
|
||||
|
||||
|
||||
public void setAlpha(float alpha) {
|
||||
this.alpha = alpha;
|
||||
}
|
||||
|
@ -52,7 +52,8 @@ public final class FileUtilities {
|
||||
} else {
|
||||
// move file
|
||||
try {
|
||||
java.nio.file.Files.move(source.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
// * On Windows ATOMIC_MOVE allows us to rename files even if only lower/upper-case changes (without ATOMIC_MOVE the operation would be ignored)
|
||||
java.nio.file.Files.move(source.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
|
||||
} catch (LinkageError e) {
|
||||
org.apache.commons.io.FileUtils.moveFile(source, destination); // use "copy and delete" as fallback if standard rename fails
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user