1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-08-31 01:30:00 +02:00

app convert to java.nio

This commit is contained in:
soloturn
2022-01-03 13:27:44 +01:00
parent 24115fbb66
commit 74291358d2

View File

@@ -1,11 +1,10 @@
package com.rarchives.ripme; package com.rarchives.ripme;
import java.awt.*; import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.FileReader; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
@@ -254,9 +253,9 @@ public class App {
//Read URLs from File //Read URLs from File
if (cl.hasOption('f')) { if (cl.hasOption('f')) {
String filename = cl.getOptionValue('f'); Path urlfile = Paths.get(cl.getOptionValue('f'));
try (BufferedReader br = new BufferedReader(new FileReader(filename))) { try (BufferedReader br = Files.newBufferedReader(urlfile)) {
String url; String url;
while ((url = br.readLine()) != null) { while ((url = br.readLine()) != null) {
if (url.startsWith("//") || url.startsWith("#")) { if (url.startsWith("//") || url.startsWith("#")) {
@@ -350,19 +349,18 @@ public class App {
/** /**
* Loads history from history file into memory. * Loads history from history file into memory.
* @see MainWindow.loadHistory
*/ */
private static void loadHistory() { private static void loadHistory() {
File historyFile = new File(Utils.getConfigDir() + File.separator + "history.json"); Path historyFile = Paths.get(Utils.getConfigDir() + "/history.json");
HISTORY.clear(); HISTORY.clear();
if (historyFile.exists()) { if (Files.exists(historyFile)) {
try { try {
logger.info("Loading history from " + historyFile.getCanonicalPath()); logger.info("Loading history from " + historyFile);
HISTORY.fromFile(historyFile.getCanonicalPath()); HISTORY.fromFile(historyFile.toString());
} catch (IOException e) { } catch (IOException e) {
logger.error("Failed to load history from file " + historyFile, e); logger.error("Failed to load history from file " + historyFile, e);
logger.warn( logger.warn(
"RipMe failed to load the history file at " + historyFile.getAbsolutePath() + "\n\n" + "RipMe failed to load the history file at " + historyFile + "\n\n" +
"Error: " + e.getMessage() + "\n\n" + "Error: " + e.getMessage() + "\n\n" +
"Closing RipMe will automatically overwrite the contents of this file,\n" + "Closing RipMe will automatically overwrite the contents of this file,\n" +
"so you may want to back the file up before closing RipMe!"); "so you may want to back the file up before closing RipMe!");
@@ -374,6 +372,7 @@ public class App {
// Loaded from config, still no entries. // Loaded from config, still no entries.
// Guess rip history based on rip folder // Guess rip history based on rip folder
String[] dirs = Utils.getWorkingDirectory().list((dir, file) -> new File(dir.getAbsolutePath() + File.separator + file).isDirectory()); String[] dirs = Utils.getWorkingDirectory().list((dir, file) -> new File(dir.getAbsolutePath() + File.separator + file).isDirectory());
assert dirs != null;
for (String dir : dirs) { for (String dir : dirs) {
String url = RipUtils.urlFromDirectoryName(dir); String url = RipUtils.urlFromDirectoryName(dir);
if (url != null) { if (url != null) {
@@ -391,7 +390,7 @@ public class App {
* @see MainWindow.saveHistory * @see MainWindow.saveHistory
*/ */
private static void saveHistory() { private static void saveHistory() {
Path historyFile = Paths.get(Utils.getConfigDir() + File.separator + "history.json"); Path historyFile = Paths.get(Utils.getConfigDir() + "/history.json");
try { try {
if (!Files.exists(historyFile)) { if (!Files.exists(historyFile)) {
Files.createDirectories(historyFile.getParent()); Files.createDirectories(historyFile.getParent());