fix: Better error handling when importing games

This commit is contained in:
lantzelot-swe 2021-02-15 13:06:28 +01:00
parent 9efacbdd18
commit 238ecd8d23
2 changed files with 157 additions and 168 deletions

View File

@ -27,7 +27,9 @@ public class ImportWorker extends SwingWorker<Void, String>
StringBuilder infoBuilder = new StringBuilder(); StringBuilder infoBuilder = new StringBuilder();
importManager.readGameInfoFiles(infoBuilder); importManager.readGameInfoFiles(infoBuilder);
publish(infoBuilder.toString()); publish(infoBuilder.toString());
importManager.convertIntoDbRows(); infoBuilder = new StringBuilder();
importManager.convertIntoDbRows(infoBuilder);
publish(infoBuilder.toString());
publish("Importing to db..."); publish("Importing to db...");
publish(importManager.insertRowsIntoDb().toString()); publish(importManager.insertRowsIntoDb().toString());
publish("Copy screenshots, covers and game files..."); publish("Copy screenshots, covers and game files...");

View File

@ -65,7 +65,7 @@ public class ImportManager
srcGamesFolder = srcParentFolder.resolve("games"); srcGamesFolder = srcParentFolder.resolve("games");
srcScreensFolder = srcParentFolder.resolve("screens"); srcScreensFolder = srcParentFolder.resolve("screens");
if (! (Files.exists(srcParentFolder, LinkOption.NOFOLLOW_LINKS) && if (!(Files.exists(srcParentFolder, LinkOption.NOFOLLOW_LINKS) &&
Files.exists(srcCoversFolder, LinkOption.NOFOLLOW_LINKS) && Files.exists(srcCoversFolder, LinkOption.NOFOLLOW_LINKS) &&
Files.exists(srcGamesFolder, LinkOption.NOFOLLOW_LINKS) && Files.exists(srcGamesFolder, LinkOption.NOFOLLOW_LINKS) &&
Files.exists(srcScreensFolder, LinkOption.NOFOLLOW_LINKS))) Files.exists(srcScreensFolder, LinkOption.NOFOLLOW_LINKS)))
@ -118,10 +118,10 @@ public class ImportManager
return (dotIndex == -1) ? "" : fileName.substring(dotIndex + 1); return (dotIndex == -1) ? "" : fileName.substring(dotIndex + 1);
} }
public void convertIntoDbRows() public void convertIntoDbRows(StringBuilder infoBuilder)
{ {
// Construct a List of comma separated strings with all info correctly added. // Construct a List of comma separated strings with all info correctly added.
gameInfoFilesMap.values().stream().forEach(this::extractInfoIntoRowString); gameInfoFilesMap.values().stream().forEach(list -> extractInfoIntoRowString(list, infoBuilder));
} }
public StringBuilder insertRowsIntoDb() public StringBuilder insertRowsIntoDb()
@ -129,7 +129,7 @@ public class ImportManager
return uiModel.importGameInfo(dbRowDataList, selectedOption, addAsFavorite); return uiModel.importGameInfo(dbRowDataList, selectedOption, addAsFavorite);
} }
private void extractInfoIntoRowString(List<String> fileLines) private void extractInfoIntoRowString(List<String> fileLines, StringBuilder infoBuilder)
{ {
String title = ""; String title = "";
String year = ""; String year = "";
@ -149,7 +149,8 @@ public class ImportManager
String joy2config = ""; String joy2config = "";
String advanced = ""; String advanced = "";
String verticalShift = ""; String verticalShift = "";
try
{
for (String line : fileLines) for (String line : fileLines)
{ {
if (line.startsWith("T:")) if (line.startsWith("T:"))
@ -269,26 +270,6 @@ public class ImportManager
description_it = ""; description_it = "";
} }
// //Don't allow same screen file for both entries
// if (screen1file.equals(screen2file))
// {
// if (screen1file.endsWith("-01.png"))
// {
// screen1file = "";
// }
// else
// {
// screen2file = "";
// }
// }
// //Special handling of screens which may have wrong name or missing entry (screen 1 might be named 01.png,
// //handle that as screen2 instead to get names set correctly)
// if (screen1file.endsWith("-01.png") && screen2file.isEmpty())
// {
// screen2file = screen1file;
// screen1file = "";
// }
// Construct a data row // Construct a data row
List<String> list = Arrays.asList(title, List<String> list = Arrays.asList(title,
year, year,
@ -312,6 +293,12 @@ public class ImportManager
result = "\"" + result + "\""; result = "\"" + result + "\"";
dbRowDataList.add(result); dbRowDataList.add(result);
} }
catch (Exception e)
{
infoBuilder.append("ERROR: Could not read info file for \"" + title + "\"\n");
logger.error("IMPORT: Could not read info file for " + title, e);
}
}
private List<String> readFileInList(Path filePath, StringBuilder infoBuilder) private List<String> readFileInList(Path filePath, StringBuilder infoBuilder)
{ {