From 1ecf5942ab17fe58338e16e7e6993c4db51473a5 Mon Sep 17 00:00:00 2001 From: Lyze <11274700+lyze237@users.noreply.github.com> Date: Thu, 15 Aug 2024 00:10:15 +0200 Subject: [PATCH] Implement looking for manually installed idea on windows --- .../ui/panels/CompleteButtonsPanel.java | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/main/java/gdx/liftoff/ui/panels/CompleteButtonsPanel.java b/src/main/java/gdx/liftoff/ui/panels/CompleteButtonsPanel.java index 8d302289..251bad3c 100644 --- a/src/main/java/gdx/liftoff/ui/panels/CompleteButtonsPanel.java +++ b/src/main/java/gdx/liftoff/ui/panels/CompleteButtonsPanel.java @@ -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.*; @@ -66,15 +66,30 @@ public void populate(boolean fullscreen) { table.add(ideaButton); addHandListener(ideaButton); try { - List 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 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);