fix: When exporting to file loader the file name for

duplicate game entires include the author in parenthesis.
This commit is contained in:
lantzelot-swe 2023-02-03 21:38:50 +01:00
parent ea6e058ae5
commit 663580be5d
5 changed files with 65 additions and 27 deletions

View File

@ -954,6 +954,7 @@ public class DbConnector
String sql = "SELECT * FROM gameinfo WHERE rowid = " + gameId; String sql = "SELECT * FROM gameinfo WHERE rowid = " + gameId;
logger.debug("Generated SELECT String:\n{}", sql); logger.debug("Generated SELECT String:\n{}", sql);
GameDetails returnValue = new GameDetails(); GameDetails returnValue = new GameDetails();
returnValue.setGameId(gameId);
try (Connection conn = this.connect(); PreparedStatement pstmt = conn.prepareStatement(sql)) try (Connection conn = this.connect(); PreparedStatement pstmt = conn.prepareStatement(sql))
{ {
ResultSet rs = pstmt.executeQuery(); ResultSet rs = pstmt.executeQuery();

View File

@ -257,7 +257,7 @@ public class ExportManager
} }
} }
} }
public void copyGamesForFileLoader(PublishWorker worker) public void copyGamesForFileLoader(PublishWorker worker)
{ {
if (gameViewMode) if (gameViewMode)
@ -306,17 +306,14 @@ public class ExportManager
} }
zipped = true; zipped = true;
} }
String gameFileNameWithoutExtension = FileManager.generateFileNameFromTitleForFileLoader(gameDetails.getTitle(), String gameFileNameWithoutExtension = FileManager.generateFileNameFromTitleForFileLoader(gameDetails
gameDetails.getDuplicateIndex()); .getGameId(), gameDetails.getTitle(), gameDetails.getAuthor(), gameDetails.getDuplicateIndex());
Path targetGamePath = targetPath Path targetGamePath = targetPath.resolve(gameFileNameWithoutExtension + "." + extension);
.resolve(gameFileNameWithoutExtension + "." + extension);
if (FileManager.hasExtraDisks(gameDetails)) if (FileManager.hasExtraDisks(gameDetails))
{ {
targetGamePath = targetPath targetGamePath = targetPath.resolve(gameFileNameWithoutExtension + " (disk 1)." + extension);
.resolve(gameFileNameWithoutExtension + " (disk 1)." + extension);
} }
try try
{ {
@ -347,27 +344,32 @@ public class ExportManager
copyExtraDiskForFileLoader(targetPath, gameFileNameWithoutExtension, gameDetails.getDisk6(), 6, worker); copyExtraDiskForFileLoader(targetPath, gameFileNameWithoutExtension, gameDetails.getDisk6(), 6, worker);
} }
} }
private void copyExtraDiskForFileLoader(Path targetPath, String gameFileNameWithoutExtension, String extraDiskName, int diskIndex, PublishWorker worker) private void copyExtraDiskForFileLoader(Path targetPath,
String gameFileNameWithoutExtension,
String extraDiskName,
int diskIndex,
PublishWorker worker)
{ {
if (extraDiskName != null && !extraDiskName.isEmpty()) if (extraDiskName != null && !extraDiskName.isEmpty())
{ {
String extension = FilenameUtils.getExtension(extraDiskName); String extension = FilenameUtils.getExtension(extraDiskName);
Path targetGamePath = targetPath Path targetGamePath =
.resolve(gameFileNameWithoutExtension + " (disk " + diskIndex + ")_CD." + extension); targetPath.resolve(gameFileNameWithoutExtension + " (disk " + diskIndex + ")_CD." + extension);
Path extraDiskPath = Paths.get("./extradisks/" + extraDiskName); Path extraDiskPath = Paths.get("./extradisks/" + extraDiskName);
try try
{ {
worker.publishMessage("Copying extra disk file from " + extraDiskPath.toString() + " to " + targetGamePath); worker.publishMessage("Copying extra disk file from " + extraDiskPath.toString() + " to " + targetGamePath);
Files.copy(extraDiskPath, targetGamePath, StandardCopyOption.REPLACE_EXISTING); Files.copy(extraDiskPath, targetGamePath, StandardCopyOption.REPLACE_EXISTING);
} }
catch (IOException e) catch (IOException e)
{ {
worker.publishMessage("ERROR: Could not copy files for " + gameFileNameWithoutExtension + ", " + e.getMessage()); worker
.publishMessage("ERROR: Could not copy files for " + gameFileNameWithoutExtension + ", " + e.getMessage());
ExceptionHandler.handleException(e, "Could NOT copy files for: " + gameFileNameWithoutExtension); ExceptionHandler.handleException(e, "Could NOT copy files for: " + gameFileNameWithoutExtension);
} }
} }

View File

@ -104,6 +104,7 @@ public class MainViewModel extends AbstractModel
.setPrimaryWithoutListenerNotification(!Boolean.valueOf(e.getActionCommand()))); .setPrimaryWithoutListenerNotification(!Boolean.valueOf(e.getActionCommand())));
resetDataChangedAfterInit(); resetDataChangedAfterInit();
fileManager.setDbConnector(dbConnector);
} }
public DbConnector getDbConnector() public DbConnector getDbConnector()

View File

@ -36,6 +36,8 @@ public class GameDetails
private String disk5 = ""; private String disk5 = "";
private String disk6 = ""; private String disk6 = "";
private String gameId = "";
public GameDetails() public GameDetails()
{ {
@ -295,4 +297,14 @@ public class GameDetails
{ {
this.disk6 = disk6 == null ? "" : disk6; this.disk6 = disk6 == null ? "" : disk6;
} }
public String getGameId()
{
return gameId;
}
public void setGameId(String gameId)
{
this.gameId = gameId;
}
} }

View File

@ -99,6 +99,7 @@ public class FileManager
private static List<String> compressedDiskFilesEndingList = Arrays.asList("d64", "d71", "x64", "g64"); private static List<String> compressedDiskFilesEndingList = Arrays.asList("d64", "d71", "x64", "g64");
private static DbConnector dbconnector;
static static
{ {
try try
@ -123,6 +124,11 @@ public class FileManager
this.savedStatesModel = model.getSavedStatesModel(); this.savedStatesModel = model.getSavedStatesModel();
this.model = model; this.model = model;
} }
public void setDbConnector(DbConnector ref)
{
dbconnector = ref;
}
public static InputStream getMissingC64GameFile() throws URISyntaxException public static InputStream getMissingC64GameFile() throws URISyntaxException
{ {
@ -715,18 +721,27 @@ public class FileManager
return newNameString; return newNameString;
} }
public static String generateFileNameFromTitleForFileLoader(String title, int duplicateIndex) public static String generateFileNameFromTitleForFileLoader(String gameId, String title, String author, int duplicateIndex)
{ {
String correctedAuthor = author.replace("\\", " ");
correctedAuthor = author.replace("/", " ");
List<Character> forbiddenCharsList = List<Character> forbiddenCharsList =
":,'ï¿!+*<>/?|\"".chars().mapToObj(item -> (char) item).collect(Collectors.toList()); ":,'ï¿!+*<>/?|\"".chars().mapToObj(item -> (char) item).collect(Collectors.toList());
List<Character> newName = title.chars().mapToObj(item -> (char) item) List<Character> newName = title.chars().mapToObj(item -> (char) item)
.filter(character -> !forbiddenCharsList.contains(character)).collect(Collectors.toList()); .filter(character -> !forbiddenCharsList.contains(character)).collect(Collectors.toList());
String newNameString = newName.stream().map(String::valueOf).collect(Collectors.joining()); String newNameString = newName.stream().map(String::valueOf).collect(Collectors.joining());
if (duplicateIndex > 0) if (duplicateIndex > 0 || (!gameId.isEmpty() && dbconnector.getGameDuplicateIndexToUse(title, gameId) > 1))
{ {
//Just add the duplicate index if there are several games with the same name //Add author and the duplicate index if larger than 0 if there are several games with the same name
newNameString = newNameString + " (" + duplicateIndex + ")"; if (duplicateIndex == 0)
{
newNameString = newNameString + " (" + correctedAuthor + ")";
}
else
{
newNameString = newNameString + " (" + correctedAuthor + ")("+ duplicateIndex +")";
}
} }
newNameString = newNameString.trim(); newNameString = newNameString.trim();
@ -749,13 +764,20 @@ public class FileManager
newNameString = newNameString.replaceAll("\\[", "("); newNameString = newNameString.replaceAll("\\[", "(");
newNameString = newNameString.replaceAll("\\]", ")"); newNameString = newNameString.replaceAll("\\]", ")");
newNameString = newNameString.replace("((", "(");
newNameString = newNameString.replace("))", ")");
newNameString = newNameString.replace(">", "");
newNameString = newNameString.replace("<", "");
newNameString = newNameString.replace("?", "");
newNameString = newNameString.replace("*", "");
logger.debug("Game title: \"{}\" ---- New fileName: \"{}\"", title, newNameString); logger.debug("Game title: \"{}\" ---- New fileName: \"{}\"", title, newNameString);
return newNameString; return newNameString;
} }
public static String generateSavedStatesFolderNameForFileLoader(String title, int duplicateIndex) public static String generateSavedStatesFolderNameForFileLoader(String title, int duplicateIndex)
{ {
String name = generateFileNameFromTitleForFileLoader(title, duplicateIndex); String name = generateFileNameFromTitleForFileLoader("", title, "", duplicateIndex);
//Special handling of titles where dots occur, e.g. G.A.C.C.R.R. or H.E.R.O. //Special handling of titles where dots occur, e.g. G.A.C.C.R.R. or H.E.R.O.
int dotCount = (int) name.chars().filter(ch -> ch == '.').count(); int dotCount = (int) name.chars().filter(ch -> ch == '.').count();
if (dotCount > 4) if (dotCount > 4)
@ -786,10 +808,10 @@ public class FileManager
} }
worker.publishMessage("Creating cjm file for " + gameDetails.getTitle()); worker.publishMessage("Creating cjm file for " + gameDetails.getTitle());
filename = filename =
generateFileNameFromTitleForFileLoader(gameDetails.getTitle(), gameDetails.getDuplicateIndex()) + ".cjm"; generateFileNameFromTitleForFileLoader(gameDetails.getGameId(), gameDetails.getTitle(), gameDetails.getAuthor(), gameDetails.getDuplicateIndex()) + ".cjm";
if (hasExtraDisks(gameDetails)) if (hasExtraDisks(gameDetails))
{ {
filename = generateFileNameFromTitleForFileLoader(gameDetails.getTitle(), gameDetails.getDuplicateIndex()) + filename = generateFileNameFromTitleForFileLoader(gameDetails.getGameId(), gameDetails.getTitle(), gameDetails.getAuthor(), gameDetails.getDuplicateIndex()) +
" (disk 1).cjm"; " (disk 1).cjm";
} }
} }