-
Notifications
You must be signed in to change notification settings - Fork 2
/
FileDirectorySyncer.java
57 lines (52 loc) · 2.26 KB
/
FileDirectorySyncer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import javax.swing.*;
import java.io.File;
import java.util.Vector;
class FileDirectorySyncer extends SwingWorker<Boolean, Object> {
private final IMessageDisplay outputArea;
private String slaveDir;
private String targetDir;
private Vector<FileInfo> masterFileInfos;
public FileDirectorySyncer(IMessageDisplay outputArea) {
this.outputArea = outputArea;
}
/*
* return false if fail
*/
public void syncItems(String master, String[] ext, String slaveDir, String targetDir) {
this.slaveDir = slaveDir;
this.targetDir = targetDir;
File slaveDirFile = new File(slaveDir);
File targetDirFile = new File(targetDir);
this.outputArea.showMessage("hole dateiinfos von master verzeichnis", IMessageDisplay.VERBOSE);
this.masterFileInfos = FileSyncerUtils.GetFileInfoItems(master, ext);
this.outputArea.showMessage("fertig mit holen von dateiinfos von master verzeichnis", IMessageDisplay.VERBOSE);
if (!FileSyncerUtils.doChecking(this.masterFileInfos, slaveDirFile, targetDirFile, this.outputArea)) {
return;
}
// output image names
this.outputArea.showMessage("im verzeichnis enthaltene bilder:\n", IMessageDisplay.VERBOSE);
for (FileInfo s : this.masterFileInfos) {
this.outputArea.showMessage(" " + s.GetString() + "\n", IMessageDisplay.VERBOSE);
}
try {
execute();
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
@Override
protected Boolean doInBackground() throws Exception {
File slaveDirFile = new File(this.slaveDir);
File targetDirFile = new File(this.targetDir);
Vector<File> toCopy = new Vector<File>();
this.outputArea.showMessage("sammle zusammengehörige dateien", IMessageDisplay.VERBOSE);
for (FileInfo fi : this.masterFileInfos) {
for (File siblingInSlave : fi.GetSiblings(slaveDirFile)) {
toCopy.add(siblingInSlave);
}
}
this.outputArea.showMessage("starte kopieren", IMessageDisplay.VERBOSE);
FileSyncerUtils.doCopying(toCopy, targetDirFile, this.outputArea);
return true;
}
}