Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of last map played URIs from 2.5. #11795

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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