Skip to content

Commit 60cdcf3

Browse files
committed
- cleanup
1 parent d4ec9e7 commit 60cdcf3

File tree

3 files changed

+20
-39
lines changed

3 files changed

+20
-39
lines changed

src/main/java/mediathek/Main.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,10 @@ private static void cleanupOsxFiles() {
9999
* CAUTION: At least some UI MUST BE INITILIZED, otherwise on macOS VM will crash in native code!!!!
100100
*/
101101
private static void removeMediaDb() {
102-
try {
103-
var mediaDbPath = StandardLocations.getSettingsDirectory().resolve("mediadb.txt");
104-
if (Files.exists(mediaDbPath)) {
105-
logger.info("Moving old unsupported media database to trash.");
106-
mediathek.tool.FileUtils.moveToTrash(mediaDbPath);
107-
}
108-
}
109-
catch (IOException ignored) {
102+
var mediaDbPath = StandardLocations.getSettingsDirectory().resolve("mediadb.txt");
103+
if (Files.exists(mediaDbPath)) {
104+
logger.info("Moving old unsupported media database to trash.");
105+
FileUtils.moveToTrash(mediaDbPath);
110106
}
111107
}
112108

src/main/java/mediathek/gui/actions/DeleteLocalFilmlistAction.java

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@
44
import mediathek.config.StandardLocations;
55
import mediathek.mainwindow.MediathekGui;
66
import mediathek.tool.FileUtils;
7-
import org.apache.logging.log4j.LogManager;
8-
import org.apache.logging.log4j.Logger;
97

108
import javax.swing.*;
119
import java.awt.event.ActionEvent;
12-
import java.io.IOException;
1310
import java.nio.file.Paths;
1411

1512
public class DeleteLocalFilmlistAction extends AbstractAction {
1613
private final JFrame owner;
17-
private static final Logger logger = LogManager.getLogger();
1814

1915
public DeleteLocalFilmlistAction(MediathekGui parent) {
2016
super();
@@ -25,23 +21,12 @@ public DeleteLocalFilmlistAction(MediathekGui parent) {
2521

2622
@Override
2723
public void actionPerformed(ActionEvent e) {
28-
try {
29-
var filmlistPathStr = StandardLocations.getFilmlistFilePathString();
30-
var fimlistPath = Paths.get(filmlistPathStr);
31-
FileUtils.moveToTrash(fimlistPath);
32-
JOptionPane.showMessageDialog(owner,
33-
"Filmliste wurde gelöscht.\nDas Programm wird nun beendet.",
34-
Konstanten.PROGRAMMNAME,JOptionPane.INFORMATION_MESSAGE);
35-
MediathekGui.ui().quitApplication();
36-
} catch (IOException ex) {
37-
logger.error("Failed to delete filmlist", ex);
38-
JOptionPane.showMessageDialog(owner,
39-
"""
40-
Es trat ein Fehler beim Löschen der Filmliste auf.
41-
Weitere Informationen finden Sie in der Logdatei.
42-
Das Programm wird nun beendet.""",
43-
Konstanten.PROGRAMMNAME,JOptionPane.ERROR_MESSAGE);
44-
MediathekGui.ui().quitApplication();
45-
}
24+
var filmlistPathStr = StandardLocations.getFilmlistFilePathString();
25+
var fimlistPath = Paths.get(filmlistPathStr);
26+
FileUtils.moveToTrash(fimlistPath);
27+
JOptionPane.showMessageDialog(owner,
28+
"Filmliste wurde gelöscht.\nDas Programm wird nun beendet.",
29+
Konstanten.PROGRAMMNAME, JOptionPane.INFORMATION_MESSAGE);
30+
MediathekGui.ui().quitApplication();
4631
}
4732
}

src/main/java/mediathek/tool/FileUtils.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ object FileUtils {
1414
/**
1515
* Move a file to the OS trash if supported, otherwise delete it.
1616
* @param filePath the pathe to the file to be deleted.
17-
* @throws IOException any occuring exception.
1817
*/
19-
@Throws(IOException::class)
2018
@JvmStatic
2119
fun moveToTrash(filePath: Path) {
22-
if (SystemUtils.IS_OS_MAC_OSX) {
23-
MacFileUtils.moveToTrash(filePath.toFile())
24-
}
25-
else if (SystemUtils.IS_OS_WINDOWS) {
26-
WindowsFileUtils.moveToTrash(filePath.toFile())
27-
}
28-
else {
20+
try {
21+
if (SystemUtils.IS_OS_MAC_OSX) {
22+
MacFileUtils.moveToTrash(filePath.toFile())
23+
} else if (SystemUtils.IS_OS_WINDOWS) {
24+
WindowsFileUtils.moveToTrash(filePath.toFile())
25+
} else {
26+
Files.deleteIfExists(filePath)
27+
}
28+
} catch (_: IOException) {
2929
Files.deleteIfExists(filePath)
3030
}
3131
}

0 commit comments

Comments
 (0)