Merge remote-tracking branch 'origin/sync_review_2'
[pub/Android/ownCloud.git] / src / com / owncloud / android / utils / FileStorageUtils.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
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 as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19 package com.owncloud.android.utils;
20
21 import java.io.File;
22
23 import android.net.Uri;
24 import android.os.Environment;
25 import android.os.StatFs;
26
27 import com.owncloud.android.datamodel.OCFile;
28
29
30 public class FileStorageUtils {
31
32 public static final String getSavePath(String accountName) {
33 File sdCard = Environment.getExternalStorageDirectory();
34 return sdCard.getAbsolutePath() + "/owncloud/" + Uri.encode(accountName, "@");
35 // 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
36 }
37
38 public static final String getDefaultSavePathFor(String accountName, OCFile file) {
39 return getSavePath(accountName) + file.getRemotePath();
40 }
41
42 public static final String getTemporalPath(String accountName) {
43 File sdCard = Environment.getExternalStorageDirectory();
44 return sdCard.getAbsolutePath() + "/owncloud/tmp/" + Uri.encode(accountName, "@");
45 // 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
46 }
47
48 public static final long getUsableSpace(String accountName) {
49 File savePath = Environment.getExternalStorageDirectory();
50 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD) {
51 return savePath.getUsableSpace();
52
53 } else {
54 StatFs stats = new StatFs(savePath.getAbsolutePath());
55 return stats.getAvailableBlocks() * stats.getBlockSize();
56 }
57
58 }
59
60 }