X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/5c24e55421b146931b4e32489d337f620cbb45e2..a99a28cc61d48eca63803c3d661ea1be14f99aec:/src/com/owncloud/android/datamodel/FileDataStorageManager.java diff --git a/src/com/owncloud/android/datamodel/FileDataStorageManager.java b/src/com/owncloud/android/datamodel/FileDataStorageManager.java index af912365..3e073759 100644 --- a/src/com/owncloud/android/datamodel/FileDataStorageManager.java +++ b/src/com/owncloud/android/datamodel/FileDataStorageManager.java @@ -142,10 +142,9 @@ public class FileDataStorageManager { } - public Vector getFolderContent(OCFile f/*, boolean onlyOnDevice*/) { + public Vector getFolderContent(OCFile f, boolean onlyOnDevice) { if (f != null && f.isFolder() && f.getFileId() != -1) { - // TODO Enable when "On Device" is recovered ? - return getFolderContent(f.getFileId()/*, onlyOnDevice*/); + return getFolderContent(f.getFileId(), onlyOnDevice); } else { return new Vector(); @@ -153,13 +152,12 @@ public class FileDataStorageManager { } - public Vector getFolderImages(OCFile folder/*, boolean onlyOnDevice*/) { - Vector ret = new Vector(); + public Vector getFolderImages(OCFile folder, boolean onlyOnDevice) { + Vector ret = new Vector(); if (folder != null) { // TODO better implementation, filtering in the access to database instead of here - // TODO Enable when "On Device" is recovered ? - Vector tmp = getFolderContent(folder/*, onlyOnDevice*/); - OCFile current = null; + Vector tmp = getFolderContent(folder, onlyOnDevice); + OCFile current = null; for (int i=0; i files = getFolderContent(folder.getFileId()/*, false*/); + Vector files = getFolderContent(folder.getFileId(), false); if (files != null) { for (OCFile file : files) { if (file.isFolder()) { @@ -712,46 +709,78 @@ public class FileDataStorageManager { if (!targetFolder.exists()) { targetFolder.mkdirs(); } - copied = copyFile(localFile, targetFile); + copied = FileStorageUtils.copyFile(localFile, targetFile); } Log_OC.d(TAG, "Local file COPIED : " + copied); } } - private boolean copyFile(File src, File target) { - boolean ret = true; + public void migrateStoredFiles(String srcPath, String dstPath) throws Exception { + Cursor c = null; + if (getContentResolver() != null) { + c = getContentResolver().query(ProviderTableMeta.CONTENT_URI_FILE, + null, + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL", + null, + null); + + } else { + try { + c = getContentProviderClient().query(ProviderTableMeta.CONTENT_URI_FILE, + new String[]{ProviderTableMeta._ID, ProviderTableMeta.FILE_STORAGE_PATH}, + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL", + null, + null); + } catch (RemoteException e) { + Log_OC.e(TAG, e.getMessage()); + throw e; + } + } + + ArrayList operations = + new ArrayList(c.getCount()); + if (c.moveToFirst()) { + do { + ContentValues cv = new ContentValues(); + long fileId = c.getLong(c.getColumnIndex(ProviderTableMeta._ID)); + String oldFileStoragePath = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_STORAGE_PATH)); + + if (oldFileStoragePath.startsWith(srcPath)) { - InputStream in = null; - OutputStream out = null; + cv.put( + ProviderTableMeta.FILE_STORAGE_PATH, + oldFileStoragePath.replaceFirst(srcPath, dstPath)); + operations.add( + ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI). + withValues(cv). + withSelection( + ProviderTableMeta._ID + "=?", + new String[]{String.valueOf(fileId)} + ) + .build()); + } + + } while (c.moveToNext()); + } + c.close(); + + /// 3. apply updates in batch try { - in = new FileInputStream(src); - out = new FileOutputStream(target); - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); - } - } catch (IOException ex) { - ret = false; - } finally { - if (in != null) try { - in.close(); - } catch (IOException e) { - e.printStackTrace(System.err); - } - if (out != null) try { - out.close(); - } catch (IOException e) { - e.printStackTrace(System.err); + if (getContentResolver() != null) { + getContentResolver().applyBatch(MainApp.getAuthority(), operations); + + } else { + getContentProviderClient().applyBatch(operations); } - } - return ret; + } catch (Exception e) { + throw e; + } } - - private Vector getFolderContent(long parentId/*, boolean onlyOnDevice*/) { + + private Vector getFolderContent(long parentId, boolean onlyOnDevice) { Vector ret = new Vector(); @@ -778,10 +807,9 @@ public class FileDataStorageManager { if (c.moveToFirst()) { do { OCFile child = createFileInstance(c); - // TODO Enable when "On Device" is recovered ? - // if (child.isFolder() || !onlyOnDevice || onlyOnDevice && child.isDown()){ - ret.add(child); - // } + if (child.isFolder() || !onlyOnDevice || onlyOnDevice && child.isDown()){ + ret.add(child); + } } while (c.moveToNext()); } @@ -1532,9 +1560,8 @@ public class FileDataStorageManager { + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + "=?"; String [] whereArgs = new String[]{ "", mAccount.name }; - // TODO Enable when "On Device" is recovered ? - Vector files = getFolderContent(folder /*, false*/); - + Vector files = getFolderContent(folder, false); + for (OCFile file : files) { whereArgs[0] = file.getRemotePath(); preparedOperations.add( @@ -1605,10 +1632,12 @@ public class FileDataStorageManager { return shares; } - public void triggerMediaScan(String path) { - Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); - intent.setData(Uri.fromFile(new File(path))); - MainApp.getAppContext().sendBroadcast(intent); + public static void triggerMediaScan(String path) { + if (path != null) { + Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); + intent.setData(Uri.fromFile(new File(path))); + MainApp.getAppContext().sendBroadcast(intent); + } } public void deleteFileInMediaScan(String path) {