Revert "Updated application sources"
[apps/web/sample/FileManager.git] / project / js / app.systemIO.js
index 4aef763..4c70377 100644 (file)
@@ -1,19 +1,3 @@
-/*
- *      Copyright 2013  Samsung Electronics Co., Ltd
- *
- *      Licensed under the Flora License, Version 1.1 (the "License");
- *      you may not use this file except in compliance with the License.
- *      You may obtain a copy of the License at
- *
- *              http://floralicense.org/license/
- *
- *      Unless required by applicable law or agreed to in writing, software
- *      distributed under the License is distributed on an "AS IS" BASIS,
- *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *      See the License for the specific language governing permissions and
- *      limitations under the License.
- */
-
 /*jslint devel: true*/
 /*global tizen, localStorage */
 
  * @class SystemIO
  */
 function SystemIO() {
-    'use strict';
+       'use strict';
 }
 
 (function () { // strict mode wrapper
-    'use strict';
-    SystemIO.prototype = {
-        /**
-         * Creates new empty file in specified location
-         *
-         * @param {File} directoryHandle
-         * @param {string} fileName
-         */
-        createFile: function SystemIO_createFile(directoryHandle, fileName) {
+       'use strict';
+       SystemIO.prototype = {
+               /**
+                * Creates new empty file in specified location
+                *
+                * @param {File} directoryHandle
+                * @param {string} fileName
+                */
+               createFile: function SystemIO_createFile(directoryHandle, fileName) {
 
-            try {
-                return directoryHandle.createFile(fileName);
-            } catch (e) {
-                console.error('SystemIO_createFile error:' + e.message);
-                return false;
-            }
-        },
+                       try {
+                               return directoryHandle.createFile(fileName);
+                       } catch (e) {
+                               console.error('SystemIO_createFile error:' + e.message);
+                               return false;
+                       }
+               },
 
-        /**
-         * Writes content to file stream
-         *
-         * @param {File} fileHandle file handler
-         * @param {string} fileContent file content
-         * @param {function} onSuccess on success callback
-         * @param {function} onError on error callback
-         * @param {string} content encoding
-         */
-        writeFile: function SystemIO_writeFile(
-            fileHandle,
-            fileContent,
-            onSuccess,
-            onError,
-            contentEncoding
-        ) {
-            onError = onError || function () {};
+               /**
+                * Writes content to file stream
+                *
+                * @param {File} fileHandle file handler
+                * @param {string} fileContent file content
+                * @param {function} onSuccess on success callback
+                * @param {function} onError on error callback
+                * @param {string} content encoding
+                */
+               writeFile: function SystemIO_writeFile(fileHandle, fileContent, onSuccess, onError, contentEncoding) {
+                       onError = onError || function () {};
 
-            fileHandle.openStream('w', function (fileStream) {
-                if (contentEncoding === 'base64') {
-                    fileStream.writeBase64(fileContent);
-                } else {
-                    fileStream.write(fileContent);
-                }
+                       fileHandle.openStream('w', function (fileStream) {
+                               if (contentEncoding === 'base64') {
+                                       fileStream.writeBase64(fileContent);
+                               } else {
+                                       fileStream.write(fileContent);
+                               }
 
-                fileStream.close();
+                               fileStream.close();
 
-                // launch onSuccess callback
-                if (typeof onSuccess === 'function') {
-                    onSuccess();
-                }
-            }, onError, 'UTF-8');
-        },
+                               // launch onSuccess callback
+                               if (typeof onSuccess === 'function') {
+                                       onSuccess();
+                               }
+                       }, onError, 'UTF-8');
+               },
 
-        /**
-         * Opens specified location
-         *
-         * @param {string} directory path
-         * @param {function} on success callback
-         * @param {function} on error callback
-         * @param {string} mode
-         */
-        openDir: function SystemIO_openDir(
-            directoryPath,
-            onSuccess,
-            onError,
-            openMode
-        ) {
-            openMode = openMode || 'rw';
-            onSuccess = onSuccess || function () {};
+               /**
+                * Opens specified location
+                *
+                * @param {string} directory path
+                * @param {function} on success callback
+                * @param {function} on error callback
+                * @param {string} mode
+                */
+               openDir: function SystemIO_openDir(directoryPath, onSuccess, onError, openMode) {
+                       openMode = openMode || 'rw';
+                       onSuccess = onSuccess || function () {};
 
-            try {
-                tizen.filesystem.resolve(
-                    directoryPath,
-                    onSuccess,
-                    onError,
-                    openMode
-                );
-            } catch (e) {
-            }
-        },
+                       try {
+                               tizen.filesystem.resolve(directoryPath, onSuccess, onError, openMode);
+                       } catch (e) {
+                       }
+               },
 
-        /**
-         * Parse specified filepath and returns data parts
-         *
-         * @param {string} filePath
-         * @returns {array}
-         */
-        getPathData: function SystemIO_getPathData(filePath) {
-            var path = {
-                originalPath: filePath,
-                fileName: '',
-                dirName: ''
-            },
-                splittedPath = filePath.split('/');
+               /**
+                * Parse specified filepath and returns data parts
+                *
+                * @param {string} filePath
+                * @returns {array}
+                */
+               getPathData: function SystemIO_getPathData(filePath) {
+                       var path = {
+                               originalPath: filePath,
+                               fileName: '',
+                               dirName: ''
+                       },
+                               splittedPath = filePath.split('/');
 
-            path.fileName = splittedPath.pop();
-            path.dirName = splittedPath.join('/') || '/';
+                       path.fileName = splittedPath.pop();
+                       path.dirName = splittedPath.join('/') || '/';
 
-            return path;
-        },
+                       return path;
+               },
 
-        /**
-         * Save specified content to file
-         *
-         * @param {string} file path
-         * @param {string} file content
-         * @param {string} file encoding
-         */
-        saveFileContent: function SystemIO_saveFileContent(
-            filePath,
-            fileContent,
-            onSaveSuccess,
-            fileEncoding
-        ) {
-            var pathData = this.getPathData(filePath),
-                self = this,
-                fileHandle;
+               /**
+                * Save specified content to file
+                *
+                * @param {string} file path
+                * @param {string} file content
+                * @param {string} file encoding
+                */
+               saveFileContent: function SystemIO_saveFileContent(filePath, fileContent, onSaveSuccess, fileEncoding) {
+                       var pathData = this.getPathData(filePath),
+                               self = this,
+                               fileHandle;
 
-            function onOpenDirSuccess(dir) {
-                // create new file
-                fileHandle = self.createFile(dir, pathData.fileName);
-                if (fileHandle !== false) {
-                    // save data into this file
-                    self.writeFile(
-                        fileHandle,
-                        fileContent,
-                        onSaveSuccess,
-                        false,
-                        fileEncoding
-                    );
-                }
-            }
+                       function onOpenDirSuccess(dir) {
+                               // create new file
+                               fileHandle = self.createFile(dir, pathData.fileName);
+                               if (fileHandle !== false) {
+                                       // save data into this file
+                                       self.writeFile(fileHandle, fileContent, onSaveSuccess, false, fileEncoding);
+                               }
+                       }
 
-            // open directory
-            this.openDir(pathData.dirName, onOpenDirSuccess);
-        },
+                       // open directory
+                       this.openDir(pathData.dirName, onOpenDirSuccess);
+               },
 
-        /**
-         * Deletes node with specified path
-         *
-         * @param {string} node path
-         * @param {function} success callback
-         */
-        deleteNode: function SystemIO_deleteNode(nodePath, onSuccess) {
-            var pathData = this.getPathData(nodePath),
-                self = this;
+               /**
+                * Deletes node with specified path
+                *
+                * @param {string} node path
+                * @param {function} success callback
+                */
+               deleteNode: function SystemIO_deleteNode(nodePath, onSuccess) {
+                       var pathData = this.getPathData(nodePath),
+                               self = this;
 
-            function onDeleteSuccess() {
-                onSuccess();
-            }
+                       function onDeleteSuccess() {
+                               onSuccess();
+                       }
 
-            function onDeleteError(e) {
-                console.error('SystemIO_deleteNode:_onDeleteError', e);
-            }
+                       function onDeleteError(e) {
+                               console.error('SystemIO_deleteNode:_onDeleteError', e);
+                       }
 
-            function onOpenDirSuccess(dir) {
-                var onListFiles = function (files) {
-                    if (files.length > 0) {
-                        // file exists;
-                        if (files[0].isDirectory) {
-                            self.deleteDir(
-                                dir,
-                                files[0].fullPath,
-                                onDeleteSuccess,
-                                onDeleteError
-                            );
-                        } else {
-                            self.deleteFile(
-                                dir,
-                                files[0].fullPath,
-                                onDeleteSuccess,
-                                onDeleteError
-                            );
-                        }
-                    } else {
-                        onDeleteSuccess();
-                    }
-                };
+                       function onOpenDirSuccess(dir) {
+                               var onListFiles = function (files) {
+                                       if (files.length > 0) {
+                                               // file exists;
+                                               if (files[0].isDirectory) {
+                                                       self.deleteDir(dir, files[0].fullPath, onDeleteSuccess, onDeleteError);
+                                               } else {
+                                                       self.deleteFile(dir, files[0].fullPath, onDeleteSuccess, onDeleteError);
+                                               }
+                                       } else {
+                                               onDeleteSuccess();
+                                       }
+                               };
 
-                // check file exists;
-                dir.listFiles(onListFiles, function (e) {
-                    console.error(e);
-                }, {
-                    name: pathData.fileName
-                });
-            }
+                               // check file exists;
+                               dir.listFiles(onListFiles, function (e) {
+                                       console.error(e);
+                               }, {
+                                       name: pathData.fileName
+                               });
+                       }
 
-            this.openDir(pathData.dirName, onOpenDirSuccess, function (e) {
-                console.error('openDir error:' + e.message);
-            });
-        },
+                       this.openDir(pathData.dirName, onOpenDirSuccess, function (e) {
+                               console.error('openDir error:' + e.message);
+                       });
+               },
 
-        /**
-         * Deletes specified file
-         *
-         * @param {File} dir
-         * @param {string} file path
-         * @param {function} delete success callback
-         * @param {function} delete error callback
-         */
-        deleteFile: function SystemIO_deleteFile(
-            dir,
-            filePath,
-            onDeleteSuccess,
-            onDeleteError
-        ) {
-            try {
-                dir.deleteFile(filePath, onDeleteSuccess, onDeleteError);
-            } catch (e) {
-                console.error('SystemIO_deleteFile error: ' + e.message);
-                return false;
-            }
-        },
+               /**
+                * Deletes specified file
+                *
+                * @param {File} dir
+                * @param {string} file path
+                * @param {function} delete success callback
+                * @param {function} delete error callback
+                */
+               deleteFile: function SystemIO_deleteFile(dir, filePath, onDeleteSuccess, onDeleteError) {
+                       try {
+                               dir.deleteFile(filePath, onDeleteSuccess, onDeleteError);
+                       } catch (e) {
+                               console.error('SystemIO_deleteFile error: ' + e.message);
+                               return false;
+                       }
+               },
 
-        /**
-         * Deletes specified directory
-         *
-         * @param {File} dir
-         * @param {string} dirPath dir path
-         * @param {function} onDeleteSuccess delete success callback
-         * @param {function} onDeleteError delete error callback
-         * @returns {boolean}
-         */
-        deleteDir: function SystemIO_deleteDir(
-            dir,
-            dirPath,
-            onDeleteSuccess,
-            onDeleteError
-        ) {
-            try {
-                dir.deleteDirectory(
-                    dirPath,
-                    false,
-                    onDeleteSuccess,
-                    onDeleteError
-                );
-            } catch (e) {
-                console.error('SystemIO_deleteDir error:' + e.message);
-                return false;
-            }
+               /**
+                * Deletes specified directory
+                *
+                * @param {File} dir
+                * @param {string} dirPath dir path
+                * @param {function} onDeleteSuccess delete success callback
+                * @param {function} onDeleteError delete error callback
+                * @returns {boolean}
+                */
+               deleteDir: function SystemIO_deleteDir(dir, dirPath, onDeleteSuccess, onDeleteError) {
+                       try {
+                               dir.deleteDirectory(dirPath, false, onDeleteSuccess, onDeleteError);
+                       } catch (e) {
+                               console.error('SystemIO_deleteDir error:' + e.message);
+                               return false;
+                       }
 
-            return true;
-        },
+                       return true;
+               },
 
-        /**
-         * @param {string} type storage type
-         * @param {function} onSuccess on success callback
-         * @param {string} excluded Excluded storage
-         */
-        getStorages: function SystemIO_getStorages(type, onSuccess, excluded) {
-            try {
-                tizen.filesystem.listStorages(function (storages) {
-                    var tmp = [],
-                        len = storages.length,
-                        i;
+               /**
+                * @param {string} type storage type
+                * @param {function} onSuccess on success callback
+                * @param {string} excluded Excluded storage
+                */
+               getStorages: function SystemIO_getStorages(type, onSuccess, excluded) {
+                       try {
+                               tizen.filesystem.listStorages(function (storages) {
+                                       var tmp = [],
+                                               len = storages.length,
+                                               i;
 
-                    if (type !== undefined) {
-                        for (i = 0; i < len; i += 1) {
-                            if (storages[i].label !== excluded) {
-                                if (
-                                    storages[i].type === 0 ||
-                                        storages[i].type === type
-                                ) {
-                                    tmp.push(storages[i]);
-                                }
-                            }
-                        }
-                    } else {
-                        tmp = storages;
-                    }
+                                       if (type !== undefined) {
+                                               for (i = 0; i < len; i += 1) {
+                                                       if (storages[i].label !== excluded) {
+                                                               if (storages[i].type === 0 || storages[i].type === type) {
+                                                                       tmp.push(storages[i]);
+                                                               }
+                                                       }
+                                               }
+                                       } else {
+                                               tmp = storages;
+                                       }
 
-                    if (typeof onSuccess === 'function') {
-                        onSuccess(tmp);
-                    }
-                });
-            } catch (e) {
-                console.error('SystemIO_getStorages error:' + e.message);
-            }
-        },
+                                       if (typeof onSuccess === 'function') {
+                                               onSuccess(tmp);
+                                       }
+                               });
+                       } catch (e) {
+                               console.error('SystemIO_getStorages error:' + e.message);
+                       }
+               },
 
-        getFilesList: function SystemIO_getFilesList(dir, onSuccess) {
-            try {
-                dir.listFiles(
-                    function (files) {
-                        var tmp = [],
-                            len = files.length,
-                            i;
+               getFilesList: function SystemIO_getFilesList(dir, onSuccess) {
+                       try {
+                               dir.listFiles(
+                                       function (files) {
+                                               var tmp = [],
+                                                       len = files.length,
+                                                       i;
 
-                        for (i = 0; i < len; i += 1) {
-                            tmp.push({
-                                name: files[i].name,
-                                isDirectory: files[i].isDirectory
-                            });
-                        }
+                                               for (i = 0; i < len; i += 1) {
+                                                       tmp.push(files[i].name);
+                                               }
 
-                        if (typeof onSuccess === 'function') {
-                            onSuccess(tmp);
-                        }
-                    },
-                    function (e) {
-                        console.error(
-                            'SystemIO_getFilesList dir.listFiles() error:',
-                            e
-                        );
-                    }
-                );
-            } catch (e) {
-                console.error('SystemIO_getFilesList error:', e.message);
-            }
-        }
-    };
-}());
+                                               if (typeof onSuccess === 'function') {
+                                                       onSuccess(tmp);
+                                               }
+                                       },
+                                       function (e) {
+                                               console.error('SystemIO_getFilesList dir.listFiles() error:', e);
+                                       }
+                               );
+                       } catch (e) {
+                               console.error('SystemIO_getFilesList error:', e.message);
+                       }
+               }
+       };
+}());
\ No newline at end of file