Skip to content

Commit

Permalink
Fix handling of last map played URIs from 2.5. (#11795)
Browse files Browse the repository at this point in the history
2.5 saves the last map played as a URI and not a path, so handle that properly.
  • Loading branch information
asvitkine committed Jul 19, 2023
1 parent 90769cb commit 48e6987
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import games.strategy.engine.framework.startup.mc.ClientModel;
import games.strategy.engine.framework.startup.mc.GameSelector;
import games.strategy.triplea.settings.ClientSetting;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.util.List;
import java.util.Observable;
Expand Down Expand Up @@ -188,14 +191,26 @@ public void loadDefaultGameSameThread() {
gameUri
.filter(Predicate.not(String::isBlank))
.filter(GameSelectorModel::gameUriExistsOnFileSystem)
.map(Path::of)
.map(GameSelectorModel::pathFromGameUri)
.ifPresentOrElse(this::load, this::resetDefaultGame);
}

private static Path pathFromGameUri(final String gameUri) {
if (gameUri.startsWith("file:")) {
try {
return Path.of(new URI(gameUri));
} catch (URISyntaxException e) {
throw new InvalidPathException(gameUri, e.getReason());
}
} else {
return Path.of(gameUri);
}
}

@SuppressWarnings("ReturnValueIgnored")
private static boolean gameUriExistsOnFileSystem(final String gameUri) {
try {
final Path gameFile = Path.of(gameUri);
final Path gameFile = pathFromGameUri(gameUri);

// starts with check is because we don't want to load a game file by default that is not
// within
Expand Down

0 comments on commit 48e6987

Please sign in to comment.