Skip to content

Commit

Permalink
Implement looking for manually installed idea on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
lyze237 committed Aug 14, 2024
1 parent 8f7b1af commit 1ecf594
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions src/main/java/gdx/liftoff/ui/panels/CompleteButtonsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import gdx.liftoff.ui.UserData;
import gdx.liftoff.ui.dialogs.FullscreenDialog;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.*;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Stream;

import static gdx.liftoff.Main.*;

Expand Down Expand Up @@ -66,15 +66,30 @@ public void populate(boolean fullscreen) {
table.add(ideaButton);
addHandListener(ideaButton);
try {
List<String> findIntellij = (UIUtils.isWindows) ? Arrays.asList("where.exe", "idea") : Arrays.asList("which", "idea");

Process process = new ProcessBuilder(findIntellij).start();
if (process.waitFor() != 0) {
throw new Exception("IntelliJ not found");
List<String> findIntellijExecutable = (UIUtils.isWindows) ? Arrays.asList("where.exe", "idea") : Arrays.asList("which", "idea");

Process process = new ProcessBuilder(findIntellijExecutable).start();
if (process.waitFor() == 0) {
intellijPath = new BufferedReader(new InputStreamReader(process.getInputStream())).readLine();
ideaButton.setDisabled(false);
} else {
if (!UIUtils.isWindows) {
throw new Exception("IntelliJ not found");
}

String programFiles = System.getenv("PROGRAMFILES");
File jetbrains = new File(programFiles, "JetBrains");
File[] ideaFolders = jetbrains.listFiles((dir, name) -> name.contains("IDEA"));
if (ideaFolders != null) {
File intellijFolder = Stream.of(ideaFolders)
.max(Comparator.comparingLong(File::lastModified))
.orElseThrow(() -> new Exception("IntelliJ not found"));

intellijPath = new File(intellijFolder, "bin/idea64.exe").getAbsolutePath();
ideaButton.setDisabled(false);
}
}

intellijPath = new BufferedReader(new InputStreamReader(process.getInputStream())).readLine();
ideaButton.setDisabled(false);
} catch (Exception e) {
addTooltip(ideaButton, Align.top, TOOLTIP_WIDTH, prop.getProperty("ideaNotFoundTip"));
ideaButton.setDisabled(true);
Expand Down

0 comments on commit 1ecf594

Please sign in to comment.