warning dialog for unsupported groove.exe versions at start and before the first apply of a session (nothing blocked)
This commit is contained in:
1 parent
ff6673af66
commit
932ccf5fc8
6 files changed
+123
-2
No files matched your search
@@ -62,6 +62,7 @@ final class MainFrame extends JFrame {
|
||||
private boolean crashReported;
|
||||
private boolean oldWineAccepted;
|
||||
private final RecoveryNotice recoveryNotice = new RecoveryNotice();
|
||||
final UnsupportedExeWarning exeWarning = new UnsupportedExeWarning();
|
||||
private boolean recoveryRunning;
|
||||
|
||||
MainFrame(AppState state) {
|
||||
@@ -223,6 +224,9 @@ final class MainFrame extends JFrame {
|
||||
showRecovery(state.recovery);
|
||||
state.recovery = ModManager.Recovery.NONE;
|
||||
}
|
||||
if (inst) {
|
||||
SwingUtilities.invokeLater(() -> exeWarning.atStart(this, state));
|
||||
}
|
||||
}
|
||||
|
||||
/** Tells the user once that an interrupted apply was repaired; BUSY is retried later. */
|
||||
|
||||
@@ -677,6 +677,7 @@ final class ModsPanel extends JPanel {
|
||||
}
|
||||
List<Mod> mods = selected();
|
||||
ModManager mm = frame.state.modManager;
|
||||
frame.exeWarning.beforeApply(frame, frame.state);
|
||||
if (!AntivirusDialogs.notice(frame, mm.exeMods(mods), true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.eliasmueller.llamamod.ui;
|
||||
|
||||
import com.eliasmueller.llamamod.exe.GameExe;
|
||||
import com.eliasmueller.llamamod.platform.FileOps;
|
||||
import com.eliasmueller.llamamod.platform.Integrity;
|
||||
import java.awt.Component;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
/**
|
||||
* Warns (never blocks) when the installed groove.exe is not one of the supported builds: once at
|
||||
* start and once before the first Apply of a session.
|
||||
*/
|
||||
final class UnsupportedExeWarning {
|
||||
private boolean shownAtStart;
|
||||
private boolean shownAtApply;
|
||||
private String checkedSha;
|
||||
private boolean unsupported;
|
||||
|
||||
/** The warning text, or null if the build is supported or unknown because nothing is installed. */
|
||||
static String message(String sha256) {
|
||||
if (sha256 == null || sha256.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
for (GameExe.Build b : GameExe.Build.values()) {
|
||||
if (b.sha256.equalsIgnoreCase(sha256)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return "You are running an unsupported version of the game. Mods, especially mods that modify"
|
||||
+ " groove.exe, probably won't work.\n\nSupported are: "
|
||||
+ Arrays.stream(GameExe.Build.values())
|
||||
.map(GameExe.Build::toString)
|
||||
.collect(Collectors.joining(", "))
|
||||
+ ".";
|
||||
}
|
||||
|
||||
/** SHA-256 of the set-up original groove.exe ("" if not installed or unreadable). */
|
||||
static String installedSha(AppState state) {
|
||||
if (!state.cfg.installed()) {
|
||||
return "";
|
||||
}
|
||||
if (!state.cfg.exeSha256.isEmpty()) {
|
||||
return state.cfg.exeSha256;
|
||||
}
|
||||
try {
|
||||
Path hd = state.paths.originalHd();
|
||||
Path exe = Files.isDirectory(hd) ? Integrity.find(hd, "groove.exe") : null;
|
||||
return exe != null && Files.isRegularFile(exe) ? FileOps.sha256(exe) : "";
|
||||
} catch (IOException e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private String current(AppState state) {
|
||||
String sha = installedSha(state);
|
||||
if (!sha.equals(checkedSha)) {
|
||||
checkedSha = sha;
|
||||
unsupported = message(sha) != null;
|
||||
shownAtStart = false;
|
||||
shownAtApply = false;
|
||||
}
|
||||
return unsupported ? message(sha) : null;
|
||||
}
|
||||
|
||||
void atStart(Component parent, AppState state) {
|
||||
String m = current(state);
|
||||
if (m != null && !shownAtStart) {
|
||||
shownAtStart = true;
|
||||
JOptionPane.showMessageDialog(parent, m, "Unsupported game version", JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
/** Shows the warning before the first Apply of a session; Apply always continues afterwards. */
|
||||
void beforeApply(Component parent, AppState state) {
|
||||
String m = current(state);
|
||||
if (m != null && !shownAtApply) {
|
||||
shownAtApply = true;
|
||||
JOptionPane.showMessageDialog(parent, m, "Unsupported game version", JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user