aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorge Ruesga <jorge@ruesga.com>2013-03-16 02:37:00 +0100
committerJorge Ruesga <jorge@ruesga.com>2013-03-17 12:03:03 +0100
commit7041313c151efd9af42ed04fdfe647999f45cb37 (patch)
treee15b386a12c3fe1a22e6251e340fee264f63cc3c
parent4477f9674d7fea30864230ff5e56550af3d94086 (diff)
downloadandroid_packages_apps_CMFileManager-7041313c151efd9af42ed04fdfe647999f45cb37.tar.gz
android_packages_apps_CMFileManager-7041313c151efd9af42ed04fdfe647999f45cb37.tar.bz2
android_packages_apps_CMFileManager-7041313c151efd9af42ed04fdfe647999f45cb37.zip
CMFM: CYAN-200 - Archiving and Extracting .ZIP files in CM File Manager
Added support for zip and unrar commands. Zip, unzip, unlzma, unxz, uncompress and unrar are now optional. Compress or uncompress of these types are only available if its commands are present in filesystem NOTE: This change requires that zip and unrar commands are present in the filesystem at /system/xbin, which actually don't. Patchset 2: Rebased Change-Id: I30667c802bc5b678015b28bb3170377ceb37a1b8 JIRA: https://jira.cyanogenmod.org/browse/CYAN-200 Bugfix: CYAN-200 Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
-rw-r--r--res/values/arrays.xml1
-rw-r--r--res/values/overlay.xml14
-rw-r--r--res/values/strings.xml1
-rw-r--r--res/xml/command_list.xml2
-rw-r--r--src/com/cyanogenmod/filemanager/FileManagerApplication.java53
-rw-r--r--src/com/cyanogenmod/filemanager/commands/shell/CompressCommand.java88
-rw-r--r--src/com/cyanogenmod/filemanager/commands/shell/UncompressCommand.java58
-rw-r--r--src/com/cyanogenmod/filemanager/preferences/CompressionMode.java23
-rw-r--r--src/com/cyanogenmod/filemanager/preferences/UncompressionMode.java6
-rw-r--r--src/com/cyanogenmod/filemanager/ui/policy/CompressActionPolicy.java40
-rw-r--r--src/com/cyanogenmod/filemanager/util/CommandHelper.java15
-rw-r--r--src/com/cyanogenmod/filemanager/util/FileHelper.java15
12 files changed, 272 insertions, 44 deletions
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 803739c3..71ab524e 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -85,6 +85,7 @@
<item>@string/compression_mode_tar_bzip</item>
<item>@string/compression_mode_gzip</item>
<item>@string/compression_mode_bzip</item>
+ <item>@string/compression_mode_zip</item>
</string-array>
<!-- The default theme definition -->
diff --git a/res/values/overlay.xml b/res/values/overlay.xml
index dcea6e6d..c0ac0786 100644
--- a/res/values/overlay.xml
+++ b/res/values/overlay.xml
@@ -64,15 +64,21 @@
/system/xbin/stat,
/system/xbin/su,
/system/xbin/tar,
- /system/xbin/uncompress,
- /system/xbin/unlzma,
- /system/xbin/unxz,
- /system/xbin/unzip,
/system/xbin/xargs,
/system/xbin/md5sum,
/system/xbin/sha1sum
</string>
+ <!-- Optional shell commands in a pair=value format -->
+ <string name="shell_optional_commands" translatable="false">
+ zip=/system/xbin/zip,
+ unzip=/system/xbin/unzip,
+ unlzma=/system/xbin/unlzma,
+ unxz=/system/xbin/unxz,
+ uncompress=/system/xbin/uncompress,
+ unrar=/system/xbin/unrar
+ </string>
+
<!-- The mounts file -->
<string name="mounts_file" translatable="false">/proc/mounts</string>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index c95af3d7..2b3d6c6c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -632,6 +632,7 @@
<string name="compression_mode_tar_bzip" translatable="false">Tar/bzip (tar.bz2)</string>
<string name="compression_mode_gzip" translatable="false">Gzip (gz)</string>
<string name="compression_mode_bzip" translatable="false">Bzip (bz2)</string>
+ <string name="compression_mode_zip" translatable="false">Zip (zip)</string>
<!-- Shortcut. Failed to handle the shortcut -->
<string name="shortcut_failed_msg">Failed to handle the shortcut.</string>
diff --git a/res/xml/command_list.xml b/res/xml/command_list.xml
index 1d61a675..2aff709a 100644
--- a/res/xml/command_list.xml
+++ b/res/xml/command_list.xml
@@ -93,6 +93,7 @@
<command commandId="tar" commandPath="/system/xbin/tar" commandArgs="-C%1$s -%2$scvf %3$s [@]" />
<command commandId="gzip" commandPath="/system/bin/gzip" commandArgs="%1$s" />
<command commandId="bzip" commandPath="/system/xbin/bzip2" commandArgs="-f %1$s" />
+ <command commandId="zip" commandPath="cd" commandArgs="%1$s &amp;&amp; ( /system/xbin/zip -9 -r -y %2$s [@] || cd /)" />
<!-- Uncompress -->
<command commandId="untar" commandPath="/system/bin/mkdir" commandArgs="-p %2$s &amp;&amp; /system/xbin/tar -C %2$s -%1$sxvf %3$s" />
@@ -102,5 +103,6 @@
<command commandId="unlzma" commandPath="/system/xbin/unlzma" commandArgs="-f %1$s" />
<command commandId="uncompress" commandPath="/system/xbin/uncompress" commandArgs="-f %1$s" />
<command commandId="unxz" commandPath="/system/xbin/unxz" commandArgs="-f %1$s" />
+ <command commandId="unrar" commandPath="/system/xbin/unrar" commandArgs="x -ry -c- -cfg- -kb -p- -o+ %2$s %1$s" />
</CommandList>
diff --git a/src/com/cyanogenmod/filemanager/FileManagerApplication.java b/src/com/cyanogenmod/filemanager/FileManagerApplication.java
index 0e3ac357..cae025e2 100644
--- a/src/com/cyanogenmod/filemanager/FileManagerApplication.java
+++ b/src/com/cyanogenmod/filemanager/FileManagerApplication.java
@@ -40,6 +40,8 @@ import com.cyanogenmod.filemanager.util.MimeTypeHelper;
import java.io.File;
import java.io.FileInputStream;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
/**
@@ -54,6 +56,8 @@ public final class FileManagerApplication extends Application {
private static boolean DEBUG = false;
private static Properties sSystemProperties;
+ private static Map<String, Boolean> sOptionalCommandsMap;
+
/**
* A constant that contains the main process name.
* @hide
@@ -234,6 +238,9 @@ public final class FileManagerApplication extends Application {
// Check if the device is rooted
sIsDeviceRooted = areShellCommandsPresent();
+ // Check optional commands
+ loadOptionalCommands();
+
//Sets the default preferences if no value is set yet
Preferences.loadDefaults();
@@ -301,6 +308,19 @@ public final class FileManagerApplication extends Application {
}
/**
+ * Method that returns if a command is present in the system
+ *
+ * @param commandId The command key
+ * @return boolean If the command is present
+ */
+ public static boolean hasOptionalCommand(String commandId) {
+ if (!sOptionalCommandsMap.containsKey(commandId)){
+ return false;
+ }
+ return sOptionalCommandsMap.get(commandId).booleanValue();
+ }
+
+ /**
* Method that returns a system property value
*
* @param property The system property key
@@ -471,4 +491,37 @@ public final class FileManagerApplication extends Application {
}
return false;
}
+
+ @SuppressWarnings("boxing")
+ private void loadOptionalCommands() {
+ try {
+ sOptionalCommandsMap = new HashMap<String, Boolean>();
+
+ String shellCommands = getString(R.string.shell_optional_commands);
+ String[] commands = shellCommands.split(","); //$NON-NLS-1$
+ int cc = commands.length;
+ if (cc == 0) {
+ Log.w(TAG, "No optional commands."); //$NON-NLS-1$
+ return;
+ }
+ for (int i = 0; i < cc; i++) {
+ String c = commands[i].trim();
+ String key = c.substring(0, c.indexOf("=")).trim(); //$NON-NLS-1$
+ c = c.substring(c.indexOf("=")+1).trim(); //$NON-NLS-1$
+ if (c.length() == 0) continue;
+ File cmd = new File(c);
+ Boolean found = Boolean.valueOf(cmd.exists() && cmd.isFile());
+ sOptionalCommandsMap.put(key, found);
+ if (DEBUG) {
+ Log.w(TAG,
+ String.format(
+ "Optional command %s %s.", //$NON-NLS-1$
+ c, found ? "found" : "not found")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ } catch (Exception e) {
+ Log.e(TAG,
+ "Failed to read optional shell commands.", e); //$NON-NLS-1$
+ }
+ }
}
diff --git a/src/com/cyanogenmod/filemanager/commands/shell/CompressCommand.java b/src/com/cyanogenmod/filemanager/commands/shell/CompressCommand.java
index 7833455d..1659fa20 100644
--- a/src/com/cyanogenmod/filemanager/commands/shell/CompressCommand.java
+++ b/src/com/cyanogenmod/filemanager/commands/shell/CompressCommand.java
@@ -63,7 +63,11 @@ public class CompressCommand extends AsyncResultProgram implements CompressExecu
/**
* Compress using Bzip algorithm
*/
- C_BZIP(BZIP_ID, "j", CompressionMode.C_BZIP); //$NON-NLS-1$
+ C_BZIP(BZIP_ID, "j", CompressionMode.C_BZIP), //$NON-NLS-1$
+ /**
+ * Archive using Zip algorithm
+ */
+ A_ZIP(ZIP_ID, "", CompressionMode.A_ZIP); //$NON-NLS-1$
final String mId;
final String mFlag;
@@ -103,10 +107,12 @@ public class CompressCommand extends AsyncResultProgram implements CompressExecu
private static final String TAR_ID = "tar"; //$NON-NLS-1$
private static final String GZIP_ID = "gzip"; //$NON-NLS-1$
private static final String BZIP_ID = "bzip"; //$NON-NLS-1$
+ private static final String ZIP_ID = "zip"; //$NON-NLS-1$
private Boolean mResult;
private String mPartial;
+ private final Mode mMode;
private final String mOutFile;
/**
@@ -122,10 +128,15 @@ public class CompressCommand extends AsyncResultProgram implements CompressExecu
public CompressCommand(
CompressionMode mode, String dst, String[] src, AsyncResultListener asyncResultListener)
throws InvalidCommandDefinitionException {
- super(TAR_ID, asyncResultListener,
- new String[]{FileHelper.getParentDir(dst),
- Mode.fromCompressionMode(mode).mFlag,
- dst});
+ super(Mode.fromCompressionMode(mode).mId,
+ asyncResultListener,
+ resolveArchiveArgs(Mode.fromCompressionMode(mode), dst));
+ this.mMode = Mode.fromCompressionMode(mode);
+
+ if (!this.mMode.mMode.mArchive) {
+ throw new InvalidCommandDefinitionException(
+ "Unsupported archive mode"); //$NON-NLS-1$
+ }
//Convert the arguments from absolute to relative
addExpandedArguments(
@@ -147,8 +158,12 @@ public class CompressCommand extends AsyncResultProgram implements CompressExecu
public CompressCommand(
CompressionMode mode, String src, AsyncResultListener asyncResultListener)
throws InvalidCommandDefinitionException {
- super(Mode.fromCompressionMode(mode).mId, asyncResultListener, resolveArguments(mode, src));
- if (Mode.fromCompressionMode(mode).mMode.mArchive) {
+ super(Mode.fromCompressionMode(mode).mId,
+ asyncResultListener,
+ resolveCompressArgs(mode, src));
+ this.mMode = Mode.fromCompressionMode(mode);
+
+ if (this.mMode.mMode.mArchive) {
throw new InvalidCommandDefinitionException(
"Unsupported compression mode"); //$NON-NLS-1$
}
@@ -174,7 +189,10 @@ public class CompressCommand extends AsyncResultProgram implements CompressExecu
// Send the last partial data
if (this.mPartial != null && this.mPartial.length() > 0) {
if (getAsyncResultListener() != null) {
- getAsyncResultListener().onPartialResult(this.mPartial);
+ String data = processPartialResult(this.mPartial);
+ if (data != null) {
+ getAsyncResultListener().onPartialResult(data);
+ }
}
}
this.mPartial = ""; //$NON-NLS-1$
@@ -196,14 +214,20 @@ public class CompressCommand extends AsyncResultProgram implements CompressExecu
int cc = lines.length;
for (int i = 0; i < cc-1; i++) {
if (getAsyncResultListener() != null) {
- getAsyncResultListener().onPartialResult(lines[i]);
+ String data = processPartialResult(lines[i]);
+ if (data != null) {
+ getAsyncResultListener().onPartialResult(data);
+ }
}
}
// Return the last line?
if (endsWithNewLine) {
if (getAsyncResultListener() != null) {
- getAsyncResultListener().onPartialResult(lines[lines.length-1]);
+ String data = processPartialResult(lines[lines.length-1]);
+ if (data != null) {
+ getAsyncResultListener().onPartialResult(data);
+ }
}
this.mPartial = ""; //$NON-NLS-1$
} else {
@@ -261,11 +285,30 @@ public class CompressCommand extends AsyncResultProgram implements CompressExecu
}
/**
- * Method that resolves the arguments for the compression
+ * Method that resolves the arguments for the archive mode
*
* @return String[] The arguments
*/
- private static String[] resolveArguments(CompressionMode mode, String src) {
+ private final static String[] resolveArchiveArgs(Mode mode, String dst) {
+ if (mode.compareTo(Mode.A_ZIP) == 0) {
+ return new String[]{
+ FileHelper.getParentDir(dst),
+ dst
+ };
+ }
+ return new String[]{
+ FileHelper.getParentDir(dst),
+ mode.mFlag,
+ dst
+ };
+ }
+
+ /**
+ * Method that resolves the arguments for the compression mode
+ *
+ * @return String[] The arguments
+ */
+ private static String[] resolveCompressArgs(CompressionMode mode, String src) {
switch (mode) {
case C_GZIP:
case C_BZIP:
@@ -276,6 +319,27 @@ public class CompressCommand extends AsyncResultProgram implements CompressExecu
}
/**
+ * Method that processes a line to determine if it's a valid partial result
+ *
+ * @param line The line to process
+ * @return String The processed line
+ */
+ private String processPartialResult(String line) {
+ if (this.mMode.compareTo(Mode.A_ZIP) == 0) {
+ if (line.startsWith(" adding: ")) { //$NON-NLS-1$
+ int pos = line.lastIndexOf('(');
+ if (pos != -1) {
+ // Remove progress
+ return line.substring(10, pos).trim();
+ }
+ return line.substring(10).trim();
+ }
+ return null;
+ }
+ return line;
+ }
+
+ /**
* Method that resolves the output path of the compressed file
*
* @return String The output path of the compressed file
diff --git a/src/com/cyanogenmod/filemanager/commands/shell/UncompressCommand.java b/src/com/cyanogenmod/filemanager/commands/shell/UncompressCommand.java
index 0bade8ac..4e77fdc7 100644
--- a/src/com/cyanogenmod/filemanager/commands/shell/UncompressCommand.java
+++ b/src/com/cyanogenmod/filemanager/commands/shell/UncompressCommand.java
@@ -85,7 +85,11 @@ public class UncompressCommand extends AsyncResultProgram implements UncompressE
/**
* Uncompress using Unix compress algorithm
*/
- C_UNXZ(UNXZ_ID, "", UncompressionMode.C_UNXZ); //$NON-NLS-1$
+ C_UNXZ(UNXZ_ID, "", UncompressionMode.C_UNXZ), //$NON-NLS-1$
+ /**
+ * Uncompress using Rar algorithm
+ */
+ A_UNRAR(UNRAR_ID, "", UncompressionMode.C_UNRAR); //$NON-NLS-1$
final String mId;
final String mFlag;
@@ -112,12 +116,13 @@ public class UncompressCommand extends AsyncResultProgram implements UncompressE
private static final String UNLZMA_ID = "unlzma"; //$NON-NLS-1$
private static final String UNCOMPRESS_ID = "uncompress"; //$NON-NLS-1$
private static final String UNXZ_ID = "unxz"; //$NON-NLS-1$
+ private static final String UNRAR_ID = "unrar"; //$NON-NLS-1$
private Boolean mResult;
private String mPartial;
private final String mOutFile;
- private final boolean mIsArchive;
+ private final Mode mMode;
/**
* Constructor of <code>UncompressCommand</code>.<br/>
@@ -146,6 +151,7 @@ public class UncompressCommand extends AsyncResultProgram implements UncompressE
throw new InvalidCommandDefinitionException(
"Unsupported uncompress mode"); //$NON-NLS-1$
}
+ this.mMode = mode;
// Retrieve information about the uncompress process
if (dst != null) {
@@ -153,7 +159,6 @@ public class UncompressCommand extends AsyncResultProgram implements UncompressE
} else {
this.mOutFile = resolveOutputFile(src);
}
- this.mIsArchive = mode.mMode.mArchive;
}
/**
@@ -173,7 +178,10 @@ public class UncompressCommand extends AsyncResultProgram implements UncompressE
// Send the last partial data
if (this.mPartial != null && this.mPartial.length() > 0) {
if (getAsyncResultListener() != null) {
- getAsyncResultListener().onPartialResult(this.mPartial);
+ String data = processPartialResult(this.mPartial);
+ if (data != null) {
+ getAsyncResultListener().onPartialResult(data);
+ }
}
}
this.mPartial = ""; //$NON-NLS-1$
@@ -194,14 +202,20 @@ public class UncompressCommand extends AsyncResultProgram implements UncompressE
// Return all the lines, except the last
for (int i = 0; i < lines.length-1; i++) {
if (getAsyncResultListener() != null) {
- getAsyncResultListener().onPartialResult(lines[i]);
+ String data = processPartialResult(lines[i]);
+ if (data != null) {
+ getAsyncResultListener().onPartialResult(data);
+ }
}
}
// Return the last line?
if (endsWithNewLine) {
if (getAsyncResultListener() != null) {
- getAsyncResultListener().onPartialResult(lines[lines.length-1]);
+ String data = processPartialResult(lines[lines.length-1]);
+ if (data != null) {
+ getAsyncResultListener().onPartialResult(data);
+ }
}
this.mPartial = ""; //$NON-NLS-1$
} else {
@@ -263,7 +277,36 @@ public class UncompressCommand extends AsyncResultProgram implements UncompressE
*/
@Override
public boolean IsArchive() {
- return this.mIsArchive;
+ return this.mMode.mMode.mArchive;
+ }
+
+ /**
+ * Method that processes a line to determine if it's a valid partial result
+ *
+ * @param line The line to process
+ * @return String The processed line
+ */
+ private String processPartialResult(String line) {
+ if (this.mMode.compareTo(Mode.A_UNRAR) == 0) {
+ if (line.startsWith("Extracting ")) { //$NON-NLS-1$
+ int pos = line.indexOf((char)8);
+ if (pos != -1) {
+ // Remove progress
+ return line.substring(12, pos).trim();
+ }
+ return line.substring(12).trim();
+ }
+ return null;
+ }
+
+ if (this.mMode.compareTo(Mode.A_UNZIP) == 0) {
+ if (line.startsWith(" inflating: ")) { //$NON-NLS-1$
+ return line.substring(13).trim();
+ }
+ return null;
+ }
+
+ return line;
}
/**
@@ -303,6 +346,7 @@ public class UncompressCommand extends AsyncResultProgram implements UncompressE
return new String[]{mode.mFlag, out, src};
case A_UNZIP:
+ case A_UNRAR:
return new String[]{out, src};
case C_GUNZIP:
diff --git a/src/com/cyanogenmod/filemanager/preferences/CompressionMode.java b/src/com/cyanogenmod/filemanager/preferences/CompressionMode.java
index 1349bbc3..7c6415a6 100644
--- a/src/com/cyanogenmod/filemanager/preferences/CompressionMode.java
+++ b/src/com/cyanogenmod/filemanager/preferences/CompressionMode.java
@@ -23,27 +23,31 @@ public enum CompressionMode {
/**
* Archive using Tar algorithm
*/
- A_TAR("tar", true), //$NON-NLS-1$
+ A_TAR("tar", true, null), //$NON-NLS-1$
/**
* Archive and compress using Gzip algorithm
*/
- AC_GZIP("tar.gz", true), //$NON-NLS-1$
+ AC_GZIP("tar.gz", true, null), //$NON-NLS-1$
/**
* Archive and compress using Gzip algorithm
*/
- AC_GZIP2("tgz", true), //$NON-NLS-1$
+ AC_GZIP2("tgz", true, null), //$NON-NLS-1$
/**
* Archive and compress using Bzip algorithm
*/
- AC_BZIP("tar.bz2", true), //$NON-NLS-1$
+ AC_BZIP("tar.bz2", true, null), //$NON-NLS-1$
/**
* Compress using Gzip algorithm
*/
- C_GZIP("gz", false), //$NON-NLS-1$
+ C_GZIP("gz", false, null), //$NON-NLS-1$
/**
* Compress using Bzip algorithm
*/
- C_BZIP("bz2", false); //$NON-NLS-1$
+ C_BZIP("bz2", false, null), //$NON-NLS-1$
+ /**
+ * Archive using Zip algorithm
+ */
+ A_ZIP("zip", true, "zip"); //$NON-NLS-1$ //$NON-NLS-2$
/**
* The file extension
@@ -53,6 +57,10 @@ public enum CompressionMode {
* If the file is an archive or archive-compressed (true) or a compressed file (false)
*/
public final boolean mArchive;
+ /**
+ * If the compress mode requires the present of an optional file (null == required)
+ */
+ public final String mCommandId;
/**
* Constructor of <code>CompressionMode</code>
@@ -60,8 +68,9 @@ public enum CompressionMode {
* @param extension The output extension
* @param archive If the output is an archive or archive-compressed
*/
- private CompressionMode(String extension, boolean archive) {
+ private CompressionMode(String extension, boolean archive, String commandId) {
this.mExtension = extension;
this.mArchive = archive;
+ this.mCommandId = commandId;
}
}
diff --git a/src/com/cyanogenmod/filemanager/preferences/UncompressionMode.java b/src/com/cyanogenmod/filemanager/preferences/UncompressionMode.java
index 94be8c7e..facdd99b 100644
--- a/src/com/cyanogenmod/filemanager/preferences/UncompressionMode.java
+++ b/src/com/cyanogenmod/filemanager/preferences/UncompressionMode.java
@@ -63,7 +63,11 @@ public enum UncompressionMode {
/**
* Uncompress using Unix compress algorithm
*/
- C_UNXZ("xz", false); //$NON-NLS-1$
+ C_UNXZ("xz", false), //$NON-NLS-1$
+ /**
+ * Uncompress using Rar algorithm
+ */
+ C_UNRAR("rar", true); //$NON-NLS-1$
/**
* The file extension
diff --git a/src/com/cyanogenmod/filemanager/ui/policy/CompressActionPolicy.java b/src/com/cyanogenmod/filemanager/ui/policy/CompressActionPolicy.java
index 6e5f57fe..c2c10e5f 100644
--- a/src/com/cyanogenmod/filemanager/ui/policy/CompressActionPolicy.java
+++ b/src/com/cyanogenmod/filemanager/ui/policy/CompressActionPolicy.java
@@ -109,9 +109,10 @@ public final class CompressActionPolicy extends ActionsPolicy {
final List<FileSystemObject> selection = onSelectionListener.onRequestSelectedFiles();
if (selection != null && selection.size() > 0) {
// Show a dialog to allow the user make the compression mode choice
+ final String[] labels = getSupportedCompressionModesLabels(ctx, selection);
AlertDialog dialog = DialogHelper.createSingleChoiceDialog(
ctx, R.string.compression_mode_title,
- getSupportedCompressionModesLabels(ctx, selection),
+ labels,
CompressionMode.AC_GZIP.ordinal(),
new DialogHelper.OnSelectChoiceListener() {
@Override
@@ -119,7 +120,7 @@ public final class CompressActionPolicy extends ActionsPolicy {
// Do the compression
compress(
ctx,
- getCompressionModeFromUserChoice(choice),
+ getCompressionModeFromUserChoice(ctx, labels, choice),
selection,
onSelectionListener,
onRequestRefreshListener);
@@ -151,6 +152,7 @@ public final class CompressActionPolicy extends ActionsPolicy {
items.add(fso);
// Show a dialog to allow the user make the compression mode choice
+ final String[] labels = getSupportedCompressionModesLabels(ctx, items);
AlertDialog dialog = DialogHelper.createSingleChoiceDialog(
ctx, R.string.compression_mode_title,
getSupportedCompressionModesLabels(ctx, items),
@@ -161,7 +163,7 @@ public final class CompressActionPolicy extends ActionsPolicy {
// Do the compression
compress(
ctx,
- getCompressionModeFromUserChoice(choice),
+ getCompressionModeFromUserChoice(ctx, labels, choice),
items,
onSelectionListener,
onRequestRefreshListener);
@@ -402,6 +404,7 @@ public final class CompressActionPolicy extends ActionsPolicy {
// Any exception?
+ Thread.sleep(100L);
if (this.mListener.mCause != null) {
throw this.mListener.mCause;
}
@@ -656,6 +659,7 @@ public final class CompressActionPolicy extends ActionsPolicy {
// Any exception?
+ Thread.sleep(100L);
if (this.mListener.mCause != null) {
throw this.mListener.mCause;
}
@@ -774,14 +778,29 @@ public final class CompressActionPolicy extends ActionsPolicy {
private static String[] getSupportedCompressionModesLabels(
Context ctx, List<FileSystemObject> fsos) {
String[] labels = ctx.getResources().getStringArray(R.array.compression_modes_labels);
+ // If more than a file are requested, compression is not available
+ // The same applies if the unique item is a folder
if (fsos.size() > 1 || (fsos.size() == 1 && FileHelper.isDirectory(fsos.get(0)))) {
- // If more that a file is requested, compression is not available
- // The same applies if the unique item is a folder
ArrayList<String> validLabels = new ArrayList<String>();
CompressionMode[] values = CompressionMode.values();
int cc = values.length;
for (int i = 0; i < cc; i++) {
if (values[i].mArchive) {
+ if (values[i].mCommandId == null ||
+ FileManagerApplication.hasOptionalCommand(values[i].mCommandId)) {
+ validLabels.add(labels[i]);
+ }
+ }
+ }
+ labels = validLabels.toArray(new String[]{});
+ } else {
+ // Remove optional commands
+ ArrayList<String> validLabels = new ArrayList<String>();
+ CompressionMode[] values = CompressionMode.values();
+ int cc = values.length;
+ for (int i = 0; i < cc; i++) {
+ if (values[i].mCommandId == null ||
+ FileManagerApplication.hasOptionalCommand(values[i].mCommandId)) {
validLabels.add(labels[i]);
}
}
@@ -793,14 +812,19 @@ public final class CompressActionPolicy extends ActionsPolicy {
/**
* Method that returns the compression mode from the user choice
*
+ * @param ctx The current context
+ * @param labels The dialog labels
* @param choice The choice of the user
* @return CompressionMode The compression mode
*/
- static CompressionMode getCompressionModeFromUserChoice(int choice) {
+ static CompressionMode getCompressionModeFromUserChoice(
+ Context ctx, String[] labels, int choice) {
+ String label = labels[choice];
+ String[] allLabels = ctx.getResources().getStringArray(R.array.compression_modes_labels);
CompressionMode[] values = CompressionMode.values();
- int cc = values.length;
+ int cc = allLabels.length;
for (int i = 0; i < cc; i++) {
- if (values[i].ordinal() == choice) {
+ if (allLabels[i].compareTo(label) == 0) {
return values[i];
}
}
diff --git a/src/com/cyanogenmod/filemanager/util/CommandHelper.java b/src/com/cyanogenmod/filemanager/util/CommandHelper.java
index 2a5925c0..e6620601 100644
--- a/src/com/cyanogenmod/filemanager/util/CommandHelper.java
+++ b/src/com/cyanogenmod/filemanager/util/CommandHelper.java
@@ -1290,9 +1290,18 @@ public final class CommandHelper {
wrapperListener.mUnmount = unmount;
wrapperListener.mMountPoint = executable2.getDstWritableMountPoint();
- //- Compress
- execute(context, executable1, c);
- return executable1;
+ // Some archive modes requires a new file. Ensure that the created
+ // file doesn't exists
+ DeleteFileExecutable executable3 =
+ c.getExecutableFactory().
+ newCreator().
+ createDeleteFileExecutable(compressOutFile);
+ writableExecute(context, executable3, c, true);
+ if(executable3.getResult().booleanValue()){
+ //- Compress
+ execute(context, executable1, c);
+ return executable1;
+ }
}
throw new ExecutionException(
String.format("Fail to create file %s", compressOutFile)); //$NON-NLS-1$
diff --git a/src/com/cyanogenmod/filemanager/util/FileHelper.java b/src/com/cyanogenmod/filemanager/util/FileHelper.java
index c5fb16a9..eff18ced 100644
--- a/src/com/cyanogenmod/filemanager/util/FileHelper.java
+++ b/src/com/cyanogenmod/filemanager/util/FileHelper.java
@@ -868,7 +868,13 @@ public final class FileHelper {
final String[] VALID =
{
"tar", "tgz", "tar.gz", "tar.bz2", "tar.lzma",
- "zip", "gz", "bz2", "lzma", "xz", "Z"
+ "zip", "gz", "bz2", "lzma", "xz", "Z", "rar"
+ };
+ // Null values for required commands
+ final String[] OPT_KEYS =
+ {
+ null, null, null, null, null,
+ "unzip", null, null, "unlzma", "unxz", "uncompress", "unrar"
};
// Check that have a valid file
@@ -883,7 +889,12 @@ public final class FileHelper {
int cc = VALID.length;
for (int i = 0; i < cc; i++) {
if (VALID[i].compareToIgnoreCase(ext) == 0) {
- return true;
+ // Is the command present
+ if (OPT_KEYS[i] != null &&
+ FileManagerApplication.hasOptionalCommand(OPT_KEYS[i])) {
+ return true;
+ }
+ return false;
}
}
}