fix: Better feedback during gamebase import.

This commit is contained in:
lantzelot-swe 2022-01-16 19:26:17 +01:00
parent 7697405147
commit ef38b60522
2 changed files with 18 additions and 18 deletions

View File

@ -18,6 +18,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import se.lantz.gui.exports.PublishWorker;
import se.lantz.manager.ImportManager; import se.lantz.manager.ImportManager;
import se.lantz.scraper.GamebaseScraper; import se.lantz.scraper.GamebaseScraper;
import se.lantz.util.ExceptionHandler; import se.lantz.util.ExceptionHandler;
@ -142,10 +143,9 @@ public class GamebaseImporter
return false; return false;
} }
public StringBuilder importFromGamebase() public void importFromGamebase(PublishWorker worker)
{ {
gbGameInfoList.clear(); gbGameInfoList.clear();
StringBuilder builder = new StringBuilder();
//Use the folder where the gamebase mdb file is located in the import manager //Use the folder where the gamebase mdb file is located in the import manager
importManager.setSelectedFoldersForGamebase(gbGamesPath, gbScreensPath, gbExtrasPath.resolve("covers")); importManager.setSelectedFoldersForGamebase(gbGamesPath, gbScreensPath, gbExtrasPath.resolve("covers"));
@ -180,22 +180,21 @@ public class GamebaseImporter
int gameCount = 0; int gameCount = 0;
while (result.next()) while (result.next())
{ {
if (createGbGameInfo(result, statement, builder)) if (createGbGameInfo(result, statement, worker))
{ {
gameCount++; gameCount++;
} }
} }
builder.append("Read " + gameCount + " games from the gamebase db.\n"); worker.publishMessage("\nRead " + gameCount + " games from the gamebase db.\n");
} }
catch (SQLException ex) catch (SQLException ex)
{ {
builder.append("ERROR: Query failed : " + ex.toString() + "\n"); worker.publishMessage("ERROR: Query failed : " + ex.toString());
ExceptionHandler.handleException(ex, "Query failed"); ExceptionHandler.handleException(ex, "Query failed");
} }
return builder;
} }
private boolean createGbGameInfo(ResultSet result, Statement statement, StringBuilder builder) private boolean createGbGameInfo(ResultSet result, Statement statement, PublishWorker worker)
{ {
String title = ""; String title = "";
try try
@ -216,13 +215,14 @@ public class GamebaseImporter
String vic20Description = ""; String vic20Description = "";
boolean vic20Cart = false; boolean vic20Cart = false;
worker.publishMessage("Creating game info for " + title + "...");
//Game file //Game file
if (isC64) if (isC64)
{ {
//GB64 includes game files for all games, no additional extras available. //GB64 includes game files for all games, no additional extras available.
if (gamefile.isEmpty() && !includeEntriesWithMissingGameFile) if (gamefile.isEmpty() && !includeEntriesWithMissingGameFile)
{ {
builder.append("Ignoring " + title + " (No game file available)\n"); worker.publishMessage("Ignoring " + title + " (No game file available)");
return false; return false;
} }
@ -264,7 +264,7 @@ public class GamebaseImporter
if (gamefile.isEmpty() && !includeEntriesWithMissingGameFile) if (gamefile.isEmpty() && !includeEntriesWithMissingGameFile)
{ {
builder.append("Ignoring " + title + " (No game file available)\n"); worker.publishMessage("Ignoring " + title + " (No game file available)");
return false; return false;
} }
} }
@ -329,7 +329,7 @@ public class GamebaseImporter
} }
catch (Exception e) catch (Exception e)
{ {
builder.append("ERROR: Could not fetch all info for " + title + ":\n" + e.toString() + "\n"); worker.publishMessage("ERROR: Could not fetch all info for " + title + ":\n" + e.toString());
ExceptionHandler.handleException(e, "Could not fetch all info for " + title); ExceptionHandler.handleException(e, "Could not fetch all info for " + title);
} }
return false; return false;
@ -424,13 +424,13 @@ public class GamebaseImporter
return importManager.getReadChunks(gbGameInfoList, CHUNK_SIZE); return importManager.getReadChunks(gbGameInfoList, CHUNK_SIZE);
} }
public StringBuilder checkGameFileForGbGames(List<GbGameInfo> gbGameList) public void checkGameFileForGbGames(List<GbGameInfo> gbGameList, PublishWorker worker)
{ {
StringBuilder builder = new StringBuilder();
for (GbGameInfo gbGameInfo : gbGameList) for (GbGameInfo gbGameInfo : gbGameList)
{ {
try try
{ {
worker.publishMessage("Checking game file for " + gbGameInfo.getTitle() + "...");
String gameFile = getFileToInclude(gbGamesPath, gbGameInfo.getGamefile(), gbGameInfo.isVic20Cart()); String gameFile = getFileToInclude(gbGamesPath, gbGameInfo.getGamefile(), gbGameInfo.isVic20Cart());
importManager.addFromGamebaseImporter(gbGameInfo.getTitle(), importManager.addFromGamebaseImporter(gbGameInfo.getTitle(),
gbGameInfo.getYear(), gbGameInfo.getYear(),
@ -449,13 +449,12 @@ public class GamebaseImporter
} }
catch (Exception e) catch (Exception e)
{ {
builder.append("Ignoring " + gbGameInfo.getTitle() + worker.publishMessage("Ignoring " + gbGameInfo.getTitle() +
", Could not check game file (file is corrupt?). Game is not imported.\n"); ", Could not check game file (file is corrupt?). Game is not imported.");
ExceptionHandler ExceptionHandler
.logException(e, "Could not check game file for " + gbGameInfo.getTitle() + ", game is not imported"); .logException(e, "Could not check game file for " + gbGameInfo.getTitle() + ", game is not imported");
} }
} }
return builder;
} }
private String constructAdvancedString(int palOrNtsc, int trueDriveEmu, String gemus) private String constructAdvancedString(int palOrNtsc, int trueDriveEmu, String gemus)

View File

@ -26,7 +26,8 @@ public class GamebaseImportWorker extends AbstractImportWorker
{ {
progressValueString = "Querying gamebase db..."; progressValueString = "Querying gamebase db...";
publish("Reading from gamebase db... this may take a while, be patient!"); publish("Reading from gamebase db... this may take a while, be patient!");
publish(gbInporter.importFromGamebase().toString());
gbInporter.importFromGamebase(this);
progressValueString = "Checking game files..."; progressValueString = "Checking game files...";
List<List<GbGameInfo>> listChunks = gbInporter.getGbGameInfoChunks(); List<List<GbGameInfo>> listChunks = gbInporter.getGbGameInfoChunks();
@ -44,14 +45,14 @@ public class GamebaseImportWorker extends AbstractImportWorker
} }
progressValue++; progressValue++;
progressValueString = String.format("Checking game files (batch %s of %s)", progressValue, progressMaximum); progressValueString = String.format("Checking game files (batch %s of %s)", progressValue, progressMaximum);
publish(gbInporter.checkGameFileForGbGames(gbInfoList).toString()); gbInporter.checkGameFileForGbGames(gbInfoList, this);
} }
List<List<String>> dbRowReadChunks = importManager.getDbRowReadChunks(); List<List<String>> dbRowReadChunks = importManager.getDbRowReadChunks();
progressValueString = "Importing to db and copying files..."; progressValueString = "Importing to db and copying files...";
progressMaximum = dbRowReadChunks.size(); progressMaximum = dbRowReadChunks.size();
progressValue = 0; progressValue = 0;
publish("Importing to db, copying covers, screens and game files..."); publish("\nImporting to db, copying covers, screens and game files...");
int chunkCount = 0; int chunkCount = 0;
for (List<String> rowList : dbRowReadChunks) for (List<String> rowList : dbRowReadChunks)
{ {