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;
logger.debug("Generated SELECT String:\n{}", sql);
GameDetails returnValue = new GameDetails();
returnValue.setGameId(gameId);
try (Connection conn = this.connect(); PreparedStatement pstmt = conn.prepareStatement(sql))
{
ResultSet rs = pstmt.executeQuery();

View File

@ -306,18 +306,15 @@ public class ExportManager
}
zipped = true;
}
String gameFileNameWithoutExtension = FileManager.generateFileNameFromTitleForFileLoader(gameDetails.getTitle(),
gameDetails.getDuplicateIndex());
String gameFileNameWithoutExtension = FileManager.generateFileNameFromTitleForFileLoader(gameDetails
.getGameId(), gameDetails.getTitle(), gameDetails.getAuthor(), gameDetails.getDuplicateIndex());
Path targetGamePath = targetPath
.resolve(gameFileNameWithoutExtension + "." + extension);
Path targetGamePath = targetPath.resolve(gameFileNameWithoutExtension + "." + extension);
if (FileManager.hasExtraDisks(gameDetails))
{
targetGamePath = targetPath
.resolve(gameFileNameWithoutExtension + " (disk 1)." + extension);
targetGamePath = targetPath.resolve(gameFileNameWithoutExtension + " (disk 1)." + extension);
}
try
{
if (!gameDetails.getGame().isEmpty())
@ -348,14 +345,18 @@ public class ExportManager
}
}
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())
{
String extension = FilenameUtils.getExtension(extraDiskName);
Path targetGamePath = targetPath
.resolve(gameFileNameWithoutExtension + " (disk " + diskIndex + ")_CD." + extension);
Path targetGamePath =
targetPath.resolve(gameFileNameWithoutExtension + " (disk " + diskIndex + ")_CD." + extension);
Path extraDiskPath = Paths.get("./extradisks/" + extraDiskName);
@ -367,7 +368,8 @@ public class ExportManager
}
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);
}
}

View File

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

View File

@ -36,6 +36,8 @@ public class GameDetails
private String disk5 = "";
private String disk6 = "";
private String gameId = "";
public GameDetails()
{
@ -295,4 +297,14 @@ public class GameDetails
{
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 DbConnector dbconnector;
static
{
try
@ -124,6 +125,11 @@ public class FileManager
this.model = model;
}
public void setDbConnector(DbConnector ref)
{
dbconnector = ref;
}
public static InputStream getMissingC64GameFile() throws URISyntaxException
{
return FileManager.class.getResourceAsStream("/se/lantz/MissingGame-C64.vsf.gz");
@ -715,18 +721,27 @@ public class FileManager
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 =
":,'ï¿!+*<>/?|\"".chars().mapToObj(item -> (char) item).collect(Collectors.toList());
List<Character> newName = title.chars().mapToObj(item -> (char) item)
.filter(character -> !forbiddenCharsList.contains(character)).collect(Collectors.toList());
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
newNameString = newNameString + " (" + duplicateIndex + ")";
//Add author and the duplicate index if larger than 0 if there are several games with the same name
if (duplicateIndex == 0)
{
newNameString = newNameString + " (" + correctedAuthor + ")";
}
else
{
newNameString = newNameString + " (" + correctedAuthor + ")("+ duplicateIndex +")";
}
}
newNameString = newNameString.trim();
@ -749,13 +764,20 @@ public class FileManager
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);
return newNameString;
}
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.
int dotCount = (int) name.chars().filter(ch -> ch == '.').count();
if (dotCount > 4)
@ -786,10 +808,10 @@ public class FileManager
}
worker.publishMessage("Creating cjm file for " + gameDetails.getTitle());
filename =
generateFileNameFromTitleForFileLoader(gameDetails.getTitle(), gameDetails.getDuplicateIndex()) + ".cjm";
generateFileNameFromTitleForFileLoader(gameDetails.getGameId(), gameDetails.getTitle(), gameDetails.getAuthor(), gameDetails.getDuplicateIndex()) + ".cjm";
if (hasExtraDisks(gameDetails))
{
filename = generateFileNameFromTitleForFileLoader(gameDetails.getTitle(), gameDetails.getDuplicateIndex()) +
filename = generateFileNameFromTitleForFileLoader(gameDetails.getGameId(), gameDetails.getTitle(), gameDetails.getAuthor(), gameDetails.getDuplicateIndex()) +
" (disk 1).cjm";
}
}