private static File checkDuplicatesSync( final Activity context, final File file, final String originalNameNoExt, final int checks) throws Exception { Log.v("checkDuplicatesSync", "Checking: " + file.getPath()); if (file.existsSync()) { String newName = originalNameNoExt; if (checks > 0) newName += " (" + checks + ")"; if (!file.isDirectory()) newName += "." + file.getExtension(); File newFile = file.isRemote() ? new CloudFile(context, (CloudFile) file.getParent(), newName, file.isDirectory()) : new LocalFile(context, file.getParent(), newName); return checkDuplicatesSync(context, newFile, originalNameNoExt, 1 + checks); } else return file; }
private static void checkDuplicates( final Activity context, final File file, final String originalNameNoExt, final int checks, final DuplicateCheckResult callback) { Log.v("checkDuplicates", "Checking: " + file.getPath()); file.exists( new File.BooleanCallback() { @Override public void onComplete(final boolean result) { context.runOnUiThread( new Runnable() { @Override public void run() { if (result) { String newName = originalNameNoExt; if (checks > 0) newName += " (" + checks + ")"; if (!file.isDirectory()) newName += "." + file.getExtension(); File newFile = file.isRemote() ? new CloudFile( context, (CloudFile) file.getParent(), newName, file.isDirectory()) : new LocalFile(context, file.getParent(), newName); checkDuplicates(context, newFile, originalNameNoExt, 1 + checks, callback); } else { callback.onResult(file); } } }); } @Override public void onError(Exception e) { if (e != null) showErrorDialog(context, e.getMessage()); } }); }