Add purge backup files menu entry
This commit is contained in:
@@ -58,6 +58,7 @@ public class AudiobookRecorder extends JFrame {
|
||||
|
||||
JMenuItem bookNewChapter;
|
||||
JMenuItem bookExportAudio;
|
||||
JMenuItem bookPurgeBackups;
|
||||
JMenu bookVisitACX;
|
||||
JMenuItem bookVisitTitle;
|
||||
JMenuItem bookVisitAudition;
|
||||
@@ -212,8 +213,16 @@ public class AudiobookRecorder extends JFrame {
|
||||
}
|
||||
});
|
||||
|
||||
bookPurgeBackups = new JMenuItem("Purge Backups");
|
||||
bookPurgeBackups.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
book.purgeBackups();
|
||||
}
|
||||
});
|
||||
|
||||
bookMenu.add(bookNewChapter);
|
||||
bookMenu.add(bookExportAudio);
|
||||
bookMenu.add(bookPurgeBackups);
|
||||
|
||||
bookVisitACX = new JMenu("Visit ACX");
|
||||
bookMenu.add(bookVisitACX);
|
||||
|
||||
@@ -206,4 +206,14 @@ public class Book extends DefaultMutableTreeNode {
|
||||
return out;
|
||||
}
|
||||
|
||||
public void purgeBackups() {
|
||||
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||
Object ob = (Object)o.nextElement();
|
||||
if (ob instanceof Chapter) {
|
||||
Chapter c = (Chapter)ob;
|
||||
c.purgeBackups();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -239,4 +239,14 @@ public class Chapter extends DefaultMutableTreeNode {
|
||||
}
|
||||
}
|
||||
|
||||
public void purgeBackups() {
|
||||
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||
Object ob = (Object)o.nextElement();
|
||||
if (ob instanceof Sentence) {
|
||||
Sentence s = (Sentence)ob;
|
||||
s.purgeBackups();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1328,4 +1328,17 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
public void purgeBackups() {
|
||||
File whereto = getFile().getParentFile();
|
||||
String name = getFile().getName();
|
||||
|
||||
File[] files = whereto.listFiles();
|
||||
for (File f : files) {
|
||||
String fn = f.getName();
|
||||
if (fn.startsWith("backup-") && fn.endsWith("-" + name)) {
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user