144ff80d165e93fabefbe43ef44f13e71e6980ec
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 as published by
6 * the Free Software Foundation, either version 2 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
.annotation
.SuppressLint
;
24 import android
.net
.Uri
;
25 import android
.os
.Environment
;
26 import android
.os
.StatFs
;
27 import android
.util
.Log
;
29 import com
.owncloud
.android
.datamodel
.OCFile
;
30 import com
.owncloud
.android
.files
.services
.InstantUploadService
;
33 * Static methods to help in access to local file system.
35 * @author David A. Velasco
37 public class FileStorageUtils
{
38 private static final String LOG_TAG
= "FileStorageUtils";
40 public static final String
getSavePath(String accountName
) {
41 File sdCard
= Environment
.getExternalStorageDirectory();
42 return sdCard
.getAbsolutePath() + "/owncloud/" + Uri
.encode(accountName
, "@");
43 // 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 public static final String
getDefaultSavePathFor(String accountName
, OCFile file
) {
47 return getSavePath(accountName
) + file
.getRemotePath();
50 public static final String
getTemporalPath(String accountName
) {
51 File sdCard
= Environment
.getExternalStorageDirectory();
52 return sdCard
.getAbsolutePath() + "/owncloud/tmp/" + Uri
.encode(accountName
, "@");
53 // 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
56 @SuppressLint("NewApi")
57 public static final long getUsableSpace(String accountName
) {
58 File savePath
= Environment
.getExternalStorageDirectory();
59 if (android
.os
.Build
.VERSION
.SDK_INT
>= android
.os
.Build
.VERSION_CODES
.GINGERBREAD
) {
60 return savePath
.getUsableSpace();
63 StatFs stats
= new StatFs(savePath
.getAbsolutePath());
64 return stats
.getAvailableBlocks() * stats
.getBlockSize();
69 public static final String
getLogPath() {
70 return Environment
.getExternalStorageDirectory() + File
.separator
+ "owncloud" + File
.separator
+ "log";
73 // to ensure we will not add the slash twice between filename and
75 private static String
getFileName(String filepath
) {
76 if (filepath
!= null
&& !"".equals(filepath
)) {
77 int psi
= filepath
.lastIndexOf('/');
78 String filename
= filepath
;
80 filename
= filepath
.substring(psi
+ 1, filepath
.length());
81 Log
.d(LOG_TAG
, "extracted filename :" + filename
);
86 Log
.w(LOG_TAG
, "the given filename was null or empty");
91 public static String
getInstantUploadFilePath(String fileName
) {
92 return InstantUploadService
.INSTANT_UPLOAD_DIR
+ "/" + getFileName(fileName
);