feat: gamebase import UI parts and fixes
This commit is contained in:
parent
33cd98b63b
commit
a91c3e9a09
|
@ -17,37 +17,39 @@ import se.lantz.util.FileManager;
|
|||
|
||||
public class GamebaseImporter
|
||||
{
|
||||
private final ImportManager importManager;
|
||||
public static void main(String[] args)
|
||||
public enum Options
|
||||
{
|
||||
//Just for test
|
||||
GamebaseImporter importer = new GamebaseImporter();
|
||||
importer.importFromGamebase();
|
||||
ALL, FAVORITES, QUERY;
|
||||
}
|
||||
|
||||
public GamebaseImporter()
|
||||
{
|
||||
importManager = null;
|
||||
}
|
||||
|
||||
private final ImportManager importManager;
|
||||
//Just for test
|
||||
private Path gbDatabasePath = Path.of("C://GameBase//GBC_V16//");
|
||||
|
||||
public GamebaseImporter(ImportManager importManager)
|
||||
{
|
||||
this.importManager = importManager;
|
||||
importManager = null;
|
||||
}
|
||||
|
||||
public void importFromGamebase()
|
||||
|
||||
public void setImportOptions(GamebaseOptions options)
|
||||
{
|
||||
//TEST!
|
||||
Path gbPath = Path.of("C://GameBase//GBC_V16//");
|
||||
importManager.setSelectedFolder(gbPath);
|
||||
this.gbDatabasePath = options.getGamebaseDbFile();
|
||||
}
|
||||
|
||||
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());
|
||||
//Just for test, use gbDatabasePath - "jdbc:ucanaccess:" + gbDatabasePath.toString()
|
||||
String databaseURL = "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";
|
||||
|
||||
try (Connection connection = DriverManager.getConnection(databaseURL))
|
||||
|
@ -64,79 +66,94 @@ public class GamebaseImporter
|
|||
System.out.println("view: " + title);
|
||||
}
|
||||
|
||||
sql = "SELECT Games.Name, Musicians.Musician, Genres.Genre, Publishers.Publisher, Games.Filename, Games.ScrnshotFilename, Years.Year, Games.GA_Id, Games.Control\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'));";
|
||||
sql =
|
||||
"SELECT Games.Name, Musicians.Musician, Genres.Genre, Publishers.Publisher, Games.Filename, Games.ScrnshotFilename, Years.Year, Games.GA_Id, Games.Control\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'));";
|
||||
|
||||
result = statement.executeQuery(sql);
|
||||
int gameCount = 0;
|
||||
while (result.next())
|
||||
{
|
||||
String title = result.getString("Name");
|
||||
String year = result.getString("Year");
|
||||
int gameId = result.getInt("GA_Id");
|
||||
String gamefile = result.getString("Filename");
|
||||
String screen1 = result.getString("ScrnShotFileName");
|
||||
String musician = result.getString("Musician");
|
||||
String genre = result.getString("Genre");
|
||||
String publisher = result.getString("Publisher");
|
||||
int control = result.getInt("Control");
|
||||
|
||||
//Fix joystick port
|
||||
if (control == 1)
|
||||
String title = "";
|
||||
try
|
||||
{
|
||||
//1 means joystick port 1 in the gb database
|
||||
joy1config = "J:1*" + joyBase;
|
||||
joy2config = "J:2" + joyBase;
|
||||
title = result.getString("Name");
|
||||
String year = result.getString("Year");
|
||||
int gameId = result.getInt("GA_Id");
|
||||
String gamefile = result.getString("Filename");
|
||||
String screen1 = result.getString("ScrnShotFileName");
|
||||
String musician = result.getString("Musician");
|
||||
String genre = result.getString("Genre");
|
||||
String publisher = result.getString("Publisher");
|
||||
int control = result.getInt("Control");
|
||||
|
||||
//Fix joystick port
|
||||
if (control == 1)
|
||||
{
|
||||
//1 means joystick port 1 in the gb database
|
||||
joy1config = "J:1*" + joyBase;
|
||||
joy2config = "J:2" + joyBase;
|
||||
}
|
||||
else
|
||||
{
|
||||
//For anything else, use port 2.
|
||||
joy1config = "J:1" + joyBase;
|
||||
joy2config = "J:2*" + joyBase;
|
||||
}
|
||||
//Fix game file
|
||||
gamefile = getFileToInclude(gbDatabasePath, gamefile);
|
||||
|
||||
//Fix screenshots
|
||||
screen1 = gbDatabasePath.toString() + "\\screenshots\\" + screen1;
|
||||
String screen2 = getScreen2(screen1);
|
||||
|
||||
//Map genre properly towards existing ones for the carousel
|
||||
genre = GamebaseScraper.mapGenre(genre);
|
||||
|
||||
//Get cover
|
||||
String coverFile = "";
|
||||
String coverSql =
|
||||
"SELECT Extras.Name, Extras.Path\r\n" + "FROM Games INNER JOIN Extras ON Games.GA_Id = Extras.GA_Id\r\n" +
|
||||
"WHERE (((Games.GA_Id)=" + gameId + ") AND ((Extras.Name) Like \"Cover*\"));";
|
||||
|
||||
ResultSet sqlResult = statement.executeQuery(coverSql);
|
||||
if (sqlResult.next())
|
||||
{
|
||||
coverFile = sqlResult.getString("Path");
|
||||
}
|
||||
if (!coverFile.isEmpty())
|
||||
{
|
||||
coverFile = gbDatabasePath.toString() + "\\extras\\" + coverFile;
|
||||
}
|
||||
importManager.addFromGamebaseImporter(title,
|
||||
year,
|
||||
publisher,
|
||||
musician,
|
||||
genre,
|
||||
gamefile,
|
||||
coverFile,
|
||||
screen1,
|
||||
screen2,
|
||||
joy1config,
|
||||
joy2config,
|
||||
advanced);
|
||||
gameCount++;
|
||||
}
|
||||
else
|
||||
catch (Exception e)
|
||||
{
|
||||
//For anything else, use port 2.
|
||||
joy1config = "J:1" + joyBase;
|
||||
joy2config = "J:2*" + joyBase;
|
||||
}
|
||||
//Fix game file
|
||||
gamefile = getFileToInclude(gbPath, gamefile);
|
||||
|
||||
//Fix screenshots
|
||||
screen1 = gbPath.toString() + "\\screenshots\\" + screen1;
|
||||
String screen2 = getScreen2(screen1);
|
||||
|
||||
//Map genre properly towards existing ones for the carousel
|
||||
genre = GamebaseScraper.mapGenre(genre);
|
||||
|
||||
//Get cover
|
||||
String coverFile = "";
|
||||
String coverSql = "SELECT Extras.Name, Extras.Path\r\n" +
|
||||
"FROM Games INNER JOIN Extras ON Games.GA_Id = Extras.GA_Id\r\n" +
|
||||
"WHERE (((Games.GA_Id)=" + gameId + ") AND ((Extras.Name) Like \"Cover*\"));";
|
||||
|
||||
ResultSet sqlResult = statement.executeQuery(coverSql);
|
||||
if (sqlResult.next())
|
||||
{
|
||||
coverFile = sqlResult.getString("Path");
|
||||
}
|
||||
if (!coverFile.isEmpty())
|
||||
{
|
||||
coverFile = gbPath.toString() + "\\extras\\" + coverFile;
|
||||
}
|
||||
|
||||
if (importManager != null)
|
||||
{
|
||||
importManager.addFromGamebaseImporter(title, year, publisher, musician, genre, gamefile, coverFile, screen1, screen2, joy1config, joy2config, advanced);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println(gameId + "," + title + ", " + gamefile + ", " + screen1 + ", " + musician + ", " + genre + ", " + publisher);
|
||||
builder.append("ERROR: Could not fetch all info for " + title + ":\n" + e.toString() + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
builder.append("Read " + gameCount + " games from the gamebase db.\n");
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
builder.append("ERROR: Query failed : " + ex.toString() + "\n");
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
private String getScreen2(String screen1)
|
||||
{
|
||||
String returnValue = "";
|
||||
|
@ -153,24 +170,16 @@ public class GamebaseImporter
|
|||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
private String getFileToInclude(Path gbPath, String filenameInGb)
|
||||
|
||||
private String getFileToInclude(Path gbPath, String filenameInGb) throws IOException
|
||||
{
|
||||
Path gamePath = gbPath.resolve("games").resolve(filenameInGb);
|
||||
File gameFile = gamePath.toFile();
|
||||
try
|
||||
{
|
||||
File selectedFile = FileManager.createTempFileForScraper(new BufferedInputStream(new FileInputStream(gameFile)));
|
||||
Path compressedFilePath = selectedFile.toPath().getParent().resolve(selectedFile.getName() + ".gz");
|
||||
FileManager.compressGzip(selectedFile.toPath(), compressedFilePath);
|
||||
return compressedFilePath.toString();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
|
||||
File selectedFile = FileManager.createTempFileForScraper(new BufferedInputStream(new FileInputStream(gameFile)));
|
||||
Path compressedFilePath = selectedFile.toPath().getParent().resolve(selectedFile.getName() + ".gz");
|
||||
FileManager.compressGzip(selectedFile.toPath(), compressedFilePath);
|
||||
return compressedFilePath.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package se.lantz.gamebase;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class GamebaseOptions
|
||||
{
|
||||
private Path gamebaseDbFile;
|
||||
private boolean c64 = true;
|
||||
private GamebaseImporter.Options selectedOption = GamebaseImporter.Options.FAVORITES;
|
||||
|
||||
public GamebaseOptions()
|
||||
{
|
||||
//Empty
|
||||
}
|
||||
|
||||
public Path getGamebaseDbFile()
|
||||
{
|
||||
return gamebaseDbFile;
|
||||
}
|
||||
|
||||
public void setGamebaseDbFile(Path gamebaseFolder)
|
||||
{
|
||||
this.gamebaseDbFile = gamebaseFolder;
|
||||
}
|
||||
|
||||
public boolean isC64()
|
||||
{
|
||||
return c64;
|
||||
}
|
||||
|
||||
public void setC64(boolean c64)
|
||||
{
|
||||
this.c64 = c64;
|
||||
}
|
||||
|
||||
public GamebaseImporter.Options getSelectedOption()
|
||||
{
|
||||
return selectedOption;
|
||||
}
|
||||
|
||||
public void setSelectedOption(GamebaseImporter.Options selectedOption)
|
||||
{
|
||||
this.selectedOption = selectedOption;
|
||||
}
|
||||
|
||||
}
|
|
@ -14,6 +14,8 @@ import javax.swing.JMenuItem;
|
|||
import javax.swing.JOptionPane;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import se.lantz.gamebase.GamebaseImporter;
|
||||
import se.lantz.gamebase.GamebaseOptions;
|
||||
import se.lantz.gui.convertscreens.ConvertProgressDialog;
|
||||
import se.lantz.gui.convertscreens.ConvertWorker;
|
||||
import se.lantz.gui.dbbackup.BackupProgressDialog;
|
||||
|
@ -26,7 +28,8 @@ import se.lantz.gui.exports.ExportProgressDialog;
|
|||
import se.lantz.gui.exports.ExportWorker;
|
||||
import se.lantz.gui.imports.ImportOptionsDialog;
|
||||
import se.lantz.gui.imports.ImportProgressDialog;
|
||||
import se.lantz.gui.imports.ImportWorker;
|
||||
import se.lantz.gui.imports.CarouselImportWorker;
|
||||
import se.lantz.gui.imports.GamebaseImportWorker;
|
||||
import se.lantz.manager.BackupManager;
|
||||
import se.lantz.manager.ExportManager;
|
||||
import se.lantz.manager.ImportManager;
|
||||
|
@ -40,6 +43,7 @@ import se.lantz.util.VersionChecker;
|
|||
public class MenuManager
|
||||
{
|
||||
private JMenu fileMenu;
|
||||
private JMenu importMenu;
|
||||
private JMenu editMenu;
|
||||
private JMenu toolsMenu;
|
||||
private JMenu helpMenu;
|
||||
|
@ -48,7 +52,8 @@ public class MenuManager
|
|||
private JMenuItem deleteGameItem;
|
||||
|
||||
private JMenuItem runGameItem;
|
||||
private JMenuItem importItem;
|
||||
private JMenuItem importCarouselItem;
|
||||
private JMenuItem importGamebaseItem;
|
||||
private JMenuItem exportItem;
|
||||
private JMenuItem refreshItem;
|
||||
|
||||
|
@ -69,6 +74,7 @@ public class MenuManager
|
|||
private JMenuItem exitItem;
|
||||
private MainViewModel uiModel;
|
||||
private ImportManager importManager;
|
||||
private GamebaseImporter gamebaseImporter;
|
||||
private ExportManager exportManager;
|
||||
private BackupManager backupManager;
|
||||
private RestoreManager restoreManager;
|
||||
|
@ -79,6 +85,7 @@ public class MenuManager
|
|||
this.uiModel = uiModel;
|
||||
this.mainWindow = mainWindow;
|
||||
this.importManager = new ImportManager(uiModel);
|
||||
this.gamebaseImporter = new GamebaseImporter(importManager);
|
||||
this.exportManager = new ExportManager(uiModel);
|
||||
this.backupManager = new BackupManager(uiModel);
|
||||
this.restoreManager = new RestoreManager(uiModel);
|
||||
|
@ -98,7 +105,11 @@ public class MenuManager
|
|||
fileMenu.addSeparator();
|
||||
fileMenu.add(getRunGameMenuItem());
|
||||
fileMenu.addSeparator();
|
||||
fileMenu.add(getImportItem());
|
||||
importMenu = new JMenu("Import");
|
||||
importMenu.setMnemonic('I');
|
||||
fileMenu.add(importMenu);
|
||||
importMenu.add(getImportCarouselItem());
|
||||
importMenu.add(getImportGamebaseItem());
|
||||
fileMenu.add(getExportItem());
|
||||
fileMenu.addSeparator();
|
||||
fileMenu.add(getRefreshItem());
|
||||
|
@ -126,7 +137,8 @@ public class MenuManager
|
|||
uiModel.addSaveChangeListener(e -> {
|
||||
boolean okToEnable = !uiModel.isDataChanged();
|
||||
addGameItem.setEnabled(okToEnable);
|
||||
importItem.setEnabled(okToEnable);
|
||||
importCarouselItem.setEnabled(okToEnable);
|
||||
importGamebaseItem.setEnabled(okToEnable);
|
||||
exportItem.setEnabled(okToEnable);
|
||||
toggleFavoriteItem.setEnabled(okToEnable);
|
||||
runGameItem.setEnabled(!uiModel.getInfoModel().getGamesFile().isEmpty());
|
||||
|
@ -185,15 +197,26 @@ public class MenuManager
|
|||
return runGameItem;
|
||||
}
|
||||
|
||||
private JMenuItem getImportItem()
|
||||
private JMenuItem getImportCarouselItem()
|
||||
{
|
||||
importItem = new JMenuItem("Import Games...");
|
||||
importCarouselItem = new JMenuItem("Import Carousel folder...");
|
||||
KeyStroke keyStrokeToImportGames = KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_DOWN_MASK);
|
||||
importItem.setAccelerator(keyStrokeToImportGames);
|
||||
importItem.setMnemonic('I');
|
||||
importItem.addActionListener(e -> importGames());
|
||||
return importItem;
|
||||
importCarouselItem.setAccelerator(keyStrokeToImportGames);
|
||||
importCarouselItem.setMnemonic('I');
|
||||
importCarouselItem.addActionListener(e -> importCarouselGames());
|
||||
return importCarouselItem;
|
||||
}
|
||||
|
||||
private JMenuItem getImportGamebaseItem()
|
||||
{
|
||||
importGamebaseItem = new JMenuItem("Import from Gamebase...");
|
||||
KeyStroke keyStrokeToImportGames = KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_DOWN_MASK);
|
||||
importGamebaseItem.setAccelerator(keyStrokeToImportGames);
|
||||
importGamebaseItem.setMnemonic('G');
|
||||
importGamebaseItem.addActionListener(e -> importGamebaseGames());
|
||||
return importGamebaseItem;
|
||||
}
|
||||
|
||||
|
||||
private JMenuItem getExportItem()
|
||||
{
|
||||
|
@ -210,7 +233,7 @@ public class MenuManager
|
|||
refreshItem = new JMenuItem("Reload current game view");
|
||||
KeyStroke keyStrokeToReloadGameView = KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0);
|
||||
refreshItem.setAccelerator(keyStrokeToReloadGameView);
|
||||
refreshItem.setMnemonic('G');
|
||||
refreshItem.setMnemonic('C');
|
||||
refreshItem.addActionListener(e -> reloadView());
|
||||
return refreshItem;
|
||||
}
|
||||
|
@ -336,9 +359,9 @@ public class MenuManager
|
|||
return newVersionItem;
|
||||
}
|
||||
|
||||
private void importGames()
|
||||
private void importCarouselGames()
|
||||
{
|
||||
ImportOptionsDialog optionsDialog = new ImportOptionsDialog(this.mainWindow);
|
||||
ImportOptionsDialog optionsDialog = new ImportOptionsDialog(this.mainWindow, true);
|
||||
optionsDialog.pack();
|
||||
optionsDialog.setLocationRelativeTo(this.mainWindow);
|
||||
if (optionsDialog.showDialog())
|
||||
|
@ -347,7 +370,29 @@ public class MenuManager
|
|||
importManager.setSelectedOption(optionsDialog.getSelectedOption());
|
||||
importManager.setAddAsFavorite(optionsDialog.getMarkAsFavorite());
|
||||
ImportProgressDialog dialog = new ImportProgressDialog(this.mainWindow);
|
||||
ImportWorker worker = new ImportWorker(importManager, dialog);
|
||||
CarouselImportWorker worker = new CarouselImportWorker(importManager, dialog);
|
||||
worker.execute();
|
||||
dialog.setVisible(true);
|
||||
//Refresh current game view after import
|
||||
uiModel.reloadCurrentGameView();
|
||||
MainWindow.getInstance().repaintAfterModifications();
|
||||
}
|
||||
}
|
||||
|
||||
private void importGamebaseGames()
|
||||
{
|
||||
ImportOptionsDialog optionsDialog = new ImportOptionsDialog(this.mainWindow, false);
|
||||
optionsDialog.pack();
|
||||
optionsDialog.setLocationRelativeTo(this.mainWindow);
|
||||
if (optionsDialog.showDialog())
|
||||
{
|
||||
//Set selected option in gamebaseImporter from the dialog.
|
||||
gamebaseImporter.setImportOptions(optionsDialog.getSelectedGbOptions());
|
||||
//Set options for how to handle games during import
|
||||
importManager.setSelectedOption(optionsDialog.getSelectedOption());
|
||||
importManager.setAddAsFavorite(optionsDialog.getMarkAsFavorite());
|
||||
ImportProgressDialog dialog = new ImportProgressDialog(this.mainWindow);
|
||||
GamebaseImportWorker worker = new GamebaseImportWorker(gamebaseImporter, importManager, dialog);
|
||||
worker.execute();
|
||||
dialog.setVisible(true);
|
||||
//Refresh current game view after import
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package se.lantz.gui.imports;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.SwingWorker;
|
||||
|
||||
import se.lantz.manager.ImportManager;
|
||||
import se.lantz.util.ExceptionHandler;
|
||||
|
||||
public class CarouselImportWorker extends SwingWorker<Void, String>
|
||||
{
|
||||
|
||||
private ImportManager importManager;
|
||||
private ImportProgressDialog dialog;
|
||||
|
||||
public CarouselImportWorker(ImportManager importManager, ImportProgressDialog dialog)
|
||||
{
|
||||
this.importManager = importManager;
|
||||
this.dialog = dialog;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground() throws Exception
|
||||
{
|
||||
publish("Reading game info files...");
|
||||
StringBuilder infoBuilder = new StringBuilder();
|
||||
importManager.readGameInfoFiles(infoBuilder);
|
||||
publish(infoBuilder.toString());
|
||||
infoBuilder = new StringBuilder();
|
||||
importManager.convertIntoDbRows(infoBuilder);
|
||||
publish(infoBuilder.toString());
|
||||
publish("Importing to db...");
|
||||
publish(importManager.insertRowsIntoDb().toString());
|
||||
publish("Copying screenshots, covers and game files...");
|
||||
publish(importManager.copyFiles().toString());
|
||||
importManager.clearAfterImport();
|
||||
publish("Done!");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void process(List<String> chunks)
|
||||
{
|
||||
for (String value : chunks)
|
||||
{
|
||||
dialog.updateProgress(value + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done()
|
||||
{
|
||||
try
|
||||
{
|
||||
get();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ExceptionHandler.handleException(e, "Error during import");
|
||||
}
|
||||
dialog.finish();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package se.lantz.gui.imports;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import se.lantz.gamebase.GamebaseOptions;
|
||||
|
||||
public class GameBaseOptionsPanel extends JPanel
|
||||
{
|
||||
|
||||
public GameBaseOptionsPanel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public GamebaseOptions getSelectedGbOptions()
|
||||
{
|
||||
//TODO: add all configurable things to this (favorites, querys gamebase location etc).
|
||||
return new GamebaseOptions();
|
||||
}
|
||||
}
|
|
@ -9,35 +9,27 @@ import se.lantz.gamebase.GamebaseImporter;
|
|||
import se.lantz.manager.ImportManager;
|
||||
import se.lantz.util.ExceptionHandler;
|
||||
|
||||
public class ImportWorker extends SwingWorker<Void, String>
|
||||
public class GamebaseImportWorker extends SwingWorker<Void, String>
|
||||
{
|
||||
|
||||
private ImportManager importManager;
|
||||
private ImportProgressDialog dialog;
|
||||
private final GamebaseImporter gbInporter;
|
||||
|
||||
public ImportWorker(ImportManager importManager, ImportProgressDialog dialog)
|
||||
public GamebaseImportWorker(GamebaseImporter gamebaseImporter, ImportManager importManager, ImportProgressDialog dialog)
|
||||
{
|
||||
this.importManager = importManager;
|
||||
this.dialog = dialog;
|
||||
gbInporter = new GamebaseImporter(importManager);
|
||||
this.gbInporter = gamebaseImporter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground() throws Exception
|
||||
{
|
||||
publish("Import from gamebase...");
|
||||
gbInporter.importFromGamebase();
|
||||
// publish("Reading game info files...");
|
||||
// StringBuilder infoBuilder = new StringBuilder();
|
||||
// importManager.readGameInfoFiles(infoBuilder);
|
||||
// publish(infoBuilder.toString());
|
||||
// infoBuilder = new StringBuilder();
|
||||
// importManager.convertIntoDbRows(infoBuilder);
|
||||
// publish(infoBuilder.toString());
|
||||
publish("Reading from gamebase db...");
|
||||
publish(gbInporter.importFromGamebase().toString());
|
||||
publish("Importing to db...");
|
||||
publish(importManager.insertRowsIntoDb().toString());
|
||||
publish("Copy screenshots, covers and game files...");
|
||||
publish("Copying screenshots, covers and game files...");
|
||||
publish(importManager.copyFiles().toString());
|
||||
importManager.clearAfterImport();
|
||||
publish("Done!");
|
|
@ -4,26 +4,37 @@ import java.awt.Dimension;
|
|||
import java.awt.Frame;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import se.lantz.gamebase.GamebaseOptions;
|
||||
import se.lantz.gui.BaseDialog;
|
||||
import se.lantz.manager.ImportManager;
|
||||
|
||||
public class ImportOptionsDialog extends BaseDialog
|
||||
{
|
||||
private ImportOptionsPanel panel;
|
||||
private boolean isCarouselImport;
|
||||
|
||||
public ImportOptionsDialog(Frame owner)
|
||||
public ImportOptionsDialog(Frame owner, boolean isCarouselImport)
|
||||
{
|
||||
super(owner);
|
||||
setTitle("Import game carousel");
|
||||
this.isCarouselImport = isCarouselImport;
|
||||
if (isCarouselImport)
|
||||
{
|
||||
setTitle("Import carousel folder");
|
||||
this.setPreferredSize(new Dimension(450,330));
|
||||
}
|
||||
else
|
||||
{
|
||||
setTitle("Import games from Gamebase");
|
||||
this.setPreferredSize(new Dimension(450,600));
|
||||
}
|
||||
addContent(getImportOptionsPanel());
|
||||
getOkButton().setText("Import");
|
||||
this.setResizable(false);
|
||||
this.setPreferredSize(new Dimension(450,330));
|
||||
this.setResizable(false);
|
||||
}
|
||||
|
||||
private ImportOptionsPanel getImportOptionsPanel() {
|
||||
if (panel == null) {
|
||||
panel = new ImportOptionsPanel();
|
||||
panel = new ImportOptionsPanel(isCarouselImport);
|
||||
}
|
||||
return panel;
|
||||
}
|
||||
|
@ -42,4 +53,9 @@ public class ImportOptionsDialog extends BaseDialog
|
|||
{
|
||||
return getImportOptionsPanel().getImportDirectory();
|
||||
}
|
||||
|
||||
public GamebaseOptions getSelectedGbOptions()
|
||||
{
|
||||
return getImportOptionsPanel().getSelectedGbOptions();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,8 @@ import se.lantz.manager.ImportManager;
|
|||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBox;
|
||||
|
||||
import se.lantz.gamebase.GamebaseOptions;
|
||||
import se.lantz.gui.SelectDirPanel;
|
||||
|
||||
public class ImportOptionsPanel extends JPanel
|
||||
|
@ -24,12 +26,19 @@ public class ImportOptionsPanel extends JPanel
|
|||
private JLabel matchLabel;
|
||||
private JCheckBox favoriteCheckBox;
|
||||
private SelectDirPanel selectDirPanel;
|
||||
private GameBaseOptionsPanel gbOptionsPanel;
|
||||
private JLabel selectDirLabel;
|
||||
private JRadioButton addRadioButton;
|
||||
private JPanel selectionPanel;
|
||||
private boolean isCarouselImport;
|
||||
|
||||
public ImportOptionsPanel()
|
||||
{
|
||||
this(true);
|
||||
}
|
||||
public ImportOptionsPanel(boolean isCarouselImport)
|
||||
{
|
||||
this.isCarouselImport = isCarouselImport;
|
||||
GridBagLayout gridBagLayout = new GridBagLayout();
|
||||
setLayout(gridBagLayout);
|
||||
GridBagConstraints gbc_selectDirPanel = new GridBagConstraints();
|
||||
|
@ -38,7 +47,14 @@ public class ImportOptionsPanel extends JPanel
|
|||
gbc_selectDirPanel.fill = GridBagConstraints.BOTH;
|
||||
gbc_selectDirPanel.gridx = 0;
|
||||
gbc_selectDirPanel.gridy = 1;
|
||||
add(getSelectDirPanel(), gbc_selectDirPanel);
|
||||
if (isCarouselImport)
|
||||
{
|
||||
add(getSelectDirPanel(), gbc_selectDirPanel);
|
||||
}
|
||||
else
|
||||
{
|
||||
add(getGbOptionsPanel(), gbc_selectDirPanel);
|
||||
}
|
||||
GridBagConstraints gbc_infoLabel = new GridBagConstraints();
|
||||
gbc_infoLabel.weightx = 1.0;
|
||||
gbc_infoLabel.insets = new Insets(15, 10, 5, 10);
|
||||
|
@ -131,9 +147,19 @@ public class ImportOptionsPanel extends JPanel
|
|||
}
|
||||
return selectDirPanel;
|
||||
}
|
||||
private GameBaseOptionsPanel getGbOptionsPanel()
|
||||
{
|
||||
if (gbOptionsPanel == null) {
|
||||
gbOptionsPanel = new GameBaseOptionsPanel();
|
||||
}
|
||||
return gbOptionsPanel;
|
||||
}
|
||||
|
||||
|
||||
private JLabel getSelectDirLabel() {
|
||||
if (selectDirLabel == null) {
|
||||
selectDirLabel = new JLabel("Select a directory to import games from:");
|
||||
String text = isCarouselImport ? "Select a directory containing a game carousel:" : "Select the gamebase database directory:";
|
||||
selectDirLabel = new JLabel(text);
|
||||
}
|
||||
return selectDirLabel;
|
||||
}
|
||||
|
@ -184,4 +210,9 @@ public class ImportOptionsPanel extends JPanel
|
|||
}
|
||||
return selectionPanel;
|
||||
}
|
||||
|
||||
public GamebaseOptions getSelectedGbOptions()
|
||||
{
|
||||
return getGbOptionsPanel().getSelectedGbOptions();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue