This commit is contained in:
crschnick
2024-10-13 08:35:13 +00:00
parent d4ad1d2e82
commit e894390124
35 changed files with 286 additions and 174 deletions
@@ -14,10 +14,12 @@ import io.xpipe.core.process.OsType;
import io.xpipe.core.process.ShellDialects;
import io.xpipe.core.store.FileKind;
import io.xpipe.core.store.FilePath;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.value.ObservableValue;
import javafx.scene.Node;
import javafx.scene.control.TextField;
import org.kordamp.ikonli.javafx.FontIcon;
import java.util.List;
@@ -26,7 +28,9 @@ public abstract class BaseCompressAction implements BrowserAction, BranchAction
private final boolean directory;
public BaseCompressAction(boolean directory) {this.directory = directory;}
public BaseCompressAction(boolean directory) {
this.directory = directory;
}
@Override
public void init(OpenFileSystemModel model) throws Exception {
@@ -38,11 +42,12 @@ public abstract class BaseCompressAction implements BrowserAction, BranchAction
if (sc.getOsType() == OsType.WINDOWS) {
var found = CommandSupport.findProgram(sc, "7z");
if (found.isPresent()) {
model.getCache().getMultiPurposeCache().put("7zExecutable","7z");
model.getCache().getMultiPurposeCache().put("7zExecutable", "7z");
return;
}
var pf = sc.command(sc.getShellDialect().getPrintEnvironmentVariableCommand("ProgramFiles")).readStdoutOrThrow();
var pf = sc.command(sc.getShellDialect().getPrintEnvironmentVariableCommand("ProgramFiles"))
.readStdoutOrThrow();
var loc = new FilePath(pf).join("7-Zip", "7z.exe").toWindows();
if (model.getFileSystem().fileExists(loc)) {
model.getCache().getMultiPurposeCache().put("7zExecutable", loc);
@@ -71,11 +76,15 @@ public abstract class BaseCompressAction implements BrowserAction, BranchAction
@Override
public boolean isApplicable(OpenFileSystemModel model, List<BrowserEntry> entries) {
var ext = List.of("zip", "tar", "tar.gz", "tgz", "7z", "rar", "xar");
if (entries.stream().anyMatch(browserEntry -> ext.stream().anyMatch(s -> browserEntry.getRawFileEntry().getPath().toLowerCase().endsWith("." + s)))) {
if (entries.stream().anyMatch(browserEntry -> ext.stream()
.anyMatch(s ->
browserEntry.getRawFileEntry().getPath().toLowerCase().endsWith("." + s)))) {
return false;
}
return directory ? entries.size() == 1 && entries.getFirst().getRawFileEntry().getKind() == FileKind.DIRECTORY : entries.size() >= 1;
return directory
? entries.size() == 1 && entries.getFirst().getRawFileEntry().getKind() == FileKind.DIRECTORY
: entries.size() >= 1;
}
@Override
@@ -85,11 +94,11 @@ public abstract class BaseCompressAction implements BrowserAction, BranchAction
new WindowsZipAction(),
new UnixZipAction(),
new TarBasedAction(false) {
@Override
protected String getExtension() {
return "tar";
}
},
@Override
protected String getExtension() {
return "tar";
}
},
new TarBasedAction(true) {
@Override
@@ -146,7 +155,10 @@ public abstract class BaseCompressAction implements BrowserAction, BranchAction
protected void create(String fileName, OpenFileSystemModel model, List<BrowserEntry> entries) {
var base = new FilePath(model.getCurrentDirectory().getPath());
var target = base.join(fileName);
var command = CommandBuilder.of().add("Compress-Archive", "-Force", "-DestinationPath").addFile(target).add("-Path");
var command = CommandBuilder.of()
.add("Compress-Archive", "-Force", "-DestinationPath")
.addFile(target)
.add("-Path");
for (int i = 0; i < entries.size(); i++) {
var rel = new FilePath(entries.get(i).getRawFileEntry().getPath()).relativize(base);
if (directory) {
@@ -159,16 +171,22 @@ public abstract class BaseCompressAction implements BrowserAction, BranchAction
}
}
model.runAsync(() -> {
var sc = model.getFileSystem().getShell().orElseThrow();
if (ShellDialects.isPowershell(sc)) {
sc.command(command).withWorkingDirectory(base.toString()).execute();
} else {
try (var sub = sc.subShell(ShellDialects.POWERSHELL)) {
sub.command(command).withWorkingDirectory(base.toString()).execute();
}
}
}, true);
model.runAsync(
() -> {
var sc = model.getFileSystem().getShell().orElseThrow();
if (ShellDialects.isPowershell(sc)) {
sc.command(command)
.withWorkingDirectory(base.toString())
.execute();
} else {
try (var sub = sc.subShell(ShellDialects.POWERSHELL)) {
sub.command(command)
.withWorkingDirectory(base.toString())
.execute();
}
}
},
true);
}
@Override
@@ -190,7 +208,9 @@ public abstract class BaseCompressAction implements BrowserAction, BranchAction
var target = base.join(fileName);
var command = CommandBuilder.of().add("zip", "-r", "-");
for (int i = 0; i < entries.size(); i++) {
var rel = new FilePath(entries.get(i).getRawFileEntry().getPath()).relativize(base).toUnix();
var rel = new FilePath(entries.get(i).getRawFileEntry().getPath())
.relativize(base)
.toUnix();
if (directory) {
command.add(".");
} else {
@@ -200,10 +220,15 @@ public abstract class BaseCompressAction implements BrowserAction, BranchAction
command.add(">").addFile(target);
if (directory) {
model.runAsync(() -> {
var sc = model.getFileSystem().getShell().orElseThrow();
sc.command(command).withWorkingDirectory(entries.getFirst().getRawFileEntry().getPath()).execute();
}, true);
model.runAsync(
() -> {
var sc = model.getFileSystem().getShell().orElseThrow();
sc.command(command)
.withWorkingDirectory(
entries.getFirst().getRawFileEntry().getPath())
.execute();
},
true);
} else {
model.runCommandAsync(command, true);
}
@@ -231,7 +256,14 @@ public abstract class BaseCompressAction implements BrowserAction, BranchAction
protected void create(String fileName, OpenFileSystemModel model, List<BrowserEntry> entries) {
var base = new FilePath(model.getCurrentDirectory().getPath());
var target = base.join(fileName);
var command = CommandBuilder.of().addFile(model.getCache().getMultiPurposeCache().get("7zExecutable").toString()).add("a").add("-r").addFile(target);
var command = CommandBuilder.of()
.addFile(model.getCache()
.getMultiPurposeCache()
.get("7zExecutable")
.toString())
.add("a")
.add("-r")
.addFile(target);
for (int i = 0; i < entries.size(); i++) {
var rel = new FilePath(entries.get(i).getRawFileEntry().getPath()).relativize(base);
if (directory) {
@@ -264,18 +296,28 @@ public abstract class BaseCompressAction implements BrowserAction, BranchAction
private final boolean gz;
private TarBasedAction(boolean gz) {this.gz = gz;}
private TarBasedAction(boolean gz) {
this.gz = gz;
}
@Override
protected void create(String fileName, OpenFileSystemModel model, List<BrowserEntry> entries) {
var tar = CommandBuilder.of().add("tar", "-c").addIf(gz, "-z").add("-f").addFile(fileName);
var tar = CommandBuilder.of()
.add("tar", "-c")
.addIf(gz, "-z")
.add("-f")
.addFile(fileName);
var base = new FilePath(model.getCurrentDirectory().getPath());
if (directory) {
var dir = new FilePath(entries.getFirst().getRawFileEntry().getPath());
// Fix for bsd find, remove /
var command = CommandBuilder.of().add("find").addFile(dir.removeTrailingSlash().toUnix())
.add("|", "sed").addLiteral("s,^" + dir.toDirectory().toUnix() + "*,,").add("|");
var command = CommandBuilder.of()
.add("find")
.addFile(dir.removeTrailingSlash().toUnix())
.add("|", "sed")
.addLiteral("s,^" + dir.toDirectory().toUnix() + "*,,")
.add("|");
command.add(tar).add("-C").addFile(dir.toDirectory().toUnix()).add("-T", "-");
model.runCommandAsync(command, true);
} else {
@@ -9,6 +9,7 @@ import io.xpipe.app.browser.icon.BrowserIcons;
import io.xpipe.app.core.AppI18n;
import io.xpipe.core.process.CommandBuilder;
import io.xpipe.core.process.ShellControl;
import javafx.beans.value.ObservableValue;
import javafx.scene.Node;
@@ -36,22 +37,27 @@ public class BaseUntarAction implements ApplicationPathAction, LeafAction {
@Override
public void execute(OpenFileSystemModel model, List<BrowserEntry> entries) throws Exception {
model.runAsync(() -> {
ShellControl sc = model.getFileSystem().getShell().orElseThrow();
for (BrowserEntry entry : entries) {
var target = getTarget(entry.getRawFileEntry().getPath());
var c = CommandBuilder.of().add("tar");
if (toDirectory) {
c.add("-C").addFile(target);
}
c.add("-x").addIf(gz, "-z").add("-f");
c.addFile(entry.getRawFileEntry().getPath());
if (toDirectory) {
model.getFileSystem().mkdirs(target);
}
sc.command(c).withWorkingDirectory(model.getCurrentDirectory().getPath()).execute();
}
}, true);
model.runAsync(
() -> {
ShellControl sc = model.getFileSystem().getShell().orElseThrow();
for (BrowserEntry entry : entries) {
var target = getTarget(entry.getRawFileEntry().getPath());
var c = CommandBuilder.of().add("tar");
if (toDirectory) {
c.add("-C").addFile(target);
}
c.add("-x").addIf(gz, "-z").add("-f");
c.addFile(entry.getRawFileEntry().getPath());
if (toDirectory) {
model.getFileSystem().mkdirs(target);
}
sc.command(c)
.withWorkingDirectory(
model.getCurrentDirectory().getPath())
.execute();
}
},
true);
}
@Override
@@ -73,9 +79,12 @@ public class BaseUntarAction implements ApplicationPathAction, LeafAction {
@Override
public boolean isApplicable(OpenFileSystemModel model, List<BrowserEntry> entries) {
if (gz) {
return entries.stream().allMatch(entry -> entry.getRawFileEntry().getPath().endsWith(".tar.gz") || entry.getRawFileEntry().getPath().endsWith(".tgz"));
return entries.stream()
.allMatch(entry -> entry.getRawFileEntry().getPath().endsWith(".tar.gz")
|| entry.getRawFileEntry().getPath().endsWith(".tgz"));
}
return entries.stream().allMatch(entry -> entry.getRawFileEntry().getPath().endsWith(".tar"));
return entries.stream()
.allMatch(entry -> entry.getRawFileEntry().getPath().endsWith(".tar"));
}
}
@@ -7,9 +7,8 @@ import io.xpipe.app.browser.icon.BrowserIcons;
import io.xpipe.app.core.AppI18n;
import io.xpipe.core.process.CommandBuilder;
import io.xpipe.core.process.OsType;
import io.xpipe.core.store.FileNames;
import io.xpipe.ext.base.browser.ExecuteApplicationAction;
import javafx.beans.value.ObservableValue;
import javafx.scene.Node;
@@ -19,7 +18,9 @@ public abstract class BaseUnzipUnixAction extends ExecuteApplicationAction {
private final boolean toDirectory;
public BaseUnzipUnixAction(boolean toDirectory) {this.toDirectory = toDirectory;}
public BaseUnzipUnixAction(boolean toDirectory) {
this.toDirectory = toDirectory;
}
@Override
public Node getIcon(OpenFileSystemModel model, List<BrowserEntry> entries) {
@@ -38,7 +39,9 @@ public abstract class BaseUnzipUnixAction extends ExecuteApplicationAction {
@Override
protected CommandBuilder createCommand(OpenFileSystemModel model, BrowserEntry entry) {
var command = CommandBuilder.of().add("unzip", "-o").addFile(entry.getRawFileEntry().getPath());
var command = CommandBuilder.of()
.add("unzip", "-o")
.addFile(entry.getRawFileEntry().getPath());
if (toDirectory) {
command.add("-d").addFile(getTarget(entry.getRawFileEntry().getPath()));
}
@@ -63,7 +66,8 @@ public abstract class BaseUnzipUnixAction extends ExecuteApplicationAction {
@Override
public boolean isApplicable(OpenFileSystemModel model, List<BrowserEntry> entries) {
return entries.stream().allMatch(entry -> entry.getRawFileEntry().getPath().endsWith(".zip"))
return entries.stream()
.allMatch(entry -> entry.getRawFileEntry().getPath().endsWith(".zip"))
&& !model.getFileSystem().getShell().orElseThrow().getOsType().equals(OsType.WINDOWS);
}
}
@@ -10,8 +10,7 @@ import io.xpipe.core.process.CommandBuilder;
import io.xpipe.core.process.OsType;
import io.xpipe.core.process.ShellControl;
import io.xpipe.core.process.ShellDialects;
import io.xpipe.core.store.FilePath;
import io.xpipe.ext.base.browser.ExecuteApplicationAction;
import javafx.beans.value.ObservableValue;
import javafx.scene.Node;
@@ -21,7 +20,9 @@ public abstract class BaseUnzipWindowsAction implements LeafAction {
private final boolean toDirectory;
public BaseUnzipWindowsAction(boolean toDirectory) {this.toDirectory = toDirectory;}
public BaseUnzipWindowsAction(boolean toDirectory) {
this.toDirectory = toDirectory;
}
@Override
public Node getIcon(OpenFileSystemModel model, List<BrowserEntry> entries) {
@@ -30,20 +31,22 @@ public abstract class BaseUnzipWindowsAction implements LeafAction {
@Override
public void execute(OpenFileSystemModel model, List<BrowserEntry> entries) throws Exception {
model.runAsync(() -> {
var sc = model.getFileSystem().getShell().orElseThrow();
if (ShellDialects.isPowershell(sc)) {
for (BrowserEntry entry : entries) {
runCommand(sc, model, entry);
}
} else {
try (var sub = sc.subShell(ShellDialects.POWERSHELL)) {
for (BrowserEntry entry : entries) {
runCommand(sub, model, entry);
model.runAsync(
() -> {
var sc = model.getFileSystem().getShell().orElseThrow();
if (ShellDialects.isPowershell(sc)) {
for (BrowserEntry entry : entries) {
runCommand(sc, model, entry);
}
} else {
try (var sub = sc.subShell(ShellDialects.POWERSHELL)) {
for (BrowserEntry entry : entries) {
runCommand(sub, model, entry);
}
}
}
}
}
}, true);
},
true);
}
private void runCommand(ShellControl sc, OpenFileSystemModel model, BrowserEntry entry) throws Exception {
@@ -53,7 +56,9 @@ public abstract class BaseUnzipWindowsAction implements LeafAction {
command.add("-DestinationPath").addFile(target);
}
command.add("-Path").addFile(entry.getRawFileEntry().getPath());
sc.command(command).withWorkingDirectory(model.getCurrentDirectory().getPath()).execute();
sc.command(command)
.withWorkingDirectory(model.getCurrentDirectory().getPath())
.execute();
}
@Override
@@ -74,7 +79,8 @@ public abstract class BaseUnzipWindowsAction implements LeafAction {
@Override
public boolean isApplicable(OpenFileSystemModel model, List<BrowserEntry> entries) {
return entries.stream().allMatch(entry -> entry.getRawFileEntry().getPath().endsWith(".zip"))
return entries.stream()
.allMatch(entry -> entry.getRawFileEntry().getPath().endsWith(".zip"))
&& model.getFileSystem().getShell().orElseThrow().getOsType().equals(OsType.WINDOWS);
}
}
@@ -51,7 +51,8 @@ public class SimpleScriptStore extends ScriptStore implements ShellInitCommand.T
if (isCompatible(shellControl)) {
var shebang = getCommands().startsWith("#");
// Fix new lines and shebang
var fixedCommands = getCommands().lines()
var fixedCommands = getCommands()
.lines()
.skip(shebang ? 1 : 0)
.collect(Collectors.joining(
shellControl.getShellDialect().getNewLine().getNewLineString()));
@@ -91,8 +92,9 @@ public class SimpleScriptStore extends ScriptStore implements ShellInitCommand.T
var added = all.add(ref);
// Prevent loop
if (added) {
getEffectiveScripts().stream().filter(scriptStoreDataStoreEntryRef -> !all.contains(scriptStoreDataStoreEntryRef)).forEach(
scriptStoreDataStoreEntryRef -> {
getEffectiveScripts().stream()
.filter(scriptStoreDataStoreEntryRef -> !all.contains(scriptStoreDataStoreEntryRef))
.forEach(scriptStoreDataStoreEntryRef -> {
scriptStoreDataStoreEntryRef.getStore().queryFlattenedScripts(all);
});
all.remove(ref);
+8 -3
View File
@@ -4,6 +4,7 @@ import io.xpipe.app.ext.DataStorageExtensionProvider;
import io.xpipe.app.ext.DataStoreProvider;
import io.xpipe.ext.base.action.*;
import io.xpipe.ext.base.browser.*;
import io.xpipe.ext.base.browser.compress.*;
import io.xpipe.ext.base.desktop.DesktopApplicationStoreProvider;
import io.xpipe.ext.base.desktop.DesktopCommandStoreProvider;
import io.xpipe.ext.base.desktop.DesktopEnvironmentStoreProvider;
@@ -12,7 +13,6 @@ import io.xpipe.ext.base.service.*;
import io.xpipe.ext.base.store.StorePauseAction;
import io.xpipe.ext.base.store.StoreStartAction;
import io.xpipe.ext.base.store.StoreStopAction;
import io.xpipe.ext.base.browser.compress.*;
open module io.xpipe.ext.base {
exports io.xpipe.ext.base;
@@ -55,7 +55,9 @@ open module io.xpipe.ext.base {
CopyAction,
CopyPathAction,
PasteAction,
NewItemAction, FileCompressAction, DirectoryCompressAction,
NewItemAction,
FileCompressAction,
DirectoryCompressAction,
RenameAction,
DeleteAction,
DeleteLinkAction,
@@ -63,7 +65,10 @@ open module io.xpipe.ext.base {
UnzipDirectoryUnixAction,
UnzipHereWindowsAction,
UnzipDirectoryWindowsAction,
UntarHereAction, UntarGzHereAction, UntarDirectoryAction, UntarGzDirectoryAction,
UntarHereAction,
UntarGzHereAction,
UntarDirectoryAction,
UntarGzDirectoryAction,
JavapAction,
JarAction;
provides ActionProvider with