unrar feature,view apk ,,view jars

This commit is contained in:
arpit khurana
2014-12-12 22:33:41 +05:30
parent 12f805ce49
commit 64338529d9
9 changed files with 107 additions and 7 deletions
Binary file not shown.
Binary file not shown.
+4
View File
@@ -258,5 +258,9 @@
<string name="unsavedchanges">Unsaved Changes</string>
<string name="unsavedchangesdesc">You have unsaved changes,do you want to save them before exiting?</string>
<string name="saving">Saving</string>
<string name="packageinstaller">Package Installer</string>
<string name="view">View</string>
<string name="install">Install</string>
<string name="pitext">This is a package installer. What action would you like to perform?</string>
</resources>
@@ -156,7 +156,6 @@ public class ZipAdapter extends ArrayAdapter<ZipObj> {
}
else { holder.imageView.setImageDrawable( Icons.loadMimeIcon(zipViewer.getActivity(),rowItem.getName(),false));
final StringBuilder stringBuilder = new StringBuilder(rowItem.getName());
if(zipViewer.showSize) holder.txtDesc.setText(new Futils().readableFileSize(rowItem.getSize()));
if(zipViewer.showLastModified)holder.date.setText(new Futils().getdate(rowItem.getTime(),"MMM dd, yyyy",zipViewer.year));
if (rowItem.isDirectory()) {
holder.imageView.setImageDrawable(folder);
@@ -167,7 +166,8 @@ public class ZipAdapter extends ArrayAdapter<ZipObj> {
}catch (Exception e)
{
holder.txtTitle.setText(rowItem.getName().substring(0, rowItem.getName().lastIndexOf("/")));
} }else{holder.txtTitle.setText(rowItem.getName().substring(rowItem.getName().lastIndexOf("/") + 1));
} }else{if(zipViewer.showSize) holder.txtDesc.setText(new Futils().readableFileSize(rowItem.getSize()));
holder.txtTitle.setText(rowItem.getName().substring(rowItem.getName().lastIndexOf("/") + 1));
if (zipViewer.coloriseIcons) {
if (Icons.isVideo(rowItem.getName()))
gradientDrawable.setColor(Color.parseColor("#f06292"));
@@ -794,7 +794,7 @@ public class Main extends android.support.v4.app.Fragment {
showOption(R.id.sethome, menu);
} else if (x.getName().toLowerCase().endsWith(".zip") || x.getName().toLowerCase().endsWith(".jar") || x.getName().toLowerCase().endsWith(".apk")) {
} else if (x.getName().toLowerCase().endsWith(".zip") || x.getName().toLowerCase().endsWith(".jar") || x.getName().toLowerCase().endsWith(".apk") || x.getName().toLowerCase().endsWith(".rar")) {
showOption(R.id.ex, menu);
@@ -34,6 +34,9 @@ import android.util.Log;
import com.amaze.filemanager.R;
import com.amaze.filemanager.activities.MainActivity;
import com.amaze.filemanager.utils.Futils;
import com.github.junrar.Archive;
import com.github.junrar.exception.RarException;
import com.github.junrar.rarfile.FileHeader;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
@@ -126,6 +129,42 @@ ArrayList<String> entries=new ArrayList<String>();
inputStream.close();
}
}
private void unzipRAREntry(int id, Archive zipfile, FileHeader entry, String outputDir)
throws IOException, RarException {
String name=entry.getFileNameString();
name=name.replaceAll("\\\\","/");
if (entry.isDirectory()) {
createDir(new File(outputDir, name));
return;
}
File outputFile = new File(outputDir, name);
if (!outputFile.getParentFile().exists()) {
createDir(outputFile.getParentFile());
}
// Log.i("Amaze", "Extracting: " + entry);
BufferedInputStream inputStream = new BufferedInputStream(
zipfile.getInputStream(entry));
BufferedOutputStream outputStream = new BufferedOutputStream(
new FileOutputStream(outputFile));
try {
int len;
byte buf[] = new byte[1024];
while ((len = inputStream.read(buf)) > 0) {
//System.out.println(id + " " + hash.get(id));
if (hash.get(id)) {
publishResults(true);
outputStream.write(buf, 0, len);
} else {
stopSelf(id);
publishResults(false);
}
}
}finally {
outputStream.close();
inputStream.close();
}
}
public boolean extract(int id, File archive, String destinationPath,ArrayList<String> x) {
int i = 0;
@@ -190,7 +229,34 @@ ArrayList<String> entries=new ArrayList<String>();
}
}
public boolean extractRar(int id, File archive, String destinationPath) {
int i = 0;
try {
Archive zipfile = new Archive(archive);
FileHeader fh = zipfile.nextFileHeader();
while(fh != null){
if (hash.get(id)) {
publishResults(true);
unzipRAREntry(id,zipfile,fh,destinationPath);
fh=zipfile.nextFileHeader();
} else {
stopSelf(id);
publishResults(false);
}
}
Intent intent = new Intent("loadlist");
sendBroadcast(intent);
return true;
} catch (Exception e) {
Log.e("amaze", "Error while extracting file " + archive, e);
Intent intent = new Intent("loadlist");
sendBroadcast(intent);
return false;
}
}
public class Doback extends AsyncTask<Bundle, Void, Integer> {
protected Integer doInBackground(Bundle... p1) {
String file = p1[0].getString("file");
@@ -198,8 +264,10 @@ ArrayList<String> entries=new ArrayList<String>();
System.out.println(f.getName()+""+eentries);
if(eentries) {
extract(p1[0].getInt("id"), f, f.getParent() + "/" + f.getName().substring(0, f.getName().lastIndexOf(".")), entries);
}else
}else if(f.getName().toLowerCase().endsWith(".zip"))
extract(p1[0].getInt("id"), f, f.getParent() + "/" + f.getName().substring(0, f.getName().lastIndexOf(".")));
else if(f.getName().toLowerCase().endsWith(".rar"))
extractRar(p1[0].getInt("id"), f, f.getParent() + "/" + f.getName().substring(0, f.getName().lastIndexOf(".")));
Log.i("Amaze", "Almost Completed");
@@ -5,7 +5,6 @@ import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;
import com.adarshr.raroscope.RARFile;
import com.amaze.filemanager.R;
import com.amaze.filemanager.activities.MainActivity;
import com.amaze.filemanager.adapters.ZipAdapter;
+30 -2
View File
@@ -469,7 +469,7 @@ public class Futils {
Intent i = new Intent(m, TextReader.class);
i.putExtra("path", f.getPath());
m.startActivity(i);
} else if (f.getName().toLowerCase().endsWith(".zip")) {
} else if (f.getName().toLowerCase().endsWith(".zip") || f.getName().toLowerCase().endsWith(".jar")) {
m.select=-2;
FragmentTransaction fragmentTransaction = m.getSupportFragmentManager().beginTransaction();
Fragment fragment = new ZipViewer();
@@ -480,7 +480,7 @@ public class Futils {
//fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
} else {
}else if(f.getName().toLowerCase().endsWith(".apk")){showPackageDialog(f,m);}else {
try {
openunknown(f, m);
} catch (Exception e) {
@@ -489,7 +489,35 @@ public class Futils {
}
}
}
public void showPackageDialog(final File f,final MainActivity m){
MaterialDialog.Builder mat=new MaterialDialog.Builder(m);
mat.title(R.string.packageinstaller).content(R.string.pitext).positiveText(R.string.install).negativeText(R.string.view).neutralText(R.string.cancel).callback(new MaterialDialog.Callback() {
@Override
public void onPositive(MaterialDialog materialDialog) {
openunknown(f,m);
}
@Override
public void onNegative(MaterialDialog materialDialog) {
m.select=-2;
FragmentTransaction fragmentTransaction = m.getSupportFragmentManager().beginTransaction();
Fragment fragment = new ZipViewer();
Bundle bundle = new Bundle();
bundle.putString("path", f.getPath());
fragment.setArguments(bundle);
fragmentTransaction.replace(R.id.content_frame, fragment);
//fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
mat.positiveColor(Color.parseColor(m.skin));
mat.neutralColor(Color.parseColor(m.skin));
mat.negativeColor(Color.parseColor(m.skin));
if(m.theme1==1)mat.theme(Theme.DARK);
mat.build().show();
}
public Layoutelements newElement(Drawable i, String d,String permissions,String symlink,String size,String directorybool,boolean b) {
Layoutelements item = new Layoutelements(i, new File(d).getName(), d,permissions,symlink,size,directorybool,b);
return item;
@@ -96,6 +96,7 @@ static {
add("application/mac-binhex40", icon);
add("application/rar", icon);
add("application/zip", icon);
add("application/java-archive",icon);
add("application/x-apple-diskimage", icon);
add("application/x-debian-package", icon);
add("application/x-gtar", icon);