Skip to content

Commit

Permalink
Adding fileops.Zip
Browse files Browse the repository at this point in the history
  • Loading branch information
marigostra committed Jun 6, 2022
1 parent 983d438 commit 8135f84
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 30 deletions.
8 changes: 0 additions & 8 deletions src/main/java/org/luwrain/app/commander/Conv.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,12 @@ final class Conv

Conv(App app)
{
NullCheck.notNull(app, "app");
this.luwrain = app.getLuwrain();
this.strings = app.getStrings();
}

Path copy(Path copyFromDir, Path[] filesToCopy, Path copyTo)
{
NullCheck.notNull(copyFromDir, "copyFromDir");
NullCheck.notNullItems(filesToCopy, "filesToCopy");
NullCheck.notNull(copyTo, "copyTo");
final DestPathPopup popup = new DestPathPopup(luwrain, strings, DestPathPopup.Type.COPY, copyFromDir, filesToCopy, copyTo);
luwrain.popup(popup);
if (popup.wasCancelled())
Expand All @@ -51,9 +47,6 @@ Path copy(Path copyFromDir, Path[] filesToCopy, Path copyTo)

Path move(Path moveFromDir, Path[] filesToMove, Path moveTo)
{
NullCheck.notNull(moveFromDir, "moveFromDir");
NullCheck.notNullItems(filesToMove, "filesToMove");
NullCheck.notNull(moveTo, "moveTo");
final DestPathPopup popup = new DestPathPopup(luwrain, strings, DestPathPopup.Type.MOVE, moveFromDir, filesToMove, moveTo);
luwrain.popup(popup);
if (popup.wasCancelled())
Expand All @@ -80,7 +73,6 @@ File mkdirPopup(File createIn)

boolean deleteConfirmation(File[] files)
{
NullCheck.notNullItems(files, "files");
final String text = strings.delPopupText(luwrain.i18n().getNumberStr(files.length, "items"));
final YesNoPopup popup = new YesNoPopup(luwrain, strings.delPopupName(), text, false, Popups.DEFAULT_POPUP_FLAGS);
luwrain.popup(popup);
Expand Down
27 changes: 5 additions & 22 deletions src/main/java/org/luwrain/app/commander/fileops/Operation.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,13 @@ public enum ConfirmationChoices {

private final OperationListener listener;
public final String name;

private boolean finished = false;
private Exception ex = null;
private Throwable ex = null;
private boolean finishingAccepted = false ;
protected boolean interrupted = false;

Operation(OperationListener listener, String name)
{
NullCheck.notNull(listener, "listener");
NullCheck.notEmpty(name, "name");
this.listener = listener;
this.name = name;
}
Expand All @@ -63,9 +60,9 @@ public void run()
try {
work();
}
catch (Exception e)
catch (Throwable e)
{
Log.error("fileops", name + ":" + e.getClass().getName() + ": " + e.getMessage());
Log.error("commander", name + ": " + e.getClass().getSimpleName() + ": " + e.getMessage());
e.printStackTrace();
this.ex = e;
}
Expand Down Expand Up @@ -94,14 +91,13 @@ public boolean finishingAccepted()
return false;
}

public Exception getException()
public Throwable getException()
{
return this.ex;
}

static protected boolean isDirectory(Path path, boolean followSymlinks) throws IOException
{
NullCheck.notNull(path, "path");
if (followSymlinks)
return Files.isDirectory(path); else
return Files.isDirectory(path, LinkOption._LINKS);
Expand All @@ -119,32 +115,25 @@ static protected Path[] getDirContent(final Path path) throws IOException

static protected boolean isRegularFile(Path path, boolean followSymlinks) throws IOException
{
NullCheck.notNull(path, "path");
if (followSymlinks)
return Files.isRegularFile(path); else
return Files.isRegularFile(path, LinkOption._LINKS);
}

static protected boolean exists(Path path, boolean followSymlinks) throws IOException
{
NullCheck.notNull(path, "path");
if (followSymlinks)
return Files.exists(path); else
return Files.exists(path, LinkOption._LINKS);
}

protected void deleteFileOrDir(Path p) throws IOException
{
NullCheck.notNull(p, "p");
if (interrupted)
throw new IOException("INTERRUPTED");
if (isDirectory(p, false))
{
final Path[] content = getDirContent(p);
for(Path pp: content)
{
deleteFileOrDir(pp);
}
}
Files.delete(p);
}
Expand Down Expand Up @@ -172,7 +161,6 @@ protected void onProgress(Operation op)

static long getTotalSize(Path p) throws IOException
{
NullCheck.notNull(p, "p");
if (Files.isRegularFile(p, LinkOption._LINKS))
return Files.size(p);
if (!Files.isDirectory(p, LinkOption._LINKS))
Expand All @@ -187,18 +175,13 @@ static long getTotalSize(Path p) throws IOException

static protected void ensureValidLocalPath(Path[] path)
{
NullCheck.notNullItems(path, "path");
NullCheck.notEmptyArray(path, "path");
for(Path p: path)
if (!p.isAbsolute())
throw new IllegalArgumentException(p.toString() + " can't be relative");
ensureValidLocalPath(p);
}

static protected void ensureValidLocalPath(Path path)
{
NullCheck.notNull(path, "path");
if (!path.isAbsolute())
throw new IllegalArgumentException(path.toString() + " can't be relative");
}

}
49 changes: 49 additions & 0 deletions src/main/java/org/luwrain/app/commander/fileops/Unzip.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
Copyright 2012-2022 Michael Pozhidaev <[email protected]>
This file is part of LUWRAIN.
LUWRAIN is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
LUWRAIN is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
*/

package org.luwrain.app.commander.fileops;

import java.io.*;
import java.nio.file.*;
import java.util.*;

import org.luwrain.core.*;
import org.luwrain.app.commander.*;
import org.luwrain.util.*;

public final class Unzip extends Operation
{
private final Path zipFile;
private final Path destDir;

public Unzip(OperationListener listener, String name, Path zipFile, Path destDir)
{
super(listener, name);
ensureValidLocalPath(zipFile);
ensureValidLocalPath(destDir);
this.zipFile = zipFile;
this.destDir = destDir;
}

@Override public void work() throws IOException
{
}

@Override public int getPercent()
{
return 0;
}
}

0 comments on commit 8135f84

Please sign in to comment.