fix: more for gamebase importer, screens and covers gets resized properly
This commit is contained in:
parent
a91c3e9a09
commit
88e54a6d70
|
@ -24,7 +24,8 @@ public class GamebaseImporter
|
|||
|
||||
private final ImportManager importManager;
|
||||
//Just for test
|
||||
private Path gbDatabasePath = Path.of("C://GameBase//GBC_V16//");
|
||||
private Path gbDatabasePath = Path.of("C://GameBase//Vic20_v03//");// Path.of("C://GameBase//GBC_V16//");
|
||||
private boolean isC64 = false;//true;
|
||||
|
||||
public GamebaseImporter(ImportManager importManager)
|
||||
{
|
||||
|
@ -34,24 +35,33 @@ public class GamebaseImporter
|
|||
|
||||
public void setImportOptions(GamebaseOptions options)
|
||||
{
|
||||
this.gbDatabasePath = options.getGamebaseDbFile();
|
||||
// this.gbDatabasePath = options.getGamebaseDbFile();
|
||||
// this.isC64 = options.isC64();
|
||||
}
|
||||
|
||||
public StringBuilder importFromGamebase()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
//Use the folder where the gamebase mdb file is located in the import manager
|
||||
importManager.setSelectedFolder(gbDatabasePath.getParent());
|
||||
// importManager.setSelectedFolder(gbDatabasePath.getParent());
|
||||
importManager.setSelectedFolder(gbDatabasePath);
|
||||
//Just for test, use gbDatabasePath - "jdbc:ucanaccess:" + gbDatabasePath.toString()
|
||||
String databaseURL = "jdbc:ucanaccess://F://Github//PCUGameManager//GBC_v16.mdb";
|
||||
String databaseURL = "jdbc:ucanaccess://C://GameBase//Vic20_v03//Vic20_v03.mdb";// "jdbc:ucanaccess://F://Github//PCUGameManager//GBC_v16.mdb";
|
||||
|
||||
String joyBase = ":JU,JD,JL,JR,JF,JF,SP,EN,,F1,F3,F5,,,";
|
||||
|
||||
String joy1config;
|
||||
String joy2config;
|
||||
|
||||
String advanced = "64,pal,sid6581";
|
||||
|
||||
//Setup advanced string (system, sid, pal, truedrive etc)
|
||||
String advanced = "sid6581";
|
||||
if (isC64)
|
||||
{
|
||||
advanced = "64," + advanced;
|
||||
}
|
||||
else
|
||||
{
|
||||
advanced = "vic," + advanced;
|
||||
}
|
||||
try (Connection connection = DriverManager.getConnection(databaseURL))
|
||||
{
|
||||
Statement statement = connection.createStatement();
|
||||
|
@ -67,9 +77,9 @@ public class GamebaseImporter
|
|||
}
|
||||
|
||||
sql =
|
||||
"SELECT Games.Name, Musicians.Musician, Genres.Genre, Publishers.Publisher, Games.Filename, Games.ScrnshotFilename, Years.Year, Games.GA_Id, Games.Control\r\n" +
|
||||
"SELECT Games.Name, Musicians.Musician, Genres.Genre, Publishers.Publisher, Games.Filename, Games.ScrnshotFilename, Years.Year, Games.GA_Id, Games.Control, Games.V_PalNTSC, Games.V_TrueDriveEmu\r\n" +
|
||||
"FROM Years INNER JOIN (Publishers INNER JOIN ((Games INNER JOIN Musicians ON Games.MU_Id = Musicians.MU_Id) INNER JOIN Genres ON Games.GE_Id = Genres.GE_Id) ON Publishers.PU_Id = Games.PU_Id) ON Years.YE_Id = Games.YE_Id\r\n" +
|
||||
"WHERE (((Games.Name)='1942'));";
|
||||
"WHERE (((Games.Name)='Castle Dracula'));";
|
||||
|
||||
result = statement.executeQuery(sql);
|
||||
int gameCount = 0;
|
||||
|
@ -87,8 +97,21 @@ public class GamebaseImporter
|
|||
String genre = result.getString("Genre");
|
||||
String publisher = result.getString("Publisher");
|
||||
int control = result.getInt("Control");
|
||||
int palOrNtsc = result.getInt("V_PalNTSC");
|
||||
int trueDriveEmu = result.getInt("V_TrueDriveEmu");
|
||||
|
||||
//Fix joystick port
|
||||
//Setup video mode
|
||||
//0=PAL, 1=BOTH, 2=NTSC, 3=PAL[+NTSC?]
|
||||
String video = (palOrNtsc == 2) ? "ntsc" : "pal";
|
||||
advanced = advanced + "," + video;
|
||||
//Setup truedrive
|
||||
if (trueDriveEmu > 0)
|
||||
{
|
||||
advanced = advanced + "," + "driveicon,accuratedisk";
|
||||
}
|
||||
|
||||
//Control: 0=JoyPort2, 1=JoyPort1, 2=Keyboard, 3=PaddlePort2, 4=PaddlePort1, 5=Mouse, 6=LightPen, 7=KoalaPad, 8=LightGun
|
||||
//Setup joystick port
|
||||
if (control == 1)
|
||||
{
|
||||
//1 means joystick port 1 in the gb database
|
||||
|
@ -101,8 +124,8 @@ public class GamebaseImporter
|
|||
joy1config = "J:1" + joyBase;
|
||||
joy2config = "J:2*" + joyBase;
|
||||
}
|
||||
//Fix game file
|
||||
gamefile = getFileToInclude(gbDatabasePath, gamefile);
|
||||
//Fix game file, but only for C64?
|
||||
gamefile = getFileToInclude(gbDatabasePath, gamefile);//isC64 ? getFileToInclude(gbDatabasePath, gamefile) : gamefile;
|
||||
|
||||
//Fix screenshots
|
||||
screen1 = gbDatabasePath.toString() + "\\screenshots\\" + screen1;
|
||||
|
|
|
@ -32,7 +32,7 @@ public class CarouselImportWorker extends SwingWorker<Void, String>
|
|||
publish("Importing to db...");
|
||||
publish(importManager.insertRowsIntoDb().toString());
|
||||
publish("Copying screenshots, covers and game files...");
|
||||
publish(importManager.copyFiles().toString());
|
||||
publish(importManager.copyFiles(false).toString());
|
||||
importManager.clearAfterImport();
|
||||
publish("Done!");
|
||||
return null;
|
||||
|
|
|
@ -30,7 +30,7 @@ public class GamebaseImportWorker extends SwingWorker<Void, String>
|
|||
publish("Importing to db...");
|
||||
publish(importManager.insertRowsIntoDb().toString());
|
||||
publish("Copying screenshots, covers and game files...");
|
||||
publish(importManager.copyFiles().toString());
|
||||
publish(importManager.copyFiles(true).toString());
|
||||
importManager.clearAfterImport();
|
||||
publish("Done!");
|
||||
return null;
|
||||
|
|
|
@ -463,15 +463,15 @@ public class ImportManager
|
|||
return lines;
|
||||
}
|
||||
|
||||
public StringBuilder copyFiles()
|
||||
public StringBuilder copyFiles(boolean gamebaseImport)
|
||||
{
|
||||
StringBuilder infoBuilder = new StringBuilder();
|
||||
//Copy with the existing file names. At export convert to a name that works with the maxi tool if needed.
|
||||
dbRowDataList.stream().forEach(dbRowData -> copyFiles(dbRowData, infoBuilder));
|
||||
dbRowDataList.stream().forEach(dbRowData -> copyFiles(dbRowData, infoBuilder, gamebaseImport));
|
||||
return infoBuilder;
|
||||
}
|
||||
|
||||
public void copyFiles(String dbRowData, StringBuilder infoBuilder)
|
||||
public void copyFiles(String dbRowData, StringBuilder infoBuilder, boolean gamebaseImport)
|
||||
{
|
||||
String coverName = "";
|
||||
String screen1Name = "";
|
||||
|
@ -504,7 +504,7 @@ public class ImportManager
|
|||
Path targetScreen2Path = Paths.get("./screens/" + screen2Name);
|
||||
|
||||
Path gamePath = srcGamesFolder.resolve(oldGameName);
|
||||
if (oldGameName.startsWith("."))
|
||||
if (gamebaseImport)
|
||||
{
|
||||
//When importing from gamebase use current folder
|
||||
gamePath = new File(oldGameName).toPath();
|
||||
|
@ -524,6 +524,10 @@ public class ImportManager
|
|||
infoBuilder.append(targetCoverPath.toString());
|
||||
infoBuilder.append("\n");
|
||||
Files.copy(coverPath, targetCoverPath, StandardCopyOption.REPLACE_EXISTING);
|
||||
if (gamebaseImport)
|
||||
{
|
||||
FileManager.scaleCoverImageAndSave(targetCoverPath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -545,6 +549,10 @@ public class ImportManager
|
|||
infoBuilder.append(targetScreen1Path.toString());
|
||||
infoBuilder.append("\n");
|
||||
Files.copy(screens1Path, targetScreen1Path, StandardCopyOption.REPLACE_EXISTING);
|
||||
if (gamebaseImport)
|
||||
{
|
||||
FileManager.scaleScreenshotImageAndSave(targetScreen1Path);
|
||||
}
|
||||
}
|
||||
if (!oldScreen2Name.isEmpty())
|
||||
{
|
||||
|
@ -554,6 +562,10 @@ public class ImportManager
|
|||
infoBuilder.append(targetScreen2Path.toString());
|
||||
infoBuilder.append("\n");
|
||||
Files.copy(screens2Path, targetScreen2Path, StandardCopyOption.REPLACE_EXISTING);
|
||||
if (gamebaseImport)
|
||||
{
|
||||
FileManager.scaleScreenshotImageAndSave(targetScreen2Path);
|
||||
}
|
||||
}
|
||||
if (!oldGameName.isEmpty())
|
||||
{
|
||||
|
|
|
@ -325,7 +325,7 @@ public class FileManager
|
|||
if (duplicateIndex > 0)
|
||||
{
|
||||
//Just add the duplicate index if there are several games with the same name
|
||||
newNameString = newNameString + "-" + duplicateIndex;
|
||||
newNameString = newNameString + "0" + duplicateIndex;
|
||||
}
|
||||
|
||||
logger.debug("Game title: \"{}\" ---- New fileName: \"{}\"", title, newNameString);
|
||||
|
@ -494,13 +494,21 @@ public class FileManager
|
|||
}
|
||||
else
|
||||
{
|
||||
if (gameFile.contains("crt"))
|
||||
//For Vic-20 treat prg's as carts. TODO: many cart alternatives for Vic-20, see GEMUS for GB-VIC20.
|
||||
if (!systemModel.isC64() && gameFile.contains("prg"))
|
||||
{
|
||||
command.append("-cartcrt \"" + decompressIfNeeded(gameFile) + "\"");
|
||||
command.append("-cartA \"" + gameFile + "\"");
|
||||
}
|
||||
else
|
||||
{
|
||||
command.append("-autostart \"" + gameFile + "\"");
|
||||
if (gameFile.contains("crt"))
|
||||
{
|
||||
command.append("-cartcrt \"" + decompressIfNeeded(gameFile) + "\"");
|
||||
}
|
||||
else
|
||||
{
|
||||
command.append("-autostart \"" + gameFile + "\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -851,6 +859,38 @@ public class FileManager
|
|||
ExceptionHandler.handleException(e, "Could not delete temp folder");
|
||||
}
|
||||
}
|
||||
|
||||
public static void scaleCoverImageAndSave(Path coverImagePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
BufferedImage coverImage = ImageIO.read(coverImagePath.toFile());
|
||||
Image newCover = coverImage.getScaledInstance(122, 175, Image.SCALE_SMOOTH);
|
||||
BufferedImage copyOfImage =
|
||||
new BufferedImage(newCover.getWidth(null), newCover.getHeight(null), BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics g = copyOfImage.createGraphics();
|
||||
g.drawImage(newCover, 0, 0, null);
|
||||
g.dispose();
|
||||
ImageIO.write(copyOfImage, "png", coverImagePath.toFile());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
ExceptionHandler.handleException(e, "Could not scale and cover");
|
||||
}
|
||||
}
|
||||
|
||||
public static void scaleScreenshotImageAndSave(Path screenshotImagePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
BufferedImage screenImage = ImageIO.read(screenshotImagePath.toFile());
|
||||
ImageIO.write(scaleImageTo320x200x32bit(screenImage), "png", screenshotImagePath.toFile());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
ExceptionHandler.handleException(e, "Could not scale and store screenshot");
|
||||
}
|
||||
}
|
||||
|
||||
public static BufferedImage scaleImageTo320x200x32bit(BufferedImage originalImage)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue