diff --git a/bfme-resfix/src/main/java/controller/Controller.java b/bfme-resfix/src/main/java/controller/Controller.java index 69c1bd7..9eb15db 100644 --- a/bfme-resfix/src/main/java/controller/Controller.java +++ b/bfme-resfix/src/main/java/controller/Controller.java @@ -16,6 +16,9 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; import java.util.concurrent.CompletableFuture; @@ -175,10 +178,53 @@ private boolean applyChanges(List games) { listener.resume(); changes = true; } + + // DVD + Intro selectedIntro = mainView.getGameView(game.getId()).getIntroSelectedItem(); + if (selectedIntro != null && !selectedIntro.equals(game.getIntro())) { + listener.pause(); + handleIntroSelection(game, selectedIntro); + listener.resume(); + changes = true; + } } return changes; } + private void handleIntroSelection(Game game, Intro selectedIntro) { + logger.info("handleIntroSelection(): {}: {} > {}", game.getId(), game.getIntro().isOriginal(), selectedIntro.isOriginal()); + + Path root = Paths.get(game.getInstallationPath() + "/data/movies/"); + List fileList = new ArrayList<>(); + fileList.add(Paths.get(root + "/NewLineLogo.vp6")); + fileList.add(Paths.get(root + "/EALogo.vp6")); // ALL + if (game.getId().equals(BFME1)) { + fileList.add(Paths.get(root + "/intel.vp6")); + fileList.add(Paths.get(root + "/THX.vp6")); + } else if (game.getId().equals(BFME2) || game.getId().equals(ROTWK)) { + fileList.add(Paths.get(root + "/NLC_LOGO.vp6")); + fileList.add(Paths.get(root + "/TE_LOGO.vp6")); + } + + // A: Restore Original from Backup + if (selectedIntro.isOriginal()) { + logger.info("handleIntroSelection(): Restore Original from Backup"); + for (Path file : fileList) { + Path backupFile = Paths.get(file + ".bak"); + boolean result = BigManager.copyBigFileFromTo(backupFile, file, labels); // Restore from Backup + if (result) BigManager.removeBigFile(backupFile, labels); // Delete previous Backup + } + + // B: Create Backup, then remove + } else { + for (Path file : fileList) { + Path backupFile = Paths.get(file + ".bak"); + boolean result = BigManager.copyBigFileFromTo(file, backupFile, labels); // Restore from Backup + if (result) BigManager.removeBigFile(file, labels); // Delete previous Backup + } + } + } + private void handleDVDSelection(Game game, DVD selectedDVD) { logger.info("handleDVDSelection(): {}: {} > {}", game.getId(), game.getDvd().isOriginal(), selectedDVD.isOriginal()); DVD dvd = game.getDvd(); @@ -354,6 +400,10 @@ public void updateDVDBox(GameID gameID) { SwingUtilities.invokeLater(() -> mainView.renderDVDBox(getGame(gameID))); } + public void updateIntroBox(GameID gameID) { + SwingUtilities.invokeLater(() -> mainView.renderIntroBox(getGame(gameID))); + } + public void updateAllResBoxes() { SwingUtilities.invokeLater(() -> { mainView.renderResBox(getGame(BFME1), display); diff --git a/bfme-resfix/src/main/java/listener/ChangeListener.java b/bfme-resfix/src/main/java/listener/ChangeListener.java index 15297b1..015dbeb 100644 --- a/bfme-resfix/src/main/java/listener/ChangeListener.java +++ b/bfme-resfix/src/main/java/listener/ChangeListener.java @@ -129,14 +129,23 @@ private void pollSingleGame(Game game, Map runningStatus) { dvd.setOriginal(retrieveGameDatVersion(dvd.getHash())); game.setDvd(dvd); + Intro intro = new Intro(); + intro.setFilePath(Paths.get(currentInstallPath + "/data/movies/NewLineLogo.vp6")); + intro.setBackupPath(Paths.get(currentInstallPath + "/data/movies/NewLineLogo.vp6.bak")); + intro.setOriginal(Files.exists(intro.getFilePath())); + game.setIntro(intro); + if (previousInstallPath != null) { unregisterListener(previousInstallPath); unregisterListener(previousUserDataPath); + unregisterListener(Paths.get(previousInstallPath + "/data/movies")); System.out.println("NEW " + game.getId() + ": Registered: " + monitoredPaths); } if (currentInstallPath != null) { registerListener(currentInstallPath, game.getId()); registerListener(currentUserDataPath, game.getId()); + registerListener(Paths.get(currentInstallPath + "/data/movies"), game.getId()); + System.out.println("NEW " + game.getId() + ": Registered: " + monitoredPaths); } @@ -249,7 +258,7 @@ private void handleFileChange(Path filePath, GameID gameId) { } // Handle File changes - if (filePath.toString().contains("Options.ini")) { + if (filePath.toString().endsWith("Options.ini")) { System.out.println("NEW " + gameId + ": Modified: " + filePath); game.setInGameResolution(retrieveResolution(filePath)); @@ -258,7 +267,7 @@ private void handleFileChange(Path filePath, GameID gameId) { controller.resolutionTooHighFeedback(game); controller.resolution32_9Feedback(game); - } else if (filePath.toString().contains("Maps.big")) { + } else if (filePath.toString().endsWith("Maps.big")) { System.out.println("NEW " + gameId + ": Modified: " + filePath); Maps maps = game.getMaps(); maps.setHash(retrieveHash(filePath)); @@ -267,7 +276,7 @@ private void handleFileChange(Path filePath, GameID gameId) { controller.updateMapsBox(game.getId()); - } else if (filePath.toString().contains("Maps_Backup.big")) { + } else if (filePath.toString().endsWith("Maps_Backup.big")) { System.out.println("NEW " + gameId + ": Modified: " + filePath); Maps maps = game.getMaps(); maps.setBackup(Files.exists(filePath)); @@ -275,7 +284,7 @@ private void handleFileChange(Path filePath, GameID gameId) { controller.updateMapsBox(game.getId()); - } else if (filePath.toString().contains("_unstretched-hud.big")) { + } else if (filePath.toString().endsWith("_unstretched-hud.big")) { System.out.println("NEW " + gameId + ": Modified: " + filePath); HUD hud = game.getHud(); hud.setOriginal(Files.notExists(filePath)); @@ -283,7 +292,7 @@ private void handleFileChange(Path filePath, GameID gameId) { controller.updateHudBox(game.getId()); - } else if (filePath.toString().contains("game.dat")) { + } else if (filePath.toString().endsWith("game.dat")) { System.out.println("NEW " + gameId + ": Modified: " + filePath); DVD dvd = game.getDvd(); dvd.setHash(retrieveHash(filePath)); @@ -291,6 +300,14 @@ private void handleFileChange(Path filePath, GameID gameId) { game.setDvd(dvd); controller.updateDVDBox(game.getId()); + + } else if (filePath.toString().endsWith("NewLineLogo.vp6")) { + System.out.println("NEW " + gameId + ": Modified: " + filePath); + Intro intro = game.getIntro(); + intro.setOriginal(Files.exists(intro.getFilePath())); + game.setIntro(intro); + + controller.updateIntroBox(game.getId()); } } diff --git a/bfme-resfix/src/main/java/model/Game.java b/bfme-resfix/src/main/java/model/Game.java index d90bdfb..940a419 100644 --- a/bfme-resfix/src/main/java/model/Game.java +++ b/bfme-resfix/src/main/java/model/Game.java @@ -14,6 +14,7 @@ public class Game { private Maps maps; private HUD hud; private DVD dvd; + private Intro intro; private boolean isInstalled; private boolean isPatched; private boolean isRunning; @@ -125,16 +126,24 @@ public void setDvd(DVD dvd) { this.dvd = dvd; } + public Intro getIntro() { + return intro; + } + + public void setIntro(Intro intro) { + this.intro = intro; + } + @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Game game = (Game) o; - return isInstalled == game.isInstalled && isPatched == game.isPatched && isRunning == game.isRunning && id == game.id && Objects.equals(language, game.language) && Objects.equals(installationPath, game.installationPath) && Objects.equals(userDataPath, game.userDataPath) && Objects.equals(versionInstalled, game.versionInstalled) && Objects.equals(versionAvailablePatch, game.versionAvailablePatch) && Objects.equals(inGameResolution, game.inGameResolution) && Objects.equals(maps, game.maps) && Objects.equals(hud, game.hud) && Objects.equals(dvd, game.dvd); + return isInstalled == game.isInstalled && isPatched == game.isPatched && isRunning == game.isRunning && id == game.id && Objects.equals(language, game.language) && Objects.equals(installationPath, game.installationPath) && Objects.equals(userDataPath, game.userDataPath) && Objects.equals(versionInstalled, game.versionInstalled) && Objects.equals(versionAvailablePatch, game.versionAvailablePatch) && Objects.equals(inGameResolution, game.inGameResolution) && Objects.equals(maps, game.maps) && Objects.equals(hud, game.hud) && Objects.equals(dvd, game.dvd) && Objects.equals(intro, game.intro); } @Override public int hashCode() { - return Objects.hash(id, language, installationPath, userDataPath, versionInstalled, versionAvailablePatch, inGameResolution, maps, hud, dvd, isInstalled, isPatched, isRunning); + return Objects.hash(id, language, installationPath, userDataPath, versionInstalled, versionAvailablePatch, inGameResolution, maps, hud, dvd, intro, isInstalled, isPatched, isRunning); } } diff --git a/bfme-resfix/src/main/java/model/Intro.java b/bfme-resfix/src/main/java/model/Intro.java new file mode 100644 index 0000000..0ec6654 --- /dev/null +++ b/bfme-resfix/src/main/java/model/Intro.java @@ -0,0 +1,71 @@ +package model; + +import java.nio.file.Path; +import java.util.Objects; + +public class Intro { + private Path filePath; + private Path backupPath; + private String label; + private boolean original; + + public Intro(Path filePath, boolean isOriginal, String label) { + this.filePath = filePath; + this.label = label; + this.original = isOriginal; + } + + public Intro() { + + } + + public Path getFilePath() { + return filePath; + } + + public void setFilePath(Path filePath) { + this.filePath = filePath; + } + + public Path getBackupPath() { + return backupPath; + } + + public void setBackupPath(Path backupPath) { + this.backupPath = backupPath; + } + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public boolean isOriginal() { + return original; + } + + public void setOriginal(boolean original) { + this.original = original; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Intro intro = (Intro) o; + return original == intro.original; + } + + @Override + public int hashCode() { + return Objects.hashCode(original); + } + + @Override + public String toString() { + return label; + } +} diff --git a/bfme-resfix/src/main/java/view/GameView.form b/bfme-resfix/src/main/java/view/GameView.form index 44b6216..730222e 100644 --- a/bfme-resfix/src/main/java/view/GameView.form +++ b/bfme-resfix/src/main/java/view/GameView.form @@ -1,9 +1,9 @@
- + - + @@ -142,6 +142,26 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/bfme-resfix/src/main/java/view/GameView.java b/bfme-resfix/src/main/java/view/GameView.java index 3c10dd4..8c11c60 100644 --- a/bfme-resfix/src/main/java/view/GameView.java +++ b/bfme-resfix/src/main/java/view/GameView.java @@ -25,6 +25,7 @@ public class GameView extends JPanel { private JComboBox comboBoxMaps; private JComboBox comboBoxHud; private JComboBox comboBoxDVD; + private JComboBox comboBoxIntro; private JLabel labelRunning; private JLabel labelInstall; private JLabel labelSpacer; @@ -41,6 +42,7 @@ public GameView() { setupComboBoxSounds(comboBoxMaps); setupComboBoxSounds(comboBoxHud); setupComboBoxSounds(comboBoxDVD); + setupComboBoxSounds(comboBoxIntro); } public Resolution getResolutionSelectedItem() { @@ -59,6 +61,10 @@ public DVD getDVDSelectedItem() { return (DVD) comboBoxDVD.getSelectedItem(); } + public Intro getIntroSelectedItem() { + return (Intro) comboBoxIntro.getSelectedItem(); + } + public void updateTitleFont(String text, Font font, Color color) { titleBFME.setText(text); titleBFME.setFont(font); @@ -74,6 +80,7 @@ public void render(Game game, Display display) { setComboBoxMaps(game); setComboBoxHud(game); setComboBoxDVD(game); + setComboBoxIntro(game); } private void enableLabel(Game game) { @@ -360,6 +367,45 @@ private void setComboBoxDVD(Game game) { isProgrammaticUpdate[0] = false; } + private void setComboBoxIntro(Game game) { + isProgrammaticUpdate[0] = true; + + // Default + comboBoxIntro.removeAllItems(); + comboBoxIntro.setEnabled(false); + comboBoxIntro.setRenderer(new CustomComboBoxRenderer()); + + // Skip + if (!game.isInstalled()) + return; + + // Enable + if (game.isPatched()) + comboBoxIntro.setEnabled(true); + + if (game.isRunning()) + comboBoxIntro.setEnabled(false); + + // Add items + Intro noIntro = new Intro(game.getDvd().getFilePath(), false, labels.getString("cb.intro.skip")); + Intro intro = new Intro(game.getDvd().getFilePath(), true, labels.getString("cb.intro.keep")); + comboBoxIntro.addItem(noIntro); + comboBoxIntro.addItem(intro); + + // Default Intro + if (game.getIntro().isOriginal()) { + intro.setLabel(intro.getLabel() + " -- " + labels.getString("cb.inGame")); + comboBoxIntro.setSelectedItem(intro); + + // No DVD + } else { + noIntro.setLabel(noIntro.getLabel() + " -- " + labels.getString("cb.inGame")); + comboBoxIntro.setSelectedItem(noIntro); + } + + isProgrammaticUpdate[0] = false; + } + private String getVersionLabel(Game game) { return "" + labels.getString("game.installed") + game.getVersionInstalled() + ""; } @@ -399,6 +445,10 @@ public void renderDVDBox(Game game) { setComboBoxDVD(game); } + public void renderIntroBox(Game game) { + setComboBoxIntro(game); + } + @Override protected void paintComponent(Graphics g) { super.paintComponent(g); @@ -435,4 +485,6 @@ public void paint(Graphics g) { } } } + + } diff --git a/bfme-resfix/src/main/java/view/MainView.java b/bfme-resfix/src/main/java/view/MainView.java index 90028bb..92eb392 100644 --- a/bfme-resfix/src/main/java/view/MainView.java +++ b/bfme-resfix/src/main/java/view/MainView.java @@ -160,6 +160,10 @@ public void renderDVDBox(Game game) { gameViews.get(game.getId()).renderDVDBox(game); } + public void renderIntroBox(Game game) { + gameViews.get(game.getId()).renderIntroBox(game); + } + @Override public void paint(Graphics g) { super.paint(g); diff --git a/bfme-resfix/src/main/resources/labels.properties b/bfme-resfix/src/main/resources/labels.properties index 6a83d25..bffeae3 100644 --- a/bfme-resfix/src/main/resources/labels.properties +++ b/bfme-resfix/src/main/resources/labels.properties @@ -10,6 +10,7 @@ title.res = &Resolution title.maps = &Maps title.hud = &HUD title.no_dvd = &DVD +title.intro = &Intro # Installation game.installed = Installed v @@ -27,6 +28,8 @@ cb.maps.default = Standard cb.maps.modified = Modified cb.dvd.notRequired = Requires no DVD cb.dvd.required = Requires DVD +cb.intro.skip = Skip Intro +cb.intro.keep = Keep Intro # Feedback feedback.resolution.tooHigh = High resolution selected, some fonts might appear small. diff --git a/bfme-resfix/src/main/resources/labels_de.properties b/bfme-resfix/src/main/resources/labels_de.properties index 14b808e..467583f 100644 --- a/bfme-resfix/src/main/resources/labels_de.properties +++ b/bfme-resfix/src/main/resources/labels_de.properties @@ -10,6 +10,7 @@ title.res = Aufl\u00F6sung title.maps = Karten title.hud = HUD title.no_dvd = DVD +title.intro = Intro # Installation game.installed = Installiert v @@ -27,6 +28,8 @@ cb.maps.default = Standard cb.maps.modified = Modifiziert cb.dvd.notRequired = Benötigt keine DVD cb.dvd.required = Benötigt DVD +cb.intro.skip = Intro überspringen +cb.intro.keep = Intro behalten # Feedback feedback.resolution.tooHigh = Hohe Aufl\u00F6sung ausgew\u00E4hlt, manche Schriften k\u00F6nnten klein erscheinen.