2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 // TODO: remove when added to public cordova repository -> begin
18 cordova.define('cordova-plugin-file.tizen.fileSystemPaths', function(require, exports, module) {
19 // TODO: remove -> end
22 sharedDirectory: 'file:///opt/usr/media/'
25 function setExternalStorage(callback) {
28 var onError = function(error) {
29 console.error('Failed to get external storage: ' + error.message);
30 callback(pathsPrefix);
33 var onSuccess = function(storages) {
34 for (var i = 0; i < storages.length; ++i) {
35 if (storages[i].type === 'EXTERNAL' && storages[i].state === 'MOUNTED') {
36 label = storages[i].label;
41 var onSuccessStorage = function(storage) {
42 pathsPrefix.externalRootDirectory = 'file://' + storage.fullPath + '/';
43 callback(pathsPrefix);
48 tizen.filesystem.resolve(label, onSuccessStorage, onError);
50 callback(pathsPrefix);
53 console.error('Failed to resolve external storage: ' + error.message);
54 callback(pathsPrefix);
59 tizen.filesystem.listStorages(onSuccess, onError);
61 console.error('Failed to list storages: ' + error.message);
62 callback(pathsPrefix);
66 function setApplicationStorageDirectory(callback) {
67 var onError = function (error) {
68 console.error('Failed to get directory: ' + error.message);
69 callback(pathsPrefix);
73 tizen.filesystem.resolve('wgt-package', function(appDir) {
74 pathsPrefix.applicationDirectory = appDir.toURI() + '/';
76 tizen.filesystem.resolve('wgt-private', function(dataDir) {
77 pathsPrefix.applicationStorageDirectory = dataDir.toURI() + '/';
78 pathsPrefix.dataDirectory = dataDir.toURI() + '/';
80 tizen.filesystem.resolve('wgt-private-tmp', function(cacheDir) {
81 pathsPrefix.cacheDirectory = cacheDir.toURI() + '/';
83 setExternalStorage(callback);
88 console.error('Failed to get current application: ' + error.message);
89 callback(pathsPrefix);
94 requestAllPaths: function(successCallback, errorCallback, args) {
95 // we ignore errorCallback here, as we're always reporting as much
96 // information as we currently have
97 setApplicationStorageDirectory(function(r) {
98 successCallback && successCallback(r);
103 //TODO: remove when added to public cordova repository -> begin
105 //TODO: remove -> end