From 830745adbe873f170d356d61f0e0974f961506b7 Mon Sep 17 00:00:00 2001 From: crschnick Date: Sun, 6 Oct 2024 00:38:26 +0000 Subject: [PATCH] Rework compress actions --- .../browser/ExecuteApplicationAction.java | 3 +- .../xpipe/ext/base/browser/UnzipAction.java | 52 -------- .../BaseCompressAction.java} | 116 ++++++++++++++---- .../browser/compress/BaseUntarAction.java | 81 ++++++++++++ .../browser/compress/BaseUnzipUnixAction.java | 69 +++++++++++ .../compress/BaseUnzipWindowsAction.java | 80 ++++++++++++ .../compress/DirectoryCompressAction.java | 8 ++ .../browser/compress/FileCompressAction.java | 8 ++ .../compress/UntarDirectoryAction.java | 8 ++ .../compress/UntarGzDirectoryAction.java | 8 ++ .../browser/compress/UntarGzHereAction.java | 8 ++ .../browser/compress/UntarHereAction.java | 8 ++ .../compress/UnzipDirectoryUnixAction.java | 8 ++ .../compress/UnzipDirectoryWindowsAction.java | 8 ++ .../browser/compress/UnzipHereUnixAction.java | 8 ++ .../compress/UnzipHereWindowsAction.java | 8 ++ ext/base/src/main/java/module-info.java | 10 +- lang/base/strings/translations_da.properties | 5 + lang/base/strings/translations_de.properties | 5 + lang/base/strings/translations_en.properties | 5 + lang/base/strings/translations_es.properties | 5 + lang/base/strings/translations_fr.properties | 5 + lang/base/strings/translations_it.properties | 5 + lang/base/strings/translations_ja.properties | 5 + lang/base/strings/translations_nl.properties | 5 + lang/base/strings/translations_pt.properties | 5 + lang/base/strings/translations_ru.properties | 5 + lang/base/strings/translations_tr.properties | 5 + lang/base/strings/translations_zh.properties | 5 + 29 files changed, 471 insertions(+), 80 deletions(-) delete mode 100644 ext/base/src/main/java/io/xpipe/ext/base/browser/UnzipAction.java rename ext/base/src/main/java/io/xpipe/ext/base/browser/{CompressAction.java => compress/BaseCompressAction.java} (65%) create mode 100644 ext/base/src/main/java/io/xpipe/ext/base/browser/compress/BaseUntarAction.java create mode 100644 ext/base/src/main/java/io/xpipe/ext/base/browser/compress/BaseUnzipUnixAction.java create mode 100644 ext/base/src/main/java/io/xpipe/ext/base/browser/compress/BaseUnzipWindowsAction.java create mode 100644 ext/base/src/main/java/io/xpipe/ext/base/browser/compress/DirectoryCompressAction.java create mode 100644 ext/base/src/main/java/io/xpipe/ext/base/browser/compress/FileCompressAction.java create mode 100644 ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UntarDirectoryAction.java create mode 100644 ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UntarGzDirectoryAction.java create mode 100644 ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UntarGzHereAction.java create mode 100644 ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UntarHereAction.java create mode 100644 ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UnzipDirectoryUnixAction.java create mode 100644 ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UnzipDirectoryWindowsAction.java create mode 100644 ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UnzipHereUnixAction.java create mode 100644 ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UnzipHereWindowsAction.java diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/ExecuteApplicationAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/ExecuteApplicationAction.java index 85e480c6c..ca45ac4d2 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/browser/ExecuteApplicationAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/ExecuteApplicationAction.java @@ -4,6 +4,7 @@ import io.xpipe.app.browser.action.ApplicationPathAction; import io.xpipe.app.browser.action.LeafAction; import io.xpipe.app.browser.file.BrowserEntry; import io.xpipe.app.browser.fs.OpenFileSystemModel; +import io.xpipe.core.process.CommandBuilder; import io.xpipe.core.process.ShellControl; import java.util.List; @@ -31,5 +32,5 @@ public abstract class ExecuteApplicationAction implements LeafAction, Applicatio return false; } - protected abstract String createCommand(OpenFileSystemModel model, BrowserEntry entry); + protected abstract CommandBuilder createCommand(OpenFileSystemModel model, BrowserEntry entry); } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/UnzipAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/UnzipAction.java deleted file mode 100644 index 2dfa938f9..000000000 --- a/ext/base/src/main/java/io/xpipe/ext/base/browser/UnzipAction.java +++ /dev/null @@ -1,52 +0,0 @@ -package io.xpipe.ext.base.browser; - -import io.xpipe.app.browser.file.BrowserEntry; -import io.xpipe.app.browser.fs.OpenFileSystemModel; -import io.xpipe.app.browser.icon.BrowserIconFileType; -import io.xpipe.core.process.OsType; -import io.xpipe.core.store.FileNames; - -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.value.ObservableValue; - -import java.util.List; - -public class UnzipAction extends ExecuteApplicationAction implements FileTypeAction { - - @Override - public String getExecutable() { - return "unzip"; - } - - @Override - protected boolean refresh() { - return true; - } - - @Override - protected String createCommand(OpenFileSystemModel model, BrowserEntry entry) { - return "unzip -o " + FileNames.quoteIfNecessary(entry.getRawFileEntry().getPath()) + " -d " - + FileNames.quoteIfNecessary(FileNames.getBaseName(entry.getFileName())); - } - - @Override - public Category getCategory() { - return Category.CUSTOM; - } - - @Override - public ObservableValue getName(OpenFileSystemModel model, List entries) { - return new SimpleStringProperty("unzip [...]"); - } - - @Override - public boolean isApplicable(OpenFileSystemModel model, List entries) { - return FileTypeAction.super.isApplicable(model, entries) - && !model.getFileSystem().getShell().orElseThrow().getOsType().equals(OsType.WINDOWS); - } - - @Override - public BrowserIconFileType getType() { - return BrowserIconFileType.byId("zip"); - } -} diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/CompressAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/BaseCompressAction.java similarity index 65% rename from ext/base/src/main/java/io/xpipe/ext/base/browser/CompressAction.java rename to ext/base/src/main/java/io/xpipe/ext/base/browser/compress/BaseCompressAction.java index 48a6301c4..ff3d5d1d0 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/browser/CompressAction.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/BaseCompressAction.java @@ -1,16 +1,18 @@ -package io.xpipe.ext.base.browser; +package io.xpipe.ext.base.browser.compress; import io.xpipe.app.browser.action.BranchAction; import io.xpipe.app.browser.action.BrowserAction; import io.xpipe.app.browser.action.LeafAction; import io.xpipe.app.browser.file.BrowserEntry; import io.xpipe.app.browser.fs.OpenFileSystemModel; -import io.xpipe.app.browser.icon.BrowserIcons; import io.xpipe.app.comp.base.ModalOverlayComp; import io.xpipe.app.core.AppI18n; import io.xpipe.app.fxcomps.Comp; import io.xpipe.app.util.CommandSupport; -import io.xpipe.core.process.*; +import io.xpipe.core.process.CommandBuilder; +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; @@ -20,11 +22,19 @@ import org.kordamp.ikonli.javafx.FontIcon; import java.util.List; -public class CompressAction implements BrowserAction, BranchAction { +public abstract class BaseCompressAction implements BrowserAction, BranchAction { + + private final boolean directory; + + public BaseCompressAction(boolean directory) {this.directory = directory;} @Override public void init(OpenFileSystemModel model) throws Exception { var sc = model.getFileSystem().getShell().orElseThrow(); + + var foundTar = CommandSupport.findProgram(sc, "tar"); + model.getCache().getInstalledApplications().put("tar", foundTar.isPresent()); + if (sc.getOsType() == OsType.WINDOWS) { var found = CommandSupport.findProgram(sc, "7z"); if (found.isPresent()) { @@ -39,7 +49,7 @@ public class CompressAction implements BrowserAction, BranchAction { } } else { var found = CommandSupport.findProgram(sc, "zip"); - model.getCache().getInstalledApplications().put("zip",found.isPresent()); + model.getCache().getInstalledApplications().put("zip", found.isPresent()); } } @@ -55,12 +65,17 @@ public class CompressAction implements BrowserAction, BranchAction { @Override public ObservableValue getName(OpenFileSystemModel model, List entries) { - return AppI18n.observable("compress"); + return AppI18n.observable(directory ? "compressContents" : "compress"); } @Override public boolean isApplicable(OpenFileSystemModel model, List entries) { - return entries.size() >= 1; + 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)))) { + return false; + } + + return directory ? entries.size() == 1 && entries.getFirst().getRawFileEntry().getKind() == FileKind.DIRECTORY : entries.size() >= 1; } @Override @@ -69,13 +84,13 @@ public class CompressAction implements BrowserAction, BranchAction { new Windows7zAction(), new WindowsZipAction(), new UnixZipAction(), - new TarBasedAction() { + new TarBasedAction(false) { @Override protected String getExtension() { return "tar"; } }, - new TarBasedAction() { + new TarBasedAction(true) { @Override protected String getExtension() { @@ -88,7 +103,7 @@ public class CompressAction implements BrowserAction, BranchAction { @Override public void execute(OpenFileSystemModel model, List entries) { - var name = new SimpleStringProperty(); + var name = new SimpleStringProperty(directory ? entries.getFirst().getFileName() : null); model.getOverlay() .setValue(new ModalOverlayComp.OverlayContent( "base.archiveName", @@ -134,7 +149,11 @@ public class CompressAction implements BrowserAction, BranchAction { 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); - command.addFile(rel); + if (directory) { + command.addQuoted(rel.toDirectory().toWindows() + "*"); + } else { + command.addFile(rel.toWindows()); + } if (i != entries.size() - 1) { command.add(","); } @@ -169,13 +188,25 @@ public class CompressAction implements BrowserAction, BranchAction { protected void create(String fileName, OpenFileSystemModel model, List entries) { var base = new FilePath(model.getCurrentDirectory().getPath()); var target = base.join(fileName); - var command = CommandBuilder.of().add("zip").addFile(target); + 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); - command.addFile(rel); + var rel = new FilePath(entries.get(i).getRawFileEntry().getPath()).relativize(base).toUnix(); + if (directory) { + command.add("."); + } else { + command.addFile(rel); + } } + command.add(">").addFile(target); - model.runCommandAsync(command, true); + if (directory) { + model.runAsync(() -> { + var sc = model.getFileSystem().getShell().orElseThrow(); + sc.command(command).withWorkingDirectory(entries.getFirst().getRawFileEntry().getPath()).execute(); + }, true); + } else { + model.runCommandAsync(command, true); + } } @Override @@ -183,9 +214,14 @@ public class CompressAction implements BrowserAction, BranchAction { return "zip"; } + @Override + public boolean isActive(OpenFileSystemModel model, List entries) { + return model.getCache().getInstalledApplications().get("zip"); + } + @Override public boolean isApplicable(OpenFileSystemModel model, List entries) { - return model.getFileSystem().getShell().orElseThrow().getOsType() != OsType.WINDOWS && model.getCache().getInstalledApplications().get("zip"); + return model.getFileSystem().getShell().orElseThrow().getOsType() != OsType.WINDOWS; } } @@ -195,10 +231,14 @@ public class CompressAction implements BrowserAction, BranchAction { protected void create(String fileName, OpenFileSystemModel model, List 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").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); - command.addFile(rel); + if (directory) { + command.addQuoted(".\\" + rel.toDirectory().toWindows() + "*"); + } else { + command.addFile(rel.toWindows()); + } } model.runCommandAsync(command, true); @@ -209,23 +249,51 @@ public class CompressAction implements BrowserAction, BranchAction { return "7z"; } + @Override + public boolean isActive(OpenFileSystemModel model, List entries) { + return model.getCache().getMultiPurposeCache().containsKey("7zExecutable"); + } + @Override public boolean isApplicable(OpenFileSystemModel model, List entries) { - return model.getFileSystem().getShell().orElseThrow().getOsType() == OsType.WINDOWS && model.getCache().getMultiPurposeCache().containsKey("7zExecutable"); + return model.getFileSystem().getShell().orElseThrow().getOsType() == OsType.WINDOWS; } } private abstract class TarBasedAction extends Action { + private final boolean gz; + + private TarBasedAction(boolean gz) {this.gz = gz;} + @Override protected void create(String fileName, OpenFileSystemModel model, List entries) { - var command = CommandBuilder.of().add("tar", "-a", "-c", "-f").addFile(fileName); + var tar = CommandBuilder.of().add("tar", "-c", "-f").addIf(gz, "-z").addFile(fileName); var base = new FilePath(model.getCurrentDirectory().getPath()); - for (BrowserEntry entry : entries) { - var rel = new FilePath(entry.getRawFileEntry().getPath()).relativize(base); - command.addFile(rel); + + if (directory) { + var dir = new FilePath(entries.getFirst().getRawFileEntry().getPath()).toDirectory().toUnix(); + var command = CommandBuilder.of().add("find").addFile(dir).add("|", "sed", "s,^" + dir + ",,", "|"); + command.add(tar).add("-C").addFile(dir).add("-T", "-"); + model.runCommandAsync(command, true); + } else { + var command = CommandBuilder.of().add(tar); + for (BrowserEntry entry : entries) { + var rel = new FilePath(entry.getRawFileEntry().getPath()).relativize(base); + command.addFile(rel); + } + model.runCommandAsync(command, true); } - model.runCommandAsync(command, true); + } + + @Override + public boolean isActive(OpenFileSystemModel model, List entries) { + return model.getCache().getInstalledApplications().get("tar"); + } + + @Override + public boolean isApplicable(OpenFileSystemModel model, List entries) { + return model.getFileSystem().getShell().orElseThrow().getOsType() != OsType.WINDOWS || !directory; } } } diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/BaseUntarAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/BaseUntarAction.java new file mode 100644 index 000000000..b9ec85083 --- /dev/null +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/BaseUntarAction.java @@ -0,0 +1,81 @@ +package io.xpipe.ext.base.browser.compress; + +import io.xpipe.app.browser.action.ApplicationPathAction; +import io.xpipe.app.browser.action.LeafAction; +import io.xpipe.app.browser.file.BrowserEntry; +import io.xpipe.app.browser.fs.OpenFileSystemModel; +import io.xpipe.app.browser.icon.BrowserIconFileType; +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; + +import java.util.List; + +public class BaseUntarAction implements ApplicationPathAction, LeafAction { + + private final boolean gz; + private final boolean toDirectory; + + public BaseUntarAction(boolean gz, boolean toDirectory) { + this.gz = gz; + this.toDirectory = toDirectory; + } + + @Override + public Node getIcon(OpenFileSystemModel model, List entries) { + return BrowserIcons.createIcon(BrowserIconFileType.byId("zip")).createRegion(); + } + + @Override + public String getExecutable() { + return "tar"; + } + + @Override + public void execute(OpenFileSystemModel model, List 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("-xv").addIf(gz, "-z").add("-f"); + c.addFile(entry.getRawFileEntry().getPath()); + if (toDirectory) { + model.getFileSystem().mkdirs(target); + } + sc.command(c).execute(); + } + }, true); + } + + @Override + public Category getCategory() { + return Category.CUSTOM; + } + + @Override + public ObservableValue getName(OpenFileSystemModel model, List entries) { + var sep = model.getFileSystem().getShell().orElseThrow().getOsType().getFileSystemSeparator(); + var dir = entries.size() > 1 ? "[...]" : getTarget(entries.getFirst().getFileName()) + sep; + return toDirectory ? AppI18n.observable("untarDirectory", dir) : AppI18n.observable("untarHere"); + } + + private String getTarget(String name) { + return name.replaceAll("\\.tar$", "").replaceAll("\\.tar.gz$", "").replaceAll("\\.tgz$", ""); + } + + @Override + public boolean isApplicable(OpenFileSystemModel model, List 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")); + } +} diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/BaseUnzipUnixAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/BaseUnzipUnixAction.java new file mode 100644 index 000000000..eb4bd8c08 --- /dev/null +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/BaseUnzipUnixAction.java @@ -0,0 +1,69 @@ +package io.xpipe.ext.base.browser.compress; + +import io.xpipe.app.browser.file.BrowserEntry; +import io.xpipe.app.browser.fs.OpenFileSystemModel; +import io.xpipe.app.browser.icon.BrowserIconFileType; +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; + +import java.util.List; + +public abstract class BaseUnzipUnixAction extends ExecuteApplicationAction { + + private final boolean toDirectory; + + public BaseUnzipUnixAction(boolean toDirectory) {this.toDirectory = toDirectory;} + + @Override + public Node getIcon(OpenFileSystemModel model, List entries) { + return BrowserIcons.createIcon(BrowserIconFileType.byId("zip")).createRegion(); + } + + @Override + public String getExecutable() { + return "unzip"; + } + + @Override + protected boolean refresh() { + return true; + } + + @Override + protected CommandBuilder createCommand(OpenFileSystemModel model, BrowserEntry entry) { + var command = CommandBuilder.of().add("unzip", "-o").addFile(entry.getRawFileEntry().getPath()); + if (toDirectory) { + command.add("-d").addFile(getTarget(entry.getRawFileEntry().getPath())); + } + return command; + } + + @Override + public Category getCategory() { + return Category.CUSTOM; + } + + @Override + public ObservableValue getName(OpenFileSystemModel model, List entries) { + var sep = model.getFileSystem().getShell().orElseThrow().getOsType().getFileSystemSeparator(); + var dir = entries.size() > 1 ? "[...]" : getTarget(entries.getFirst().getFileName()) + sep; + return toDirectory ? AppI18n.observable("unzipDirectory", dir) : AppI18n.observable("unzipHere"); + } + + private String getTarget(String name) { + return name.replaceAll("\\.zip$", ""); + } + + @Override + public boolean isApplicable(OpenFileSystemModel model, List entries) { + return entries.stream().allMatch(entry -> entry.getRawFileEntry().getPath().endsWith(".zip")) + && !model.getFileSystem().getShell().orElseThrow().getOsType().equals(OsType.WINDOWS); + } +} diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/BaseUnzipWindowsAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/BaseUnzipWindowsAction.java new file mode 100644 index 000000000..5642599d4 --- /dev/null +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/BaseUnzipWindowsAction.java @@ -0,0 +1,80 @@ +package io.xpipe.ext.base.browser.compress; + +import io.xpipe.app.browser.action.LeafAction; +import io.xpipe.app.browser.file.BrowserEntry; +import io.xpipe.app.browser.fs.OpenFileSystemModel; +import io.xpipe.app.browser.icon.BrowserIconFileType; +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.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; + +import java.util.List; + +public abstract class BaseUnzipWindowsAction implements LeafAction { + + private final boolean toDirectory; + + public BaseUnzipWindowsAction(boolean toDirectory) {this.toDirectory = toDirectory;} + + @Override + public Node getIcon(OpenFileSystemModel model, List entries) { + return BrowserIcons.createIcon(BrowserIconFileType.byId("zip")).createRegion(); + } + + @Override + public void execute(OpenFileSystemModel model, List 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); + } + } + } + }, true); + } + + private void runCommand(ShellControl sc, OpenFileSystemModel model, BrowserEntry entry) throws Exception { + var command = CommandBuilder.of().add("Expand-Archive", "-Force"); + if (toDirectory) { + var target = getTarget(entry.getRawFileEntry().getPath()); + command.add("-DestinationPath").addFile(target); + } + command.add("-Path").addFile(entry.getRawFileEntry().getPath()); + sc.command(command).withWorkingDirectory(model.getCurrentDirectory().getPath()).execute(); + } + + @Override + public Category getCategory() { + return Category.CUSTOM; + } + + @Override + public ObservableValue getName(OpenFileSystemModel model, List entries) { + var sep = model.getFileSystem().getShell().orElseThrow().getOsType().getFileSystemSeparator(); + var dir = entries.size() > 1 ? "[...]" : getTarget(entries.getFirst().getFileName()) + sep; + return toDirectory ? AppI18n.observable("unzipDirectory", dir) : AppI18n.observable("unzipHere"); + } + + private String getTarget(String name) { + return name.replaceAll("\\.zip$", ""); + } + + @Override + public boolean isApplicable(OpenFileSystemModel model, List entries) { + return entries.stream().allMatch(entry -> entry.getRawFileEntry().getPath().endsWith(".zip")) + && model.getFileSystem().getShell().orElseThrow().getOsType().equals(OsType.WINDOWS); + } +} diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/DirectoryCompressAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/DirectoryCompressAction.java new file mode 100644 index 000000000..bb4bbc25f --- /dev/null +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/DirectoryCompressAction.java @@ -0,0 +1,8 @@ +package io.xpipe.ext.base.browser.compress; + +public class DirectoryCompressAction extends BaseCompressAction { + + public DirectoryCompressAction() { + super(true); + } +} diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/FileCompressAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/FileCompressAction.java new file mode 100644 index 000000000..f51f55b77 --- /dev/null +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/FileCompressAction.java @@ -0,0 +1,8 @@ +package io.xpipe.ext.base.browser.compress; + +public class FileCompressAction extends BaseCompressAction { + + public FileCompressAction() { + super(false); + } +} diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UntarDirectoryAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UntarDirectoryAction.java new file mode 100644 index 000000000..73d405db1 --- /dev/null +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UntarDirectoryAction.java @@ -0,0 +1,8 @@ +package io.xpipe.ext.base.browser.compress; + +public class UntarDirectoryAction extends BaseUntarAction { + + public UntarDirectoryAction() { + super(false, true); + } +} diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UntarGzDirectoryAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UntarGzDirectoryAction.java new file mode 100644 index 000000000..5cec156df --- /dev/null +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UntarGzDirectoryAction.java @@ -0,0 +1,8 @@ +package io.xpipe.ext.base.browser.compress; + +public class UntarGzDirectoryAction extends BaseUntarAction { + + public UntarGzDirectoryAction() { + super(true, true); + } +} diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UntarGzHereAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UntarGzHereAction.java new file mode 100644 index 000000000..2edf61b3f --- /dev/null +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UntarGzHereAction.java @@ -0,0 +1,8 @@ +package io.xpipe.ext.base.browser.compress; + +public class UntarGzHereAction extends BaseUntarAction { + + public UntarGzHereAction() { + super(true, false); + } +} diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UntarHereAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UntarHereAction.java new file mode 100644 index 000000000..0940b528a --- /dev/null +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UntarHereAction.java @@ -0,0 +1,8 @@ +package io.xpipe.ext.base.browser.compress; + +public class UntarHereAction extends BaseUntarAction { + + public UntarHereAction() { + super(false, false); + } +} diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UnzipDirectoryUnixAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UnzipDirectoryUnixAction.java new file mode 100644 index 000000000..c5e5e80e2 --- /dev/null +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UnzipDirectoryUnixAction.java @@ -0,0 +1,8 @@ +package io.xpipe.ext.base.browser.compress; + +public class UnzipDirectoryUnixAction extends BaseUnzipUnixAction { + + public UnzipDirectoryUnixAction() { + super(true); + } +} diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UnzipDirectoryWindowsAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UnzipDirectoryWindowsAction.java new file mode 100644 index 000000000..27ed331ed --- /dev/null +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UnzipDirectoryWindowsAction.java @@ -0,0 +1,8 @@ +package io.xpipe.ext.base.browser.compress; + +public class UnzipDirectoryWindowsAction extends BaseUnzipWindowsAction { + + public UnzipDirectoryWindowsAction() { + super(true); + } +} diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UnzipHereUnixAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UnzipHereUnixAction.java new file mode 100644 index 000000000..8c1780e49 --- /dev/null +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UnzipHereUnixAction.java @@ -0,0 +1,8 @@ +package io.xpipe.ext.base.browser.compress; + +public class UnzipHereUnixAction extends BaseUnzipUnixAction { + + public UnzipHereUnixAction() { + super(false); + } +} diff --git a/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UnzipHereWindowsAction.java b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UnzipHereWindowsAction.java new file mode 100644 index 000000000..3435916cd --- /dev/null +++ b/ext/base/src/main/java/io/xpipe/ext/base/browser/compress/UnzipHereWindowsAction.java @@ -0,0 +1,8 @@ +package io.xpipe.ext.base.browser.compress; + +public class UnzipHereWindowsAction extends BaseUnzipWindowsAction { + + public UnzipHereWindowsAction() { + super(false); + } +} diff --git a/ext/base/src/main/java/module-info.java b/ext/base/src/main/java/module-info.java index 268bd7b8c..3af815b4e 100644 --- a/ext/base/src/main/java/module-info.java +++ b/ext/base/src/main/java/module-info.java @@ -12,6 +12,7 @@ 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; @@ -54,12 +55,15 @@ open module io.xpipe.ext.base { CopyAction, CopyPathAction, PasteAction, - NewItemAction, - CompressAction, + NewItemAction, FileCompressAction, DirectoryCompressAction, RenameAction, DeleteAction, DeleteLinkAction, - UnzipAction, + UnzipHereUnixAction, + UnzipDirectoryUnixAction, + UnzipHereWindowsAction, + UnzipDirectoryWindowsAction, + UntarHereAction, UntarGzHereAction, UntarDirectoryAction, UntarGzDirectoryAction, JavapAction, JarAction; provides ActionProvider with diff --git a/lang/base/strings/translations_da.properties b/lang/base/strings/translations_da.properties index 5e8dbb401..c76dd0efe 100644 --- a/lang/base/strings/translations_da.properties +++ b/lang/base/strings/translations_da.properties @@ -180,3 +180,8 @@ hub=Hub script=script archiveName=Arkivets navn compress=Komprimere +compressContents=Komprimere indhold +untarHere=Untar her +untarDirectory=Untar to $DIR$ +unzipDirectory=Pak ud til $DIR$ +unzipHere=Pak ud her diff --git a/lang/base/strings/translations_de.properties b/lang/base/strings/translations_de.properties index 9ffa7119b..bf978e4b7 100644 --- a/lang/base/strings/translations_de.properties +++ b/lang/base/strings/translations_de.properties @@ -171,3 +171,8 @@ hub=Hub script=skript archiveName=Name des Archivs compress=Komprimieren +compressContents=Inhalte komprimieren +untarHere=Untar hier +untarDirectory=Untar zu $DIR$ +unzipDirectory=Entpacken nach $DIR$ +unzipHere=Hier entpacken diff --git a/lang/base/strings/translations_en.properties b/lang/base/strings/translations_en.properties index dd9bf2dde..bbd4f7278 100644 --- a/lang/base/strings/translations_en.properties +++ b/lang/base/strings/translations_en.properties @@ -170,5 +170,10 @@ hub=Hub script=script archiveName=Archive name compress=Compress +compressContents=Compress contents +untarHere=Untar here +untarDirectory=Untar to $DIR$ +unzipDirectory=Unzip to $DIR$ +unzipHere=Unzip here diff --git a/lang/base/strings/translations_es.properties b/lang/base/strings/translations_es.properties index 9c6966088..e2bb98b9d 100644 --- a/lang/base/strings/translations_es.properties +++ b/lang/base/strings/translations_es.properties @@ -169,3 +169,8 @@ hub=Hub script=script archiveName=Nombre de archivo compress=Comprime +compressContents=Comprimir contenidos +untarHere=Untar aquí +untarDirectory=Untar a $DIR$ +unzipDirectory=Descomprimir a $DIR$ +unzipHere=Descomprimir aquí diff --git a/lang/base/strings/translations_fr.properties b/lang/base/strings/translations_fr.properties index 4de542195..0b30403d8 100644 --- a/lang/base/strings/translations_fr.properties +++ b/lang/base/strings/translations_fr.properties @@ -169,3 +169,8 @@ hub=Hub script=script archiveName=Nom de l'archive compress=Compresser +compressContents=Compresser le contenu +untarHere=Untar ici +untarDirectory=Untar to $DIR$ +unzipDirectory=Décompresser pour $DIR$ +unzipHere=Décompresse ici diff --git a/lang/base/strings/translations_it.properties b/lang/base/strings/translations_it.properties index 822db5bc6..6a60ac414 100644 --- a/lang/base/strings/translations_it.properties +++ b/lang/base/strings/translations_it.properties @@ -169,3 +169,8 @@ hub=Hub script=script archiveName=Nome dell'archivio compress=Comprimere +compressContents=Comprimere i contenuti +untarHere=Non scrivere qui +untarDirectory=Untar a $DIR$ +unzipDirectory=Decomprimere in $DIR$ +unzipHere=Decomprimi qui diff --git a/lang/base/strings/translations_ja.properties b/lang/base/strings/translations_ja.properties index 14caaab3d..85f05c894 100644 --- a/lang/base/strings/translations_ja.properties +++ b/lang/base/strings/translations_ja.properties @@ -169,3 +169,8 @@ hub=ハブ script=スクリプト archiveName=アーカイブ名 compress=圧縮する +compressContents=コンテンツを圧縮する +untarHere=ここをクリック +untarDirectory=未対応$DIR$ +unzipDirectory=解凍先$DIR$ +unzipHere=ここで解凍する diff --git a/lang/base/strings/translations_nl.properties b/lang/base/strings/translations_nl.properties index d581566e4..cf63c1928 100644 --- a/lang/base/strings/translations_nl.properties +++ b/lang/base/strings/translations_nl.properties @@ -169,3 +169,8 @@ hub=Hub script=script archiveName=Naam archief compress=Comprimeren +compressContents=Inhoud comprimeren +untarHere=Untar hier +untarDirectory=Naar $DIR$ +unzipDirectory=Uitpakken naar $DIR$ +unzipHere=Hier uitpakken diff --git a/lang/base/strings/translations_pt.properties b/lang/base/strings/translations_pt.properties index be2832b3a..7ed09ba83 100644 --- a/lang/base/strings/translations_pt.properties +++ b/lang/base/strings/translations_pt.properties @@ -169,3 +169,8 @@ hub=Hub script=guião archiveName=Nome do arquivo compress=Comprimir +compressContents=Comprime o conteúdo +untarHere=Untar aqui +untarDirectory=Untar para $DIR$ +unzipDirectory=Descompacta para $DIR$ +unzipHere=Descompacta aqui diff --git a/lang/base/strings/translations_ru.properties b/lang/base/strings/translations_ru.properties index 2076a2f6d..b72622998 100644 --- a/lang/base/strings/translations_ru.properties +++ b/lang/base/strings/translations_ru.properties @@ -169,3 +169,8 @@ hub=Хаб script=скрипт archiveName=Название архива compress=Сжать +compressContents=Сжать содержимое +untarHere=Унтар здесь +untarDirectory=Унтар к $DIR$ +unzipDirectory=Разархивировать в $DIR$ +unzipHere=Распакуйте здесь diff --git a/lang/base/strings/translations_tr.properties b/lang/base/strings/translations_tr.properties index 18b028d91..766d664f8 100644 --- a/lang/base/strings/translations_tr.properties +++ b/lang/base/strings/translations_tr.properties @@ -169,3 +169,8 @@ hub=Hub script=senaryo archiveName=Arşiv adı compress=Sıkıştır +compressContents=İçeriği sıkıştır +untarHere=Untar burada +untarDirectory=Untar'a $DIR$ +unzipDirectory=Açmak için $DIR$ +unzipHere=Buradan açın diff --git a/lang/base/strings/translations_zh.properties b/lang/base/strings/translations_zh.properties index 462fecff8..12ef1c8ea 100644 --- a/lang/base/strings/translations_zh.properties +++ b/lang/base/strings/translations_zh.properties @@ -169,3 +169,8 @@ hub=枢纽 script=脚本 archiveName=档案名称 compress=压缩 +compressContents=压缩内容 +untarHere=点击此处 +untarDirectory=到$DIR$ +unzipDirectory=解压缩为$DIR$ +unzipHere=在此解压缩