Skip to content

Commit f41a0a3

Browse files
committed
delete filesinfolder faster
1 parent f4a8154 commit f41a0a3

File tree

8 files changed

+66
-44
lines changed

8 files changed

+66
-44
lines changed

PowerFileExplorer/src/main/java/com/amaze/filemanager/filesystem/FileUtil.java

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import jcifs.smb.SmbFile;
4949
import android.os.AsyncTask;
5050
import net.gnu.explorer.ExplorerActivity;
51+
import java.util.*;
5152

5253
/**
5354
* Utility class for helping parsing file systems.
@@ -313,25 +314,25 @@ public void onPreExecute() {
313314
*/
314315
static boolean deleteFile(@NonNull final File file, Context context) {
315316
// First try the normal deletion.
316-
if (file == null || !file.exists()) return true;
317-
boolean fileDelete = deleteFilesInFolder(file, context);
318-
if (file.delete() || fileDelete)
317+
if (file == null || !file.exists())
318+
return true;
319+
if (file.delete() || deleteFilesInFolder(file, context))
319320
return true;
320321

321322
// Try with Storage Access Framework.
322323
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && FileUtil.isOnExtSdCard(file, context)) {
323-
DocumentFile document = getDocumentFile(file, false, context);
324+
final DocumentFile document = getDocumentFile(file, false, context);
324325
if (document != null) {
325326
return document.delete();
326327
}
327328
}
328329

329330
// Try the Kitkat workaround.
330331
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
331-
ContentResolver resolver = context.getContentResolver();
332+
final ContentResolver resolver = context.getContentResolver();
332333

333334
try {
334-
Uri uri = MediaStoreHack.getUriFromFile(file.getAbsolutePath(), context);
335+
final Uri uri = MediaStoreHack.getUriFromFile(file.getAbsolutePath(), context);
335336
resolver.delete(uri, null, null);
336337
return !file.exists();
337338
} catch (Exception e) {
@@ -600,20 +601,40 @@ private static boolean rmdir(final File file, Context context) {
600601
* @return true if successful.
601602
*/
602603
private static final boolean deleteFilesInFolder(final File folder, Context context) {
603-
boolean totalSuccess = true;
604604
if (folder == null)
605605
return false;
606+
final boolean totalSuccess;
606607
if (folder.isDirectory()) {//TODO remove recursive
607-
for (File child : folder.listFiles()) {
608-
deleteFilesInFolder(child, context);
609-
}
610-
611-
if (!folder.delete())
612-
totalSuccess = false;
608+
final LinkedList<File> folderQueue = new LinkedList<File>();
609+
folderQueue.add(folder);
610+
final LinkedList<File> allFolders = new LinkedList<File>();
611+
File fi = null;
612+
File[] fs;
613+
while (folderQueue.size() > 0) {
614+
fi = folderQueue.pop();
615+
allFolders.add(fi);
616+
fs = fi.listFiles();
617+
if (fs != null)
618+
for (File f2 : fs) {
619+
if (f2.isDirectory()) {
620+
folderQueue.push(f2);
621+
} else {
622+
f2.delete();
623+
}
624+
}
625+
}
626+
final int size = allFolders.size();
627+
for (int i = 0; i < size - 1; i++) {
628+
allFolders.pop().delete();
629+
}
630+
totalSuccess = allFolders.pop().delete();
631+
// for (File child : listFiles) {
632+
// deleteFilesInFolder(child, context);
633+
// }
634+
// if (!folder.delete())
635+
// totalSuccess = false;
613636
} else {
614-
615-
if (!folder.delete())
616-
totalSuccess = false;
637+
totalSuccess = folder.delete();
617638
}
618639
return totalSuccess;
619640
}

PowerFileExplorer/src/main/java/com/amaze/filemanager/services/asynctasks/CopyFileCheck.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ class CopyNode {
309309
final HFile destination = new HFile(openMode, path);
310310
conflictingFiles = checkConflicts(filesToCopy, destination);
311311

312-
final int size = conflictingFiles.size();
313-
for (int i = 0; i < size; i++) {
312+
for (int i = 0; i < conflictingFiles.size(); i++) {
314313
if (conflictingFiles.get(i).isDirectory()) {
315314
if (deleteCopiedFolder == null)
316315
deleteCopiedFolder = new ArrayList<>();

PowerFileExplorer/src/main/java/com/amaze/filemanager/utils/files/GenericCopyUtil.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,9 @@ private void startCopy(boolean lowOnMemory) throws IOException {
213213

214214
///
215215
try {
216+
//Log.d(TAG, "mTargetFile.delete " + mTargetFile);
216217
mTargetFile.delete(mContext, mTargetFile.isRoot());
217-
}
218-
catch (RootNotPermittedException e) {
218+
} catch (RootNotPermittedException e) {
219219
e.printStackTrace();
220220
}
221221
///
@@ -250,13 +250,13 @@ else if (outChannel != null) {
250250
else if (outChannel != null)
251251
success = copyFile(inChannel, outChannel);
252252
}
253-
if (!success) {
254-
if (documentTargetFile != null) {
255-
documentTargetFile.delete();
256-
} else if (targetFile != null) {
257-
targetFile.delete();
258-
}
259-
}
253+
// if (!success) {
254+
// if (documentTargetFile != null) {
255+
// documentTargetFile.delete();
256+
// } else if (targetFile != null) {
257+
// targetFile.delete();
258+
// }
259+
// }
260260
} catch (IOException e) {
261261
Log.e(TAG, e.getMessage());
262262
throw e;

PowerFileExplorer/src/main/java/jp/sblo/pandora/jota/KeywordHighlght.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static private void loadColorSettings()
156156

157157
try{
158158
int color = Integer.parseInt(body, 16);
159-
sColorMap.put(head , color );
159+
sColorMap.put(head , Integer.valueOf(color) );
160160
}
161161
catch(Exception e){}
162162
}

PowerFileExplorer/src/main/java/jp/sblo/pandora/jota/SettingsShortcutActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ static public HashMap<Integer,Integer> loadShortcuts(Context context)
307307
String key = KEY_SHORTCUT + sd.key;
308308
String strfunction = sp.getString(key, "0" );
309309
int function = Integer.parseInt(strfunction);
310-
result.put(sd.key, function);
310+
result.put(Integer.valueOf(sd.key), Integer.valueOf(function));
311311
}
312312
return result;
313313
}

PowerFileExplorer/src/main/java/jp/sblo/pandora/jota/SettingsToolbarActivity.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void onClick(View v) {
8989

9090
@Override
9191
public void onClick(DialogInterface dialog, int which) {
92-
mData.add(mFunctions[which]);
92+
mData.add(Integer.valueOf(mFunctions[which]));
9393
mAdapter.notifyDataSetChanged();
9494
writeToolbarSettings();
9595
checkAddButton();
@@ -144,7 +144,8 @@ private void writeToolbarSettings() {
144144
String key = String.format(KEY_TOOLBAR, i);
145145
editor.remove(key);
146146
}
147-
for (int i=0;i < mData.size();i++) {
147+
final int size = mData.size();
148+
for (int i=0;i < size;i++) {
148149
String key = String.format(KEY_TOOLBAR, i);
149150
editor.putInt(key, mData.get(i).intValue());
150151
}
@@ -181,7 +182,7 @@ static public ArrayList<Integer> readToolbarSettings(Context context) {
181182
int f = sp.getInt(key, jp.sblo.pandora.jota.text.TextView.FUNCTION_NONE);
182183
if (f != jp.sblo.pandora.jota.text.TextView.FUNCTION_NONE) {
183184
//if (context instanceof Main) {
184-
result.add(f);
185+
result.add(Integer.valueOf(f));
185186
//} else if (f != jp.sblo.pandora.jota.text.TextView.FUNCTION_QUIT) {
186187
//result.add(f);
187188
//}

PowerFileExplorer/src/main/java/jp/sblo/pandora/jota/text/EditText.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ public boolean doShortcut(int keycode) {
322322

323323
Integer ss = mShortcuts.get(keycode);
324324

325-
if (ss!=null && ss != EditText.FUNCTION_NONE ) {
325+
if (ss!=null && ss.intValue() != EditText.FUNCTION_NONE ) {
326326
return doFunction( ss.intValue() );
327327
}
328328
return false;
@@ -332,7 +332,7 @@ public boolean isShortcut(int keycode) {
332332

333333
Integer ss = mShortcuts.get(keycode);
334334

335-
if (ss!=null && ss != EditText.FUNCTION_NONE ) {
335+
if (ss!=null && ss.intValue() != EditText.FUNCTION_NONE ) {
336336
return true;
337337
}
338338
return false;

PowerFileExplorer/src/main/java/net/gnu/texteditor/TextFrag.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,7 +2784,7 @@ private jp.sblo.pandora.jota.text.EditText getCurrentFocusEditText( )
27842784
public void onClick(View v) {
27852785

27862786
Integer function = (Integer)v.getTag();
2787-
switch( function ){
2787+
switch( function.intValue() ){
27882788
case jp.sblo.pandora.jota.text.TextView.FUNCTION_UNDO:
27892789
case jp.sblo.pandora.jota.text.TextView.FUNCTION_COPY:
27902790
case jp.sblo.pandora.jota.text.TextView.FUNCTION_CUT:
@@ -2853,6 +2853,7 @@ private void initToolbar( ArrayList<Integer> toolbars , boolean bigButton)
28532853
lp.width = 44 * density;
28542854
final Context ctx = getContext();
28552855
for( Integer function : toolbars ){
2856+
final int func = function.intValue();
28562857
if ( bigButton ){
28572858
button = new Button(ctx);//, null, R.style.Widget_AppCompat_Button);
28582859
button.setTextSize(16);
@@ -2872,32 +2873,32 @@ private void initToolbar( ArrayList<Integer> toolbars , boolean bigButton)
28722873
} else {
28732874
iv.setColorFilter(0xff404040, PorterDuff.Mode.SRC_IN);
28742875
}
2875-
if (function == jp.sblo.pandora.jota.text.TextView.FUNCTION_SELECT_ALL) {//}"Select All".equals(toolname)) {
2876+
if (func == jp.sblo.pandora.jota.text.TextView.FUNCTION_SELECT_ALL) {//}"Select All".equals(toolname)) {
28762877
iv.setImageResource(R.drawable.ic_select_all_white_36dp);
28772878
button = null;
2878-
} else if (function == jp.sblo.pandora.jota.text.TextView.FUNCTION_UNDO) {//"Undo".equals(toolname)) {
2879+
} else if (func == jp.sblo.pandora.jota.text.TextView.FUNCTION_UNDO) {//"Undo".equals(toolname)) {
28792880
iv.setImageResource(R.drawable.ic_action_undo);
28802881
button = null;
2881-
} else if (function == jp.sblo.pandora.jota.text.TextView.FUNCTION_COPY) {//"Copy".equals(toolname)) {
2882+
} else if (func == jp.sblo.pandora.jota.text.TextView.FUNCTION_COPY) {//"Copy".equals(toolname)) {
28822883
iv.setImageResource(R.drawable.ic_action_copy);
28832884
button = null;
2884-
} else if (function == jp.sblo.pandora.jota.text.TextView.FUNCTION_CUT) {//" Cut ".equals(toolname)) {
2885+
} else if (func == jp.sblo.pandora.jota.text.TextView.FUNCTION_CUT) {//" Cut ".equals(toolname)) {
28852886
iv.setImageResource(R.drawable.ic_action_cut);
28862887
button = null;
2887-
} else if (function == jp.sblo.pandora.jota.text.TextView.FUNCTION_PASTE) {//"Paste".equals(toolname)) {
2888+
} else if (func == jp.sblo.pandora.jota.text.TextView.FUNCTION_PASTE) {//"Paste".equals(toolname)) {
28882889
iv.setImageResource(R.drawable.ic_action_paste);
28892890
button = null;
2890-
} else if (function == jp.sblo.pandora.jota.text.TextView.FUNCTION_SAVE) {//"Save".equals(toolname)) {
2891+
} else if (func == jp.sblo.pandora.jota.text.TextView.FUNCTION_SAVE) {//"Save".equals(toolname)) {
28912892
iv.setImageResource(R.drawable.ic_action_save);
28922893
button = null;
2893-
} else if (function == jp.sblo.pandora.jota.text.TextView.FUNCTION_SEARCH) {//"Search".equals(toolname)) {
2894+
} else if (func == jp.sblo.pandora.jota.text.TextView.FUNCTION_SEARCH) {//"Search".equals(toolname)) {
28942895
iv.setImageResource(R.drawable.ic_action_search);
28952896
button = null;
2896-
} else if (function == jp.sblo.pandora.jota.text.TextView.FUNCTION_REDO) {//"Redo".equals(toolname)) {
2897+
} else if (func == jp.sblo.pandora.jota.text.TextView.FUNCTION_REDO) {//"Redo".equals(toolname)) {
28972898
iv.setImageResource(R.drawable.ic_action_redo);
28982899
button = null;
28992900
} else {
2900-
button.setText(getToolbarLabel(function));
2901+
button.setText(getToolbarLabel(func));
29012902
button.setTextColor(ExplorerActivity.TEXT_COLOR);
29022903
iv = null;
29032904
}

0 commit comments

Comments
 (0)