Fix: Many bug fixes:

- Paths.ini is read properly and paths for screenshots, extras and games are correct when copying files.
- Fixed a bug when importing from GB64 where "vtde=yes" did not set true drive emulation correctly.
- Fixed a bug where game files where overwritten during import for games with very similar names (but not identical, e.g. "Last Ninja, The" and "Last Ninja , The")
- Memory banks for Vic-20 are set when importing games (a best effort is made, does not work 100%). Key-value pairs are read from the gb database and added to the description field
so that all info for memory expansion is available.
- Games that are not zipped in gamebase are imported properly now, previously they was ignored.
This commit is contained in:
lantzelot-swe 2021-03-16 23:18:28 +01:00
parent a649888670
commit b79505429f
7 changed files with 140 additions and 37 deletions

View File

@ -72,28 +72,51 @@ public class GamebaseImporter
{
Path iniFile = this.gbDatabasePath.getParent().resolve("Paths.ini");
List<String> lines = Files.readAllLines(iniFile, StandardCharsets.ISO_8859_1);
//Is lines returned in the expected order?
boolean games = false;
boolean pictures = false;
boolean extras = false;
for (String line : lines)
{
if (line.startsWith("1="))
if (line.equals("[Games]"))
{
if (this.gbGamesPath == null)
{
this.gbGamesPath = Paths.get(line.substring(2));
}
else if (this.gbScreensPath == null)
{
this.gbScreensPath = Paths.get(line.substring(2));
}
else if (this.gbExtrasPath == null)
{
this.gbExtrasPath = Paths.get(line.substring(2));
}
else
{
//Do nothing
}
games = true;
pictures = false;
extras = false;
}
else if (line.equals("[Pictures]"))
{
games = false;
pictures = true;
extras = false;
}
else if (line.equals("[Extras]"))
{
games = false;
pictures = false;
extras = true;
}
else
{
if (line.startsWith("1="))
{
if (games)
{
this.gbGamesPath = Paths.get(line.substring(2));
}
else if (pictures)
{
this.gbScreensPath = Paths.get(line.substring(2));
}
else if (extras)
{
this.gbExtrasPath = Paths.get(line.substring(2));
}
else
{
//Do nothing
}
}
}
}
return true;
}
@ -182,6 +205,12 @@ public class GamebaseImporter
//Setup advanced string (system, sid, pal, truedrive etc)
String advanced = constructAdvancedString(palOrNtsc, trueDriveEmu, gemus);
//Description: add key-value pairs for Vic-20 since that holds important info about memory expansion
String description = "";
if (!isC64)
{
description = gemus;
}
//Control: 0=JoyPort2, 1=JoyPort1, 2=Keyboard, 3=PaddlePort2, 4=PaddlePort1, 5=Mouse, 6=LightPen, 7=KoalaPad, 8=LightGun
//Setup joystick port
String joy1config;
@ -246,7 +275,8 @@ public class GamebaseImporter
screen2,
joy1config,
joy2config,
advanced);
advanced,
description);
gbGameInfoList.add(info);
gameCount++;
@ -376,6 +406,7 @@ public class GamebaseImporter
gbGameInfo.getJoy1config(),
gbGameInfo.getJoy2config(),
gbGameInfo.getAdvanced(),
gbGameInfo.getDescription(),
isC64);
}
catch (Exception e)
@ -406,10 +437,64 @@ public class GamebaseImporter
String video = (palOrNtsc == 2) ? "ntsc" : "pal";
advanced = advanced + "," + video;
//Setup truedrive
if (trueDriveEmu > 0 || "vte=yes".equalsIgnoreCase(gemus))
if (trueDriveEmu > 0 || "vtde=yes".equalsIgnoreCase(gemus))
{
advanced = advanced + "," + "driveicon,accuratedisk";
}
//For Vic-20 setup memory banks
if (!isC64)
{
String memoryBanks = "";
switch (gemus)
{
case "memory=3k":
memoryBanks = "bank0";
break;
case "memory=8k":
memoryBanks = "bank1";
break;
case "memory=16k":
memoryBanks = "bank1,bank2";
break;
case "memory=24k":
memoryBanks = "bank1,bank2,bank3";
break;
case "cart=a0":
memoryBanks = "bank5";
break;
case "cart=a000":
memoryBanks = "bank5";
break;
case "cart=20":
memoryBanks = "bank1";
break;
case "cart=2000":
memoryBanks = "bank1";
break;
case "cart=40":
memoryBanks = "bank2";
break;
case "cart=4000":
memoryBanks = "bank2";
break;
case "cart=60":
memoryBanks = "bank3";
break;
case "cart=6000":
memoryBanks = "bank3";
break;
case "memory=all":
memoryBanks = "bank0,bank1,bank2,bank3,bank5";
break;
default:
break;
}
if (!memoryBanks.isEmpty())
{
advanced = advanced + "," + memoryBanks;
}
}
return advanced;
}
@ -432,9 +517,8 @@ public class GamebaseImporter
private String getFileToInclude(Path gbPath, String filenameInGb) throws IOException
{
//TODO: check if gzipped, otherwise include anyway
File gameFile = gbPath.resolve(filenameInGb).toFile();
File selectedFile = FileManager.createTempFileForScraper(new BufferedInputStream(new FileInputStream(gameFile)));
File selectedFile = FileManager.createTempFileForScraper(new BufferedInputStream(new FileInputStream(gameFile)), gameFile.getName());
Path compressedFilePath = selectedFile.toPath().getParent().resolve(selectedFile.getName() + ".gz");
FileManager.compressGzip(selectedFile.toPath(), compressedFilePath);
return compressedFilePath.toString();

View File

@ -15,6 +15,7 @@ public class GbGameInfo
private String joy1config;
private String joy2config;
private String advanced;
private String description;
public GbGameInfo(String title,
String year,
@ -27,7 +28,8 @@ public class GbGameInfo
String screen2,
String joy1config,
String joy2config,
String advanced)
String advanced,
String description)
{
this.title = title;
this.year = year;
@ -41,6 +43,7 @@ public class GbGameInfo
this.joy1config = joy1config;
this.joy2config = joy2config;
this.advanced = advanced;
this.description = description;
}
public String getTitle()
@ -163,4 +166,13 @@ public class GbGameInfo
this.advanced = advanced;
}
public String getDescription()
{
return description;
}
public void setDescription(String description)
{
this.description = description;
}
}

View File

@ -164,6 +164,7 @@ public class SystemPanel extends JPanel
getConfigTextField().setText(model.getConfigString());
}
getDisplayShiftComboBox().setSelectedItem(Integer.toString(model.getVerticalShift()));
calculateTotalRam();
}
private JPanel getRadioPanel()

View File

@ -49,6 +49,7 @@ public class ImportManager
Map<Path, List<String>> gameInfoFilesMap = new HashMap<>();
List<String> dbRowDataList = new ArrayList<>();
Map<String, Integer> gameFileNamesDuringImportMap = new HashMap<>();
private MainViewModel uiModel;
private Options selectedOption;
@ -68,7 +69,7 @@ public class ImportManager
{
this.addAsFavorite = favorite;
}
public void setSelectedFoldersForGamebase(Path gamesFolder, Path screensPath, Path coversPath)
{
srcGamesFolder = gamesFolder;
@ -347,6 +348,7 @@ public class ImportManager
String joy1config,
String joy2config,
String advanced,
String description,
boolean isC64)
{
//Generate proper names for files
@ -369,7 +371,7 @@ public class ImportManager
author,
composer,
genre,
"",
description,
"",
"",
"",
@ -455,14 +457,15 @@ public class ImportManager
private int getDbRowDuplicate(String title)
{
String gamefileName = FileManager.generateFileNameFromTitle(title, 0);
int returnValue = 0;
for (String dbRow : dbRowDataList)
Integer existingDuplicate = gameFileNamesDuringImportMap.get(gamefileName);
if (existingDuplicate != null)
{
if (dbRow.startsWith("\"" + title + "\","))
{
returnValue++;
}
returnValue = existingDuplicate + 1;
}
//Add last to keep track of all added games
gameFileNamesDuringImportMap.put(gamefileName, returnValue);
return returnValue;
}
@ -615,6 +618,7 @@ public class ImportManager
int size = dbRowDataList.size();
dbRowDataList.clear();
gameInfoFilesMap.clear();
gameFileNamesDuringImportMap.clear();
uiModel.cleanupAfterImport();
return size;
}

View File

@ -240,7 +240,7 @@ public class C64comScraper implements Scraper
.execute();
//create a temp file and fetch the content
scrapedFile = FileManager.createTempFileForScraper(response.bodyStream());
scrapedFile = FileManager.createTempFileForScraper(response.bodyStream(), "ScrapedFile");
logger.debug("File to include as game: {}", scrapedFile != null ? scrapedFile.getAbsolutePath() : null);
}
catch (Exception e)

View File

@ -285,7 +285,7 @@ public class GamebaseScraper implements Scraper
URLConnection conn = url.openConnection();
InputStream inputStream = conn.getInputStream();
//create a temp file and fetch the content
scrapedFile = FileManager.createTempFileForScraper(new BufferedInputStream(inputStream));
scrapedFile = FileManager.createTempFileForScraper(new BufferedInputStream(inputStream), "ScrapedFile");
logger.debug("File to include as game: {}", scrapedFile != null ? scrapedFile.getAbsolutePath() : null);
}
catch (Exception e)

View File

@ -1010,10 +1010,10 @@ public class FileManager
return newImage;
}
public static File createTempFileForScraper(BufferedInputStream inputStream) throws IOException
public static File createTempFileForScraper(BufferedInputStream inputStream, String gameFilename) throws IOException
{
Files.createDirectories(TEMP_PATH);
File file = new File(TEMP_PATH + File.separator + "scrapedFile.zip");
File file = new File(TEMP_PATH + File.separator + gameFilename + ".zip");
FileOutputStream fos = new FileOutputStream(file, false);
byte[] buffer = new byte[1024];
int len;
@ -1023,11 +1023,12 @@ public class FileManager
}
inputStream.close();
fos.close();
return unzipAndPickFirstEntry(file.getAbsolutePath());
return unzipAndPickFirstEntry(file);
}
public static File unzipAndPickFirstEntry(String zipFilePath)
public static File unzipAndPickFirstEntry(File file)
{
String zipFilePath = file.getAbsolutePath();
Path filePath = null;
FileInputStream fis;
//buffer for read and write data to file
@ -1060,7 +1061,8 @@ public class FileManager
{
ExceptionHandler.logException(e, "Could not unzip file");
}
return filePath != null ? filePath.toFile() : null;
//Return original file if no zip entry found, it's not zipped
return filePath != null ? filePath.toFile() : file;
}
private static ZipEntry getFirstMatchingZipEntry(ZipArchiveInputStream zis) throws IOException