()
| 1268 | } |
| 1269 | |
| 1270 | private void loadHistory() throws IOException { |
| 1271 | File historyFile = new File(Utils.getConfigDir() + "/history.json"); |
| 1272 | HISTORY.clear(); |
| 1273 | if (historyFile.exists()) { |
| 1274 | try { |
| 1275 | LOGGER.info(Utils.getLocalizedString("loading.history.from") + " " + historyFile.getCanonicalPath()); |
| 1276 | HISTORY.fromFile(historyFile.getCanonicalPath()); |
| 1277 | } catch (IOException e) { |
| 1278 | LOGGER.error("Failed to load history from file " + historyFile, e); |
| 1279 | JOptionPane.showMessageDialog(null, |
| 1280 | String.format(Utils.getLocalizedString("history.load.failed.warning"), e.getMessage()), |
| 1281 | |
| 1282 | "RipMe - history load failure", JOptionPane.ERROR_MESSAGE); |
| 1283 | } |
| 1284 | } else { |
| 1285 | LOGGER.info(Utils.getLocalizedString("loading.history.from.configuration")); |
| 1286 | HISTORY.fromList(Utils.getConfigList("download.history")); |
| 1287 | if (HISTORY.toList().isEmpty()) { |
| 1288 | // Loaded from config, still no entries. |
| 1289 | // Guess rip history based on rip folder |
| 1290 | Stream<Path> stream = Files.list(Utils.getWorkingDirectory()) |
| 1291 | .filter(Files::isDirectory); |
| 1292 | |
| 1293 | stream.forEach(dir -> { |
| 1294 | String url = RipUtils.urlFromDirectoryName(dir.toString()); |
| 1295 | if (url != null) { |
| 1296 | // We found one, add it to history |
| 1297 | HistoryEntry entry = new HistoryEntry(); |
| 1298 | entry.url = url; |
| 1299 | HISTORY.add(entry); |
| 1300 | } |
| 1301 | }); |
| 1302 | } |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | private void saveHistory() { |
| 1307 | Path historyFile = Paths.get(Utils.getConfigDir() + "/history.json"); |
no test coverage detected