diff --git a/src/main/java/se/lantz/db/DbConnector.java b/src/main/java/se/lantz/db/DbConnector.java index 0289b88..aa3337a 100644 --- a/src/main/java/se/lantz/db/DbConnector.java +++ b/src/main/java/se/lantz/db/DbConnector.java @@ -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"); @@ -357,7 +358,7 @@ public class DbConnector Collections.sort(returnList, new GameListDataComparator()); return returnList; } - + private int updateDiskCount(String disk, int fileCount) { if (disk != null && !disk.isEmpty()) @@ -366,7 +367,6 @@ public class DbConnector } return fileCount; } - public List fetchAllGamesForGameCount() { @@ -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"); + } + } } diff --git a/src/main/java/se/lantz/gui/ListPanel.java b/src/main/java/se/lantz/gui/ListPanel.java index 5656912..171b26d 100644 --- a/src/main/java/se/lantz/gui/ListPanel.java +++ b/src/main/java/se/lantz/gui/ListPanel.java @@ -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); } diff --git a/src/main/java/se/lantz/gui/MenuManager.java b/src/main/java/se/lantz/gui/MenuManager.java index 03ca1a5..97deeac 100644 --- a/src/main/java/se/lantz/gui/MenuManager.java +++ b/src/main/java/se/lantz/gui/MenuManager.java @@ -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"); @@ -892,6 +896,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() { @@ -1445,6 +1471,46 @@ public class MenuManager MainWindow.getInstance().reloadCurrentGameView(); } } + + 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() { diff --git a/src/main/java/se/lantz/gui/ScreenshotsPanel.java b/src/main/java/se/lantz/gui/ScreenshotsPanel.java index f763e1c..88da8bb 100644 --- a/src/main/java/se/lantz/gui/ScreenshotsPanel.java +++ b/src/main/java/se/lantz/gui/ScreenshotsPanel.java @@ -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 diff --git a/src/main/java/se/lantz/gui/imports/GamebaseImportWorker.java b/src/main/java/se/lantz/gui/imports/GamebaseImportWorker.java index 7330f32..47ba2e7 100644 --- a/src/main/java/se/lantz/gui/imports/GamebaseImportWorker.java +++ b/src/main/java/se/lantz/gui/imports/GamebaseImportWorker.java @@ -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 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> 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> 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 copyList = new ArrayList<>(); copyList.addAll(rowList); diff --git a/src/main/java/se/lantz/model/MainViewModel.java b/src/main/java/se/lantz/model/MainViewModel.java index a78e01d..8123ba0 100644 --- a/src/main/java/se/lantz/model/MainViewModel.java +++ b/src/main/java/se/lantz/model/MainViewModel.java @@ -496,7 +496,7 @@ public class MainViewModel extends AbstractModel logger.debug("...done."); } - private int getFileCount(List gamesList) + public int getFileCount(List gamesList) { int fileCount = 0; for (GameListData gameListData : gamesList) @@ -1012,6 +1012,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) {