A terminal style view onto the filesystem, with the concept of current working directory. File systems can be mounted to root using libraries such as LocalFileSystem and SDFileSystem. Initial version only allows changing the current working directory and retrieving a directory listing. Required libraries: <<library /users/Phlaphead/libraries/Util/latest>> library.
FileSystemInterface.h@0:63761ecf509c, 2011-06-19 (annotated)
- Committer:
- Phlaphead
- Date:
- Sun Jun 19 13:35:48 2011 +0000
- Revision:
- 0:63761ecf509c
Initial revision. Incomplete version, allows manipulation of working directory and listing files only.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Phlaphead | 0:63761ecf509c | 1 | /* |
Phlaphead | 0:63761ecf509c | 2 | Copyright (c) 2011 Robert Ellis (holistic [at] robellis [dot] org [dot] uk) |
Phlaphead | 0:63761ecf509c | 3 | |
Phlaphead | 0:63761ecf509c | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
Phlaphead | 0:63761ecf509c | 5 | of this software and associated documentation files (the "Software"), to deal |
Phlaphead | 0:63761ecf509c | 6 | in the Software without restriction, including without limitation the rights |
Phlaphead | 0:63761ecf509c | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
Phlaphead | 0:63761ecf509c | 8 | copies of the Software, and to permit persons to whom the Software is |
Phlaphead | 0:63761ecf509c | 9 | furnished to do so, subject to the following conditions: |
Phlaphead | 0:63761ecf509c | 10 | |
Phlaphead | 0:63761ecf509c | 11 | The above copyright notice and this permission notice shall be included in |
Phlaphead | 0:63761ecf509c | 12 | all copies or substantial portions of the Software. |
Phlaphead | 0:63761ecf509c | 13 | |
Phlaphead | 0:63761ecf509c | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Phlaphead | 0:63761ecf509c | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Phlaphead | 0:63761ecf509c | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
Phlaphead | 0:63761ecf509c | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
Phlaphead | 0:63761ecf509c | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Phlaphead | 0:63761ecf509c | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
Phlaphead | 0:63761ecf509c | 20 | THE SOFTWARE. |
Phlaphead | 0:63761ecf509c | 21 | */ |
Phlaphead | 0:63761ecf509c | 22 | |
Phlaphead | 0:63761ecf509c | 23 | #ifndef FILE_SYSTEM_INTERFACE_H |
Phlaphead | 0:63761ecf509c | 24 | #define FILE_SYSTEM_INTERFACE_H |
Phlaphead | 0:63761ecf509c | 25 | |
Phlaphead | 0:63761ecf509c | 26 | #include "File.h" |
Phlaphead | 0:63761ecf509c | 27 | |
Phlaphead | 0:63761ecf509c | 28 | #include <string> |
Phlaphead | 0:63761ecf509c | 29 | #include <vector> |
Phlaphead | 0:63761ecf509c | 30 | #include <list> |
Phlaphead | 0:63761ecf509c | 31 | using namespace std; |
Phlaphead | 0:63761ecf509c | 32 | |
Phlaphead | 0:63761ecf509c | 33 | /** |
Phlaphead | 0:63761ecf509c | 34 | * A terminal style view onto the filesystem, with the concept of current working directory. |
Phlaphead | 0:63761ecf509c | 35 | */ |
Phlaphead | 0:63761ecf509c | 36 | class FileSystemInterface |
Phlaphead | 0:63761ecf509c | 37 | { |
Phlaphead | 0:63761ecf509c | 38 | public: |
Phlaphead | 0:63761ecf509c | 39 | |
Phlaphead | 0:63761ecf509c | 40 | /** |
Phlaphead | 0:63761ecf509c | 41 | * Constructor. |
Phlaphead | 0:63761ecf509c | 42 | */ |
Phlaphead | 0:63761ecf509c | 43 | FileSystemInterface(); |
Phlaphead | 0:63761ecf509c | 44 | |
Phlaphead | 0:63761ecf509c | 45 | /** |
Phlaphead | 0:63761ecf509c | 46 | * Get the current working directory. |
Phlaphead | 0:63761ecf509c | 47 | */ |
Phlaphead | 0:63761ecf509c | 48 | string getWorkingDirectory(); |
Phlaphead | 0:63761ecf509c | 49 | |
Phlaphead | 0:63761ecf509c | 50 | /** |
Phlaphead | 0:63761ecf509c | 51 | * Change the working directory. |
Phlaphead | 0:63761ecf509c | 52 | * @param dir The directory to change to. Can be relative to the current working directory or absolute (begins with '/'). '..' moves to the parent directory. |
Phlaphead | 0:63761ecf509c | 53 | */ |
Phlaphead | 0:63761ecf509c | 54 | bool changeWorkingDirectory(const string& dir); |
Phlaphead | 0:63761ecf509c | 55 | |
Phlaphead | 0:63761ecf509c | 56 | /** |
Phlaphead | 0:63761ecf509c | 57 | * Get a list of files and directories in the current working directory. |
Phlaphead | 0:63761ecf509c | 58 | */ |
Phlaphead | 0:63761ecf509c | 59 | list<File>& getFileList(); |
Phlaphead | 0:63761ecf509c | 60 | |
Phlaphead | 0:63761ecf509c | 61 | |
Phlaphead | 0:63761ecf509c | 62 | private: |
Phlaphead | 0:63761ecf509c | 63 | |
Phlaphead | 0:63761ecf509c | 64 | string getPathAsString(vector<string>& path); |
Phlaphead | 0:63761ecf509c | 65 | bool isFile(const string& path); |
Phlaphead | 0:63761ecf509c | 66 | bool isDir(const string& path); |
Phlaphead | 0:63761ecf509c | 67 | |
Phlaphead | 0:63761ecf509c | 68 | |
Phlaphead | 0:63761ecf509c | 69 | vector<string> m_workDir; //current working path |
Phlaphead | 0:63761ecf509c | 70 | string m_workDirString; |
Phlaphead | 0:63761ecf509c | 71 | list<File> m_ls; |
Phlaphead | 0:63761ecf509c | 72 | |
Phlaphead | 0:63761ecf509c | 73 | }; |
Phlaphead | 0:63761ecf509c | 74 | |
Phlaphead | 0:63761ecf509c | 75 | |
Phlaphead | 0:63761ecf509c | 76 | |
Phlaphead | 0:63761ecf509c | 77 | #endif |