Loads history from history file into memory.
()
| 350 | * Loads history from history file into memory. |
| 351 | */ |
| 352 | private static void loadHistory() throws IOException { |
| 353 | Path historyFile = Paths.get(Utils.getConfigDir() + "/history.json"); |
| 354 | HISTORY.clear(); |
| 355 | if (Files.exists(historyFile)) { |
| 356 | try { |
| 357 | logger.info("Loading history from " + historyFile); |
| 358 | HISTORY.fromFile(historyFile.toString()); |
| 359 | } catch (IOException e) { |
| 360 | logger.error("Failed to load history from file " + historyFile, e); |
| 361 | logger.warn( |
| 362 | "RipMe failed to load the history file at " + historyFile + "\n\n" + |
| 363 | "Error: " + e.getMessage() + "\n\n" + |
| 364 | "Closing RipMe will automatically overwrite the contents of this file,\n" + |
| 365 | "so you may want to back the file up before closing RipMe!"); |
| 366 | } |
| 367 | } else { |
| 368 | logger.info("Loading history from configuration"); |
| 369 | HISTORY.fromList(Utils.getConfigList("download.history")); |
| 370 | if (HISTORY.toList().isEmpty()) { |
| 371 | // Loaded from config, still no entries. |
| 372 | // Guess rip history based on rip folder |
| 373 | Stream<Path> stream = Files.list(Utils.getWorkingDirectory()) |
| 374 | .filter(Files::isDirectory); |
| 375 | |
| 376 | stream.forEach(dir -> { |
| 377 | String url = RipUtils.urlFromDirectoryName(dir.toString()); |
| 378 | if (url != null) { |
| 379 | // We found one, add it to history |
| 380 | HistoryEntry entry = new HistoryEntry(); |
| 381 | entry.url = url; |
| 382 | HISTORY.add(entry); |
| 383 | } |
| 384 | }); |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | /* |
| 390 | * @see MainWindow.saveHistory |
no test coverage detected