feat: add menu options to enable/disable accurate disk

for all disk games in the current game view.
feat: When importing an entire gamebase db additional game views are created if the number of games for a genre is larger than 250.
This commit is contained in:
lantzelot-swe 2023-08-01 21:58:59 +02:00
parent 23e3117f61
commit 0049bc7ace
6 changed files with 146 additions and 24 deletions

View File

@ -313,7 +313,8 @@ public class DbConnector
//Construct SQL
StringBuilder sqlBuilder = new StringBuilder();
sqlBuilder.append("SELECT title, gamefile, rowid, favorite, viewtag, disk2, disk3, disk4, disk5, disk6 FROM gameinfo ");
sqlBuilder
.append("SELECT title, gamefile, rowid, favorite, viewtag, disk2, disk3, disk4, disk5, disk6 FROM gameinfo ");
sqlBuilder.append(view.getSqlQuery());
sqlBuilder.append(" ORDER BY title COLLATE NOCASE ASC");
@ -367,7 +368,6 @@ public class DbConnector
return fileCount;
}
public List<GameListData> fetchAllGamesForGameCount()
{
List<GameListData> returnList = new ArrayList<>();
@ -1530,4 +1530,55 @@ public class DbConnector
ExceptionHandler.handleException(e, "Could not update joystick configurations");
}
}
public void setAccurateDiskForView(GameView view, boolean accurateDisk)
{
String validDiskEndings =
"(gamefile LIKE '%D64%' OR gamefile LIKE '%D8%' OR gamefile LIKE '%D7%' OR gamefile LIKE '%X64%' OR gamefile LIKE '%G64%')";
StringBuilder accurateDiskBuilder = new StringBuilder();
if (accurateDisk)
{
accurateDiskBuilder.append("UPDATE gameinfo SET System = System || ',driveicon,accuratedisk' ");
if (view.getSqlQuery().isEmpty())
{
accurateDiskBuilder.append("WHERE ");
}
else
{
accurateDiskBuilder.append(view.getSqlQuery());
accurateDiskBuilder.append(" AND ");
}
accurateDiskBuilder.append(validDiskEndings);
accurateDiskBuilder.append(" AND System NOT LIKE '%accuratedisk%'");
}
else
{
accurateDiskBuilder.append("UPDATE gameinfo SET System = REPLACE(System, ',driveicon,accuratedisk', '') ");
if (view.getSqlQuery().isEmpty())
{
accurateDiskBuilder.append("WHERE ");
}
else
{
accurateDiskBuilder.append(view.getSqlQuery());
accurateDiskBuilder.append(" AND ");
}
accurateDiskBuilder.append(validDiskEndings);
}
logger.debug("Generated SQL for accurate disk:\n{}", accurateDiskBuilder.toString());
try (Connection conn = this.connect();
PreparedStatement adstmt = conn.prepareStatement(accurateDiskBuilder.toString());)
{
int value = adstmt.executeUpdate();
logger.debug("Executed successfully, value = {}", value);
}
catch (SQLException e)
{
ExceptionHandler.handleException(e, "Could not update accurate disk");
}
}
}

View File

@ -481,7 +481,8 @@ public class ListPanel extends JPanel
int selectedGames = list.getSelectedIndices().length;
if (selectedGames > 1)
{
text = text + " (" + selectedGames + ")";
int selectedFileCount = uiModel.getFileCount(list.getSelectedValuesList());
text = text + " (" + selectedGames + "/" + selectedFileCount + ")";
}
getViewInfoLabel().setText(text);
}

View File

@ -121,6 +121,8 @@ public class MenuManager
private JMenuItem convertSavedStatesItem;
private JMenuItem copySavedStatesItem;
private JMenuItem resetJoystickConfigItem;
private JMenuItem enableAccurateDiskItem;
private JMenuItem disableAccurateDiskItem;
private JMenuItem installPCUAEItem;
private JMenuItem installAmigaModeItem;
@ -219,6 +221,8 @@ public class MenuManager
toolsMenu.add(getConvertSavedStatesItem());
toolsMenu.add(getCopySavedStatesToFileLoaderItem());
toolsMenu.add(getResetJoystickConfigItem());
toolsMenu.add(getEnableAccurateDiskItem());
toolsMenu.add(getDisableAccurateDiskItem());
toolsMenu.addSeparator();
toolsMenu.add(getPalNtscFixMenuItem());
pcuaeMenu = new JMenu("PCUAE");
@ -893,6 +897,28 @@ public class MenuManager
return resetJoystickConfigItem;
}
private JMenuItem getEnableAccurateDiskItem()
{
if (enableAccurateDiskItem == null)
{
enableAccurateDiskItem = new JMenuItem("Enable accurate disk for current gamelist view");
enableAccurateDiskItem.setMnemonic('e');
enableAccurateDiskItem.addActionListener(e -> enableAccurateDisk());
}
return enableAccurateDiskItem;
}
private JMenuItem getDisableAccurateDiskItem()
{
if (disableAccurateDiskItem == null)
{
disableAccurateDiskItem = new JMenuItem("Disable accurate disk for current gamelist view");
disableAccurateDiskItem.setMnemonic('u');
disableAccurateDiskItem.addActionListener(e -> disableAccurateDisk());
}
return disableAccurateDiskItem;
}
private JMenuItem getInstallPCUAEItem()
{
if (installPCUAEItem == null)
@ -1446,6 +1472,46 @@ public class MenuManager
}
}
private void enableAccurateDisk()
{
String message = "Do you want to enable accurate disk for all disk games in the current gamelist view?";
int option = JOptionPane.showConfirmDialog(MainWindow.getInstance().getMainPanel(),
message,
"Enable accurate disk",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (option == JOptionPane.YES_OPTION)
{
uiModel.enableAccurateDiskForAllGamesInCurrentView();
JOptionPane.showMessageDialog(MainWindow.getInstance().getMainPanel(),
"Accurate disk enabled for all disk games.",
"Enable accurate disk",
JOptionPane.INFORMATION_MESSAGE);
MainWindow.getInstance().reloadCurrentGameView();
}
}
private void disableAccurateDisk()
{
String message = "Do you want to disable accurate disk for all disk games in the current gamelist view?";
int option = JOptionPane.showConfirmDialog(MainWindow.getInstance().getMainPanel(),
message,
"Disable accurate disk",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if (option == JOptionPane.YES_OPTION)
{
uiModel.disableAccurateDiskForAllGamesInCurrentView();
JOptionPane.showMessageDialog(MainWindow.getInstance().getMainPanel(),
"Accurate disk disabled for all disk games.",
"Disable accurate disk",
JOptionPane.INFORMATION_MESSAGE);
MainWindow.getInstance().reloadCurrentGameView();
}
}
private void installPCUAE()
{
installPCUAEManager.installPCUAE();

View File

@ -944,7 +944,7 @@ public class ScreenshotsPanel extends JPanel
if (viewTagTextField == null)
{
viewTagTextField = new JTextField();
viewTagTextField.setColumns(15);
viewTagTextField.setColumns(25);
viewTagTextField.setDocument(new CustomUndoPlainDocument()
{
@Override

View File

@ -34,24 +34,18 @@ public class GamebaseImportWorker extends AbstractImportWorker
int totalProcessed = 0;
//Get all genres and create viewtags, then run one-by-one
int counter = 0;
for (GenreInfo genre : gbInporter.getAvailableGenres())
List<GenreInfo> genreList = gbInporter.getAvailableGenres();
int numberOfGenres = genreList.size();
for (GenreInfo genre : genreList)
{
if (counter == 0)
{
counter++;
continue;
}
if (counter > 1)
{
break;
}
counter++;
this.gbInporter.setGenreOption(genre);
publish("Processing games for " + genre.getGenreName());
importManager.setViewTag(genre.getGenreName());
String viewName = getViewName(genre);
importManager.setViewName(viewName);
int processedForGenre = executeImport();
String additonalInfo = ", genre: " + genre.getGenreName() + " (" + counter + " of " + numberOfGenres + ")";
int processedForGenre = executeImport(additonalInfo);
createAdditionalGameViews(processedForGenre, viewName, genre.getGenreName());
@ -65,7 +59,7 @@ public class GamebaseImportWorker extends AbstractImportWorker
}
else
{
int numberOfGamesProcessed = executeImport();
int numberOfGamesProcessed = executeImport("");
if (numberOfGamesProcessed > 0)
{
publish("Processed " + numberOfGamesProcessed + " games.");
@ -87,7 +81,7 @@ public class GamebaseImportWorker extends AbstractImportWorker
}
for (int i = 2; i < (numOfViews + 1); i++)
{
//Create additional views to be filled later
//Create additional views that can be filled later by editing view tags
importManager.setViewName(viewName + "/" + i);
importManager.setViewTag(viewTag + "-" + i);
importManager.createGameViewForViewTag(this);
@ -109,10 +103,10 @@ public class GamebaseImportWorker extends AbstractImportWorker
return newName;
}
private int executeImport()
private int executeImport(String additionalInfo)
{
gbInporter.importFromGamebase(this);
progressValueString = "Checking game files...";
progressValueString = "Checking game files" + additionalInfo;
List<List<GbGameInfo>> listChunks = gbInporter.getGbGameInfoChunks();
progressMaximum = listChunks.size();
@ -128,12 +122,12 @@ public class GamebaseImportWorker extends AbstractImportWorker
return -1;
}
progressValue++;
progressValueString = String.format("Checking game files (batch %s of %s)", progressValue, progressMaximum);
progressValueString = String.format("Checking game files (batch %s of %s)" + additionalInfo, progressValue, progressMaximum);
gbInporter.checkGameFileForGbGames(gbInfoList, this);
}
List<List<String>> dbRowReadChunks = importManager.getDbRowReadChunks();
progressValueString = "Importing to db and copying files...";
progressValueString = "Importing to db and copying files" + additionalInfo;
progressMaximum = dbRowReadChunks.size();
progressValue = 0;
publish("\nImporting to db, copying covers, screens and game files...");
@ -159,7 +153,7 @@ public class GamebaseImportWorker extends AbstractImportWorker
chunkCount++;
progressValue++;
progressValueString =
String.format("Importing to db and copying files (batch %s of %s)", progressValue, progressMaximum);
String.format("Importing to db and copying files (batch %s of %s)" + additionalInfo, progressValue, progressMaximum);
//Copy the list to avoid modifying it when reading several chunks
ArrayList<String> copyList = new ArrayList<>();
copyList.addAll(rowList);

View File

@ -496,7 +496,7 @@ public class MainViewModel extends AbstractModel
logger.debug("...done.");
}
private int getFileCount(List<GameListData> gamesList)
public int getFileCount(List<GameListData> gamesList)
{
int fileCount = 0;
for (GameListData gameListData : gamesList)
@ -1013,6 +1013,16 @@ public class MainViewModel extends AbstractModel
dbConnector.resetJoystickConfigsForView(getSelectedGameView());
}
public void enableAccurateDiskForAllGamesInCurrentView()
{
dbConnector.setAccurateDiskForView(getSelectedGameView(), true);
}
public void disableAccurateDiskForAllGamesInCurrentView()
{
dbConnector.setAccurateDiskForView(getSelectedGameView(), false);
}
private void generateInfoSlot(GameDetails gameDetails)
{
String gameViewTitle = this.selectedGameView.getName();