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
;
21 import java
.util
.Vector
;
23 import android
.annotation
.SuppressLint
;
24 import android
.content
.Context
;
25 import android
.net
.Uri
;
26 import android
.os
.Environment
;
27 import android
.os
.StatFs
;
29 import com
.owncloud
.android
.Log_OC
;
30 import com
.owncloud
.android
.R
;
31 import com
.owncloud
.android
.datamodel
.DataStorageManager
;
32 import com
.owncloud
.android
.datamodel
.OCFile
;
35 * Static methods to help in access to local file system.
37 * @author David A. Velasco
39 public class FileStorageUtils
{
40 private static final String LOG_TAG
= "FileStorageUtils";
42 public static final String
getSavePath(String accountName
) {
43 File sdCard
= Environment
.getExternalStorageDirectory();
44 return sdCard
.getAbsolutePath() + "/owncloud/" + 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
48 public static final String
getDefaultSavePathFor(String accountName
, OCFile file
) {
49 return getSavePath(accountName
) + file
.getRemotePath();
52 public static final String
getTemporalPath(String accountName
) {
53 File sdCard
= Environment
.getExternalStorageDirectory();
54 return sdCard
.getAbsolutePath() + "/owncloud/tmp/" + Uri
.encode(accountName
, "@");
55 // 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
58 @SuppressLint("NewApi")
59 public static final long getUsableSpace(String accountName
) {
60 File savePath
= Environment
.getExternalStorageDirectory();
61 if (android
.os
.Build
.VERSION
.SDK_INT
>= android
.os
.Build
.VERSION_CODES
.GINGERBREAD
) {
62 return savePath
.getUsableSpace();
65 StatFs stats
= new StatFs(savePath
.getAbsolutePath());
66 return stats
.getAvailableBlocks() * stats
.getBlockSize();
71 public static final String
getLogPath() {
72 return Environment
.getExternalStorageDirectory() + File
.separator
+ "owncloud" + File
.separator
+ "log";
75 public static String
getInstantUploadFilePath(Context context
, String fileName
) {
76 String uploadPath
= context
.getString(R
.string
.instant_upload_path
);
77 String value
= uploadPath
+ OCFile
.PATH_SEPARATOR
+ (fileName
== null ?
"" : fileName
);
81 public static void saveFolderSize(long id
, DataStorageManager storageManager
)
85 Vector
<OCFile
> files
= storageManager
.getFilesbyParent(id
);
87 Log_OC
.d(LOG_TAG
, "Folder " + String
.valueOf(id
) + "--- Number of Files = " + String
.valueOf(files
.size()));
91 folderSize
= folderSize
+ f
.getFileLength();
92 Log_OC
.d(LOG_TAG
, "Folder Size = " + String
.valueOf(folderSize
));
95 storageManager
.updatefolderSize(id
, folderSize
);