Updated copyright in source files
[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 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 /**
31 * Static methods to help in access to local file system.
32 *
33 * @author David A. Velasco
34 */
35 public class FileStorageUtils {
36
37 public static final String getSavePath(String accountName) {
38 File sdCard = Environment.getExternalStorageDirectory();
39 return sdCard.getAbsolutePath() + "/owncloud/" + Uri.encode(accountName, "@");
40 // 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
41 }
42
43 public static final String getDefaultSavePathFor(String accountName, OCFile file) {
44 return getSavePath(accountName) + file.getRemotePath();
45 }
46
47 public static final String getTemporalPath(String accountName) {
48 File sdCard = Environment.getExternalStorageDirectory();
49 return sdCard.getAbsolutePath() + "/owncloud/tmp/" + Uri.encode(accountName, "@");
50 // 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
51 }
52
53 public static final long getUsableSpace(String accountName) {
54 File savePath = Environment.getExternalStorageDirectory();
55 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD) {
56 return savePath.getUsableSpace();
57
58 } else {
59 StatFs stats = new StatFs(savePath.getAbsolutePath());
60 return stats.getAvailableBlocks() * stats.getBlockSize();
61 }
62
63 }
64
65 }