Skip to content

Commit 308a3f9

Browse files
committed
review fix
1 parent 3d7d654 commit 308a3f9

2 files changed

Lines changed: 61 additions & 5 deletions

File tree

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/RunMap.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ private void startGame(WurstGui gui, CompilationResult result) throws Exception
157157
return;
158158
} catch (IOException e) {
159159
WLogger.warning("Could not launch Warcraft III", e);
160-
launchData = recoverFromLaunchFailure(launchData, e);
160+
launchData = resolveLaunchData(recoverFromLaunchFailure(launchData, e));
161+
if (launchData == null) {
162+
throw new RequestFailedException(MessageType.Info, "Run canceled.");
163+
}
161164
}
162165
}
163166
}
@@ -260,7 +263,11 @@ static String launchFailureMessage(@Nullable File gameExe, IOException failure)
260263
}
261264

262265
private W3InstallationData resolveLaunchData() {
263-
W3InstallationData launchData = w3data;
266+
return resolveLaunchData(w3data);
267+
}
268+
269+
@Nullable
270+
protected W3InstallationData resolveLaunchData(W3InstallationData launchData) {
264271
// When the project pins a wc3Patch, only auto-launch an install we can confirm is patch-compliant.
265272
// A mismatching OR unverifiable client is delegated to the user instead of "randomly" launching and failing.
266273
while (!isLaunchDataPatchCompliant(launchData)) {
@@ -332,7 +339,7 @@ private static String describeClientVersion(GameVersion version) {
332339
return kindForVersion(version) + " (" + version + ")";
333340
}
334341

335-
private MismatchChoice chooseMismatchAction(String message) {
342+
protected MismatchChoice chooseMismatchAction(String message) {
336343
if (GraphicsEnvironment.isHeadless()) {
337344
return MismatchChoice.CONTINUE;
338345
}
@@ -356,7 +363,7 @@ private MismatchChoice chooseMismatchAction(String message) {
356363
return MismatchChoice.CONTINUE;
357364
}
358365

359-
private Optional<W3InstallationData> chooseAlternateGamePath() {
366+
protected Optional<W3InstallationData> chooseAlternateGamePath() {
360367
if (GraphicsEnvironment.isHeadless()) {
361368
return Optional.empty();
362369
}
@@ -371,7 +378,7 @@ private Optional<W3InstallationData> chooseAlternateGamePath() {
371378
return Optional.of(new W3InstallationData(langServer, selectedFolder, true, Optional.empty()));
372379
}
373380

374-
private enum MismatchChoice {
381+
protected enum MismatchChoice {
375382
CONTINUE,
376383
CHOOSE_OTHER,
377384
CANCEL

de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/MapRequestPatchTargetTests.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,30 @@ public void patchComplianceRequiresKnownMatchingClientWhenPinned() throws Except
205205
assertFalse(isPatchCompliant(Optional.of(WurstBuildConfig.Wc3Patch.PRE_129), Optional.empty()));
206206
}
207207

208+
@Test
209+
public void retryLaunchSelectionRechecksPatchCompliance() throws Exception {
210+
Path project = projectWithPatch("v1.27b");
211+
W3InstallationData reforgedRetry = installationData("warcraft-reforged-retry", "Warcraft III.exe", GameVersion.VERSION_1_32);
212+
W3InstallationData legacySelection = installationData("warcraft-legacy-selection", "war3.exe", new GameVersion("1.27"));
213+
Path fakeInitialExe = Files.writeString(Files.createTempFile("not-warcraft-initial", ".exe"), "not a PE file");
214+
215+
PatchComplianceRunMap request = new PatchComplianceRunMap(project, legacySelection, fakeInitialExe.toString());
216+
217+
W3InstallationData resolved = request.resolveAfterRetry(reforgedRetry);
218+
219+
assertEquals(request.mismatchPrompts, 1);
220+
assertEquals(
221+
resolved.getGameExe().orElseThrow().getAbsoluteFile(),
222+
legacySelection.getGameExe().orElseThrow().getAbsoluteFile()
223+
);
224+
}
225+
226+
private static W3InstallationData installationData(String folderPrefix, String exeName, GameVersion version) throws IOException {
227+
Path install = Files.createTempDirectory(folderPrefix);
228+
Path exe = Files.writeString(install.resolve(exeName), "not a PE file");
229+
return new W3InstallationData(Optional.of(exe.toFile()), Optional.of(version));
230+
}
231+
208232
private static boolean isPatchCompliant(Optional<WurstBuildConfig.Wc3Patch> projectKind,
209233
Optional<GameVersion> clientVersion) throws Exception {
210234
Method method = RunMap.class.getDeclaredMethod("isPatchCompliant", Optional.class, Optional.class);
@@ -274,4 +298,29 @@ Optional<File> gameExe() {
274298
return w3data.getGameExe();
275299
}
276300
}
301+
302+
private static final class PatchComplianceRunMap extends RunMap {
303+
private final W3InstallationData alternateSelection;
304+
private int mismatchPrompts = 0;
305+
306+
PatchComplianceRunMap(Path projectRoot, W3InstallationData alternateSelection, String gameExePath) {
307+
super(null, WFile.create(projectRoot), Optional.empty(), Optional.empty(), List.of(), Optional.of(gameExePath));
308+
this.alternateSelection = alternateSelection;
309+
}
310+
311+
W3InstallationData resolveAfterRetry(W3InstallationData retrySelection) {
312+
return resolveLaunchData(retrySelection);
313+
}
314+
315+
@Override
316+
protected MismatchChoice chooseMismatchAction(String message) {
317+
mismatchPrompts++;
318+
return MismatchChoice.CHOOSE_OTHER;
319+
}
320+
321+
@Override
322+
protected Optional<W3InstallationData> chooseAlternateGamePath() {
323+
return Optional.of(alternateSelection);
324+
}
325+
}
277326
}

0 commit comments

Comments
 (0)