Skip to content

Commit

Permalink
fixed bugs related to deleting files in imagecopyfinder
Browse files Browse the repository at this point in the history
  • Loading branch information
kamil-sita committed Feb 1, 2019
1 parent 9f48203 commit 2c0185b
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import sections.Interruptible;
import toolset.io.MultipleFileIO;

import java.util.Arrays;
import java.util.List;

public final class FolderImageComparator {

private ImageComparator imageComparator;
Expand All @@ -17,7 +20,9 @@ public FolderImageComparator(String[] fileFolders, int miniatureSize, boolean ge

public ImageComparator compare(Interruptible interruptible) {

var folders = MultipleFileIO.getFoldersFromStrings(fileFolders);
var folderList = Arrays.asList(fileFolders);
removeDuplicateStrings(folderList);
var folders = MultipleFileIO.getFoldersFromStrings(folderList);

boolean status = imageComparator.initialize(folders, geometricalMode, interruptible);
if (interruptible.isInterrupted()) return null;
Expand All @@ -35,4 +40,18 @@ public ImageComparator compare(Interruptible interruptible) {

return imageComparator;
}

private static void removeDuplicateStrings(List<String> strings) {
for (int i = 0; i < strings.size(); i++) {
final int[] occurrenceCount = {0};
var stringToCheckFor = strings.get(i);
strings.removeIf(s -> {
if (s.equals(stringToCheckFor)) {
occurrenceCount[0]++;
return occurrenceCount[0] != 1;
}
return false;
});
}
}
}
6 changes: 6 additions & 0 deletions src/main/java/sections/imagecopyfinder/ImageCopyFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import sections.Vista;

import java.nio.file.FileSystems;

public final class ImageCopyFinder extends Vista {

private static final String LOCATION_VIEW1 = "sections/imagecopyfinder/view1settings/view1.fxml";
Expand Down Expand Up @@ -37,6 +39,10 @@ public static String getDeleteDirectory() {
}

public static void setDeleteDirectory(String loc) {
String separator = FileSystems.getDefault().getSeparator();
if (!loc.endsWith(separator)) {
loc = loc + separator;
}
deleteDirectory = loc;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Runnable onUninterruptedFinish() {
private void onFinish(ImageComparator imageComparator) {
if (imageComparator.getStatus() == ImageComparator.ImageComparatorStatus.SUCCESSFUL) {
ImageCopyFinder.setImageComparator(imageComparator);
ImageCopyFinder.setDeleteDirectory(deleteFolder.toString());
ImageCopyFinder.setDeleteDirectory(deleteFolder.getText());
MainViewController.imageCopyFinder.setInterface(ImageCopyFinder.ImageCopyFinderViews.compareCopiedImagesView);
MainViewController.refreshVista();
} else {
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/sections/main/MainViewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,14 @@ private static void resizeAnchorPane() {

public static void addNotifier(Notifier notifier) {
notifiers.add(notifier);
System.out.println(notifiers.size());
}

public static void removeNotifier(Notifier notifier) {
if (notifier == null) return;
notifiers.remove(notifier);
System.out.println(notifiers.size());
}

public static void removeAllNotifiers() {
notifiers.clear();
System.out.println(notifiers.size());
}
}
18 changes: 16 additions & 2 deletions src/main/java/toolset/FileManagementTools.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
package toolset;

import sections.UserFeedback;

import java.io.File;

public final class FileManagementTools {

public static void moveFile(File file, String deleteDirectory) {
if (!new File(deleteDirectory).exists()) {
new File(deleteDirectory).mkdir();
if (!new File(deleteDirectory).mkdir()) {
UserFeedback.popup("Couldn't create directory");
return;
}
}
String s = file.getName();
String localDeleteDirectory = deleteDirectory;
localDeleteDirectory += s;
file.renameTo(new File(localDeleteDirectory));
if (!file.renameTo(new File(localDeleteDirectory))) {
UserFeedback.popup("Couldn't move file!");
}
try {
System.out.println(file.getCanonicalPath());
System.out.println(file.getName());
System.out.println("+++++");
} catch (Exception e) {
//
}
}
}
8 changes: 4 additions & 4 deletions src/main/java/toolset/io/MultipleFileIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

public class MultipleFileIO {

public static File[] getFoldersFromStrings(String[] fileFolders) {
File[] folders = new File[fileFolders.length];
for (int i = 0; i < fileFolders.length; i++) {
String s = fileFolders[i];
public static File[] getFoldersFromStrings(List<String> fileFolders) {
File[] folders = new File[fileFolders.size()];
for (int i = 0; i < fileFolders.size(); i++) {
String s = fileFolders.get(i);
File folder = null;
try {
folder = new File(s);
Expand Down

0 comments on commit 2c0185b

Please sign in to comment.