mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-21 23:20:23 +00:00
Rework compress actions
This commit is contained in:
parent
f13eac1c75
commit
830745adbe
29 changed files with 471 additions and 80 deletions
|
@ -4,6 +4,7 @@ import io.xpipe.app.browser.action.ApplicationPathAction;
|
||||||
import io.xpipe.app.browser.action.LeafAction;
|
import io.xpipe.app.browser.action.LeafAction;
|
||||||
import io.xpipe.app.browser.file.BrowserEntry;
|
import io.xpipe.app.browser.file.BrowserEntry;
|
||||||
import io.xpipe.app.browser.fs.OpenFileSystemModel;
|
import io.xpipe.app.browser.fs.OpenFileSystemModel;
|
||||||
|
import io.xpipe.core.process.CommandBuilder;
|
||||||
import io.xpipe.core.process.ShellControl;
|
import io.xpipe.core.process.ShellControl;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -31,5 +32,5 @@ public abstract class ExecuteApplicationAction implements LeafAction, Applicatio
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract String createCommand(OpenFileSystemModel model, BrowserEntry entry);
|
protected abstract CommandBuilder createCommand(OpenFileSystemModel model, BrowserEntry entry);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<String> getName(OpenFileSystemModel model, List<BrowserEntry> entries) {
|
|
||||||
return new SimpleStringProperty("unzip [...]");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isApplicable(OpenFileSystemModel model, List<BrowserEntry> entries) {
|
|
||||||
return FileTypeAction.super.isApplicable(model, entries)
|
|
||||||
&& !model.getFileSystem().getShell().orElseThrow().getOsType().equals(OsType.WINDOWS);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BrowserIconFileType getType() {
|
|
||||||
return BrowserIconFileType.byId("zip");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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.BranchAction;
|
||||||
import io.xpipe.app.browser.action.BrowserAction;
|
import io.xpipe.app.browser.action.BrowserAction;
|
||||||
import io.xpipe.app.browser.action.LeafAction;
|
import io.xpipe.app.browser.action.LeafAction;
|
||||||
import io.xpipe.app.browser.file.BrowserEntry;
|
import io.xpipe.app.browser.file.BrowserEntry;
|
||||||
import io.xpipe.app.browser.fs.OpenFileSystemModel;
|
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.comp.base.ModalOverlayComp;
|
||||||
import io.xpipe.app.core.AppI18n;
|
import io.xpipe.app.core.AppI18n;
|
||||||
import io.xpipe.app.fxcomps.Comp;
|
import io.xpipe.app.fxcomps.Comp;
|
||||||
import io.xpipe.app.util.CommandSupport;
|
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 io.xpipe.core.store.FilePath;
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.beans.value.ObservableValue;
|
import javafx.beans.value.ObservableValue;
|
||||||
|
@ -20,11 +22,19 @@ import org.kordamp.ikonli.javafx.FontIcon;
|
||||||
|
|
||||||
import java.util.List;
|
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
|
@Override
|
||||||
public void init(OpenFileSystemModel model) throws Exception {
|
public void init(OpenFileSystemModel model) throws Exception {
|
||||||
var sc = model.getFileSystem().getShell().orElseThrow();
|
var sc = model.getFileSystem().getShell().orElseThrow();
|
||||||
|
|
||||||
|
var foundTar = CommandSupport.findProgram(sc, "tar");
|
||||||
|
model.getCache().getInstalledApplications().put("tar", foundTar.isPresent());
|
||||||
|
|
||||||
if (sc.getOsType() == OsType.WINDOWS) {
|
if (sc.getOsType() == OsType.WINDOWS) {
|
||||||
var found = CommandSupport.findProgram(sc, "7z");
|
var found = CommandSupport.findProgram(sc, "7z");
|
||||||
if (found.isPresent()) {
|
if (found.isPresent()) {
|
||||||
|
@ -39,7 +49,7 @@ public class CompressAction implements BrowserAction, BranchAction {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var found = CommandSupport.findProgram(sc, "zip");
|
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
|
@Override
|
||||||
public ObservableValue<String> getName(OpenFileSystemModel model, List<BrowserEntry> entries) {
|
public ObservableValue<String> getName(OpenFileSystemModel model, List<BrowserEntry> entries) {
|
||||||
return AppI18n.observable("compress");
|
return AppI18n.observable(directory ? "compressContents" : "compress");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isApplicable(OpenFileSystemModel model, List<BrowserEntry> entries) {
|
public boolean isApplicable(OpenFileSystemModel model, List<BrowserEntry> 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
|
@Override
|
||||||
|
@ -69,13 +84,13 @@ public class CompressAction implements BrowserAction, BranchAction {
|
||||||
new Windows7zAction(),
|
new Windows7zAction(),
|
||||||
new WindowsZipAction(),
|
new WindowsZipAction(),
|
||||||
new UnixZipAction(),
|
new UnixZipAction(),
|
||||||
new TarBasedAction() {
|
new TarBasedAction(false) {
|
||||||
@Override
|
@Override
|
||||||
protected String getExtension() {
|
protected String getExtension() {
|
||||||
return "tar";
|
return "tar";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new TarBasedAction() {
|
new TarBasedAction(true) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getExtension() {
|
protected String getExtension() {
|
||||||
|
@ -88,7 +103,7 @@ public class CompressAction implements BrowserAction, BranchAction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(OpenFileSystemModel model, List<BrowserEntry> entries) {
|
public void execute(OpenFileSystemModel model, List<BrowserEntry> entries) {
|
||||||
var name = new SimpleStringProperty();
|
var name = new SimpleStringProperty(directory ? entries.getFirst().getFileName() : null);
|
||||||
model.getOverlay()
|
model.getOverlay()
|
||||||
.setValue(new ModalOverlayComp.OverlayContent(
|
.setValue(new ModalOverlayComp.OverlayContent(
|
||||||
"base.archiveName",
|
"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");
|
var command = CommandBuilder.of().add("Compress-Archive", "-Force", "-DestinationPath").addFile(target).add("-Path");
|
||||||
for (int i = 0; i < entries.size(); i++) {
|
for (int i = 0; i < entries.size(); i++) {
|
||||||
var rel = new FilePath(entries.get(i).getRawFileEntry().getPath()).relativize(base);
|
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) {
|
if (i != entries.size() - 1) {
|
||||||
command.add(",");
|
command.add(",");
|
||||||
}
|
}
|
||||||
|
@ -169,13 +188,25 @@ public class CompressAction implements BrowserAction, BranchAction {
|
||||||
protected void create(String fileName, OpenFileSystemModel model, List<BrowserEntry> entries) {
|
protected void create(String fileName, OpenFileSystemModel model, List<BrowserEntry> entries) {
|
||||||
var base = new FilePath(model.getCurrentDirectory().getPath());
|
var base = new FilePath(model.getCurrentDirectory().getPath());
|
||||||
var target = base.join(fileName);
|
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++) {
|
for (int i = 0; i < entries.size(); i++) {
|
||||||
var rel = new FilePath(entries.get(i).getRawFileEntry().getPath()).relativize(base);
|
var rel = new FilePath(entries.get(i).getRawFileEntry().getPath()).relativize(base).toUnix();
|
||||||
command.addFile(rel);
|
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
|
@Override
|
||||||
|
@ -183,9 +214,14 @@ public class CompressAction implements BrowserAction, BranchAction {
|
||||||
return "zip";
|
return "zip";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActive(OpenFileSystemModel model, List<BrowserEntry> entries) {
|
||||||
|
return model.getCache().getInstalledApplications().get("zip");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isApplicable(OpenFileSystemModel model, List<BrowserEntry> entries) {
|
public boolean isApplicable(OpenFileSystemModel model, List<BrowserEntry> 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<BrowserEntry> entries) {
|
protected void create(String fileName, OpenFileSystemModel model, List<BrowserEntry> entries) {
|
||||||
var base = new FilePath(model.getCurrentDirectory().getPath());
|
var base = new FilePath(model.getCurrentDirectory().getPath());
|
||||||
var target = base.join(fileName);
|
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++) {
|
for (int i = 0; i < entries.size(); i++) {
|
||||||
var rel = new FilePath(entries.get(i).getRawFileEntry().getPath()).relativize(base);
|
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);
|
model.runCommandAsync(command, true);
|
||||||
|
@ -209,23 +249,51 @@ public class CompressAction implements BrowserAction, BranchAction {
|
||||||
return "7z";
|
return "7z";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActive(OpenFileSystemModel model, List<BrowserEntry> entries) {
|
||||||
|
return model.getCache().getMultiPurposeCache().containsKey("7zExecutable");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isApplicable(OpenFileSystemModel model, List<BrowserEntry> entries) {
|
public boolean isApplicable(OpenFileSystemModel model, List<BrowserEntry> 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 abstract class TarBasedAction extends Action {
|
||||||
|
|
||||||
|
private final boolean gz;
|
||||||
|
|
||||||
|
private TarBasedAction(boolean gz) {this.gz = gz;}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void create(String fileName, OpenFileSystemModel model, List<BrowserEntry> entries) {
|
protected void create(String fileName, OpenFileSystemModel model, List<BrowserEntry> 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());
|
var base = new FilePath(model.getCurrentDirectory().getPath());
|
||||||
for (BrowserEntry entry : entries) {
|
|
||||||
var rel = new FilePath(entry.getRawFileEntry().getPath()).relativize(base);
|
if (directory) {
|
||||||
command.addFile(rel);
|
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<BrowserEntry> entries) {
|
||||||
|
return model.getCache().getInstalledApplications().get("tar");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isApplicable(OpenFileSystemModel model, List<BrowserEntry> entries) {
|
||||||
|
return model.getFileSystem().getShell().orElseThrow().getOsType() != OsType.WINDOWS || !directory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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<BrowserEntry> entries) {
|
||||||
|
return BrowserIcons.createIcon(BrowserIconFileType.byId("zip")).createRegion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getExecutable() {
|
||||||
|
return "tar";
|
||||||
|
}
|
||||||
|
|
||||||
|
@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("-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<String> getName(OpenFileSystemModel model, List<BrowserEntry> 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<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"));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<BrowserEntry> 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<String> getName(OpenFileSystemModel model, List<BrowserEntry> 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<BrowserEntry> entries) {
|
||||||
|
return entries.stream().allMatch(entry -> entry.getRawFileEntry().getPath().endsWith(".zip"))
|
||||||
|
&& !model.getFileSystem().getShell().orElseThrow().getOsType().equals(OsType.WINDOWS);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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<BrowserEntry> entries) {
|
||||||
|
return BrowserIcons.createIcon(BrowserIconFileType.byId("zip")).createRegion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 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<String> getName(OpenFileSystemModel model, List<BrowserEntry> 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<BrowserEntry> entries) {
|
||||||
|
return entries.stream().allMatch(entry -> entry.getRawFileEntry().getPath().endsWith(".zip"))
|
||||||
|
&& model.getFileSystem().getShell().orElseThrow().getOsType().equals(OsType.WINDOWS);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package io.xpipe.ext.base.browser.compress;
|
||||||
|
|
||||||
|
public class DirectoryCompressAction extends BaseCompressAction {
|
||||||
|
|
||||||
|
public DirectoryCompressAction() {
|
||||||
|
super(true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package io.xpipe.ext.base.browser.compress;
|
||||||
|
|
||||||
|
public class FileCompressAction extends BaseCompressAction {
|
||||||
|
|
||||||
|
public FileCompressAction() {
|
||||||
|
super(false);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package io.xpipe.ext.base.browser.compress;
|
||||||
|
|
||||||
|
public class UntarDirectoryAction extends BaseUntarAction {
|
||||||
|
|
||||||
|
public UntarDirectoryAction() {
|
||||||
|
super(false, true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package io.xpipe.ext.base.browser.compress;
|
||||||
|
|
||||||
|
public class UntarGzDirectoryAction extends BaseUntarAction {
|
||||||
|
|
||||||
|
public UntarGzDirectoryAction() {
|
||||||
|
super(true, true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package io.xpipe.ext.base.browser.compress;
|
||||||
|
|
||||||
|
public class UntarGzHereAction extends BaseUntarAction {
|
||||||
|
|
||||||
|
public UntarGzHereAction() {
|
||||||
|
super(true, false);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package io.xpipe.ext.base.browser.compress;
|
||||||
|
|
||||||
|
public class UntarHereAction extends BaseUntarAction {
|
||||||
|
|
||||||
|
public UntarHereAction() {
|
||||||
|
super(false, false);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package io.xpipe.ext.base.browser.compress;
|
||||||
|
|
||||||
|
public class UnzipDirectoryUnixAction extends BaseUnzipUnixAction {
|
||||||
|
|
||||||
|
public UnzipDirectoryUnixAction() {
|
||||||
|
super(true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package io.xpipe.ext.base.browser.compress;
|
||||||
|
|
||||||
|
public class UnzipDirectoryWindowsAction extends BaseUnzipWindowsAction {
|
||||||
|
|
||||||
|
public UnzipDirectoryWindowsAction() {
|
||||||
|
super(true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package io.xpipe.ext.base.browser.compress;
|
||||||
|
|
||||||
|
public class UnzipHereUnixAction extends BaseUnzipUnixAction {
|
||||||
|
|
||||||
|
public UnzipHereUnixAction() {
|
||||||
|
super(false);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package io.xpipe.ext.base.browser.compress;
|
||||||
|
|
||||||
|
public class UnzipHereWindowsAction extends BaseUnzipWindowsAction {
|
||||||
|
|
||||||
|
public UnzipHereWindowsAction() {
|
||||||
|
super(false);
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,6 +12,7 @@ import io.xpipe.ext.base.service.*;
|
||||||
import io.xpipe.ext.base.store.StorePauseAction;
|
import io.xpipe.ext.base.store.StorePauseAction;
|
||||||
import io.xpipe.ext.base.store.StoreStartAction;
|
import io.xpipe.ext.base.store.StoreStartAction;
|
||||||
import io.xpipe.ext.base.store.StoreStopAction;
|
import io.xpipe.ext.base.store.StoreStopAction;
|
||||||
|
import io.xpipe.ext.base.browser.compress.*;
|
||||||
|
|
||||||
open module io.xpipe.ext.base {
|
open module io.xpipe.ext.base {
|
||||||
exports io.xpipe.ext.base;
|
exports io.xpipe.ext.base;
|
||||||
|
@ -54,12 +55,15 @@ open module io.xpipe.ext.base {
|
||||||
CopyAction,
|
CopyAction,
|
||||||
CopyPathAction,
|
CopyPathAction,
|
||||||
PasteAction,
|
PasteAction,
|
||||||
NewItemAction,
|
NewItemAction, FileCompressAction, DirectoryCompressAction,
|
||||||
CompressAction,
|
|
||||||
RenameAction,
|
RenameAction,
|
||||||
DeleteAction,
|
DeleteAction,
|
||||||
DeleteLinkAction,
|
DeleteLinkAction,
|
||||||
UnzipAction,
|
UnzipHereUnixAction,
|
||||||
|
UnzipDirectoryUnixAction,
|
||||||
|
UnzipHereWindowsAction,
|
||||||
|
UnzipDirectoryWindowsAction,
|
||||||
|
UntarHereAction, UntarGzHereAction, UntarDirectoryAction, UntarGzDirectoryAction,
|
||||||
JavapAction,
|
JavapAction,
|
||||||
JarAction;
|
JarAction;
|
||||||
provides ActionProvider with
|
provides ActionProvider with
|
||||||
|
|
|
@ -180,3 +180,8 @@ hub=Hub
|
||||||
script=script
|
script=script
|
||||||
archiveName=Arkivets navn
|
archiveName=Arkivets navn
|
||||||
compress=Komprimere
|
compress=Komprimere
|
||||||
|
compressContents=Komprimere indhold
|
||||||
|
untarHere=Untar her
|
||||||
|
untarDirectory=Untar to $DIR$
|
||||||
|
unzipDirectory=Pak ud til $DIR$
|
||||||
|
unzipHere=Pak ud her
|
||||||
|
|
|
@ -171,3 +171,8 @@ hub=Hub
|
||||||
script=skript
|
script=skript
|
||||||
archiveName=Name des Archivs
|
archiveName=Name des Archivs
|
||||||
compress=Komprimieren
|
compress=Komprimieren
|
||||||
|
compressContents=Inhalte komprimieren
|
||||||
|
untarHere=Untar hier
|
||||||
|
untarDirectory=Untar zu $DIR$
|
||||||
|
unzipDirectory=Entpacken nach $DIR$
|
||||||
|
unzipHere=Hier entpacken
|
||||||
|
|
|
@ -170,5 +170,10 @@ hub=Hub
|
||||||
script=script
|
script=script
|
||||||
archiveName=Archive name
|
archiveName=Archive name
|
||||||
compress=Compress
|
compress=Compress
|
||||||
|
compressContents=Compress contents
|
||||||
|
untarHere=Untar here
|
||||||
|
untarDirectory=Untar to $DIR$
|
||||||
|
unzipDirectory=Unzip to $DIR$
|
||||||
|
unzipHere=Unzip here
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -169,3 +169,8 @@ hub=Hub
|
||||||
script=script
|
script=script
|
||||||
archiveName=Nombre de archivo
|
archiveName=Nombre de archivo
|
||||||
compress=Comprime
|
compress=Comprime
|
||||||
|
compressContents=Comprimir contenidos
|
||||||
|
untarHere=Untar aquí
|
||||||
|
untarDirectory=Untar a $DIR$
|
||||||
|
unzipDirectory=Descomprimir a $DIR$
|
||||||
|
unzipHere=Descomprimir aquí
|
||||||
|
|
|
@ -169,3 +169,8 @@ hub=Hub
|
||||||
script=script
|
script=script
|
||||||
archiveName=Nom de l'archive
|
archiveName=Nom de l'archive
|
||||||
compress=Compresser
|
compress=Compresser
|
||||||
|
compressContents=Compresser le contenu
|
||||||
|
untarHere=Untar ici
|
||||||
|
untarDirectory=Untar to $DIR$
|
||||||
|
unzipDirectory=Décompresser pour $DIR$
|
||||||
|
unzipHere=Décompresse ici
|
||||||
|
|
|
@ -169,3 +169,8 @@ hub=Hub
|
||||||
script=script
|
script=script
|
||||||
archiveName=Nome dell'archivio
|
archiveName=Nome dell'archivio
|
||||||
compress=Comprimere
|
compress=Comprimere
|
||||||
|
compressContents=Comprimere i contenuti
|
||||||
|
untarHere=Non scrivere qui
|
||||||
|
untarDirectory=Untar a $DIR$
|
||||||
|
unzipDirectory=Decomprimere in $DIR$
|
||||||
|
unzipHere=Decomprimi qui
|
||||||
|
|
|
@ -169,3 +169,8 @@ hub=ハブ
|
||||||
script=スクリプト
|
script=スクリプト
|
||||||
archiveName=アーカイブ名
|
archiveName=アーカイブ名
|
||||||
compress=圧縮する
|
compress=圧縮する
|
||||||
|
compressContents=コンテンツを圧縮する
|
||||||
|
untarHere=ここをクリック
|
||||||
|
untarDirectory=未対応$DIR$
|
||||||
|
unzipDirectory=解凍先$DIR$
|
||||||
|
unzipHere=ここで解凍する
|
||||||
|
|
|
@ -169,3 +169,8 @@ hub=Hub
|
||||||
script=script
|
script=script
|
||||||
archiveName=Naam archief
|
archiveName=Naam archief
|
||||||
compress=Comprimeren
|
compress=Comprimeren
|
||||||
|
compressContents=Inhoud comprimeren
|
||||||
|
untarHere=Untar hier
|
||||||
|
untarDirectory=Naar $DIR$
|
||||||
|
unzipDirectory=Uitpakken naar $DIR$
|
||||||
|
unzipHere=Hier uitpakken
|
||||||
|
|
|
@ -169,3 +169,8 @@ hub=Hub
|
||||||
script=guião
|
script=guião
|
||||||
archiveName=Nome do arquivo
|
archiveName=Nome do arquivo
|
||||||
compress=Comprimir
|
compress=Comprimir
|
||||||
|
compressContents=Comprime o conteúdo
|
||||||
|
untarHere=Untar aqui
|
||||||
|
untarDirectory=Untar para $DIR$
|
||||||
|
unzipDirectory=Descompacta para $DIR$
|
||||||
|
unzipHere=Descompacta aqui
|
||||||
|
|
|
@ -169,3 +169,8 @@ hub=Хаб
|
||||||
script=скрипт
|
script=скрипт
|
||||||
archiveName=Название архива
|
archiveName=Название архива
|
||||||
compress=Сжать
|
compress=Сжать
|
||||||
|
compressContents=Сжать содержимое
|
||||||
|
untarHere=Унтар здесь
|
||||||
|
untarDirectory=Унтар к $DIR$
|
||||||
|
unzipDirectory=Разархивировать в $DIR$
|
||||||
|
unzipHere=Распакуйте здесь
|
||||||
|
|
|
@ -169,3 +169,8 @@ hub=Hub
|
||||||
script=senaryo
|
script=senaryo
|
||||||
archiveName=Arşiv adı
|
archiveName=Arşiv adı
|
||||||
compress=Sıkıştır
|
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
|
||||||
|
|
|
@ -169,3 +169,8 @@ hub=枢纽
|
||||||
script=脚本
|
script=脚本
|
||||||
archiveName=档案名称
|
archiveName=档案名称
|
||||||
compress=压缩
|
compress=压缩
|
||||||
|
compressContents=压缩内容
|
||||||
|
untarHere=点击此处
|
||||||
|
untarDirectory=到$DIR$
|
||||||
|
unzipDirectory=解压缩为$DIR$
|
||||||
|
unzipHere=在此解压缩
|
||||||
|
|
Loading…
Reference in a new issue