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

-added Win11's alternate path for ExecuteInfo.txt #72

Merged
merged 1 commit into from
Jan 20, 2024
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 @@ -47,7 +47,7 @@
import static com.github.ocraft.s2client.protocol.Errors.required;
import static com.github.ocraft.s2client.protocol.Preconditions.isSet;
import static java.lang.String.format;
import static java.util.Comparator.reverseOrder;
import static java.util.Comparator.naturalOrder;
import static java.util.Optional.ofNullable;

public final class ExecutableParser {
Expand All @@ -60,6 +60,7 @@ public final class ExecutableParser {
public static final String X64_SUFFIX = "_x64";
public static final Path CFG_PATH = Paths.get("Starcraft II", EXECUTE_INFO);
public static final Path WIN_CFG = Paths.get("Documents").resolve(CFG_PATH);
public static final Path WIN_CFG_ONE_DRIVE = Paths.get("OneDrive","Documents").resolve(CFG_PATH);
public static final Path LINUX_CFG = CFG_PATH;
public static final Path MAC_CFG = Paths.get("Library", "Application Support", "Blizzard").resolve(CFG_PATH);

Expand Down Expand Up @@ -146,12 +147,14 @@ private static Path findExecutablePath() {
private static Optional<Path> resolveExecuteInfoPath() {
String os = System.getProperty("os.name").toLowerCase();
String userHome = System.getProperty("user.home");
Path userHomePath = Paths.get(userHome);
if (isWindows(os)) {
return Optional.of(Paths.get(userHome).resolve(WIN_CFG));
Path executeInfoPath = userHomePath.resolve(WIN_CFG);
return Files.exists(executeInfoPath) ? Optional.of(executeInfoPath) : Optional.of(userHomePath.resolve(WIN_CFG_ONE_DRIVE));
} else if (isUnix(os)) {
return Optional.of(Paths.get(userHome).resolve(LINUX_CFG));
return Optional.of(userHomePath.resolve(LINUX_CFG));
} else if (isMac(os)) {
return Optional.of(Paths.get(userHome).resolve(MAC_CFG));
return Optional.of(userHomePath.resolve(MAC_CFG));
} else {
return Optional.empty();
}
Expand Down Expand Up @@ -201,7 +204,7 @@ private static Function<Path, String> toNewestBaseBuild(String exeFile) {
.orElseThrow(required("version directory")))
.filter(file -> file.getFileName().toString().startsWith(BUILD_PREFIX))
) {
return builds.min(reverseOrder())
return builds.max(naturalOrder())
.filter(path -> Files.exists(path.resolve(exeFile)))
.map(Path::getFileName)
.map(Path::toString)
Expand Down