Determine vscode installation directory on windows from Path

This commit is contained in:
crschnick 2023-07-10 04:00:07 +00:00
parent b3f299dbe6
commit 2e54c9368d

View file

@ -1,9 +1,12 @@
package io.xpipe.app.prefs;
import io.xpipe.app.ext.PrefsChoiceValue;
import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.app.util.ApplicationHelper;
import io.xpipe.app.util.WindowsRegistry;
import io.xpipe.core.impl.LocalStore;
import io.xpipe.core.process.OsType;
import io.xpipe.core.process.ShellDialects;
import java.io.IOException;
import java.nio.file.Path;
@ -30,6 +33,22 @@ public interface ExternalEditorType extends PrefsChoiceValue {
@Override
protected Optional<Path> determinePath() {
// Try to locate if it is in the Path
try (var cc = LocalStore.getShell()
.command(ShellDialects.getPlatformDefault().getWhichCommand("code.cmd"))
.start()) {
var out = cc.readStdoutDiscardErr();
var exit = cc.getExitCode();
if (exit == 0) {
var first = out.lines().findFirst();
if (first.isPresent()) {
return first.map(Path::of);
}
}
} catch (Exception ex) {
ErrorEvent.fromThrowable(ex).omit().handle();
}
return Optional.of(Path.of(System.getenv("LOCALAPPDATA"))
.resolve("Programs")
.resolve("Microsoft VS Code")