package com.owncloud.android.providers;
import java.io.File;
-import java.security.Provider;
import java.util.ArrayList;
import java.util.HashMap;
ProviderTableMeta.FILE_UPDATE_THUMBNAIL);
mFileProjectionMap.put(ProviderTableMeta.FILE_IS_DOWNLOADING,
ProviderTableMeta.FILE_IS_DOWNLOADING);
+ mFileProjectionMap.put(ProviderTableMeta.FILE_IN_CONFLICT,
+ ProviderTableMeta.FILE_IN_CONFLICT);
}
private static final int SINGLE_FILE = 1;
String remoteId = "";
if (c != null && c.moveToFirst()) {
remoteId = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID));
+ //ThumbnailsCacheManager.removeFileFromCache(remoteId);
+ c.close();
}
Log_OC.d(TAG, "Removing FILE " + remoteId);
+ uri.getPathSegments().get(1)
+ (!TextUtils.isEmpty(where) ? " AND (" + where
+ ")" : ""), whereArgs);
- /* just for log
- if (c!=null) {
- c.close();
- }
- */
break;
case DIRECTORY:
// deletion of folder is recursive
// ugly patch; serious refactorization is needed to reduce work in
// FileDataStorageManager and bring it to FileContentProvider
if (doubleCheck == null || !doubleCheck.moveToFirst()) {
+ if (doubleCheck != null) {
+ doubleCheck.close();
+ }
long rowId = db.insert(ProviderTableMeta.FILE_TABLE_NAME, null, values);
if (rowId > 0) {
Uri insertedFileUri =
// ugly patch; serious refactorization is needed to reduce work in
// FileDataStorageManager and bring it to FileContentProvider
if (doubleCheckShare == null || !doubleCheckShare.moveToFirst()) {
+ if (doubleCheckShare != null) {
+ doubleCheckShare.close();
+ }
long rowId = db.insert(ProviderTableMeta.OCSHARES_TABLE_NAME, null, values);
if (rowId >0) {
insertedShareUri =
}
}
- /*
- private int updateFolderSize(SQLiteDatabase db, String folderId) {
- int count = 0;
- String [] whereArgs = new String[] { folderId };
-
- // read current size saved for the folder
- long folderSize = 0;
- long folderParentId = -1;
- Uri selectFolderUri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_FILE, folderId);
- String[] folderProjection = new String[] { ProviderTableMeta.FILE_CONTENT_LENGTH, ProviderTableMeta.FILE_PARENT};
- String folderWhere = ProviderTableMeta._ID + "=?";
- Cursor folderCursor = query(db, selectFolderUri, folderProjection, folderWhere, whereArgs, null);
- if (folderCursor != null && folderCursor.moveToFirst()) {
- folderSize = folderCursor.getLong(folderCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_LENGTH));;
- folderParentId = folderCursor.getLong(folderCursor.getColumnIndex(ProviderTableMeta.FILE_PARENT));;
- }
- folderCursor.close();
-
- // read and sum sizes of children
- long childrenSize = 0;
- Uri selectChildrenUri = Uri.withAppendedPath(ProviderTableMeta.CONTENT_URI_DIR, folderId);
- String[] childrenProjection = new String[] { ProviderTableMeta.FILE_CONTENT_LENGTH, ProviderTableMeta.FILE_PARENT};
- String childrenWhere = ProviderTableMeta.FILE_PARENT + "=?";
- Cursor childrenCursor = query(db, selectChildrenUri, childrenProjection, childrenWhere, whereArgs, null);
- if (childrenCursor != null && childrenCursor.moveToFirst()) {
- while (!childrenCursor.isAfterLast()) {
- childrenSize += childrenCursor.getLong(childrenCursor.getColumnIndex(ProviderTableMeta.FILE_CONTENT_LENGTH));
- childrenCursor.moveToNext();
- }
- }
- childrenCursor.close();
-
- // update if needed
- if (folderSize != childrenSize) {
- Log_OC.d("FileContentProvider", "Updating " + folderSize + " to " + childrenSize);
- ContentValues cv = new ContentValues();
- cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, childrenSize);
- count = db.update(ProviderTableMeta.FILE_TABLE_NAME, cv, folderWhere, whereArgs);
-
- // propagate update until root
- if (folderParentId > FileDataStorageManager.ROOT_PARENT_ID) {
- Log_OC.d("FileContentProvider", "Propagating update to " + folderParentId);
- updateFolderSize(db, String.valueOf(folderParentId));
- } else {
- Log_OC.d("FileContentProvider", "NOT propagating to " + folderParentId);
- }
- } else {
- Log_OC.d("FileContentProvider", "NOT updating, sizes are " + folderSize + " and " + childrenSize);
- }
- return count;
- }
-*/
-
@Override
public ContentProviderResult[] applyBatch (ArrayList<ContentProviderOperation> operations)
throws OperationApplicationException {
+ ProviderTableMeta.FILE_PERMISSIONS + " TEXT null,"
+ ProviderTableMeta.FILE_REMOTE_ID + " TEXT null,"
+ ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER," //boolean
- + ProviderTableMeta.FILE_IS_DOWNLOADING + " INTEGER);" //boolean
+ + ProviderTableMeta.FILE_IS_DOWNLOADING + " INTEGER," //boolean
+ + ProviderTableMeta.FILE_IN_CONFLICT + " INTEGER);" //boolean
);
// Create table ocshares
if (!upgraded)
Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
", newVersion == " + newVersion);
+
+ if (oldVersion < 11 && newVersion >= 11) {
+ Log_OC.i("SQL", "Entering in the #11 ADD in onUpgrade");
+ db.beginTransaction();
+ try {
+ db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
+ " ADD COLUMN " + ProviderTableMeta.FILE_IN_CONFLICT + " INTEGER " +
+ " DEFAULT 0");
+ upgraded = true;
+ db.setTransactionSuccessful();
+ } finally {
+ db.endTransaction();
+ }
+ }
+ if (!upgraded)
+ Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion +
+ ", newVersion == " + newVersion);
+
}
}
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.resources.files.RemoteFile;
+import android.accounts.Account;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
* Static methods to help in access to local file system.
*/
public class FileStorageUtils {
- public static Integer mSortOrder;
- public static Boolean mSortAscending;
public static final Integer SORT_NAME = 0;
public static final Integer SORT_DATE = 1;
public static final Integer SORT_SIZE = 2;
-
+ public static Integer mSortOrder = SORT_NAME;
+ public static Boolean mSortAscending = true;
+
- //private static final String LOG_TAG = "FileStorageUtils";
-
public static final String getSavePath(String accountName) {
File sdCard = Environment.getExternalStorageDirectory();
return sdCard.getAbsolutePath() + "/" + MainApp.getDataFolder() + "/" + Uri.encode(accountName, "@");
* Creates and populates a new {@link OCFile} object with the data read from the server.
*
* @param remote remote file read from the server (remote file or folder).
- * @return New OCFile instance representing the remote resource described by we.
+ * @return New OCFile instance representing the remote resource described by remote.
*/
public static OCFile fillOCFile(RemoteFile remote) {
OCFile file = new OCFile(remote.getRemotePath());
String result = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.toLowerCase());
return (result != null) ? result : "";
}
-
+
+ /**
+ * Scans the default location for saving local copies of files searching for
+ * a 'lost' file with the same full name as the {@link OCFile} received as
+ * parameter.
+ *
+ * This method helps to keep linked local copies of the files when the app is uninstalled, and then
+ * reinstalled in the device. OR after the cache of the app was deleted in system settings.
+ *
+ * The method is assuming that all the local changes in the file where synchronized in the past. This is dangerous,
+ * but assuming the contrary could lead to massive unnecessary synchronizations of downloaded file after deleting
+ * the app cache.
+ *
+ * This should be changed in the near future to avoid any chance of data loss, but we need to add some options
+ * to limit hard automatic synchronizations to wifi, unless the user wants otherwise.
+ *
+ * @param file File to associate a possible 'lost' local file.
+ * @param account Account holding file.
+ */
+ public static void searchForLocalFileInDefaultPath(OCFile file, Account account) {
+ if (file.getStoragePath() == null && !file.isFolder()) {
+ File f = new File(FileStorageUtils.getDefaultSavePathFor(account.name, file));
+ if (f.exists()) {
+ file.setStoragePath(f.getAbsolutePath());
+ file.setLastSyncDateForData(f.lastModified());
+ }
+ }
+ }
+
}