1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
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.
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.
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/>.
18 package com
.owncloud
.android
.utils
;
22 import com
.owncloud
.android
.MainApp
;
23 import com
.owncloud
.android
.R
;
24 import com
.owncloud
.android
.datamodel
.OCFile
;
26 import android
.annotation
.SuppressLint
;
27 import android
.content
.Context
;
28 import android
.net
.Uri
;
29 import android
.os
.Environment
;
30 import android
.os
.StatFs
;
34 * Static methods to help in access to local file system.
36 * @author David A. Velasco
38 public class FileStorageUtils
{
39 //private static final String LOG_TAG = "FileStorageUtils";
41 public static final String
getSavePath(String accountName
) {
42 File sdCard
= Environment
.getExternalStorageDirectory();
43 return sdCard
.getAbsolutePath() + "/" + MainApp
.getDataFolder() + "/" + Uri
.encode(accountName
, "@");
44 // 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
47 public static final String
getDefaultSavePathFor(String accountName
, OCFile file
) {
48 return getSavePath(accountName
) + file
.getRemotePath();
51 public static final String
getTemporalPath(String accountName
) {
52 File sdCard
= Environment
.getExternalStorageDirectory();
53 return sdCard
.getAbsolutePath() + "/" + MainApp
.getDataFolder() + "/tmp/" + Uri
.encode(accountName
, "@");
54 // 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
57 @SuppressLint("NewApi")
58 public static final long getUsableSpace(String accountName
) {
59 File savePath
= Environment
.getExternalStorageDirectory();
60 if (android
.os
.Build
.VERSION
.SDK_INT
>= android
.os
.Build
.VERSION_CODES
.GINGERBREAD
) {
61 return savePath
.getUsableSpace();
64 StatFs stats
= new StatFs(savePath
.getAbsolutePath());
65 return stats
.getAvailableBlocks() * stats
.getBlockSize();
70 public static final String
getLogPath() {
71 return Environment
.getExternalStorageDirectory() + File
.separator
+ MainApp
.getDataFolder() + File
.separator
+ "log";
74 public static String
getInstantUploadFilePath(Context context
, String fileName
) {
75 String uploadPath
= context
.getString(R
.string
.instant_upload_path
);
76 String value
= uploadPath
+ OCFile
.PATH_SEPARATOR
+ (fileName
== null ?
"" : fileName
);
80 public static String
getParentPath(String remotePath
) {
81 String parentPath
= new File(remotePath
).getParent();
82 parentPath
= parentPath
.endsWith(OCFile
.PATH_SEPARATOR
) ? parentPath
: parentPath
+ OCFile
.PATH_SEPARATOR
;