Add purge backup files menu entry

This commit is contained in:
2019-11-28 14:32:11 +00:00
parent d3d81d71fe
commit 1dd3e9d86f
4 changed files with 42 additions and 0 deletions

View File

@@ -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);

View File

@@ -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();
}
}
}
}

View File

@@ -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();
}
}
}
}

View File

@@ -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();
}
}
}
}