1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
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.
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.
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/>.
19 package com
.owncloud
.android
.utils
;
23 import android
.net
.Uri
;
24 import android
.os
.Environment
;
25 import android
.os
.StatFs
;
27 import com
.owncloud
.android
.datamodel
.OCFile
;
30 public class FileStorageUtils
{
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
38 public static final String
getDefaultSavePathFor(String accountName
, OCFile file
) {
39 return getSavePath(accountName
) + file
.getRemotePath();
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
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();
54 StatFs stats
= new StatFs(savePath
.getAbsolutePath());
55 return stats
.getAvailableBlocks() * stats
.getBlockSize();