Merge branch 'contact_settings' into setup_app_name
[pub/Android/ownCloud.git] / src / com / owncloud / android / utils / FileStorageUtils.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18 package com.owncloud.android.utils;
19
20 import java.io.File;
21
22 import android.annotation.SuppressLint;
23 import android.content.Context;
24 import android.net.Uri;
25 import android.os.Environment;
26 import android.os.StatFs;
27
28 import com.owncloud.android.MainApp;
29 import com.owncloud.android.R;
30 import com.owncloud.android.datamodel.OCFile;
31
32 /**
33 * Static methods to help in access to local file system.
34 *
35 * @author David A. Velasco
36 */
37 public class FileStorageUtils {
38 //private static final String LOG_TAG = "FileStorageUtils";
39
40 public static final String getSavePath(String accountName) {
41 File sdCard = Environment.getExternalStorageDirectory();
42 return sdCard.getAbsolutePath() + "/" + MainApp.getDataFolder() + "/" + Uri.encode(accountName, "@");
43 // URL encoding is an 'easy fix' to overcome that NTFS and FAT32 don't allow ":" in file names, that can be in the accountName since 0.1.190B
44 }
45
46 public static final String getDefaultSavePathFor(String accountName, OCFile file) {
47 return getSavePath(accountName) + file.getRemotePath();
48 }
49
50 public static final String getTemporalPath(String accountName) {
51 File sdCard = Environment.getExternalStorageDirectory();
52 return sdCard.getAbsolutePath() + "/" + MainApp.getDataFolder() + "/tmp/" + Uri.encode(accountName, "@");
53 // URL encoding is an 'easy fix' to overcome that NTFS and FAT32 don't allow ":" in file names, that can be in the accountName since 0.1.190B
54 }
55
56 @SuppressLint("NewApi")
57 public static final long getUsableSpace(String accountName) {
58 File savePath = Environment.getExternalStorageDirectory();
59 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD) {
60 return savePath.getUsableSpace();
61
62 } else {
63 StatFs stats = new StatFs(savePath.getAbsolutePath());
64 return stats.getAvailableBlocks() * stats.getBlockSize();
65 }
66
67 }
68
69 public static final String getLogPath() {
70 return Environment.getExternalStorageDirectory() + File.separator + MainApp.getDataFolder() + File.separator + "log";
71 }
72
73 public static String getInstantUploadFilePath(Context context, String fileName) {
74 String uploadPath = context.getString(R.string.instant_upload_path);
75 String value = uploadPath + OCFile.PATH_SEPARATOR + (fileName == null ? "" : fileName);
76 return value;
77 }
78
79 }