-
|
|
|
| 1 | #ifndef ABSTRACT_FILESYSTEM_FACTORY_H |
| 2 | #define ABSTRACT_FILESYSTEM_FACTORY_H |
| 3 | |
| 4 | #include "common/str.h" |
| 5 | #include "backends/fs/abstract-fs.h" |
| 6 | |
| 7 | /** |
| 8 | * Creates concrete FilesystemNode objects depending on the current architecture. |
| 9 | */ |
| 10 | class AbstractFilesystemFactory { |
| 11 | public: |
| 12 | typedef Common::String String; |
| 13 | |
| 14 | /** |
| 15 | * Destructor. |
| 16 | */ |
| 17 | virtual ~AbstractFilesystemFactory() {} |
| 18 | |
| 19 | /** |
| 20 | * Returns a node representing the "current directory". |
| 21 | * If your system does not support this concept, you can either try to |
| 22 | * emulate it or simply return some "sensible" default directory node, |
| 23 | * e.g. the same value as getRoot() returns. |
| 24 | */ |
| 25 | virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const = 0; |
| 26 | |
| 27 | /** |
| 28 | * Construct a node based on a path; the path is in the same format as it |
| 29 | * would be for calls to fopen(). |
| 30 | * |
| 31 | * Furthermore getNodeForPath(oldNode.path()) should create a new node |
| 32 | * identical to oldNode. Hence, we can use the "path" value for persistent |
| 33 | * storage e.g. in the config file. |
| 34 | * |
| 35 | * @param path The path string to create a FilesystemNode for. |
| 36 | */ |
| 37 | virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const = 0; |
| 38 | |
| 39 | /** |
| 40 | * Returns a special node representing the filesystem root. |
| 41 | * The starting point for any file system browsing. |
| 42 | * |
| 43 | * On Unix, this will be simply the node for / (the root directory). |
| 44 | * On Windows, it will be a special node which "contains" all drives (C:, D:, E:). |
| 45 | */ |
| 46 | virtual AbstractFilesystemNode *makeRootFileNode() const = 0; |
| 47 | }; |
| 48 | |
| 49 | #endif /*ABSTRACT_FILESYSTEM_FACTORY_H*/ |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/abstract-fs-factory.h
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #include "backends/factories/amigaos4/amigaos4-fs-factory.h" |
| 2 | #include "backends/fs/amigaos4/amigaos4-fs.cpp" |
| 3 | |
| 4 | DECLARE_SINGLETON(AmigaOSFilesystemFactory); |
| 5 | |
| 6 | AbstractFilesystemNode *AmigaOSFilesystemFactory::makeRootFileNode() const { |
| 7 | return new AmigaOSFilesystemNode(); |
| 8 | } |
| 9 | |
| 10 | AbstractFilesystemNode *AmigaOSFilesystemFactory::makeCurrentDirectoryFileNode() const { |
| 11 | return new AmigaOSFilesystemNode(); |
| 12 | } |
| 13 | |
| 14 | AbstractFilesystemNode *AmigaOSFilesystemFactory::makeFileNodePath(const String &path) const { |
| 15 | return new AmigaOSFilesystemNode(path); |
| 16 | } |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/amigaos4/amigaos4-fs-factory.cpp
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #ifndef AMIGAOS_FILESYSTEM_FACTORY_H |
| 2 | #define AMIGAOS_FILESYSTEM_FACTORY_H |
| 3 | |
| 4 | #include "common/singleton.h" |
| 5 | #include "backends/factories/abstract-fs-factory.h" |
| 6 | |
| 7 | /** |
| 8 | * Creates AmigaOSFilesystemNode objects. |
| 9 | * |
| 10 | * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. |
| 11 | */ |
| 12 | class AmigaOSFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<AmigaOSFilesystemFactory> { |
| 13 | public: |
| 14 | typedef Common::String String; |
| 15 | |
| 16 | virtual AbstractFilesystemNode *makeRootFileNode() const; |
| 17 | virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; |
| 18 | virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; |
| 19 | |
| 20 | protected: |
| 21 | AmigaOSFilesystemFactory() {}; |
| 22 | |
| 23 | private: |
| 24 | friend class Common::Singleton<SingletonBaseType>; |
| 25 | }; |
| 26 | |
| 27 | #endif /*AMIGAOS_FILESYSTEM_FACTORY_H*/ |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/amigaos4/amigaos4-fs-factory.h
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #include "backends/factories/dc/ronincd-fs-factory.h" |
| 2 | #include "backends/fs/dc/dc-fs.cpp" |
| 3 | |
| 4 | DECLARE_SINGLETON(RoninCDFilesystemFactory); |
| 5 | |
| 6 | AbstractFilesystemNode *RoninCDFilesystemFactory::makeRootFileNode() const { |
| 7 | return new RoninCDFilesystemNode(); |
| 8 | } |
| 9 | |
| 10 | AbstractFilesystemNode *RoninCDFilesystemFactory::makeCurrentDirectoryFileNode() const { |
| 11 | return new RoninCDFilesystemNode(); |
| 12 | } |
| 13 | |
| 14 | AbstractFilesystemNode *RoninCDFilesystemFactory::makeFileNodePath(const String &path) const { |
| 15 | return new RoninCDFilesystemNode(path, true); |
| 16 | } |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/dc/ronincd-fs-factory.cpp
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #ifndef RONINCD_FILESYSTEM_FACTORY_H |
| 2 | #define RONINCD_FILESYSTEM_FACTORY_H |
| 3 | |
| 4 | #include "common/singleton.h" |
| 5 | #include "backends/factories/abstract-fs-factory.h" |
| 6 | |
| 7 | /** |
| 8 | * Creates RoninCDFilesystemNode objects. |
| 9 | * |
| 10 | * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. |
| 11 | */ |
| 12 | class RoninCDFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<RoninCDFilesystemFactory> { |
| 13 | public: |
| 14 | typedef Common::String String; |
| 15 | |
| 16 | virtual AbstractFilesystemNode *makeRootFileNode() const; |
| 17 | virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; |
| 18 | virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; |
| 19 | |
| 20 | protected: |
| 21 | RoninCDFilesystemFactory() {}; |
| 22 | |
| 23 | private: |
| 24 | friend class Common::Singleton<SingletonBaseType>; |
| 25 | }; |
| 26 | |
| 27 | #endif /*RONINCD_FILESYSTEM_FACTORY_H*/ |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/dc/ronincd-fs-factory.h
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #include "backends/factories/ds/ds-fs-factory.h" |
| 2 | #include "backends/fs/ds/ds-fs.cpp" |
| 3 | #include "dsmain.h" //for the isGBAMPAvailable() function |
| 4 | |
| 5 | DECLARE_SINGLETON(DSFilesystemFactory); |
| 6 | |
| 7 | AbstractFilesystemNode *DSFilesystemFactory::makeRootFileNode() const { |
| 8 | if (DS::isGBAMPAvailable()) { |
| 9 | return new DS::GBAMPFileSystemNode(); |
| 10 | } else { |
| 11 | return new DS::DSFileSystemNode(); |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | AbstractFilesystemNode *DSFilesystemFactory::makeCurrentDirectoryFileNode() const { |
| 16 | if (DS::isGBAMPAvailable()) { |
| 17 | return new DS::GBAMPFileSystemNode(); |
| 18 | } else { |
| 19 | return new DS::DSFileSystemNode(); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | AbstractFilesystemNode *DSFilesystemFactory::makeFileNodePath(const String &path) const { |
| 24 | if (DS::isGBAMPAvailable()) { |
| 25 | return new DS::GBAMPFileSystemNode(path); |
| 26 | } else { |
| 27 | return new DS::DSFileSystemNode(path); |
| 28 | } |
| 29 | } |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/ds/ds-fs-factory.cpp
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #ifndef DS_FILESYSTEM_FACTORY_H |
| 2 | #define DS_FILESYSTEM_FACTORY_H |
| 3 | |
| 4 | #include "common/singleton.h" |
| 5 | #include "backends/factories/abstract-fs-factory.h" |
| 6 | |
| 7 | /** |
| 8 | * Creates DSFilesystemNode objects. |
| 9 | * |
| 10 | * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. |
| 11 | */ |
| 12 | class DSFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<DSFilesystemFactory> { |
| 13 | public: |
| 14 | typedef Common::String String; |
| 15 | |
| 16 | virtual AbstractFilesystemNode *makeRootFileNode() const; |
| 17 | virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; |
| 18 | virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; |
| 19 | |
| 20 | protected: |
| 21 | DSFilesystemFactory() {}; |
| 22 | |
| 23 | private: |
| 24 | friend class Common::Singleton<SingletonBaseType>; |
| 25 | }; |
| 26 | |
| 27 | #endif /*DS_FILESYSTEM_FACTORY_H*/ |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/ds/ds-fs-factory.h
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #include "backends/factories/abstract-fs-factory.h" |
| 2 | |
| 3 | /* |
| 4 | * All the following includes choose, at compile time, which specific backend will be used |
| 5 | * during the execution of the ScummVM. |
| 6 | * |
| 7 | * It has to be done this way because not all the necessary libraries will be available in |
| 8 | * all build environments. Additionally, this results in smaller binaries. |
| 9 | */ |
| 10 | #if defined(__amigaos4__) |
| 11 | #include "backends/factories/amigaos4/amigaos4-fs-factory.cpp" |
| 12 | #endif |
| 13 | |
| 14 | #if defined(__DC__) |
| 15 | #include "backends/factories/dc/ronincd-fs-factory.cpp" |
| 16 | #endif |
| 17 | |
| 18 | #if defined(__DS__) |
| 19 | #include "backends/factories/ds/ds-fs-factory.cpp" |
| 20 | #endif |
| 21 | |
| 22 | #if defined(__GP32__) |
| 23 | #include "backends/factories/gp32/gp32-fs-factory.cpp" |
| 24 | #endif |
| 25 | |
| 26 | #if defined(__MORPHOS__) |
| 27 | #include "backends/factories/morphos/abox-fs-factory.cpp" |
| 28 | #endif |
| 29 | |
| 30 | #if defined(PALMOS_MODE) |
| 31 | #include "backends/factories/palmos/palmos-fs-factory.cpp" |
| 32 | #endif |
| 33 | |
| 34 | #if defined(__PLAYSTATION2__) |
| 35 | #include "backends/factories/ps2/ps2-fs-factory.cpp" |
| 36 | #endif |
| 37 | |
| 38 | #if defined(__PSP__) |
| 39 | #include "backends/factories/psp/psp-fs-factory.cpp" |
| 40 | #endif |
| 41 | |
| 42 | #if defined(__SYMBIAN32__) |
| 43 | #include "backends/factories/symbian/symbian-fs-factory.cpp" |
| 44 | #endif |
| 45 | |
| 46 | #if defined(UNIX) |
| 47 | #include "backends/factories/posix/posix-fs-factory.cpp" |
| 48 | #endif |
| 49 | |
| 50 | #if defined(WIN32) |
| 51 | #include "backends/factories/windows/windows-fs-factory.cpp" |
| 52 | #endif |
| 53 | |
| 54 | /** |
| 55 | * Creates concrete FilesystemFactory and FileFactory objects depending on the current architecture. |
| 56 | */ |
| 57 | class FilesystemFactoryMaker { |
| 58 | public: |
| 59 | |
| 60 | /** |
| 61 | * Returns the correct concrete filesystem factory depending on the current build architecture. |
| 62 | */ |
| 63 | static AbstractFilesystemFactory *makeFactory(); |
| 64 | |
| 65 | protected: |
| 66 | FilesystemFactoryMaker() {}; // avoid instances of this class |
| 67 | }; |
| 68 | |
| 69 | AbstractFilesystemFactory *FilesystemFactoryMaker::makeFactory(){ |
| 70 | #if defined(__amigaos4__) |
| 71 | return &AmigaOSFilesystemFactory::instance(); |
| 72 | #endif |
| 73 | |
| 74 | #if defined(__DC__) |
| 75 | return &RoninCDFilesystemFactory::instance(); |
| 76 | #endif |
| 77 | |
| 78 | #if defined(__DS__) |
| 79 | return &DSFilesystemFactory::instance(); |
| 80 | #endif |
| 81 | |
| 82 | #if defined(__GP32__) |
| 83 | return &GP32FilesystemFactory::instance(); |
| 84 | #endif |
| 85 | |
| 86 | #if defined(__MORPHOS__) |
| 87 | return &ABoxFilesystemFactory::instance(); |
| 88 | #endif |
| 89 | |
| 90 | #if defined(PALMOS_MODE) |
| 91 | return &PalmOSFilesystemFactory::instance(); |
| 92 | #endif |
| 93 | |
| 94 | #if defined(__PLAYSTATION2__) |
| 95 | return &Ps2FilesystemFactory::instance(); |
| 96 | #endif |
| 97 | |
| 98 | #if defined(__PSP__) |
| 99 | return &PSPFilesystemFactory::instance(); |
| 100 | #endif |
| 101 | |
| 102 | #if defined(__SYMBIAN32__) |
| 103 | return &SymbianFilesystemFactory::instance(); |
| 104 | #endif |
| 105 | |
| 106 | #if defined(UNIX) |
| 107 | return &POSIXFilesystemFactory::instance(); |
| 108 | #endif |
| 109 | |
| 110 | #if defined(WIN32) |
| 111 | return &WindowsFilesystemFactory::instance(); |
| 112 | #endif |
| 113 | } |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/fs-factory-maker.cpp
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #include "backends/factories/gp32/gp32-fs-factory.h" |
| 2 | #include "backends/fs/gp32/gp32-fs.cpp" |
| 3 | |
| 4 | DECLARE_SINGLETON(GP32FilesystemFactory); |
| 5 | |
| 6 | AbstractFilesystemNode *GP32FilesystemFactory::makeRootFileNode() const { |
| 7 | return new GP32FilesystemNode(); |
| 8 | } |
| 9 | |
| 10 | AbstractFilesystemNode *GP32FilesystemFactory::makeCurrentDirectoryFileNode() const { |
| 11 | return new GP32FilesystemNode(); |
| 12 | } |
| 13 | |
| 14 | AbstractFilesystemNode *GP32FilesystemFactory::makeFileNodePath(const String &path) const { |
| 15 | return new GP32FilesystemNode(path); |
| 16 | } |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/gp32/gp32-fs-factory.cpp
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #ifndef GP32_FILESYSTEM_FACTORY_H |
| 2 | #define GP32_FILESYSTEM_FACTORY_H |
| 3 | |
| 4 | #include "common/singleton.h" |
| 5 | #include "backends/factories/abstract-fs-factory.h" |
| 6 | |
| 7 | /** |
| 8 | * Creates GP32FilesystemNode objects. |
| 9 | * |
| 10 | * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. |
| 11 | */ |
| 12 | class GP32FilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<GP32FilesystemFactory> { |
| 13 | public: |
| 14 | typedef Common::String String; |
| 15 | |
| 16 | virtual AbstractFilesystemNode *makeRootFileNode() const; |
| 17 | virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; |
| 18 | virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; |
| 19 | |
| 20 | protected: |
| 21 | GP32FilesystemFactory() {}; |
| 22 | |
| 23 | private: |
| 24 | friend class Common::Singleton<SingletonBaseType>; |
| 25 | }; |
| 26 | |
| 27 | #endif /*GP32_FILESYSTEM_FACTORY_H*/ |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/gp32/gp32-fs-factory.h
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #include "backends/factories/morphos/abox-fs-factory.h" |
| 2 | #include "backends/fs/morphos/abox-fs.cpp" |
| 3 | |
| 4 | DECLARE_SINGLETON(ABoxFilesystemFactory); |
| 5 | |
| 6 | AbstractFilesystemNode *ABoxFilesystemFactory::makeRootFileNode() const { |
| 7 | return new ABoxFilesystemNode(); |
| 8 | } |
| 9 | |
| 10 | AbstractFilesystemNode *ABoxFilesystemFactory::makeCurrentDirectoryFileNode() const { |
| 11 | return new ABoxFilesystemNode(); |
| 12 | } |
| 13 | |
| 14 | AbstractFilesystemNode *ABoxFilesystemFactory::makeFileNodePath(const String &path) const { |
| 15 | return new ABoxFilesystemNode(path); |
| 16 | } |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/morphos/abox-fs-factory.cpp
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #ifndef ABOX_FILESYSTEM_FACTORY_H |
| 2 | #define ABOX_FILESYSTEM_FACTORY_H |
| 3 | |
| 4 | #include "common/singleton.h" |
| 5 | #include "backends/factories/abstract-fs-factory.h" |
| 6 | |
| 7 | /** |
| 8 | * Creates ABoxFilesystemNode objects. |
| 9 | * |
| 10 | * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. |
| 11 | */ |
| 12 | class ABoxFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<ABoxFilesystemFactory> { |
| 13 | public: |
| 14 | typedef Common::String String; |
| 15 | |
| 16 | virtual AbstractFilesystemNode *makeRootFileNode() const; |
| 17 | virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; |
| 18 | virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; |
| 19 | |
| 20 | protected: |
| 21 | ABoxFilesystemFactory() {}; |
| 22 | |
| 23 | private: |
| 24 | friend class Common::Singleton<SingletonBaseType>; |
| 25 | }; |
| 26 | |
| 27 | #endif /*ABOX_FILESYSTEM_FACTORY_H*/ |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/morphos/abox-fs-factory.h
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #include "backends/factories/palmos/palmos-fs-factory.h" |
| 2 | #include "backends/fs/palmos/palmos-fs.cpp" |
| 3 | |
| 4 | DECLARE_SINGLETON(PalmOSFilesystemFactory); |
| 5 | |
| 6 | AbstractFilesystemNode *PalmOSFilesystemFactory::makeRootFileNode() const { |
| 7 | return new PalmOSFilesystemNode(); |
| 8 | } |
| 9 | |
| 10 | AbstractFilesystemNode *PalmOSFilesystemFactory::makeCurrentDirectoryFileNode() const { |
| 11 | return new PalmOSFilesystemNode(); |
| 12 | } |
| 13 | |
| 14 | AbstractFilesystemNode *PalmOSFilesystemFactory::makeFileNodePath(const String &path) const { |
| 15 | return new PalmOSFilesystemNode(path); |
| 16 | } |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/palmos/palmos-fs-factory.cpp
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #ifndef PALMOS_FILESYSTEM_FACTORY_H |
| 2 | #define PALMOS_FILESYSTEM_FACTORY_H |
| 3 | |
| 4 | #include "common/singleton.h" |
| 5 | #include "backends/factories/abstract-fs-factory.h" |
| 6 | |
| 7 | /** |
| 8 | * Creates PalmOSFilesystemNode objects. |
| 9 | * |
| 10 | * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. |
| 11 | */ |
| 12 | class PalmOSFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<PalmOSFilesystemFactory> { |
| 13 | public: |
| 14 | typedef Common::String String; |
| 15 | |
| 16 | virtual AbstractFilesystemNode *makeRootFileNode() const; |
| 17 | virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; |
| 18 | virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; |
| 19 | |
| 20 | protected: |
| 21 | PalmOSFilesystemFactory() {}; |
| 22 | |
| 23 | private: |
| 24 | friend class Common::Singleton<SingletonBaseType>; |
| 25 | }; |
| 26 | |
| 27 | #endif /*PALMOS_FILESYSTEM_FACTORY_H*/ |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/palmos/palmos-fs-factory.h
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #include "backends/factories/posix/posix-fs-factory.h" |
| 2 | #include "backends/fs/posix/posix-fs.cpp" |
| 3 | |
| 4 | DECLARE_SINGLETON(POSIXFilesystemFactory); |
| 5 | |
| 6 | AbstractFilesystemNode *POSIXFilesystemFactory::makeRootFileNode() const { |
| 7 | return new POSIXFilesystemNode(); |
| 8 | } |
| 9 | |
| 10 | AbstractFilesystemNode *POSIXFilesystemFactory::makeCurrentDirectoryFileNode() const { |
| 11 | char buf[MAXPATHLEN]; |
| 12 | getcwd(buf, MAXPATHLEN); |
| 13 | return new POSIXFilesystemNode(buf, true); |
| 14 | } |
| 15 | |
| 16 | AbstractFilesystemNode *POSIXFilesystemFactory::makeFileNodePath(const String &path) const { |
| 17 | return new POSIXFilesystemNode(path, true); |
| 18 | } |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/posix/posix-fs-factory.cpp
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #ifndef POSIX_FILESYSTEM_FACTORY_H |
| 2 | #define POSIX_FILESYSTEM_FACTORY_H |
| 3 | |
| 4 | #include "common/singleton.h" |
| 5 | #include "backends/factories/abstract-fs-factory.h" |
| 6 | |
| 7 | /** |
| 8 | * Creates POSIXFilesystemNode objects. |
| 9 | * |
| 10 | * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. |
| 11 | */ |
| 12 | class POSIXFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<POSIXFilesystemFactory> { |
| 13 | public: |
| 14 | typedef Common::String String; |
| 15 | |
| 16 | virtual AbstractFilesystemNode *makeRootFileNode() const; |
| 17 | virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; |
| 18 | virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; |
| 19 | |
| 20 | protected: |
| 21 | POSIXFilesystemFactory() {}; |
| 22 | |
| 23 | private: |
| 24 | friend class Common::Singleton<SingletonBaseType>; |
| 25 | }; |
| 26 | |
| 27 | #endif /*POSIX_FILESYSTEM_FACTORY_H*/ |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/posix/posix-fs-factory.h
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #include "backends/factories/ps2/ps2-fs-factory.h" |
| 2 | #include "backends/fs/ps2/ps2-fs.cpp" |
| 3 | |
| 4 | DECLARE_SINGLETON(Ps2FilesystemFactory); |
| 5 | |
| 6 | AbstractFilesystemNode *Ps2FilesystemFactory::makeRootFileNode() const { |
| 7 | return new Ps2FilesystemNode(); |
| 8 | } |
| 9 | |
| 10 | AbstractFilesystemNode *Ps2FilesystemFactory::makeCurrentDirectoryFileNode() const { |
| 11 | return new Ps2FilesystemNode(); |
| 12 | } |
| 13 | |
| 14 | AbstractFilesystemNode *Ps2FilesystemFactory::makeFileNodePath(const String &path) const { |
| 15 | return new Ps2FilesystemNode(path); |
| 16 | } |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/ps2/ps2-fs-factory.cpp
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #ifndef PS2_FILESYSTEM_FACTORY_H |
| 2 | #define PS2_FILESYSTEM_FACTORY_H |
| 3 | |
| 4 | #include "common/singleton.h" |
| 5 | #include "backends/factories/abstract-fs-factory.h" |
| 6 | |
| 7 | /** |
| 8 | * Creates PS2FilesystemNode objects. |
| 9 | * |
| 10 | * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. |
| 11 | */ |
| 12 | class Ps2FilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<Ps2FilesystemFactory> { |
| 13 | public: |
| 14 | typedef Common::String String; |
| 15 | |
| 16 | virtual AbstractFilesystemNode *makeRootFileNode() const; |
| 17 | virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; |
| 18 | virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; |
| 19 | |
| 20 | protected: |
| 21 | Ps2FilesystemFactory() {}; |
| 22 | |
| 23 | private: |
| 24 | friend class Common::Singleton<SingletonBaseType>; |
| 25 | }; |
| 26 | |
| 27 | #endif /*PS2_FILESYSTEM_FACTORY_H*/ |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/ps2/ps2-fs-factory.h
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #include "backends/factories/psp/psp-fs-factory.h" |
| 2 | #include "backends/fs/psp/psp_fs.cpp" |
| 3 | |
| 4 | DECLARE_SINGLETON(PSPFilesystemFactory); |
| 5 | |
| 6 | AbstractFilesystemNode *PSPFilesystemFactory::makeRootFileNode() const { |
| 7 | return new PSPFilesystemNode(); |
| 8 | } |
| 9 | |
| 10 | AbstractFilesystemNode *PSPFilesystemFactory::makeCurrentDirectoryFileNode() const { |
| 11 | return new PSPFilesystemNode(); |
| 12 | } |
| 13 | |
| 14 | AbstractFilesystemNode *PSPFilesystemFactory::makeFileNodePath(const String &path) const { |
| 15 | return new PSPFilesystemNode(path, true); |
| 16 | } |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/psp/psp-fs-factory.cpp
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #ifndef PSP_FILESYSTEM_FACTORY_H |
| 2 | #define PSP_FILESYSTEM_FACTORY_H |
| 3 | |
| 4 | #include "common/singleton.h" |
| 5 | #include "backends/factories/abstract-fs-factory.h" |
| 6 | |
| 7 | /** |
| 8 | * Creates PSPFilesystemNode objects. |
| 9 | * |
| 10 | * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. |
| 11 | */ |
| 12 | class PSPFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<PSPFilesystemFactory> { |
| 13 | public: |
| 14 | typedef Common::String String; |
| 15 | |
| 16 | virtual AbstractFilesystemNode *makeRootFileNode() const; |
| 17 | virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; |
| 18 | virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; |
| 19 | |
| 20 | protected: |
| 21 | PSPFilesystemFactory() {}; |
| 22 | |
| 23 | private: |
| 24 | friend class Common::Singleton<SingletonBaseType>; |
| 25 | }; |
| 26 | |
| 27 | #endif /*PSP_FILESYSTEM_FACTORY_H*/ |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/psp/psp-fs-factory.h
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #include "backends/factories/symbian/symbian-fs-factory.h" |
| 2 | #include "backends/fs/symbian/symbian-fs.cpp" |
| 3 | |
| 4 | DECLARE_SINGLETON(SymbianFilesystemFactory); |
| 5 | |
| 6 | AbstractFilesystemNode *SymbianFilesystemFactory::makeRootFileNode() const { |
| 7 | return new SymbianFilesystemNode(true); |
| 8 | } |
| 9 | |
| 10 | AbstractFilesystemNode *SymbianFilesystemFactory::makeCurrentDirectoryFileNode() const { |
| 11 | char path[MAXPATHLEN]; |
| 12 | getcwd(path, MAXPATHLEN); |
| 13 | return new SymbianFilesystemNode(path); |
| 14 | } |
| 15 | |
| 16 | AbstractFilesystemNode *SymbianFilesystemFactory::makeFileNodePath(const String &path) const { |
| 17 | return new SymbianFilesystemNode(path); |
| 18 | } |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/symbian/symbian-fs-factory.cpp
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #ifndef SYMBIAN_FILESYSTEM_FACTORY_H |
| 2 | #define SYMBIAN_FILESYSTEM_FACTORY_H |
| 3 | |
| 4 | #include "common/singleton.h" |
| 5 | #include "backends/factories/abstract-fs-factory.h" |
| 6 | |
| 7 | /** |
| 8 | * Creates SymbianFilesystemNode objects. |
| 9 | * |
| 10 | * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. |
| 11 | */ |
| 12 | class SymbianFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<SymbianFilesystemFactory> { |
| 13 | public: |
| 14 | typedef Common::String String; |
| 15 | |
| 16 | virtual AbstractFilesystemNode *makeRootFileNode() const; |
| 17 | virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; |
| 18 | virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; |
| 19 | |
| 20 | protected: |
| 21 | SymbianFilesystemFactory() {}; |
| 22 | |
| 23 | private: |
| 24 | friend class Common::Singleton<SingletonBaseType>; |
| 25 | }; |
| 26 | |
| 27 | #endif /*SYMBIAN_FILESYSTEM_FACTORY_H*/ |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/symbian/symbian-fs-factory.h
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #include "backends/factories/windows/windows-fs-factory.h" |
| 2 | #include "backends/fs/windows/windows-fs.cpp" |
| 3 | |
| 4 | DECLARE_SINGLETON(WindowsFilesystemFactory); |
| 5 | |
| 6 | AbstractFilesystemNode *WindowsFilesystemFactory::makeRootFileNode() const { |
| 7 | return new WindowsFilesystemNode(); |
| 8 | } |
| 9 | |
| 10 | AbstractFilesystemNode *WindowsFilesystemFactory::makeCurrentDirectoryFileNode() const { |
| 11 | return new WindowsFilesystemNode("", true); |
| 12 | } |
| 13 | |
| 14 | AbstractFilesystemNode *WindowsFilesystemFactory::makeFileNodePath(const String &path) const { |
| 15 | return new WindowsFilesystemNode(path, false); |
| 16 | } |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/windows/windows-fs-factory.cpp
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
| 1 | #ifndef WINDOWS_FILESYSTEM_FACTORY_H |
| 2 | #define WINDOWS_FILESYSTEM_FACTORY_H |
| 3 | |
| 4 | #include "common/singleton.h" |
| 5 | #include "backends/factories/abstract-fs-factory.h" |
| 6 | |
| 7 | /** |
| 8 | * Creates WindowsFilesystemNode objects. |
| 9 | * |
| 10 | * Parts of this class are documented in the base interface class, AbstractFilesystemFactory. |
| 11 | */ |
| 12 | class WindowsFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<WindowsFilesystemFactory> { |
| 13 | public: |
| 14 | typedef Common::String String; |
| 15 | |
| 16 | virtual AbstractFilesystemNode *makeRootFileNode() const; |
| 17 | virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const; |
| 18 | virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const; |
| 19 | |
| 20 | protected: |
| 21 | WindowsFilesystemFactory() {}; |
| 22 | |
| 23 | private: |
| 24 | friend class Common::Singleton<SingletonBaseType>; |
| 25 | }; |
| 26 | |
| 27 | #endif /*WINDOWS_FILESYSTEM_FACTORY_H*/ |
-
Property changes on: /home/david/Projects/scummvm/backends/factories/windows/windows-fs-factory.h
___________________________________________________________________
Name: svn:eol-style
+ native
Name: svn:keywords
+ Date Rev Author URL Id
Name: svn:mime-type
+ text/plain
|
|
|
27 | 27 | |
28 | 28 | #include "common/array.h" |
29 | 29 | #include "common/str.h" |
30 | | |
31 | 30 | #include "common/fs.h" |
32 | 31 | |
33 | 32 | class AbstractFilesystemNode; |
… |
… |
|
47 | 46 | friend class FilesystemNode; |
48 | 47 | typedef Common::String String; |
49 | 48 | typedef FilesystemNode::ListMode ListMode; |
50 | | |
51 | | /** |
52 | | * The parent node of this directory. |
53 | | * The parent of the root is the root itself. |
54 | | */ |
55 | | virtual AbstractFilesystemNode *parent() const = 0; |
56 | | |
| 49 | |
57 | 50 | /** |
58 | | * The child node with the given name. If no child with this name |
| 51 | * Returns the child node with the given name. If no child with this name |
59 | 52 | * exists, returns 0. When called on a non-directory node, it should |
60 | 53 | * handle this gracefully by returning 0. |
61 | 54 | * |
| 55 | * Example: |
| 56 | * Calling getChild() for a node with path "/foo/bar" using name="file.txt", |
| 57 | * would produce a new node with "/foo/bar/file.txt" as path. |
| 58 | * |
| 59 | * @note This function will append a separator char (\ or /) to the end of the |
| 60 | * path if needed. |
| 61 | * |
62 | 62 | * @note Handling calls on non-dir nodes gracefully makes it possible to |
63 | 63 | * switch to a lazy type detection scheme in the future. |
| 64 | * |
| 65 | * @param name String containing the name of the child to create a new node. |
64 | 66 | */ |
65 | | virtual AbstractFilesystemNode *child(const String &name) const = 0; |
66 | | |
| 67 | virtual AbstractFilesystemNode *getChild(const String &name) const = 0; |
67 | 68 | |
68 | 69 | /** |
69 | | * Returns a special node representing the FS root. The starting point for |
70 | | * any file system browsing. |
71 | | * On Unix, this will be simply the node for / (the root directory). |
72 | | * On Windows, it will be a special node which "contains" all drives (C:, D:, E:). |
| 70 | * The parent node of this directory. |
| 71 | * The parent of the root is the root itself. |
73 | 72 | */ |
74 | | static AbstractFilesystemNode *getRoot(); |
| 73 | virtual AbstractFilesystemNode *getParent() const = 0; |
75 | 74 | |
| 75 | public: |
76 | 76 | /** |
77 | | * Returns a node representing the "current directory". If your system does |
78 | | * not support this concept, you can either try to emulate it or |
79 | | * simply return some "sensible" default directory node, e.g. the same |
80 | | * value as getRoot() returns. |
| 77 | * Destructor. |
| 78 | */ |
| 79 | virtual ~AbstractFilesystemNode() {} |
| 80 | |
| 81 | /* |
| 82 | * Indicates whether the object refered by this path exists in the filesystem or not. |
81 | 83 | */ |
82 | | static AbstractFilesystemNode *getCurrentDirectory(); |
83 | | |
| 84 | virtual bool exists() const = 0; |
84 | 85 | |
85 | 86 | /** |
86 | | * Construct a node based on a path; the path is in the same format as it |
87 | | * would be for calls to fopen(). |
88 | | * |
89 | | * Furthermore getNodeForPath(oldNode.path()) should create a new node |
90 | | * identical to oldNode. Hence, we can use the "path" value for persistent |
91 | | * storage e.g. in the config file. |
92 | | * |
93 | | * @todo: This is of course a place where non-portable code easily will sneak |
94 | | * in, because the format of the path used here is not well-defined. |
95 | | * So we really should reconsider this API and try to come up with |
96 | | * something which is more portable but still flexible enough for our |
97 | | * purposes. |
| 87 | * Return a list of child nodes of this directory node. If called on a node |
| 88 | * that does not represent a directory, false is returned. |
| 89 | * |
| 90 | * @param list List to put the contents of the directory in. |
| 91 | * @param mode Mode to use while listing the directory. |
| 92 | * @param hidden Whether to include hidden files or not in the results. |
| 93 | * |
| 94 | * @return true if succesful, false otherwise (e.g. when the directory does not exist). |
98 | 95 | */ |
99 | | static AbstractFilesystemNode *getNodeForPath(const String &path); |
| 96 | virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const = 0; |
100 | 97 | |
101 | | |
102 | | public: |
103 | | virtual ~AbstractFilesystemNode() {} |
| 98 | /** |
| 99 | * Returns a human readable path string. |
| 100 | * |
| 101 | * @note By default, this method returns the value of getName(). |
| 102 | */ |
| 103 | virtual String getDisplayName() const { return getName(); } |
104 | 104 | |
105 | | virtual String name() const = 0; |
| 105 | /** |
| 106 | * Returns a string with an architecture dependent path description. |
| 107 | */ |
| 108 | virtual String getName() const = 0; |
106 | 109 | |
107 | | // By default, we use the actual file name as 'display name'. |
108 | | virtual String displayName() const { return name(); } |
109 | | |
110 | | virtual bool isValid() const = 0; |
111 | | |
| 110 | /** |
| 111 | * Returns the 'path' of the current node, usable in fopen(). |
| 112 | */ |
| 113 | virtual String getPath() const = 0; |
| 114 | |
| 115 | /** |
| 116 | * Indicates whether this path refers to a directory or not. |
| 117 | */ |
112 | 118 | virtual bool isDirectory() const = 0; |
113 | 119 | |
114 | 120 | /** |
115 | | * Return the 'path' of the current node, usable in fopen(). See also |
116 | | * the static getNodeForPath() method. |
| 121 | * Indicates whether this path can be read from or not. |
117 | 122 | */ |
118 | | virtual String path() const = 0; |
119 | | virtual bool listDir(AbstractFSList &list, ListMode mode) const = 0; |
120 | | |
| 123 | virtual bool isReadable() const = 0; |
| 124 | |
| 125 | /** |
| 126 | * Indicates whether this path can be written to or not. |
| 127 | */ |
| 128 | virtual bool isWritable() const = 0; |
121 | 129 | |
122 | 130 | /* TODO: |
123 | | bool exists(); |
124 | | |
125 | | bool isDirectory(); |
126 | 131 | bool isFile(); |
127 | | |
128 | | bool isReadable(); |
129 | | bool isWriteable(); |
130 | 132 | */ |
131 | 133 | }; |
132 | 134 | |
133 | | |
134 | 135 | #endif |
-
|
|
|
38 | 38 | #include <common/stdafx.h> |
39 | 39 | |
40 | 40 | #include "common/util.h" |
41 | | |
42 | 41 | #include "engines/engine.h" |
43 | 42 | #include "backends/fs/abstract-fs.h" |
44 | 43 | |
… |
… |
|
45 | 44 | #define ENTER() /* debug(6, "Enter") */ |
46 | 45 | #define LEAVE() /* debug(6, "Leave") */ |
47 | 46 | |
48 | | |
49 | 47 | const uint32 kExAllBufferSize = 40960; // TODO: is this okay for sure? |
50 | 48 | |
| 49 | /** |
| 50 | * Implementation of the ScummVM file system API. |
| 51 | * |
| 52 | * Parts of this class are documented in the base interface class, AbstractFilesystemNode. |
| 53 | */ |
51 | 54 | class AmigaOSFilesystemNode : public AbstractFilesystemNode { |
52 | | protected: |
53 | | BPTR _pFileLock; |
54 | | String _sDisplayName; |
55 | | bool _bIsDirectory; |
56 | | bool _bIsValid; |
57 | | String _sPath; |
| 55 | protected: |
| 56 | BPTR _pFileLock; |
| 57 | String _sDisplayName; |
| 58 | String _sPath; |
| 59 | bool _bIsDirectory; |
| 60 | bool _bIsValid; |
58 | 61 | |
59 | | public: |
60 | | AmigaOSFilesystemNode(); |
61 | | AmigaOSFilesystemNode(BPTR pLock, const char *pDisplayName = 0); |
62 | | AmigaOSFilesystemNode(const String &p); |
| 62 | public: |
| 63 | /** |
| 64 | * Creates a AmigaOSFilesystemNode with the root node as path. |
| 65 | */ |
| 66 | AmigaOSFilesystemNode(); |
| 67 | |
| 68 | /** |
| 69 | * Creates a AmigaOSFilesystemNode for a given path. |
| 70 | * |
| 71 | * @param path String with the path the new node should point to. |
| 72 | */ |
| 73 | AmigaOSFilesystemNode(const String &p); |
| 74 | |
| 75 | /** |
| 76 | * FIXME: document this constructor. |
| 77 | */ |
| 78 | AmigaOSFilesystemNode(BPTR pLock, const char *pDisplayName = 0); |
63 | 79 | |
64 | | // Note: Copy constructor is needed because it duplicates the file lock |
65 | | AmigaOSFilesystemNode(const AmigaOSFilesystemNode &node); |
66 | | |
67 | | virtual ~AmigaOSFilesystemNode(); |
| 80 | /** |
| 81 | * Copy constructor. |
| 82 | * |
| 83 | * @note Needed because it duplicates the file lock |
| 84 | */ |
| 85 | AmigaOSFilesystemNode(const AmigaOSFilesystemNode &node); |
| 86 | |
| 87 | /** |
| 88 | * Destructor. |
| 89 | */ |
| 90 | virtual ~AmigaOSFilesystemNode(); |
68 | 91 | |
69 | | virtual String displayName() const { return _sDisplayName; }; |
70 | | virtual String name() const { return _sDisplayName; }; |
71 | | virtual bool isValid() const { return _bIsValid; }; |
72 | | virtual bool isDirectory() const { return _bIsDirectory; }; |
73 | | virtual String path() const { return _sPath; }; |
74 | | |
75 | | virtual bool listDir(AbstractFSList &list, ListMode mode) const; |
76 | | virtual AbstractFSList listVolumes() const; |
77 | | virtual AbstractFilesystemNode *parent() const; |
78 | | virtual AbstractFilesystemNode *child(const String &n) const; |
| 92 | virtual bool exists() const { return true; } //FIXME: this is just a stub |
| 93 | virtual String getDisplayName() const { return _sDisplayName; }; |
| 94 | virtual String getName() const { return _sDisplayName; }; |
| 95 | virtual String getPath() const { return _sPath; }; |
| 96 | virtual bool isDirectory() const { return _bIsDirectory; }; |
| 97 | virtual bool isReadable() const { return true; } //FIXME: this is just a stub |
| 98 | virtual bool isValid() const { return _bIsValid; }; |
| 99 | virtual bool isWritable() const { return true; } //FIXME: this is just a stub |
| 100 | |
| 101 | virtual AbstractFilesystemNode *getChild(const String &n) const; |
| 102 | virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; |
| 103 | virtual AbstractFilesystemNode *getParent() const; |
| 104 | |
| 105 | /** |
| 106 | * Creates a list with all the volumes present in the root node. |
| 107 | */ |
| 108 | virtual AbstractFSList listVolumes() const; |
79 | 109 | }; |
80 | 110 | |
81 | | AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { |
82 | | return AbstractFilesystemNode::getRoot(); |
83 | | } |
84 | | |
85 | | AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { |
86 | | return new AmigaOSFilesystemNode(); |
87 | | } |
88 | | |
89 | | AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { |
90 | | return new AmigaOSFilesystemNode(path); |
91 | | } |
92 | | |
93 | 111 | AmigaOSFilesystemNode::AmigaOSFilesystemNode() { |
94 | 112 | ENTER(); |
95 | 113 | _sDisplayName = "Available Disks"; |
… |
… |
|
100 | 118 | LEAVE(); |
101 | 119 | } |
102 | 120 | |
103 | | |
104 | 121 | AmigaOSFilesystemNode::AmigaOSFilesystemNode(const String &p) { |
105 | 122 | ENTER(); |
106 | 123 | |
… |
… |
|
150 | 167 | const char c = _sPath.lastChar(); |
151 | 168 | if (c != '/' && c != ':') |
152 | 169 | _sPath += '/'; |
153 | | |
154 | 170 | } |
155 | 171 | else { |
156 | 172 | //_bIsDirectory = false; |
… |
… |
|
170 | 186 | int bufSize = MAXPATHLEN; |
171 | 187 | _pFileLock = 0; |
172 | 188 | |
173 | | while (1) { |
| 189 | while (true) { |
174 | 190 | char *n = new char[bufSize]; |
175 | 191 | if (IDOS->NameFromLock(pLock, (STRPTR)n, bufSize) != DOSFALSE) { |
176 | 192 | _sPath = n; |
… |
… |
|
186 | 202 | delete [] n; |
187 | 203 | return; |
188 | 204 | } |
| 205 | |
189 | 206 | bufSize *= 2; |
190 | 207 | delete [] n; |
191 | 208 | } |
… |
… |
|
238 | 255 | LEAVE(); |
239 | 256 | } |
240 | 257 | |
241 | | bool AmigaOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { |
| 258 | AbstractFilesystemNode *AmigaOSFilesystemNode::getChild(const String &n) const { |
| 259 | if (!_bIsDirectory) { |
| 260 | debug(6, "Not a directory"); |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | String newPath(_sPath); |
| 265 | |
| 266 | if (_sPath.lastChar() != '/') |
| 267 | newPath += '/'; |
| 268 | |
| 269 | newPath += n; |
| 270 | BPTR lock = IDOS->Lock(newPath.c_str(), SHARED_LOCK); |
| 271 | |
| 272 | if (!lock) { |
| 273 | debug(6, "Bad path"); |
| 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | IDOS->UnLock(lock); |
| 278 | |
| 279 | return new AmigaOSFilesystemNode(newPath); |
| 280 | } |
| 281 | |
| 282 | bool AmigaOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { |
242 | 283 | ENTER(); |
243 | 284 | |
| 285 | //TODO: honor the hidden flag |
| 286 | |
244 | 287 | if (!_bIsValid) { |
245 | 288 | debug(6, "Invalid node"); |
246 | 289 | LEAVE(); |
… |
… |
|
308 | 351 | } |
309 | 352 | |
310 | 353 | LEAVE(); |
| 354 | |
311 | 355 | return true; |
312 | 356 | } |
313 | 357 | |
314 | | AbstractFilesystemNode *AmigaOSFilesystemNode::parent() const { |
| 358 | AbstractFilesystemNode *AmigaOSFilesystemNode::getParent() const { |
315 | 359 | ENTER(); |
316 | 360 | |
317 | 361 | if (!_bIsDirectory) { |
… |
… |
|
337 | 381 | node = new AmigaOSFilesystemNode(); |
338 | 382 | |
339 | 383 | LEAVE(); |
| 384 | |
340 | 385 | return node; |
341 | 386 | } |
342 | 387 | |
343 | | AbstractFilesystemNode *AmigaOSFilesystemNode::child(const String &n) const { |
344 | | |
345 | | if (!_bIsDirectory) { |
346 | | debug(6, "Not a directory"); |
347 | | return 0; |
348 | | } |
349 | | |
350 | | String newPath(_sPath); |
351 | | |
352 | | if (_sPath.lastChar() != '/') |
353 | | newPath += '/'; |
354 | | |
355 | | newPath += n; |
356 | | |
357 | | BPTR lock = IDOS->Lock(newPath.c_str(), SHARED_LOCK); |
358 | | |
359 | | if (!lock) { |
360 | | debug(6, "Bad path"); |
361 | | return 0; |
362 | | } |
363 | | |
364 | | IDOS->UnLock(lock); |
365 | | |
366 | | return new AmigaOSFilesystemNode(newPath); |
367 | | } |
368 | | |
369 | 388 | AbstractFSList AmigaOSFilesystemNode::listVolumes() const { |
370 | 389 | ENTER(); |
371 | 390 | |
… |
… |
|
431 | 450 | IDOS->UnLockDosList(kLockFlags); |
432 | 451 | |
433 | 452 | LEAVE(); |
| 453 | |
434 | 454 | return myList; |
435 | 455 | } |
436 | 456 | |
437 | | #endif |
| 457 | #endif //defined(__amigaos4__) |
-
|
|
|
25 | 25 | #if defined(__DC__) |
26 | 26 | |
27 | 27 | #include "common/stdafx.h" |
28 | | |
29 | 28 | #include "backends/fs/abstract-fs.h" |
30 | 29 | |
31 | 30 | #include <ronin/cdfs.h> |
… |
… |
|
32 | 31 | #include <stdio.h> |
33 | 32 | #include <unistd.h> |
34 | 33 | |
35 | | /* |
36 | | * Implementation of the ScummVM file system API based on ronin. |
| 34 | /** |
| 35 | * Implementation of the ScummVM file system API based on POSIX. |
| 36 | * |
| 37 | * Parts of this class are documented in the base interface class, AbstractFilesystemNode. |
37 | 38 | */ |
38 | | |
39 | 39 | class RoninCDFilesystemNode : public AbstractFilesystemNode { |
40 | 40 | protected: |
41 | 41 | String _displayName; |
| 42 | String _path; |
42 | 43 | bool _isDirectory; |
43 | 44 | bool _isValid; |
44 | | String _path; |
45 | 45 | |
46 | 46 | public: |
| 47 | /** |
| 48 | * Creates a RoninCDFilesystemNode with the root node as path. |
| 49 | */ |
47 | 50 | RoninCDFilesystemNode(); |
| 51 | |
| 52 | /** |
| 53 | * Creates a RoninCDFilesystemNode for a given path. |
| 54 | * |
| 55 | * @param path String with the path the new node should point to. |
| 56 | * @param verify true if the isValid and isDirectory flags should be verified during the construction. |
| 57 | */ |
48 | 58 | RoninCDFilesystemNode(const String &path, bool verify); |
49 | 59 | |
50 | | virtual String displayName() const { return _displayName; } |
51 | | virtual String name() const { return _displayName; } |
| 60 | virtual bool exists() const { return true; } //FIXME: this is just a stub |
| 61 | virtual String getDisplayName() const { return _displayName; } |
| 62 | virtual String getName() const { return _displayName; } |
| 63 | virtual String getPath() const { return _path; } |
| 64 | virtual bool isDirectory() const { return _isDirectory; } |
| 65 | virtual bool isReadable() const { return true; } //FIXME: this is just a stub |
52 | 66 | virtual bool isValid() const { return _isValid; } |
53 | | virtual bool isDirectory() const { return _isDirectory; } |
54 | | virtual String path() const { return _path; } |
| 67 | virtual bool isWritable() const { return true; } //FIXME: this is just a stub |
55 | 68 | |
56 | | virtual bool listDir(AbstractFSList &list, ListMode mode) const; |
57 | | virtual AbstractFilesystemNode *parent() const; |
58 | | virtual AbstractFilesystemNode *child(const String &n) const; |
| 69 | virtual AbstractFilesystemNode *getChild(const String &n) const; |
| 70 | virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; |
| 71 | virtual AbstractFilesystemNode *getParent() const; |
59 | 72 | }; |
60 | 73 | |
61 | | |
| 74 | /** |
| 75 | * Returns the last component of a given path. |
| 76 | * |
| 77 | * Examples: |
| 78 | * /foo/bar.txt would return /bar.txt |
| 79 | * /foo/bar/ would return /bar/ |
| 80 | * |
| 81 | * @param str String containing the path. |
| 82 | * @return Pointer to the first char of the last component inside str. |
| 83 | */ |
62 | 84 | static const char *lastPathComponent(const Common::String &str) { |
63 | 85 | const char *start = str.c_str(); |
64 | 86 | const char *cur = start + str.size() - 2; |
… |
… |
|
70 | 92 | return cur + 1; |
71 | 93 | } |
72 | 94 | |
73 | | |
74 | | AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { |
75 | | // Since there is no way to _set_ the current directory, |
76 | | // it will always be /... |
77 | | |
78 | | return getRoot(); |
79 | | } |
80 | | |
81 | | AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { |
82 | | return new RoninCDFilesystemNode(); |
83 | | } |
84 | | |
85 | | AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { |
86 | | return new RoninCDFilesystemNode(path, true); |
87 | | } |
88 | | |
89 | 95 | RoninCDFilesystemNode::RoninCDFilesystemNode() { |
90 | 96 | // The root dir. |
91 | 97 | _path = "/"; |
… |
… |
|
118 | 124 | } |
119 | 125 | } |
120 | 126 | |
121 | | bool RoninCDFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { |
| 127 | AbstractFilesystemNode *RoninCDFilesystemNode::getChild(const String &n) const { |
| 128 | // FIXME: Pretty lame implementation! We do no error checking to speak |
| 129 | // of, do not check if this is a special node, etc. |
| 130 | assert(_isDirectory); |
| 131 | |
| 132 | String newPath(_path); |
| 133 | if (_path.lastChar() != '/') |
| 134 | newPath += '/'; |
| 135 | newPath += n; |
| 136 | |
| 137 | return new RoninCDFilesystemNode(newPath, true); |
| 138 | } |
| 139 | |
| 140 | bool RoninCDFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { |
122 | 141 | assert(_isDirectory); |
| 142 | |
| 143 | //TODO: honor the hidden flag |
| 144 | |
123 | 145 | DIR *dirp = opendir(_path.c_str()); |
124 | | |
125 | 146 | struct dirent *dp; |
126 | 147 | |
127 | 148 | if (dirp == NULL) |
… |
… |
|
150 | 171 | |
151 | 172 | if (entry._isDirectory) |
152 | 173 | entry._path += "/"; |
| 174 | |
153 | 175 | myList.push_back(new RoninCDFilesystemNode(entry)); |
154 | 176 | } |
155 | 177 | closedir(dirp); |
| 178 | |
156 | 179 | return true; |
157 | 180 | } |
158 | 181 | |
159 | | AbstractFilesystemNode *RoninCDFilesystemNode::parent() const { |
| 182 | AbstractFilesystemNode *RoninCDFilesystemNode::getParent() const { |
160 | 183 | if (_path == "/") |
161 | 184 | return 0; |
162 | 185 | |
… |
… |
|
163 | 186 | const char *start = _path.c_str(); |
164 | 187 | const char *end = lastPathComponent(_path); |
165 | 188 | |
166 | | RoninCDFilesystemNode *p = new RoninCDFilesystemNode(String(start, end - start), false); |
167 | | |
168 | | return p; |
169 | | } |
170 | | |
171 | | AbstractFilesystemNode *RoninCDFilesystemNode::child(const String &n) const { |
172 | | // FIXME: Pretty lame implementation! We do no error checking to speak |
173 | | // of, do not check if this is a special node, etc. |
174 | | assert(_isDirectory); |
175 | | String newPath(_path); |
176 | | if (_path.lastChar() != '/') |
177 | | newPath += '/'; |
178 | | newPath += n; |
179 | | RoninCDFilesystemNode *p = new RoninCDFilesystemNode(newPath, true); |
180 | | |
181 | | return p; |
| 189 | return new RoninCDFilesystemNode(String(start, end - start), false); |
182 | 190 | } |
183 | 191 | |
184 | 192 | #endif // defined(__DC__) |
-
|
|
|
20 | 20 | * |
21 | 21 | */ |
22 | 22 | |
23 | | |
24 | 23 | #include "stdafx.h" |
25 | 24 | #include "str.h" |
26 | | #include "fs.h" |
27 | 25 | #include "common/util.h" |
28 | 26 | //#include <NDS/ARM9/console.h> //basic print funcionality |
29 | 27 | #include "ds-fs.h" |
… |
… |
|
30 | 28 | #include "dsmain.h" |
31 | 29 | #include "gba_nds_fat.h" |
32 | 30 | |
33 | | |
34 | 31 | namespace DS { |
35 | 32 | |
36 | | |
37 | | |
38 | | |
39 | 33 | ////////////////////////////////////////////////////////////// |
40 | | // DSFileSystemNode - Flash ROM file system using Zip files |
| 34 | // DSFileSystemNode - Flash ROM file system using Zip files // |
41 | 35 | ////////////////////////////////////////////////////////////// |
42 | 36 | |
43 | 37 | ZipFile* DSFileSystemNode::_zipFile = NULL; |
… |
… |
|
66 | 60 | char disp[128]; |
67 | 61 | char* pathStr = (char *) path.c_str(); |
68 | 62 | |
69 | | |
70 | 63 | int lastSlash = 3; |
71 | 64 | for (int r = 0; r < (int) strlen(pathStr) - 1; r++) { |
72 | 65 | if (path[r] == '\\') { |
… |
… |
|
81 | 74 | // _isValid = true; |
82 | 75 | // _isDirectory = false; |
83 | 76 | |
84 | | |
85 | | |
86 | 77 | if (!strncmp(pathStr, "ds:/", 4)) { |
87 | 78 | pathStr += 4; |
88 | 79 | } |
… |
… |
|
87 | 78 | pathStr += 4; |
88 | 79 | } |
89 | 80 | |
90 | | |
91 | 81 | if (*pathStr == '\0') { |
92 | 82 | _isValid = true; |
93 | 83 | _isDirectory = true; |
… |
… |
|
130 | 120 | } |
131 | 121 | |
132 | 122 | DSFileSystemNode::DSFileSystemNode(const DSFileSystemNode* node) { |
133 | | |
| 123 | //TODO: not implemented? |
134 | 124 | } |
135 | 125 | |
136 | | AbstractFilesystemNode* DSFileSystemNode::parent() const { |
137 | | // consolePrintf("parent\n"); |
138 | | DSFileSystemNode *p; |
139 | | |
140 | | if (_path != "ds:/") { |
141 | | char *path = (char *) _path.c_str(); |
142 | | int lastSlash = 4; |
143 | | |
144 | | for (int r = 4; r < (int) strlen((char *) path); r++) { |
145 | | if (path[r] == '\\') { |
146 | | lastSlash = r; |
147 | | } |
148 | | } |
149 | | |
150 | | p = new DSFileSystemNode(String(path, lastSlash)); |
151 | | ((DSFileSystemNode *) (p))->_isDirectory = true; |
152 | | } else { |
153 | | p = new DSFileSystemNode(); |
154 | | } |
155 | | |
156 | | return p; |
157 | | |
158 | | } |
159 | | |
160 | | |
161 | | AbstractFilesystemNode *DSFileSystemNode::child(const Common::String& n) const { |
| 126 | AbstractFilesystemNode *DSFileSystemNode::getChild(const Common::String& n) const { |
162 | 127 | if (_path.lastChar() == '\\') { |
163 | 128 | return new DSFileSystemNode(_path + n); |
164 | 129 | } else { |
… |
… |
|
168 | 133 | return NULL; |
169 | 134 | } |
170 | 135 | |
171 | | |
172 | | bool DSFileSystemNode::listDir(AbstractFSList &dirList, ListMode mode) const { |
| 136 | bool DSFileSystemNode::getChildren(AbstractFSList &dirList, ListMode mode, bool hidden) const { |
173 | 137 | // consolePrintf("Listdir\n"); |
174 | | |
175 | | |
176 | 138 | // consolePrintf("Directory\n"); |
177 | 139 | |
178 | | |
| 140 | //TODO: honor the hidden flag |
| 141 | |
179 | 142 | char temp[128]; |
180 | 143 | strcpy(temp, _path.c_str()); |
181 | 144 | |
… |
… |
|
190 | 153 | /* // This is the root dir, so add the RAM folder |
191 | 154 | DSFileSystemNode* dsfsn = new DSFileSystemNode("ds:/ram"); |
192 | 155 | dsfsn->_isDirectory = true; |
193 | | dirList->push_back(wrap(dsfsn));*/ |
| 156 | dirList->push_back(wrap(dsfsn)); |
| 157 | */ |
194 | 158 | } |
195 | 159 | } else { |
196 | 160 | _zipFile->changeDirectory(temp); |
… |
… |
|
196 | 160 | _zipFile->changeDirectory(temp); |
197 | 161 | } |
198 | 162 | |
199 | | |
200 | | |
201 | 163 | if (_zipFile->restartFile()) { |
202 | 164 | do { |
203 | 165 | char n[128]; |
… |
… |
|
218 | 180 | return true; |
219 | 181 | } |
220 | 182 | |
| 183 | AbstractFilesystemNode* DSFileSystemNode::getParent() const { |
| 184 | // consolePrintf("parent\n"); |
| 185 | DSFileSystemNode *p; |
| 186 | |
| 187 | if (_path != "ds:/") { |
| 188 | char *path = (char *) _path.c_str(); |
| 189 | int lastSlash = 4; |
| 190 | |
| 191 | for (int r = 4; r < (int) strlen((char *) path); r++) { |
| 192 | if (path[r] == '\\') { |
| 193 | lastSlash = r; |
| 194 | } |
| 195 | } |
221 | 196 | |
| 197 | p = new DSFileSystemNode(String(path, lastSlash)); |
| 198 | ((DSFileSystemNode *) (p))->_isDirectory = true; |
| 199 | } else { |
| 200 | p = new DSFileSystemNode(); |
| 201 | } |
222 | 202 | |
| 203 | return p; |
| 204 | } |
223 | 205 | |
224 | | ///////////////////////////////////////////////////////////////////////// |
225 | | // GBAMPFileSystemNode - File system using GBA Movie Player and CF card |
226 | | ///////////////////////////////////////////////////////////////////////// |
| 206 | ////////////////////////////////////////////////////////////////////////// |
| 207 | // GBAMPFileSystemNode - File system using GBA Movie Player and CF card // |
| 208 | ////////////////////////////////////////////////////////////////////////// |
227 | 209 | |
228 | 210 | GBAMPFileSystemNode::GBAMPFileSystemNode() { |
229 | 211 | _displayName = "mp:/"; |
… |
… |
|
290 | 272 | |
291 | 273 | |
292 | 274 | GBAMPFileSystemNode::GBAMPFileSystemNode(const GBAMPFileSystemNode* node) { |
293 | | |
| 275 | //TODO: not implemented? |
294 | 276 | } |
295 | 277 | |
296 | | |
297 | | AbstractFilesystemNode* GBAMPFileSystemNode::parent() const { |
298 | | // consolePrintf("parent\n"); |
299 | | GBAMPFileSystemNode *p; |
300 | | |
301 | | if (_path != "mp:/") { |
302 | | char *path = (char *) _path.c_str(); |
303 | | int lastSlash = 4; |
304 | | |
305 | | for (int r = 4; r < (int) strlen((char *) path); r++) { |
306 | | if (path[r] == '/') { |
307 | | lastSlash = r; |
308 | | } |
309 | | } |
310 | | |
311 | | p = new GBAMPFileSystemNode(String(path, lastSlash)); |
312 | | p->_isDirectory = true; |
313 | | } else { |
314 | | p = new GBAMPFileSystemNode(); |
315 | | } |
316 | | |
317 | | return p; |
318 | | |
319 | | } |
320 | | |
321 | | AbstractFilesystemNode *GBAMPFileSystemNode::child(const Common::String& n) const { |
| 278 | AbstractFilesystemNode *GBAMPFileSystemNode::getChild(const Common::String& n) const { |
322 | 279 | if (_path.lastChar() == '\\') { |
323 | 280 | return new DSFileSystemNode(_path + n); |
324 | 281 | } else { |
… |
… |
|
328 | 285 | return NULL; |
329 | 286 | } |
330 | 287 | |
331 | | bool GBAMPFileSystemNode::listDir(AbstractFSList& dirList, ListMode mode) const { |
| 288 | bool GBAMPFileSystemNode::getChildren(AbstractFSList& dirList, ListMode mode, bool hidden) const { |
332 | 289 | // consolePrintf("Listdir\n"); |
333 | 290 | |
| 291 | //TODO: honor the hidden flag |
| 292 | |
334 | 293 | enum { TYPE_NO_MORE = 0, TYPE_FILE = 1, TYPE_DIR = 2 }; |
335 | 294 | |
336 | 295 | char temp[128], fname[128], *path, *pathTemp; |
… |
… |
|
346 | 305 | pathTemp++; |
347 | 306 | } |
348 | 307 | |
349 | | |
350 | 308 | // consolePrintf("This dir: %s\n", path); |
351 | 309 | FAT_chdir(path); |
352 | 310 | |
… |
… |
|
369 | 327 | // dsfsn->_isDirectory = entryType == DIR; |
370 | 328 | dirList.push_back((dsfsn)); |
371 | 329 | } |
372 | | |
373 | | |
374 | 330 | } else { |
375 | 331 | // consolePrintf("Skipping %s\n", fname); |
376 | 332 | } |
… |
… |
|
385 | 341 | return true; |
386 | 342 | } |
387 | 343 | |
| 344 | AbstractFilesystemNode* GBAMPFileSystemNode::getParent() const { |
| 345 | // consolePrintf("parent\n"); |
| 346 | GBAMPFileSystemNode *p; |
| 347 | |
| 348 | if (_path != "mp:/") { |
| 349 | char *path = (char *) _path.c_str(); |
| 350 | int lastSlash = 4; |
| 351 | |
| 352 | for (int r = 4; r < (int) strlen((char *) path); r++) { |
| 353 | if (path[r] == '/') { |
| 354 | lastSlash = r; |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | p = new GBAMPFileSystemNode(String(path, lastSlash)); |
| 359 | p->_isDirectory = true; |
| 360 | } else { |
| 361 | p = new GBAMPFileSystemNode(); |
| 362 | } |
| 363 | |
| 364 | return p; |
| 365 | } |
388 | 366 | |
389 | 367 | // Stdio replacements |
390 | 368 | #define MAX_FILE_HANDLES 32 |
… |
… |
|
393 | 371 | DS::fileHandle handle[MAX_FILE_HANDLES]; |
394 | 372 | |
395 | 373 | FILE* std_fopen(const char* name, const char* mode) { |
396 | | |
397 | | |
398 | | |
399 | 374 | if (!inited) { |
400 | 375 | for (int r = 0; r < MAX_FILE_HANDLES; r++) { |
401 | 376 | handle[r].used = false; |
… |
… |
|
403 | 378 | inited = true; |
404 | 379 | currentDir[0] = '\0'; |
405 | 380 | } |
406 | | |
407 | | |
408 | | |
409 | 381 | |
410 | 382 | char* realName = (char *) name; |
411 | 383 | |
… |
… |
|
413 | 385 | if ((name[0] == 'd') && (name[1] == 's') && (name[2] == ':') && (name[3] == '/')) { |
414 | 386 | realName += 4; |
415 | 387 | } |
416 | | |
| 388 | |
417 | 389 | if ((name[0] == 'm') && (name[1] == 'p') && (name[2] == ':') && (name[3] == '/')) { |
418 | 390 | realName += 4; |
419 | 391 | } |
… |
… |
|
421 | 393 | // consolePrintf("Open file:"); |
422 | 394 | // consolePrintf("'%s', [%s]", realName, mode); |
423 | 395 | |
424 | | |
425 | 396 | if (DS::isGBAMPAvailable()) { |
426 | 397 | FAT_chdir("/"); |
427 | 398 | |
… |
… |
|
443 | 414 | |
444 | 415 | return (FILE *) result; |
445 | 416 | } |
446 | | |
447 | 417 | |
448 | 418 | // Fail to open file for writing. It's in ROM! |
449 | | |
| 419 | |
450 | 420 | // Allocate a file handle |
451 | 421 | int r = 0; |
452 | 422 | while (handle[r].used) r++; |
… |
… |
|
459 | 429 | handle[r].sramFile = (DSSaveFile *) DSSaveFileManager::instance()->openSavefile(realName, false); |
460 | 430 | } |
461 | 431 | |
462 | | |
463 | 432 | if (handle[r].sramFile) { |
464 | 433 | handle[r].used = true; |
465 | 434 | handle[r].pos = 0; |
… |
… |
|
513 | 482 | return NULL; |
514 | 483 | } |
515 | 484 | } |
| 485 | |
516 | 486 | void std_fclose(FILE* handle) { |
517 | 487 | |
518 | 488 | if (DS::isGBAMPAvailable()) { |
… |
… |
|
528 | 498 | } |
529 | 499 | |
530 | 500 | size_t std_fread(const void* ptr, size_t size, size_t numItems, FILE* handle) { |
531 | | |
532 | 501 | // consolePrintf("fread %d,%d %d ", size, numItems, ptr); |
533 | | |
534 | | |
535 | 502 | |
536 | 503 | if (DS::isGBAMPAvailable()) { |
537 | | |
538 | | |
539 | 504 | int bytes = FAT_fread((void *) ptr, size, numItems, (FAT_FILE *) handle); |
540 | 505 | if (!std_feof(handle)) { |
541 | 506 | return numItems; |
… |
… |
|
560 | 525 | |
561 | 526 | } |
562 | 527 | |
563 | | return item;*/ |
564 | | |
565 | | |
| 528 | return item; |
| 529 | */ |
566 | 530 | int items = 0; |
567 | 531 | |
568 | 532 | //for (int r = 0; r < numItems; r++) { |
… |
… |
|
567 | 531 | |
568 | 532 | //for (int r = 0; r < numItems; r++) { |
569 | 533 | if (!std_feof(handle)) { |
570 | | |
571 | | |
572 | | |
573 | 534 | /* for (int t = 0; t < size; t++) { |
574 | 535 | if (feof(handle)) eof = true; |
575 | 536 | *(((char *) (ptr)) + r * size + t) = getc(handle); |
… |
… |
|
576 | 537 | }*/ |
577 | 538 | int left = size * numItems; |
578 | 539 | int bytesRead = -1; |
| 540 | |
579 | 541 | while ((left > 0) && (!FAT_feof((FAT_FILE *) handle))) { |
580 | 542 | int amount = left > 8192? 8192: left; |
581 | 543 | // do { |
… |
… |
|
580 | 542 | int amount = left > 8192? 8192: left; |
581 | 543 | // do { |
582 | 544 | bytesRead = FAT_fread((void *) ptr, 1, amount, (FAT_FILE *) handle); |
583 | | /* if (bytesRead == 0) { |
| 545 | /* if (bytesRead == 0) { |
584 | 546 | consolePrintf("Pos:%d items:%d num:%d amount:%d read:%d\n", ftell(handle), items, numItems, amount, bytesRead); |
585 | 547 | left++; |
586 | 548 | |
… |
… |
|
592 | 554 | fread(ptr, 1024, 1, handle); |
593 | 555 | swiWaitForVBlank(); |
594 | 556 | //while (true); |
595 | | }*/ |
596 | | //} while (bytesRead == 0); |
| 557 | } |
| 558 | |
| 559 | } while (bytesRead == 0); |
| 560 | */ |
597 | 561 | left -= bytesRead; |
598 | 562 | ptr = ((char *) (ptr)) + bytesRead; |
599 | 563 | } |
… |
… |
|
599 | 563 | } |
600 | 564 | |
601 | 565 | items = numItems - (left / size); |
602 | | |
603 | | |
604 | | |
605 | | |
| 566 | |
606 | 567 | // FAT_fread((void *) ptr, size, 1, ((int) (handle)) - 1); |
607 | | // ptr = ((char *) (ptr)) + size; |
608 | | |
| 568 | // ptr = ((char *) (ptr)) + size; |
609 | 569 | } |
610 | | //} |
| 570 | // } |
611 | 571 | |
612 | 572 | // consolePrintf("...done %d \n", items) |
613 | 573 | |
… |
… |
|
612 | 572 | // consolePrintf("...done %d \n", items) |
613 | 573 | |
614 | 574 | return items; |
615 | | |
616 | 575 | } |
617 | 576 | |
618 | 577 | if (handle->sramFile) { |
… |
… |
|
630 | 589 | return bytes / size; |
631 | 590 | } |
632 | 591 | |
633 | | |
634 | 592 | if (handle->pos + size * numItems > handle->size) { |
635 | 593 | numItems = (handle->size - handle->pos) / size; |
636 | 594 | if (numItems < 0) numItems = 0; |
… |
… |
|
639 | 597 | // consolePrintf("read %d ", size * numItems); |
640 | 598 | |
641 | 599 | memcpy((void *) ptr, handle->data + handle->pos, size * numItems); |
642 | | |
643 | 600 | handle->pos += size * numItems; |
644 | 601 | |
645 | | |
646 | 602 | return numItems; |
647 | 603 | } |
648 | 604 | |
… |
… |
|
657 | 613 | //consolePrintf("fwrite size=%d\n", size * numItems); |
658 | 614 | |
659 | 615 | if (DS::isGBAMPAvailable()) { |
660 | | |
661 | 616 | FAT_fwrite(((char *) (ptr)), size, numItems, (FAT_FILE *) handle); |
662 | 617 | return numItems; |
663 | 618 | |
… |
… |
|
675 | 630 | return numItems; |
676 | 631 | } |
677 | 632 | |
678 | | |
679 | 633 | if (handle->sramFile) { |
680 | 634 | handle->sramFile->write(ptr, size); |
681 | 635 | return size; |
… |
… |
|
704 | 658 | } |
705 | 659 | |
706 | 660 | void std_fflush(FILE* handle) { |
| 661 | //FIXME: not implemented? |
707 | 662 | // consolePrintf("fflush "); |
708 | 663 | } |
709 | 664 | |
… |
… |
|
711 | 666 | // consolePrintf("fgets file=%d ", file); |
712 | 667 | |
713 | 668 | if (DS::isGBAMPAvailable()) { |
714 | | |
715 | 669 | char* s = str; |
716 | 670 | while ((*s++ = std_getc(file)) >= 32) { |
717 | 671 | // consolePrintf("%d ", *s); |
… |
… |
|
723 | 677 | return str; |
724 | 678 | } |
725 | 679 | |
726 | | |
727 | 680 | if (file->sramFile) { |
728 | 681 | file->pos--; |
729 | 682 | int p = -1; |
… |
… |
|
743 | 696 | } |
744 | 697 | |
745 | 698 | long int std_ftell(FILE* handle) { |
746 | | |
747 | 699 | if (DS::isGBAMPAvailable()) { |
748 | 700 | return FAT_ftell((FAT_FILE *) handle); |
749 | 701 | } |
… |
… |
|
758 | 710 | return FAT_fseek((FAT_FILE *) handle, offset, whence); |
759 | 711 | } |
760 | 712 | |
761 | | |
762 | 713 | switch (whence) { |
763 | | case SEEK_CUR: { |
| 714 | case SEEK_CUR: |
764 | 715 | handle->pos += offset; |
765 | 716 | break; |
766 | | } |
767 | | |
768 | | case SEEK_SET: { |
| 717 | case SEEK_SET: |
769 | 718 | handle->pos = offset; |
770 | 719 | break; |
771 | | } |
772 | | |
773 | | case SEEK_END: { |
| 720 | case SEEK_END: |
774 | 721 | handle->pos = handle->size + offset; |
775 | 722 | break; |
776 | | } |
777 | | |
778 | | default: { |
| 723 | default: |
779 | 724 | handle->pos = offset; |
780 | 725 | break; |
781 | | } |
782 | | |
783 | 726 | } |
784 | 727 | |
785 | 728 | return 0; |
… |
… |
|
786 | 729 | } |
787 | 730 | |
788 | 731 | void std_clearerr(FILE* handle) { |
| 732 | //FIXME: not implemented? |
789 | 733 | // consolePrintf("clearerr "); |
790 | 734 | } |
791 | 735 | |
… |
… |
|
790 | 734 | } |
791 | 735 | |
792 | 736 | int std_getc(FILE* handle) { |
793 | | |
794 | 737 | if (DS::isGBAMPAvailable()) { |
795 | 738 | char c; |
796 | 739 | FAT_fread(&c, 1, 1, (FAT_FILE *) handle); |
… |
… |
|
852 | 795 | } |
853 | 796 | |
854 | 797 | } // namespace DS |
855 | | |
856 | | // These functions are added to AbstractFileSystemNode and are therefore outside |
857 | | // the DS namespace. |
858 | | |
859 | | AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { |
860 | | // consolePrintf("New node"); |
861 | | |
862 | | if (DS::isGBAMPAvailable()) { |
863 | | return new DS::GBAMPFileSystemNode(); |
864 | | } else { |
865 | | return new DS::DSFileSystemNode(); |
866 | | } |
867 | | } |
868 | | |
869 | | AbstractFilesystemNode* AbstractFilesystemNode::getNodeForPath(const String& path) { |
870 | | if (DS::isGBAMPAvailable()) { |
871 | | return new DS::GBAMPFileSystemNode(path); |
872 | | } else { |
873 | | return new DS::DSFileSystemNode(path); |
874 | | } |
875 | | } |
-
|
|
|
23 | 23 | #ifndef _DS_FS_H |
24 | 24 | #define _DS_FS_H |
25 | 25 | |
26 | | |
27 | | |
28 | 26 | //#include <NDS/ARM9/console.h> |
29 | 27 | #include "fs.h" |
30 | 28 | #include "zipreader.h" |
… |
… |
|
32 | 30 | #include "scummconsole.h" |
33 | 31 | #include "gba_nds_fat.h" |
34 | 32 | #include "backends/fs/abstract-fs.h" |
35 | | //#include "backends/fs/fs.h" |
36 | 33 | |
37 | 34 | namespace DS { |
38 | 35 | |
… |
… |
|
37 | 34 | namespace DS { |
38 | 35 | |
39 | 36 | /** |
| 37 | * Implementation of the ScummVM file system API. |
40 | 38 | * This class is used when a Flash cart is in use. |
| 39 | * |
| 40 | * Parts of this class are documented in the base interface class, AbstractFilesystemNode. |
41 | 41 | */ |
42 | 42 | class DSFileSystemNode : public AbstractFilesystemNode { |
43 | 43 | protected: |
44 | | static ZipFile* _zipFile; |
45 | | |
46 | 44 | typedef class Common::String String; |
47 | 45 | |
| 46 | static ZipFile* _zipFile; |
| 47 | |
48 | 48 | String _displayName; |
| 49 | String _path; |
49 | 50 | bool _isDirectory; |
50 | 51 | bool _isValid; |
51 | | String _path; |
52 | 52 | int _refCountVal; |
53 | 53 | |
54 | 54 | public: |
| 55 | /** |
| 56 | * Creates a DSFilesystemNode with the root node as path. |
| 57 | */ |
55 | 58 | DSFileSystemNode(); |
| 59 | |
| 60 | /** |
| 61 | * Creates a DSFilesystemNode for a given path. |
| 62 | * |
| 63 | * @param path String with the path the new node should point to. |
| 64 | */ |
56 | 65 | DSFileSystemNode(const String &path); |
57 | | DSFileSystemNode(const DSFileSystemNode *node); |
| 66 | |
| 67 | /** |
| 68 | * Creates a DSFilesystemNode for a given path. |
| 69 | * |
| 70 | * @param path String with the path the new node should point to. |
| 71 | * @param path true if path is a directory, false otherwise. |
| 72 | */ |
58 | 73 | DSFileSystemNode(const String& path, bool isDir); |
59 | 74 | |
60 | | virtual String displayName() const { return _displayName; } |
61 | | virtual String name() const { return _displayName; } |
62 | | virtual bool isValid() const { return _isValid; } |
| 75 | /** |
| 76 | * Copy constructor. |
| 77 | */ |
| 78 | DSFileSystemNode(const DSFileSystemNode *node); |
| 79 | |
| 80 | virtual bool exists() const { return true; } //FIXME: this is just a stub |
| 81 | virtual String getDisplayName() const { return _displayName; } |
| 82 | virtual String getName() const { return _displayName; } |
| 83 | virtual String getPath() const { return _path; } |
63 | 84 | virtual bool isDirectory() const { return _isDirectory; } |
64 | | virtual String path() const { return _path; } |
| 85 | virtual bool isReadable() const { return true; } //FIXME: this is just a stub |
| 86 | virtual bool isValid() const { return _isValid; } |
| 87 | virtual bool isWritable() const { return true; } //FIXME: this is just a stub |
65 | 88 | |
66 | | virtual bool listDir(AbstractFSList &list, ListMode mode = FilesystemNode::kListDirectoriesOnly) const; |
67 | | virtual AbstractFilesystemNode *parent() const; |
| 89 | /** |
| 90 | * Returns a copy of this node. |
| 91 | */ |
68 | 92 | virtual AbstractFilesystemNode *clone() const { return new DSFileSystemNode(this); } |
69 | | virtual AbstractFilesystemNode *child(const Common::String& name) const; |
| 93 | virtual AbstractFilesystemNode *getChild(const Common::String& name) const; |
| 94 | virtual bool getChildren(AbstractFSList &list, ListMode mode = FilesystemNode::kListDirectoriesOnly, bool hidden) const; |
| 95 | virtual AbstractFilesystemNode *getParent() const; |
| 96 | |
| 97 | /** |
| 98 | * Returns the zip file this node points to. |
| 99 | * TODO: check this documentation. |
| 100 | */ |
70 | 101 | static ZipFile* getZip() { return _zipFile; } |
71 | 102 | }; |
72 | 103 | |
73 | | |
74 | | /** |
| 104 | /** |
| 105 | * Implementation of the ScummVM file system API. |
75 | 106 | * This class is used when the GBAMP (GBA Movie Player) is used with a CompactFlash card. |
| 107 | * |
| 108 | * Parts of this class are documented in the base interface class, AbstractFilesystemNode. |
76 | 109 | */ |
77 | 110 | class GBAMPFileSystemNode : public AbstractFilesystemNode { |
78 | 111 | protected: |
… |
… |
|
79 | 112 | typedef class Common::String String; |
80 | 113 | |
81 | 114 | String _displayName; |
| 115 | String _path; |
82 | 116 | bool _isDirectory; |
83 | 117 | bool _isValid; |
84 | | String _path; |
85 | | |
86 | 118 | int _refCountVal; |
87 | 119 | |
88 | 120 | public: |
| 121 | /** |
| 122 | * Creates a GBAMPFilesystemNode with the root node as path. |
| 123 | */ |
89 | 124 | GBAMPFileSystemNode(); |
| 125 | |
| 126 | /** |
| 127 | * Creates a GBAMPFilesystemNode for a given path. |
| 128 | * |
| 129 | * @param path String with the path the new node should point to. |
| 130 | */ |
90 | 131 | GBAMPFileSystemNode(const String &path); |
| 132 | |
| 133 | /** |
| 134 | * Creates a DSFilesystemNode for a given path. |
| 135 | * |
| 136 | * @param path String with the path the new node should point to. |
| 137 | * @param path true if path is a directory, false otherwise. |
| 138 | */ |
91 | 139 | GBAMPFileSystemNode(const String &path, bool isDirectory); |
| 140 | |
| 141 | /** |
| 142 | * Copy constructor. |
| 143 | */ |
92 | 144 | GBAMPFileSystemNode(const GBAMPFileSystemNode *node); |
93 | 145 | |
94 | | virtual String displayName() const { return _displayName; } |
95 | | virtual String name() const { return _displayName; } |
| 146 | virtual bool exists() const { return true; } //FIXME: this is just a stub |
| 147 | virtual String getDisplayName() const { return _displayName; } |
| 148 | virtual String getName() const { return _displayName; } |
| 149 | virtual String getPath() const { return _path; } |
| 150 | virtual bool isDirectory() const { return _isDirectory; } |
| 151 | virtual bool isReadable() const { return true; } //FIXME: this is just a stub |
| 152 | virtual bool isValid() const { return _isValid; } |
| 153 | virtual bool isWritable() const { return true; } //FIXME: this is just a stub |
96 | 154 | |
97 | | virtual bool isValid() const { return _isValid; } |
98 | | virtual bool isDirectory() const { return _isDirectory; } |
99 | | virtual String path() const { return _path; } |
100 | | virtual bool listDir(AbstractFSList &list, ListMode mode = FilesystemNode::kListDirectoriesOnly) const; |
101 | | virtual AbstractFilesystemNode *parent() const; |
| 155 | /** |
| 156 | * Returns a copy of this node. |
| 157 | */ |
102 | 158 | virtual AbstractFilesystemNode *clone() const { return new GBAMPFileSystemNode(this); } |
103 | | virtual AbstractFilesystemNode *child(const Common::String& name) const; |
104 | | |
| 159 | virtual AbstractFilesystemNode *getChild(const Common::String& name) const; |
| 160 | virtual bool getChildren(AbstractFSList &list, ListMode mode = FilesystemNode::kListDirectoriesOnly, bool hidden) const; |
| 161 | virtual AbstractFilesystemNode *getParent() const; |
105 | 162 | }; |
106 | 163 | |
107 | | |
108 | | |
109 | | |
110 | 164 | struct fileHandle { |
111 | 165 | int pos; |
112 | 166 | bool used; |
… |
… |
|
116 | 170 | DSSaveFile* sramFile; |
117 | 171 | }; |
118 | 172 | |
119 | | |
120 | 173 | #undef stderr |
121 | 174 | #undef stdout |
122 | 175 | #undef stdin |
… |
… |
|
140 | 193 | void std_cwd(char* dir); |
141 | 194 | void std_fflush(FILE* handle); |
142 | 195 | |
143 | | } |
| 196 | } //namespace DS |
144 | 197 | |
145 | | #endif |
| 198 | #endif //_DS_FS_H |
-
|
|
|
24 | 24 | */ |
25 | 25 | |
26 | 26 | #include "stdafx.h" |
| 27 | #include "backends/fs/abstract-fs.h" |
27 | 28 | |
28 | | #include "backends/fs/abstract-fs.h" |
| 29 | #define MAX_PATH_SIZE 256 |
29 | 30 | |
| 31 | /** |
| 32 | * Implementation of the ScummVM file system API. |
| 33 | * |
| 34 | * Parts of this class are documented in the base interface class, AbstractFilesystemNode. |
| 35 | */ |
30 | 36 | class GP32FilesystemNode : public AbstractFilesystemNode { |
31 | 37 | protected: |
32 | 38 | String _displayName; |
| 39 | String _path; |
33 | 40 | bool _isDirectory; |
34 | 41 | bool _isRoot; |
35 | | String _path; |
36 | 42 | |
37 | 43 | public: |
| 44 | /** |
| 45 | * Creates a GP32FilesystemNode with the root node as path. |
| 46 | */ |
38 | 47 | GP32FilesystemNode(); |
| 48 | |
| 49 | /** |
| 50 | * Creates a GP32FilesystemNode for a given path. |
| 51 | * |
| 52 | * @param path String with the path the new node should point to. |
| 53 | */ |
39 | 54 | GP32FilesystemNode(const String &path); |
40 | 55 | |
41 | | virtual String displayName() const { return _displayName; } |
42 | | virtual String name() const { return _displayName; } |
| 56 | virtual bool exists() const { return true; } //FIXME: this is just a stub |
| 57 | virtual String getDisplayName() const { return _displayName; } |
| 58 | virtual String getName() const { return _displayName; } |
| 59 | virtual String getPath() const { return _path; } |
| 60 | virtual bool isDirectory() const { return _isDirectory; } |
43 | 61 | // FIXME: isValid should return false if this Node can't be used! |
44 | | // client code can rely on the return value. |
| 62 | // so client code can rely on the return value. |
| 63 | virtual bool isReadable() const { return true; } //FIXME: this is just a stub |
45 | 64 | virtual bool isValid() const { return true; } |
46 | | virtual bool isDirectory() const { return _isDirectory; } |
47 | | virtual String path() const { return _path; } |
| 65 | virtual bool isWritable() const { return true; } //FIXME: this is just a stub |
48 | 66 | |
49 | | virtual bool listDir(AbstractFSList &list, ListMode mode) const; |
50 | | virtual AbstractFilesystemNode *parent() const; |
51 | | virtual AbstractFilesystemNode *child(const String &n) const; |
| 67 | virtual AbstractFilesystemNode *getChild(const String &n) const; |
| 68 | virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; |
| 69 | virtual AbstractFilesystemNode *getParent() const; |
52 | 70 | }; |
53 | 71 | |
54 | | #define MAX_PATH_SIZE 256 |
55 | | |
56 | 72 | const char gpRootPath[] = "gp:\\"; |
57 | 73 | //char gpCurrentPath[MAX_PATH_SIZE] = "gp:\\"; // must end with '\' |
58 | 74 | |
| 75 | /** |
| 76 | * Returns the last component of a given path. |
| 77 | * |
| 78 | * Examples: |
| 79 | * gp:\foo\bar.txt would return "\bar.txt" |
| 80 | * gp:\foo\bar\ would return "\bar\" |
| 81 | * |
| 82 | * @param str Path to obtain the last component from. |
| 83 | * @return Pointer to the first char of the last component inside str. |
| 84 | */ |
| 85 | static const char *lastPathComponent(const Common::String &str) { |
| 86 | const char *start = str.c_str(); |
| 87 | const char *cur = start + str.size() - 2; |
| 88 | |
| 89 | while (cur >= start && *cur != '\\') { |
| 90 | --cur; |
| 91 | } |
| 92 | |
| 93 | return cur + 1; |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * FIXME: document this function. |
| 98 | * |
| 99 | * @param path |
| 100 | * @param convPath |
| 101 | */ |
59 | 102 | int gpMakePath(const char *path, char *convPath) { |
60 | 103 | // copy root or current directory |
61 | 104 | const char *p; |
… |
… |
|
106 | 149 | return 0; |
107 | 150 | } |
108 | 151 | |
109 | | AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { |
110 | | return AbstractFilesystemNode::getRoot(); |
111 | | } |
112 | | |
113 | | AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { |
114 | | return new GP32FilesystemNode(); |
115 | | } |
116 | | |
117 | | AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { |
118 | | return new GP32FilesystemNode(path); |
119 | | } |
120 | | |
121 | 152 | GP32FilesystemNode::GP32FilesystemNode() { |
122 | 153 | _isDirectory = true; |
123 | 154 | _isRoot = true; |
… |
… |
|
132 | 163 | gpMakePath(path.c_str(), convPath); |
133 | 164 | |
134 | 165 | _path = convPath; |
135 | | |
136 | 166 | pos = convPath; |
| 167 | |
137 | 168 | while (*pos) |
138 | 169 | if (*pos++ == '\\') |
139 | 170 | dsplName = pos; |
… |
… |
|
150 | 181 | _isDirectory = true; |
151 | 182 | } |
152 | 183 | |
153 | | bool GP32FilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { |
| 184 | AbstractFilesystemNode *GP32FilesystemNode::getChild(const String &n) const { |
| 185 | // FIXME: Pretty lame implementation! We do no error checking to speak |
| 186 | // of, do not check if this is a special node, etc. |
154 | 187 | assert(_isDirectory); |
| 188 | |
| 189 | String newPath(_path); |
| 190 | if (_path.lastChar() != '\\') |
| 191 | newPath += '\\'; |
| 192 | newPath += n; |
| 193 | |
| 194 | return new GP32FilesystemNode(newPath); |
| 195 | } |
| 196 | |
| 197 | bool GP32FilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { |
| 198 | assert(_isDirectory); |
| 199 | |
| 200 | //TODO: honor the hidden flag |
155 | 201 | |
156 | 202 | GPDIRENTRY dirEntry; |
157 | 203 | GPFILEATTR attr; |
158 | | |
159 | 204 | GP32FilesystemNode entry; |
160 | | |
161 | 205 | uint32 read; |
162 | 206 | |
163 | 207 | if (mode == FilesystemNode::kListAll) |
… |
… |
|
168 | 212 | int startIdx = 0; // current file |
169 | 213 | String listDir(_path); |
170 | 214 | //listDir += "/"; |
| 215 | |
171 | 216 | while (GpDirEnumList(listDir.c_str(), startIdx++, 1, &dirEntry, &read) == SM_OK) { |
172 | 217 | if (dirEntry.name[0] == '.') |
173 | 218 | continue; |
| 219 | |
174 | 220 | entry._displayName = dirEntry.name; |
175 | 221 | entry._path = _path; |
176 | 222 | entry._path += dirEntry.name; |
… |
… |
|
194 | 240 | return true; |
195 | 241 | } |
196 | 242 | |
197 | | static const char *lastPathComponent(const Common::String &str) { |
198 | | const char *start = str.c_str(); |
199 | | const char *cur = start + str.size() - 2; |
200 | | |
201 | | while (cur >= start && *cur != '\\') { |
202 | | --cur; |
203 | | } |
204 | | |
205 | | return cur + 1; |
206 | | } |
207 | | |
208 | | AbstractFilesystemNode *GP32FilesystemNode::parent() const { |
| 243 | AbstractFilesystemNode *GP32FilesystemNode::getParent() const { |
209 | 244 | if(_isRoot) |
210 | 245 | return 0; |
211 | 246 | |
… |
… |
|
218 | 253 | |
219 | 254 | return p; |
220 | 255 | } |
221 | | |
222 | | AbstractFilesystemNode *GP32FilesystemNode::child(const String &n) const { |
223 | | // FIXME: Pretty lame implementation! We do no error checking to speak |
224 | | // of, do not check if this is a special node, etc. |
225 | | assert(_isDirectory); |
226 | | String newPath(_path); |
227 | | if (_path.lastChar() != '\\') |
228 | | newPath += '\\'; |
229 | | newPath += n; |
230 | | GP32FilesystemNode *p = new GP32FilesystemNode(newPath); |
231 | | |
232 | | return p; |
233 | | } |
-
|
|
|
35 | 35 | #include "base/engine.h" |
36 | 36 | #include "backends/fs/abstract-fs.h" |
37 | 37 | |
38 | | /* |
| 38 | /** |
39 | 39 | * Implementation of the ScummVM file system API based on the MorphOS A-Box API. |
| 40 | * |
| 41 | * Parts of this class are documented in the base interface class, AbstractFilesystemNode. |
40 | 42 | */ |
41 | | |
42 | 43 | class ABoxFilesystemNode : public AbstractFilesystemNode { |
43 | | protected: |
44 | | BPTR _lock; |
45 | | String _displayName; |
46 | | bool _isDirectory; |
47 | | bool _isValid; |
48 | | String _path; |
| 44 | protected: |
| 45 | BPTR _lock; |
| 46 | String _displayName; |
| 47 | String _path; |
| 48 | bool _isDirectory; |
| 49 | bool _isValid; |
49 | 50 | |
50 | | public: |
51 | | ABoxFilesystemNode(); |
52 | | ABoxFilesystemNode(BPTR lock, CONST_STRPTR display_name = NULL); |
53 | | ABoxFilesystemNode(const String &p); |
54 | | ABoxFilesystemNode(const ABoxFilesystemNode &node); |
| 51 | public: |
| 52 | /** |
| 53 | * Creates a ABoxFilesystemNode with the root node as path. |
| 54 | */ |
| 55 | ABoxFilesystemNode(); |
| 56 | |
| 57 | /** |
| 58 | * Creates a ABoxFilesystemNode for a given path. |
| 59 | * |
| 60 | * @param path String with the path the new node should point to. |
| 61 | */ |
| 62 | ABoxFilesystemNode(const String &p); |
| 63 | |
| 64 | /** |
| 65 | * FIXME: document this constructor. |
| 66 | */ |
| 67 | ABoxFilesystemNode(BPTR lock, CONST_STRPTR display_name = NULL); |
| 68 | |
| 69 | /** |
| 70 | * Copy constructor. |
| 71 | */ |
| 72 | ABoxFilesystemNode(const ABoxFilesystemNode &node); |
55 | 73 | |
56 | | ~ABoxFilesystemNode(); |
| 74 | /** |
| 75 | * Destructor. |
| 76 | */ |
| 77 | ~ABoxFilesystemNode(); |
57 | 78 | |
58 | | virtual String displayName() const { return _displayName; } |
59 | | virtual String name() const { return _displayName; }; |
60 | | virtual bool isValid() const { return _isValid; } |
61 | | virtual bool isDirectory() const { return _isDirectory; } |
62 | | virtual String path() const { return _path; } |
63 | | |
64 | | virtual bool listDir(AbstractFSList &list, ListMode mode) const; |
65 | | static AbstractFSList listRoot(); |
66 | | virtual AbstractFilesystemNode *parent() const; |
67 | | virtual AbstractFilesystemNode *child(const String &name) const; |
| 79 | virtual bool exists() const { return true; } //FIXME: this is just a stub |
| 80 | virtual String getDisplayName() const { return _displayName; } |
| 81 | virtual String getName() const { return _displayName; }; |
| 82 | virtual String getPath() const { return _path; } |
| 83 | virtual bool isDirectory() const { return _isDirectory; } |
| 84 | virtual bool isReadable() const { return true; } //FIXME: this is just a stub |
| 85 | virtual bool isValid() const { return _isValid; } |
| 86 | virtual bool isWritable() const { return true; } //FIXME: this is just a stub |
| 87 | |
| 88 | virtual AbstractFilesystemNode *getChild(const String &name) const; |
| 89 | virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; |
| 90 | virtual AbstractFilesystemNode *getParent() const; |
| 91 | |
| 92 | /** |
| 93 | * Return the list of child nodes for the root node. |
| 94 | */ |
| 95 | static AbstractFSList getRootChildren(); |
68 | 96 | }; |
69 | 97 | |
70 | | |
71 | | AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { |
72 | | return AbstractFilesystemNode::getRoot(); |
73 | | } |
74 | | |
75 | | AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { |
76 | | return new ABoxFilesystemNode(path); |
77 | | } |
78 | | |
79 | | AbstractFilesystemNode *AbstractFilesystemNode::getRoot() |
80 | | { |
81 | | return new ABoxFilesystemNode(); |
82 | | } |
83 | | |
84 | 98 | ABoxFilesystemNode::ABoxFilesystemNode() |
85 | 99 | { |
86 | 100 | _displayName = "Mounted Volumes"; |
… |
… |
|
90 | 104 | _lock = NULL; |
91 | 105 | } |
92 | 106 | |
93 | | ABoxFilesystemNode::ABoxFilesystemNode(BPTR lock, CONST_STRPTR display_name) |
94 | | { |
95 | | int bufsize = 256; |
96 | | |
97 | | _lock = NULL; |
98 | | for (;;) |
99 | | { |
100 | | char name[bufsize]; |
101 | | if (NameFromLock(lock, name, bufsize) != DOSFALSE) |
102 | | { |
103 | | _path = name; |
104 | | _displayName = display_name ? display_name : FilePart(name); |
105 | | break; |
106 | | } |
107 | | if (IoErr() != ERROR_LINE_TOO_LONG) |
108 | | { |
109 | | _isValid = false; |
110 | | debug(6, "Error while retrieving path name: %ld", IoErr()); |
111 | | return; |
112 | | } |
113 | | bufsize *= 2; |
114 | | } |
115 | | |
116 | | _isDirectory = false; |
117 | | _isValid = false; |
118 | | |
119 | | FileInfoBlock *fib = (FileInfoBlock*) AllocDosObject(DOS_FIB, NULL); |
120 | | if (fib == NULL) |
121 | | { |
122 | | debug(6, "Failed to allocate memory for FileInfoBlock"); |
123 | | return; |
124 | | } |
125 | | |
126 | | if (Examine(lock, fib) != DOSFALSE) |
127 | | { |
128 | | _isDirectory = fib->fib_EntryType > 0; |
129 | | if (_isDirectory) |
130 | | { |
131 | | if (fib->fib_EntryType != ST_ROOT) |
132 | | _path += "/"; |
133 | | _lock = DupLock(lock); |
134 | | _isValid = (_lock != NULL); |
135 | | } |
136 | | else |
137 | | { |
138 | | _isValid = true; |
139 | | } |
140 | | } |
141 | | FreeDosObject(DOS_FIB, fib); |
142 | | } |
143 | | |
144 | 107 | ABoxFilesystemNode::ABoxFilesystemNode(const String &p) { |
145 | 108 | int len = 0, offset = p.size(); |
146 | 109 | |
… |
… |
|
168 | 131 | } |
169 | 132 | |
170 | 133 | // Check whether the node exists and if it is a directory |
171 | | |
172 | 134 | BPTR pLock = Lock((STRPTR)_path.c_str(), SHARED_LOCK); |
173 | 135 | if (pLock) |
174 | 136 | { |
… |
… |
|
198 | 160 | FreeDosObject(DOS_FIB, fib); |
199 | 161 | } |
200 | 162 | |
| 163 | ABoxFilesystemNode::ABoxFilesystemNode(BPTR lock, CONST_STRPTR display_name) |
| 164 | { |
| 165 | int bufsize = 256; |
| 166 | |
| 167 | _lock = NULL; |
| 168 | for (;;) |
| 169 | { |
| 170 | char name[bufsize]; |
| 171 | if (NameFromLock(lock, name, bufsize) != DOSFALSE) |
| 172 | { |
| 173 | _path = name; |
| 174 | _displayName = display_name ? display_name : FilePart(name); |
| 175 | break; |
| 176 | } |
| 177 | if (IoErr() != ERROR_LINE_TOO_LONG) |
| 178 | { |
| 179 | _isValid = false; |
| 180 | debug(6, "Error while retrieving path name: %ld", IoErr()); |
| 181 | return; |
| 182 | } |
| 183 | bufsize *= 2; |
| 184 | } |
| 185 | |
| 186 | _isDirectory = false; |
| 187 | _isValid = false; |
| 188 | |
| 189 | FileInfoBlock *fib = (FileInfoBlock*) AllocDosObject(DOS_FIB, NULL); |
| 190 | if (fib == NULL) |
| 191 | { |
| 192 | debug(6, "Failed to allocate memory for FileInfoBlock"); |
| 193 | return; |
| 194 | } |
| 195 | |
| 196 | if (Examine(lock, fib) != DOSFALSE) |
| 197 | { |
| 198 | _isDirectory = fib->fib_EntryType > 0; |
| 199 | if (_isDirectory) |
| 200 | { |
| 201 | if (fib->fib_EntryType != ST_ROOT) |
| 202 | _path += "/"; |
| 203 | _lock = DupLock(lock); |
| 204 | _isValid = (_lock != NULL); |
| 205 | } |
| 206 | else |
| 207 | { |
| 208 | _isValid = true; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | FreeDosObject(DOS_FIB, fib); |
| 213 | } |
| 214 | |
201 | 215 | ABoxFilesystemNode::ABoxFilesystemNode(const ABoxFilesystemNode& node) |
202 | 216 | { |
203 | 217 | _displayName = node._displayName; |
… |
… |
|
216 | 230 | } |
217 | 231 | } |
218 | 232 | |
219 | | bool ABoxFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const |
| 233 | AbstractFilesystemNode *ABoxFilesystemNode::getChild(const String &name) const { |
| 234 | assert(_isDirectory); |
| 235 | String newPath(_path); |
| 236 | |
| 237 | if (_path.lastChar() != '/') |
| 238 | newPath += '/'; |
| 239 | newPath += name; |
| 240 | |
| 241 | BPTR lock = Lock(newPath.c_str(), SHARED_LOCK); |
| 242 | |
| 243 | if (!lock) |
| 244 | { |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | UnLock(lock); |
| 249 | |
| 250 | return new ABoxFilesystemNode(newPath); |
| 251 | } |
| 252 | |
| 253 | bool ABoxFilesystemNode::getChildren(AbstractFSList &list, ListMode mode, bool hidden) const |
220 | 254 | { |
| 255 | //TODO: honor the hidden flag |
| 256 | |
221 | 257 | if (!_isValid) |
222 | 258 | { |
223 | 259 | debug(6, "listDir() called on invalid node"); |
… |
… |
|
232 | 268 | if (_lock == NULL) |
233 | 269 | { |
234 | 270 | /* This is the root node */ |
235 | | myList = listRoot(); |
| 271 | list = getRootChildren(); |
236 | 272 | return true; |
237 | 273 | } |
238 | 274 | |
… |
… |
|
266 | 302 | if (entry) |
267 | 303 | { |
268 | 304 | if (entry->isValid()) |
269 | | myList.push_back(entry); |
| 305 | list.push_back(entry); |
270 | 306 | else |
271 | 307 | delete entry; |
272 | 308 | } |
… |
… |
|
284 | 320 | return true; |
285 | 321 | } |
286 | 322 | |
287 | | AbstractFilesystemNode *ABoxFilesystemNode::parent() const |
| 323 | AbstractFilesystemNode *ABoxFilesystemNode::getParent() const |
288 | 324 | { |
289 | 325 | AbstractFilesystemNode *node = NULL; |
290 | 326 | |
… |
… |
|
309 | 345 | return node; |
310 | 346 | } |
311 | 347 | |
312 | | AbstractFilesystemNode *ABoxFilesystemNode::child(const String &name) const { |
313 | | assert(_isDirectory); |
314 | | String newPath(_path); |
315 | | |
316 | | if (_path.lastChar() != '/') |
317 | | newPath += '/'; |
318 | | newPath += name; |
319 | | |
320 | | BPTR lock = Lock(newPath.c_str(), SHARED_LOCK); |
321 | | |
322 | | if (!lock) |
323 | | { |
324 | | return 0; |
325 | | } |
326 | | |
327 | | UnLock(lock); |
328 | | |
329 | | return new ABoxFilesystemNode(newPath); |
330 | | } |
331 | | |
332 | | AbstractFSList ABoxFilesystemNode::listRoot() |
| 348 | AbstractFSList ABoxFilesystemNode::getRootChildren() |
333 | 349 | { |
334 | | AbstractFSList myList; |
| 350 | AbstractFSList list; |
335 | 351 | DosList *dosList; |
336 | 352 | CONST ULONG lockDosListFlags = LDF_READ | LDF_VOLUMES; |
337 | 353 | char name[256]; |
… |
… |
|
339 | 355 | dosList = LockDosList(lockDosListFlags); |
340 | 356 | if (dosList == NULL) |
341 | 357 | { |
342 | | return myList; |
| 358 | return list; |
343 | 359 | } |
344 | 360 | |
345 | 361 | dosList = NextDosEntry(dosList, LDF_VOLUMES); |
… |
… |
|
345 | 361 | dosList = NextDosEntry(dosList, LDF_VOLUMES); |
346 | 362 | while (dosList) |
347 | 363 | { |
348 | | if (dosList->dol_Type == DLT_VOLUME && // Should always be true, but ... |
349 | | dosList->dol_Name && // Same here |
350 | | dosList->dol_Task // Will be NULL if volume is removed from drive but still in use by some program |
| 364 | if (dosList->dol_Type == DLT_VOLUME && // Should always be true, but ... |
| 365 | dosList->dol_Name && // Same here |
| 366 | dosList->dol_Task // Will be NULL if volume is removed from drive but still in use by some program |
351 | 367 | ) |
352 | 368 | { |
353 | 369 | ABoxFilesystemNode *entry; |
… |
… |
|
365 | 381 | if (entry) |
366 | 382 | { |
367 | 383 | if (entry->isValid()) |
368 | | myList.push_back(entry); |
| 384 | list.push_back(entry); |
369 | 385 | else |
370 | 386 | delete entry; |
371 | 387 | } |
… |
… |
|
377 | 393 | |
378 | 394 | UnLockDosList(lockDosListFlags); |
379 | 395 | |
380 | | return myList; |
| 396 | return list; |
381 | 397 | } |
382 | 398 | |
383 | 399 | #endif // defined(__MORPHOS__) |
384 | | |
385 | | |
-
|
|
|
30 | 30 | #include "common/stdafx.h" |
31 | 31 | #include "backends/fs/abstract-fs.h" |
32 | 32 | |
33 | | /* |
| 33 | /** |
34 | 34 | * Implementation of the ScummVM file system API based on PalmOS VFS API. |
| 35 | * |
| 36 | * Parts of this class are documented in the base interface class, AbstractFilesystemNode. |
35 | 37 | */ |
36 | | |
37 | 38 | class PalmOSFilesystemNode : public AbstractFilesystemNode { |
38 | 39 | protected: |
39 | 40 | String _displayName; |
| 41 | String _path; |
40 | 42 | bool _isDirectory; |
41 | 43 | bool _isValid; |
42 | 44 | bool _isPseudoRoot; |
43 | | String _path; |
44 | 45 | |
45 | 46 | public: |
| 47 | /** |
| 48 | * Creates a PalmOSFilesystemNode with the root node as path. |
| 49 | */ |
46 | 50 | PalmOSFilesystemNode(); |
| 51 | |
| 52 | /** |
| 53 | * Creates a POSIXFilesystemNode for a given path. |
| 54 | * |
| 55 | * @param path String with the path the new node should point to. |
| 56 | */ |
47 | 57 | PalmOSFilesystemNode(const String &p); |
48 | 58 | |
49 | | virtual String displayName() const { return _displayName; } |
50 | | virtual String name() const { return _displayName; } |
| 59 | virtual bool exists() const { return true; } //FIXME: this is just a stub |
| 60 | virtual String getDisplayName() const { return _displayName; } |
| 61 | virtual String getName() const { return _displayName; } |
| 62 | virtual String getPath() const { return _path; } |
| 63 | virtual bool isDirectory() const { return _isDirectory; } |
| 64 | virtual bool isReadable() const { return true; } //FIXME: this is just a stub |
51 | 65 | virtual bool isValid() const { return _isValid; } |
52 | | virtual bool isDirectory() const { return _isDirectory; } |
53 | | virtual String path() const { return _path; } |
| 66 | virtual bool isWritable() const { return true; } //FIXME: this is just a stub |
54 | 67 | |
55 | | virtual bool listDir(AbstractFSList &list, ListMode mode) const; |
56 | | virtual AbstractFilesystemNode *parent() const; |
57 | | virtual AbstractFilesystemNode *child(const String &n) const; |
| 68 | virtual AbstractFilesystemNode *getChild(const String &n) const; |
| 69 | virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; |
| 70 | virtual AbstractFilesystemNode *getParent() const; |
58 | 71 | |
59 | 72 | private: |
60 | | static void addFile (AbstractFSList &list, ListMode mode, const Char *base, FileInfoType* find_data); |
| 73 | /** |
| 74 | * Adds a single WindowsFilesystemNode to a given list. |
| 75 | * This method is used by getChildren() to populate the directory entries list. |
| 76 | * |
| 77 | * @param list List to put the file entry node in. |
| 78 | * @param mode Mode to use while adding the file entry to the list. |
| 79 | * @param base String with the directory being listed. |
| 80 | * @param find_data Describes a file that the FindFirstFile, FindFirstFileEx, or FindNextFile functions find. |
| 81 | */ |
| 82 | static void addFile(AbstractFSList &list, ListMode mode, const Char *base, FileInfoType* find_data); |
61 | 83 | }; |
62 | 84 | |
| 85 | /** |
| 86 | * Returns the last component of a given path. |
| 87 | * |
| 88 | * Examples: |
| 89 | * /foo/bar.txt would return /bar.txt |
| 90 | * /foo/bar/ would return /bar/ |
| 91 | * |
| 92 | * @param str String containing the path. |
| 93 | * @return Pointer to the first char of the last component inside str. |
| 94 | */ |
63 | 95 | static const char *lastPathComponent(const Common::String &str) { |
64 | 96 | const char *start = str.c_str(); |
65 | 97 | const char *cur = start + str.size() - 2; |
… |
… |
|
95 | 127 | list.push_back(new PalmOSFilesystemNode(entry)); |
96 | 128 | } |
97 | 129 | |
98 | | AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { |
99 | | return AbstractFilesystemNode::getRoot(); |
100 | | } |
101 | | |
102 | | AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { |
103 | | return new PalmOSFilesystemNode(); |
104 | | } |
105 | | |
106 | | AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { |
107 | | return new PalmOSFilesystemNode(path); |
108 | | } |
109 | | |
110 | | |
111 | 130 | PalmOSFilesystemNode::PalmOSFilesystemNode() { |
112 | 131 | _isDirectory = true; |
113 | 132 | _displayName = "Root"; |
… |
… |
|
122 | 141 | |
123 | 142 | UInt32 attr; |
124 | 143 | FileRef handle; |
125 | | Err e = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle); |
126 | | if (!e) { |
127 | | e = VFSFileGetAttributes(handle, &attr); |
| 144 | Err error = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle); |
| 145 | if (!error) { |
| 146 | error = VFSFileGetAttributes(handle, &attr); |
128 | 147 | VFSFileClose(handle); |
129 | 148 | } |
130 | 149 | |
131 | | if (e) { |
| 150 | if (error) { |
132 | 151 | _isValid = false; |
133 | 152 | _isDirectory = false; |
134 | 153 | |
… |
… |
|
139 | 158 | _isPseudoRoot = false; |
140 | 159 | } |
141 | 160 | |
142 | | bool PalmOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { |
143 | | Err e; |
| 161 | AbstractFilesystemNode *PalmOSFilesystemNode::getChild(const String &n) const { |
| 162 | assert(_isDirectory); |
| 163 | |
| 164 | String newPath(_path); |
| 165 | if (_path.lastChar() != '/') |
| 166 | newPath += '/'; |
| 167 | newPath += n; |
| 168 | |
| 169 | FileRef handle; |
| 170 | UInt32 attr; |
| 171 | Err error = VFSFileOpen(gVars->VFS.volRefNum, newPath.c_str(), vfsModeRead, &handle); |
| 172 | if (error) |
| 173 | return 0; |
| 174 | |
| 175 | error = VFSFileGetAttributes(handle, &attr); |
| 176 | VFSFileClose(handle); |
| 177 | |
| 178 | if (error || !(attr & vfsFileAttrDirectory)) |
| 179 | return 0; |
| 180 | |
| 181 | return new PalmOSFilesystemNode(newPath); |
| 182 | } |
| 183 | |
| 184 | bool PalmOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { |
| 185 | //TODO: honor the hidden flag |
| 186 | |
| 187 | Err error; |
144 | 188 | Char nameP[256]; |
145 | 189 | FileInfoType desc; |
146 | 190 | FileRef handle; |
… |
… |
|
148 | 192 | |
149 | 193 | desc.nameP = nameP; |
150 | 194 | desc.nameBufLen = 256; |
151 | | e = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle); |
| 195 | error = VFSFileOpen(gVars->VFS.volRefNum, _path.c_str(), vfsModeRead, &handle); |
152 | 196 | |
153 | | if (e) |
| 197 | if (error) |
154 | 198 | return false; |
155 | 199 | |
156 | 200 | while(dirIterator != expIteratorStop) { |
157 | | e = VFSDirEntryEnumerate(handle, &dirIterator, &desc); |
158 | | if (!e) { |
| 201 | error = VFSDirEntryEnumerate(handle, &dirIterator, &desc); |
| 202 | if (!error) { |
159 | 203 | addFile(myList, mode, _path.c_str(), &desc); |
160 | 204 | } |
161 | 205 | } |
… |
… |
|
165 | 209 | return true; |
166 | 210 | } |
167 | 211 | |
168 | | |
169 | | AbstractFilesystemNode *PalmOSFilesystemNode::parent() const { |
| 212 | AbstractFilesystemNode *PalmOSFilesystemNode::getParent() const { |
170 | 213 | PalmOSFilesystemNode *p = 0; |
171 | 214 | |
172 | 215 | if (!_isPseudoRoot) { |
… |
… |
|
180 | 223 | p->_displayName = lastPathComponent(p->_path); |
181 | 224 | p->_isPseudoRoot =(p->_path == "/"); |
182 | 225 | } |
183 | | return p; |
184 | | } |
185 | | |
186 | | |
187 | | AbstractFilesystemNode *PalmOSFilesystemNode::child(const String &n) const { |
188 | | assert(_isDirectory); |
189 | | String newPath(_path); |
190 | | |
191 | | if (_path.lastChar() != '/') |
192 | | newPath += '/'; |
193 | | newPath += n; |
194 | | |
195 | | FileRef handle; |
196 | | UInt32 attr; |
197 | | Err e = VFSFileOpen(gVars->VFS.volRefNum, newPath.c_str(), vfsModeRead, &handle); |
198 | | if (e) |
199 | | return 0; |
200 | 226 | |
201 | | e = VFSFileGetAttributes(handle, &attr); |
202 | | VFSFileClose(handle); |
203 | | |
204 | | if (e || !(attr & vfsFileAttrDirectory)) |
205 | | return 0; |
206 | | |
207 | | PalmOSFilesystemNode *p = new PalmOSFilesystemNode(newPath); |
208 | 227 | return p; |
209 | 228 | } |
210 | 229 | |
-
|
|
|
25 | 25 | #if defined(UNIX) |
26 | 26 | |
27 | 27 | #include "common/stdafx.h" |
28 | | |
29 | 28 | #include "backends/fs/abstract-fs.h" |
30 | 29 | |
31 | 30 | #ifdef MACOSX |
… |
… |
|
37 | 36 | #include <stdio.h> |
38 | 37 | #include <unistd.h> |
39 | 38 | |
40 | | /* |
| 39 | /** |
41 | 40 | * Implementation of the ScummVM file system API based on POSIX. |
| 41 | * |
| 42 | * Parts of this class are documented in the base interface class, AbstractFilesystemNode. |
42 | 43 | */ |
43 | | |
44 | 44 | class POSIXFilesystemNode : public AbstractFilesystemNode { |
45 | 45 | protected: |
46 | 46 | String _displayName; |
| 47 | String _path; |
47 | 48 | bool _isDirectory; |
48 | 49 | bool _isValid; |
49 | | String _path; |
50 | 50 | |
51 | 51 | public: |
| 52 | /** |
| 53 | * Creates a POSIXFilesystemNode with the root node as path. |
| 54 | */ |
52 | 55 | POSIXFilesystemNode(); |
| 56 | |
| 57 | /** |
| 58 | * Creates a POSIXFilesystemNode for a given path. |
| 59 | * |
| 60 | * @param path String with the path the new node should point to. |
| 61 | * @param verify true if the isValid and isDirectory flags should be verified during the construction. |
| 62 | */ |
53 | 63 | POSIXFilesystemNode(const String &path, bool verify); |
54 | | |
55 | | virtual String displayName() const { return _displayName; } |
56 | | virtual String name() const { return _displayName; } |
57 | | virtual bool isValid() const { return _isValid; } |
| 64 | |
| 65 | virtual bool exists() const { return access(_path.c_str(), F_OK) == 0; } |
| 66 | virtual String getDisplayName() const { return _displayName; } |
| 67 | virtual String getName() const { return _displayName; } |
| 68 | virtual String getPath() const { return _path; } |
58 | 69 | virtual bool isDirectory() const { return _isDirectory; } |
59 | | virtual String path() const { return _path; } |
60 | | |
61 | | virtual bool listDir(AbstractFSList &list, ListMode mode) const; |
62 | | virtual AbstractFilesystemNode *parent() const; |
63 | | virtual AbstractFilesystemNode *child(const String &n) const; |
| 70 | virtual bool isReadable() const { return access(_path.c_str(), R_OK) == 0; } |
| 71 | virtual bool isWritable() const { return access(_path.c_str(), W_OK) == 0; } |
| 72 | |
| 73 | virtual AbstractFilesystemNode *getChild(const String &n) const; |
| 74 | virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; |
| 75 | virtual AbstractFilesystemNode *getParent() const; |
| 76 | |
| 77 | private: |
| 78 | /** |
| 79 | * Tests and sets the _isValid and _isDirectory flags, using the stat() function. |
| 80 | */ |
| 81 | virtual void setFlags(); |
64 | 82 | }; |
65 | 83 | |
66 | | |
| 84 | /** |
| 85 | * Returns the last component of a given path. |
| 86 | * |
| 87 | * Examples: |
| 88 | * /foo/bar.txt would return /bar.txt |
| 89 | * /foo/bar/ would return /bar/ |
| 90 | * |
| 91 | * @param str String containing the path. |
| 92 | * @return Pointer to the first char of the last component inside str. |
| 93 | */ |
67 | 94 | static const char *lastPathComponent(const Common::String &str) { |
68 | 95 | const char *start = str.c_str(); |
69 | 96 | const char *cur = start + str.size() - 2; |
… |
… |
|
75 | 102 | return cur + 1; |
76 | 103 | } |
77 | 104 | |
78 | | AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { |
79 | | char buf[MAXPATHLEN]; |
80 | | getcwd(buf, MAXPATHLEN); |
81 | | return new POSIXFilesystemNode(buf, true); |
82 | | } |
83 | | |
84 | | AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { |
85 | | return new POSIXFilesystemNode(); |
86 | | } |
87 | | |
88 | | AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { |
89 | | return new POSIXFilesystemNode(path, true); |
| 105 | void POSIXFilesystemNode::setFlags() { |
| 106 | struct stat st; |
| 107 | |
| 108 | _isValid = (0 == stat(_path.c_str(), &st)); |
| 109 | _isDirectory = _isValid ? S_ISDIR(st.st_mode) : false; |
90 | 110 | } |
91 | 111 | |
92 | 112 | POSIXFilesystemNode::POSIXFilesystemNode() { |
… |
… |
|
123 | 143 | |
124 | 144 | _path = p; |
125 | 145 | _displayName = lastPathComponent(_path); |
126 | | _isValid = true; |
127 | | _isDirectory = true; |
128 | 146 | |
129 | 147 | if (verify) { |
130 | | struct stat st; |
131 | | _isValid = (0 == stat(_path.c_str(), &st)); |
132 | | _isDirectory = _isValid ? S_ISDIR(st.st_mode) : false; |
| 148 | setFlags(); |
133 | 149 | } |
134 | 150 | } |
135 | 151 | |
136 | | bool POSIXFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { |
| 152 | AbstractFilesystemNode *POSIXFilesystemNode::getChild(const String &n) const { |
| 153 | // FIXME: Pretty lame implementation! We do no error checking to speak |
| 154 | // of, do not check if this is a special node, etc. |
| 155 | assert(_isDirectory); |
| 156 | |
| 157 | String newPath(_path); |
| 158 | if (_path.lastChar() != '/') |
| 159 | newPath += '/'; |
| 160 | newPath += n; |
| 161 | |
| 162 | return new POSIXFilesystemNode(newPath, true); |
| 163 | } |
| 164 | |
| 165 | bool POSIXFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { |
137 | 166 | assert(_isDirectory); |
| 167 | |
138 | 168 | DIR *dirp = opendir(_path.c_str()); |
139 | | |
140 | 169 | struct dirent *dp; |
141 | 170 | |
142 | 171 | if (dirp == NULL) |
… |
… |
|
142 | 171 | if (dirp == NULL) |
143 | 172 | return false; |
144 | 173 | |
145 | | // ... loop over dir entries using readdir |
| 174 | // loop over dir entries using readdir |
146 | 175 | while ((dp = readdir(dirp)) != NULL) { |
147 | | // Skip 'invisible' files |
148 | | if (dp->d_name[0] == '.') |
| 176 | // Skip 'invisible' files if necessary |
| 177 | if (dp->d_name[0] == '.' && !hidden) { |
149 | 178 | continue; |
| 179 | } |
| 180 | // Skip '.' and '..' to avoid cycles |
| 181 | if((dp->d_name[0] == '.' && dp->d_name[1] == 0) || (dp->d_name[0] == '.' && dp->d_name[1] == '.')) { |
| 182 | continue; |
| 183 | } |
150 | 184 | |
151 | 185 | String newPath(_path); |
152 | 186 | if (newPath.lastChar() != '/') |
… |
… |
|
156 | 190 | POSIXFilesystemNode entry(newPath, false); |
157 | 191 | |
158 | 192 | #if defined(SYSTEM_NOT_SUPPORTING_D_TYPE) |
159 | | // TODO: d_type is not part of POSIX, so it might not be supported |
160 | | // on some of our targets. For those systems where it isn't supported, |
161 | | // add this #elif case, which tries to use stat() instead. |
162 | | struct stat st; |
163 | | entry._isValid = (0 == stat(entry._path.c_str(), &st)); |
164 | | entry._isDirectory = entry._isValid ? S_ISDIR(st.st_mode) : false; |
| 193 | /* TODO: d_type is not part of POSIX, so it might not be supported |
| 194 | * on some of our targets. For those systems where it isn't supported, |
| 195 | * add this #elif case, which tries to use stat() instead. |
| 196 | * |
| 197 | * The d_type method is used to avoid costly recurrent stat() calls in big |
| 198 | * directories. |
| 199 | */ |
| 200 | entry.setFlags(); |
165 | 201 | #else |
166 | 202 | if (dp->d_type == DT_UNKNOWN) { |
167 | 203 | // Fall back to stat() |
168 | | struct stat st; |
169 | | entry._isValid = (0 == stat(entry._path.c_str(), &st)); |
170 | | entry._isDirectory = entry._isValid ? S_ISDIR(st.st_mode) : false; |
| 204 | entry.setFlags(); |
171 | 205 | } else { |
172 | 206 | entry._isValid = (dp->d_type == DT_DIR) || (dp->d_type == DT_REG) || (dp->d_type == DT_LNK); |
173 | 207 | if (dp->d_type == DT_LNK) { |
… |
… |
|
194 | 228 | |
195 | 229 | if (entry._isDirectory) |
196 | 230 | entry._path += "/"; |
| 231 | |
197 | 232 | myList.push_back(new POSIXFilesystemNode(entry)); |
198 | 233 | } |
199 | 234 | closedir(dirp); |
| 235 | |
200 | 236 | return true; |
201 | 237 | } |
202 | 238 | |
203 | | AbstractFilesystemNode *POSIXFilesystemNode::parent() const { |
| 239 | AbstractFilesystemNode *POSIXFilesystemNode::getParent() const { |
204 | 240 | if (_path == "/") |
205 | 241 | return 0; |
206 | 242 | |
… |
… |
|
207 | 243 | const char *start = _path.c_str(); |
208 | 244 | const char *end = lastPathComponent(_path); |
209 | 245 | |
210 | | POSIXFilesystemNode *p = new POSIXFilesystemNode(String(start, end - start), false); |
211 | | |
212 | | return p; |
213 | | } |
214 | | |
215 | | AbstractFilesystemNode *POSIXFilesystemNode::child(const String &n) const { |
216 | | // FIXME: Pretty lame implementation! We do no error checking to speak |
217 | | // of, do not check if this is a special node, etc. |
218 | | assert(_isDirectory); |
219 | | String newPath(_path); |
220 | | if (_path.lastChar() != '/') |
221 | | newPath += '/'; |
222 | | newPath += n; |
223 | | POSIXFilesystemNode *p = new POSIXFilesystemNode(newPath, true); |
224 | | |
225 | | return p; |
| 246 | return new POSIXFilesystemNode(String(start, end - start), true); |
226 | 247 | } |
227 | 248 | |
228 | | #endif // defined(UNIX) |
| 249 | #endif //#if defined(UNIX) |
-
|
|
|
32 | 32 | extern AsyncFio fio; |
33 | 33 | extern OSystem_PS2 *g_systemPs2; |
34 | 34 | |
| 35 | /** |
| 36 | * Implementation of the ScummVM file system API based on the Ps2SDK. |
| 37 | * |
| 38 | * Parts of this class are documented in the base interface class, AbstractFilesystemNode. |
| 39 | */ |
35 | 40 | class Ps2FilesystemNode : public AbstractFilesystemNode { |
36 | 41 | protected: |
37 | 42 | String _displayName; |
| 43 | String _path; |
38 | 44 | bool _isDirectory; |
39 | 45 | bool _isRoot; |
40 | | String _path; |
41 | 46 | |
42 | 47 | public: |
43 | | Ps2FilesystemNode(void); |
| 48 | /** |
| 49 | * Creates a PS2FilesystemNode with the root node as path. |
| 50 | */ |
| 51 | Ps2FilesystemNode(); |
| 52 | |
| 53 | /** |
| 54 | * Creates a PS2FilesystemNode for a given path. |
| 55 | * |
| 56 | * @param path String with the path the new node should point to. |
| 57 | */ |
| 58 | Ps2FilesystemNode(const String &path); |
| 59 | |
| 60 | /** |
| 61 | * Copy constructor. |
| 62 | */ |
44 | 63 | Ps2FilesystemNode(const Ps2FilesystemNode *node); |
45 | | Ps2FilesystemNode(const String &path); |
46 | 64 | |
47 | | virtual String displayName() const { return _displayName; } |
48 | | virtual String name() const { return _displayName; } |
49 | | virtual bool isValid() const { return !_isRoot; } |
| 65 | virtual bool exists() const { return true; } //FIXME: this is just a stub |
| 66 | virtual String getDisplayName() const { return _displayName; } |
| 67 | virtual String getName() const { return _displayName; } |
| 68 | virtual String getPath() const { return _path; } |
50 | 69 | virtual bool isDirectory() const { return _isDirectory; } |
51 | | virtual String path() const { return _path; } |
| 70 | virtual bool isReadable() const { return true; } //FIXME: this is just a stub |
| 71 | virtual bool isValid() const { return !_isRoot; } |
| 72 | virtual bool isWritable() const { return true; } //FIXME: this is just a stub |
52 | 73 | |
53 | | //virtual FSList listDir(ListMode) const; |
54 | | virtual bool listDir(AbstractFSList &list, ListMode mode) const; |
55 | | virtual AbstractFilesystemNode *parent() const; |
56 | 74 | virtual AbstractFilesystemNode *clone() const { return new Ps2FilesystemNode(this); } |
57 | | virtual AbstractFilesystemNode *child(const String &n) const; |
| 75 | virtual AbstractFilesystemNode *getChild(const String &n) const; |
| 76 | virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; |
| 77 | virtual AbstractFilesystemNode *getParent() const; |
58 | 78 | }; |
59 | 79 | |
60 | | AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { |
61 | | return AbstractFilesystemNode::getRoot(); |
62 | | } |
63 | | |
64 | | AbstractFilesystemNode *AbstractFilesystemNode::getRoot(void) { |
65 | | return new Ps2FilesystemNode(); |
66 | | } |
67 | | |
68 | | AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { |
69 | | return new Ps2FilesystemNode(path); |
70 | | } |
71 | | |
72 | | Ps2FilesystemNode::Ps2FilesystemNode(void) { |
| 80 | Ps2FilesystemNode::Ps2FilesystemNode() { |
73 | 81 | _isDirectory = true; |
74 | 82 | _isRoot = true; |
75 | 83 | _displayName = "PlayStation 2"; |
… |
… |
|
108 | 116 | _isRoot = node->_isRoot; |
109 | 117 | } |
110 | 118 | |
111 | | bool Ps2FilesystemNode::listDir(AbstractFSList &list, ListMode mode) const { |
| 119 | AbstractFilesystemNode *Ps2FilesystemNode::getChild(const String &n) const { |
| 120 | if (!_isDirectory) |
| 121 | return NULL; |
| 122 | |
| 123 | char listDir[256]; |
| 124 | sprintf(listDir, "%s/", _path.c_str()); |
| 125 | int fd = fio.dopen(listDir); |
| 126 | |
| 127 | if (fd >= 0) { |
| 128 | iox_dirent_t dirent; |
| 129 | |
| 130 | while (fio.dread(fd, &dirent) > 0) { |
| 131 | if (strcmp(n.c_str(), dirent.name) == 0) { |
| 132 | Ps2FilesystemNode *dirEntry = new Ps2FilesystemNode(); |
| 133 | |
| 134 | dirEntry->_isDirectory = (bool)(dirent.stat.mode & FIO_S_IFDIR); |
| 135 | dirEntry->_isRoot = false; |
| 136 | |
| 137 | dirEntry->_path = _path; |
| 138 | dirEntry->_path += "/"; |
| 139 | dirEntry->_path += dirent.name; |
| 140 | |
| 141 | dirEntry->_displayName = dirent.name; |
| 142 | |
| 143 | fio.dclose(fd); |
| 144 | return dirEntry; |
| 145 | } |
| 146 | } |
| 147 | fio.dclose(fd); |
| 148 | } |
| 149 | |
| 150 | return NULL; |
| 151 | } |
| 152 | |
| 153 | bool Ps2FilesystemNode::getChildren(AbstractFSList &list, ListMode mode, bool hidden) const { |
| 154 | //TODO: honor the hidden flag |
| 155 | |
112 | 156 | if (!_isDirectory) |
113 | 157 | return false; |
114 | 158 | |
… |
… |
|
135 | 179 | } else { |
136 | 180 | char listDir[256]; |
137 | 181 | int fd; |
| 182 | |
138 | 183 | if (_path.lastChar() == '/') |
139 | 184 | fd = fio.dopen(_path.c_str()); |
140 | 185 | else { |
… |
… |
|
173 | 218 | } |
174 | 219 | } |
175 | 220 | |
176 | | AbstractFilesystemNode *Ps2FilesystemNode::parent() const { |
| 221 | AbstractFilesystemNode *Ps2FilesystemNode::getParent() const { |
177 | 222 | if (_isRoot) |
178 | 223 | return new Ps2FilesystemNode(this); |
179 | 224 | |
… |
… |
|
191 | 236 | else |
192 | 237 | return new Ps2FilesystemNode(); |
193 | 238 | } |
194 | | |
195 | | AbstractFilesystemNode *Ps2FilesystemNode::child(const String &n) const { |
196 | | if (!_isDirectory) |
197 | | return NULL; |
198 | | |
199 | | char listDir[256]; |
200 | | sprintf(listDir, "%s/", _path.c_str()); |
201 | | int fd = fio.dopen(listDir); |
202 | | |
203 | | if (fd >= 0) { |
204 | | iox_dirent_t dirent; |
205 | | |
206 | | while (fio.dread(fd, &dirent) > 0) { |
207 | | if (strcmp(n.c_str(), dirent.name) == 0) { |
208 | | Ps2FilesystemNode *dirEntry = new Ps2FilesystemNode(); |
209 | | |
210 | | dirEntry->_isDirectory = (bool)(dirent.stat.mode & FIO_S_IFDIR); |
211 | | dirEntry->_isRoot = false; |
212 | | |
213 | | dirEntry->_path = _path; |
214 | | dirEntry->_path += "/"; |
215 | | dirEntry->_path += dirent.name; |
216 | | |
217 | | dirEntry->_displayName = dirent.name; |
218 | | |
219 | | fio.dclose(fd); |
220 | | return dirEntry; |
221 | | } |
222 | | } |
223 | | fio.dclose(fd); |
224 | | } |
225 | | return NULL; |
226 | | } |
-
|
|
|
23 | 23 | */ |
24 | 24 | |
25 | 25 | #ifdef __PSP__ |
| 26 | |
26 | 27 | #include "engines/engine.h" |
27 | | |
28 | 28 | #include "backends/fs/abstract-fs.h" |
29 | 29 | |
30 | 30 | #include <sys/stat.h> |
… |
… |
|
32 | 32 | |
33 | 33 | #define ROOT_PATH "ms0:/" |
34 | 34 | |
35 | | |
36 | | /* |
| 35 | /** |
37 | 36 | * Implementation of the ScummVM file system API based on PSPSDK API. |
| 37 | * |
| 38 | * Parts of this class are documented in the base interface class, AbstractFilesystemNode. |
38 | 39 | */ |
39 | | |
40 | 40 | class PSPFilesystemNode : public AbstractFilesystemNode { |
41 | 41 | protected: |
42 | 42 | String _displayName; |
| 43 | String _path; |
43 | 44 | bool _isDirectory; |
44 | 45 | bool _isValid; |
45 | | String _path; |
46 | 46 | |
47 | 47 | public: |
| 48 | /** |
| 49 | * Creates a PSPFilesystemNode with the root node as path. |
| 50 | */ |
48 | 51 | PSPFilesystemNode(); |
| 52 | |
| 53 | /** |
| 54 | * Creates a PSPFilesystemNode for a given path. |
| 55 | * |
| 56 | * @param path String with the path the new node should point to. |
| 57 | * @param verify true if the isValid and isDirectory flags should be verified during the construction. |
| 58 | */ |
49 | 59 | PSPFilesystemNode(const Common::String &p, bool verify); |
50 | 60 | |
51 | | virtual String displayName() const { return _displayName; } |
52 | | virtual String name() const { return _displayName; } |
| 61 | virtual bool exists() const { return true; } //FIXME: this is just a stub |
| 62 | virtual String getDisplayName() const { return _displayName; } |
| 63 | virtual String getName() const { return _displayName; } |
| 64 | virtual String getPath() const { return _path; } |
| 65 | virtual bool isDirectory() const { return _isDirectory; } |
| 66 | virtual bool isReadable() const { return true; } //FIXME: this is just a stub |
53 | 67 | virtual bool isValid() const { return _isValid; } |
54 | | virtual bool isDirectory() const { return _isDirectory; } |
55 | | virtual String path() const { return _path; } |
| 68 | virtual bool isWritable() const { return true; } //FIXME: this is just a stub |
56 | 69 | |
57 | | virtual bool listDir(AbstractFSList &list, ListMode mode) const; |
58 | | virtual AbstractFilesystemNode *parent() const; |
59 | | virtual AbstractFilesystemNode *child(const String &n) const; |
| 70 | virtual AbstractFilesystemNode *getChild(const String &n) const; |
| 71 | virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; |
| 72 | virtual AbstractFilesystemNode *getParent() const; |
60 | 73 | }; |
61 | 74 | |
62 | | AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { |
63 | | return AbstractFilesystemNode::getRoot(); |
64 | | } |
| 75 | /** |
| 76 | * Returns the last component of a given path. |
| 77 | * |
| 78 | * Examples: |
| 79 | * /foo/bar.txt would return /bar.txt |
| 80 | * /foo/bar/ would return /bar/ |
| 81 | * |
| 82 | * @param str String containing the path. |
| 83 | * @return Pointer to the first char of the last component inside str. |
| 84 | */ |
| 85 | static const char *lastPathComponent(const Common::String &str) { |
| 86 | const char *start = str.c_str(); |
| 87 | const char *cur = start + str.size() - 2; |
65 | 88 | |
66 | | AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { |
67 | | return new PSPFilesystemNode(); |
| 89 | while (cur >= start && *cur != '/') { |
| 90 | --cur; |
| 91 | } |
| 92 | |
| 93 | return cur + 1; |
68 | 94 | } |
69 | 95 | |
70 | 96 | PSPFilesystemNode::PSPFilesystemNode() { |
… |
… |
|
89 | 115 | } |
90 | 116 | } |
91 | 117 | |
92 | | AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { |
93 | | return new PSPFilesystemNode(path, true); |
| 118 | AbstractFilesystemNode *PSPFilesystemNode::getChild(const String &n) const { |
| 119 | // FIXME: Pretty lame implementation! We do no error checking to speak |
| 120 | // of, do not check if this is a special node, etc. |
| 121 | assert(_isDirectory); |
| 122 | |
| 123 | String newPath(_path); |
| 124 | if (_path.lastChar() != '/') |
| 125 | newPath += '/'; |
| 126 | newPath += n; |
| 127 | |
| 128 | return new PSPFilesystemNode(newPath, true); |
94 | 129 | } |
95 | 130 | |
| 131 | bool PSPFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { |
| 132 | assert(_isDirectory); |
96 | 133 | |
97 | | bool PSPFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { |
98 | | assert(_isDirectory); |
| 134 | //TODO: honor the hidden flag |
99 | 135 | |
100 | 136 | int dfd = sceIoDopen(_path.c_str()); |
101 | 137 | if (dfd > 0) { |
… |
… |
|
133 | 169 | } |
134 | 170 | } |
135 | 171 | |
136 | | static const char *lastPathComponent(const Common::String &str) { |
137 | | const char *start = str.c_str(); |
138 | | const char *cur = start + str.size() - 2; |
139 | | |
140 | | while (cur >= start && *cur != '/') { |
141 | | --cur; |
142 | | } |
143 | | |
144 | | return cur + 1; |
145 | | } |
146 | | |
147 | | AbstractFilesystemNode *PSPFilesystemNode::parent() const { |
| 172 | AbstractFilesystemNode *PSPFilesystemNode::getParent() const { |
148 | 173 | assert(_isValid); |
149 | 174 | |
150 | 175 | if (_path == ROOT_PATH) |
… |
… |
|
153 | 178 | const char *start = _path.c_str(); |
154 | 179 | const char *end = lastPathComponent(_path); |
155 | 180 | |
156 | | PSPFilesystemNode *p = new PSPFilesystemNode(String(start, end - start), false); |
157 | | |
158 | | return p; |
| 181 | return new PSPFilesystemNode(String(start, end - start), false); |
159 | 182 | } |
160 | 183 | |
161 | | AbstractFilesystemNode *PSPFilesystemNode::child(const String &n) const { |
162 | | // FIXME: Pretty lame implementation! We do no error checking to speak |
163 | | // of, do not check if this is a special node, etc. |
164 | | assert(_isDirectory); |
165 | | String newPath(_path); |
166 | | if (_path.lastChar() != '/') |
167 | | newPath += '/'; |
168 | | newPath += n; |
169 | | PSPFilesystemNode *p = new PSPFilesystemNode(newPath, true); |
170 | | |
171 | | return p; |
172 | | } |
173 | | |
174 | | #endif // PSP |
| 184 | #endif //#ifdef __PSP__ |
-
|
|
|
31 | 31 | #include <f32file.h> |
32 | 32 | #include <bautils.h> |
33 | 33 | |
34 | | /* |
| 34 | /** |
35 | 35 | * Implementation of the ScummVM file system API based on POSIX. |
| 36 | * |
| 37 | * Parts of this class are documented in the base interface class, AbstractFilesystemNode. |
36 | 38 | */ |
37 | | |
38 | 39 | class SymbianFilesystemNode : public AbstractFilesystemNode { |
39 | 40 | protected: |
40 | 41 | String _displayName; |
| 42 | String _path; |
41 | 43 | bool _isDirectory; |
42 | 44 | bool _isValid; |
43 | | String _path; |
44 | 45 | bool _isPseudoRoot; |
45 | 46 | |
46 | 47 | public: |
| 48 | /** |
| 49 | * Creates a SymbianFilesystemNode with the root node as path. |
| 50 | * |
| 51 | * @param aIsRoot true if the node will be a pseudo root, false otherwise. |
| 52 | */ |
47 | 53 | SymbianFilesystemNode(bool aIsRoot); |
| 54 | |
| 55 | /** |
| 56 | * Creates a SymbianFilesystemNode for a given path. |
| 57 | * |
| 58 | * @param path String with the path the new node should point to. |
| 59 | */ |
48 | 60 | SymbianFilesystemNode(const String &path); |
49 | | virtual String displayName() const { return _displayName; } |
50 | | virtual String name() const { return _displayName; } |
| 61 | |
| 62 | virtual bool exists() const { return true; } //FIXME: this is just a stub |
| 63 | virtual String getDisplayName() const { return _displayName; } |
| 64 | virtual String getName() const { return _displayName; } |
| 65 | virtual String getPath() const { return _path; } |
| 66 | virtual bool isDirectory() const { return _isDirectory; } |
| 67 | virtual bool isReadable() const { return true; } //FIXME: this is just a stub |
51 | 68 | virtual bool isValid() const { return _isValid; } |
52 | | virtual bool isDirectory() const { return _isDirectory; } |
53 | | virtual String path() const { return _path; } |
| 69 | virtual bool isWritable() const { return true; } //FIXME: this is just a stub |
54 | 70 | |
55 | | virtual bool listDir(AbstractFSList &list, ListMode mode) const; |
56 | | virtual AbstractFilesystemNode *parent() const; |
57 | | virtual AbstractFilesystemNode *child(const String &n) const; |
| 71 | virtual AbstractFilesystemNode *getChild(const String &n) const; |
| 72 | virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; |
| 73 | virtual AbstractFilesystemNode *getParent() const; |
58 | 74 | }; |
59 | 75 | |
60 | | |
| 76 | /** |
| 77 | * Returns the last component of a given path. |
| 78 | * |
| 79 | * Examples: |
| 80 | * c:\foo\bar.txt would return "\bar.txt" |
| 81 | * c:\foo\bar\ would return "\bar\" |
| 82 | * |
| 83 | * @param str Path to obtain the last component from. |
| 84 | * @return Pointer to the first char of the last component inside str. |
| 85 | */ |
61 | 86 | static const char *lastPathComponent(const Common::String &str) { |
62 | 87 | const char *start = str.c_str(); |
63 | 88 | const char *cur = start + str.size() - 2; |
… |
… |
|
69 | 94 | return cur + 1; |
70 | 95 | } |
71 | 96 | |
| 97 | /** |
| 98 | * Fixes the path by changing all slashes to backslashes. |
| 99 | * |
| 100 | * @param path String with the path to be fixed. |
| 101 | */ |
72 | 102 | static void fixFilePath(Common::String& path) { |
73 | 103 | TInt len = path.size(); |
74 | 104 | |
… |
… |
|
79 | 109 | } |
80 | 110 | } |
81 | 111 | |
82 | | AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { |
83 | | char path[MAXPATHLEN]; |
84 | | getcwd(path, MAXPATHLEN); |
85 | | return new SymbianFilesystemNode(path); |
86 | | } |
87 | | |
88 | | AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { |
89 | | return new SymbianFilesystemNode(true); |
90 | | } |
91 | | |
92 | | AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { |
93 | | return new SymbianFilesystemNode(path); |
94 | | } |
95 | | |
96 | 112 | SymbianFilesystemNode::SymbianFilesystemNode(bool aIsRoot) { |
97 | 113 | _path = ""; |
98 | 114 | _isValid = true; |
… |
… |
|
128 | 144 | } |
129 | 145 | } |
130 | 146 | |
131 | | bool SymbianFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { |
| 147 | AbstractFilesystemNode *SymbianFilesystemNode::getChild(const String &n) const { |
132 | 148 | assert(_isDirectory); |
| 149 | String newPath(_path); |
| 150 | |
| 151 | if (_path.lastChar() != '\\') |
| 152 | newPath += '\\'; |
| 153 | newPath += n; |
| 154 | |
| 155 | TPtrC8 ptr((const unsigned char*) newPath.c_str(), newPath.size()); |
| 156 | TFileName fname; |
| 157 | fname.Copy(ptr); |
| 158 | TBool isFolder = EFalse; |
| 159 | BaflUtils::IsFolder(CEikonEnv::Static()->FsSession(), fname, isFolder); |
| 160 | if(!isFolder) |
| 161 | return 0; |
| 162 | |
| 163 | return new SymbianFilesystemNode(newPath); |
| 164 | } |
| 165 | |
| 166 | bool SymbianFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { |
| 167 | assert(_isDirectory); |
| 168 | |
| 169 | //TODO: honor the hidden flag |
133 | 170 | |
134 | 171 | if (_isPseudoRoot) { |
135 | 172 | // Drives enumeration |
… |
… |
|
199 | 236 | } |
200 | 237 | CleanupStack::PopAndDestroy(dirPtr); |
201 | 238 | } |
202 | | |
203 | 239 | } |
| 240 | |
204 | 241 | return true; |
205 | 242 | } |
206 | 243 | |
207 | | AbstractFilesystemNode *SymbianFilesystemNode::parent() const { |
| 244 | AbstractFilesystemNode *SymbianFilesystemNode::getParent() const { |
208 | 245 | SymbianFilesystemNode *p =NULL; |
209 | 246 | |
210 | 247 | // Root node is its own parent. Still we can't just return this |
… |
… |
|
210 | 247 | // Root node is its own parent. Still we can't just return this |
211 | 248 | // as the GUI code will call delete on the old node. |
212 | 249 | if (!_isPseudoRoot && _path.size() > 3) { |
213 | | p=new SymbianFilesystemNode(false); |
| 250 | p = new SymbianFilesystemNode(false); |
214 | 251 | const char *start = _path.c_str(); |
215 | 252 | const char *end = lastPathComponent(_path); |
216 | 253 | |
… |
… |
|
221 | 258 | } |
222 | 259 | else |
223 | 260 | { |
224 | | p=new SymbianFilesystemNode(true); |
| 261 | p = new SymbianFilesystemNode(true); |
225 | 262 | } |
226 | | return p; |
227 | | } |
228 | | |
229 | | AbstractFilesystemNode *SymbianFilesystemNode::child(const String &n) const { |
230 | | assert(_isDirectory); |
231 | | String newPath(_path); |
232 | | |
233 | | if (_path.lastChar() != '\\') |
234 | | newPath += '\\'; |
235 | | newPath += n; |
236 | | |
237 | | TPtrC8 ptr((const unsigned char*) newPath.c_str(), newPath.size()); |
238 | | TFileName fname; |
239 | | fname.Copy(ptr); |
240 | | TBool isFolder = EFalse; |
241 | | BaflUtils::IsFolder(CEikonEnv::Static()->FsSession(), fname, isFolder); |
242 | | if(!isFolder) |
243 | | return 0; |
244 | | |
245 | | SymbianFilesystemNode *p = new SymbianFilesystemNode(newPath); |
| 263 | |
246 | 264 | return p; |
247 | 265 | } |
248 | 266 | |
249 | | #endif // defined(__SYMBIAN32__) |
| 267 | #endif //#if defined (__SYMBIAN32__) |
-
|
|
|
29 | 29 | #endif |
30 | 30 | #include "common/stdafx.h" |
31 | 31 | #include "backends/fs/abstract-fs.h" |
| 32 | #include <io.h> |
32 | 33 | #include <stdio.h> |
33 | 34 | #include <stdlib.h> |
34 | 35 | #ifndef _WIN32_WCE |
… |
… |
|
36 | 37 | #endif |
37 | 38 | #include <tchar.h> |
38 | 39 | |
39 | | /* |
| 40 | /** |
40 | 41 | * Implementation of the ScummVM file system API based on Windows API. |
| 42 | * |
| 43 | * Parts of this class are documented in the base interface class, AbstractFilesystemNode. |
41 | 44 | */ |
42 | | |
43 | 45 | class WindowsFilesystemNode : public AbstractFilesystemNode { |
44 | 46 | protected: |
45 | 47 | String _displayName; |
| 48 | String _path; |
46 | 49 | bool _isDirectory; |
47 | | bool _isValid; |
48 | 50 | bool _isPseudoRoot; |
49 | | String _path; |
| 51 | bool _isValid; |
50 | 52 | |
51 | 53 | public: |
| 54 | /** |
| 55 | * Creates a WindowsFilesystemNode with the root node as path. |
| 56 | * |
| 57 | * In regular windows systems, a virtual root path is used "". |
| 58 | * In windows CE, the "\" root is used instead. |
| 59 | */ |
52 | 60 | WindowsFilesystemNode(); |
53 | | WindowsFilesystemNode(const String &path); |
54 | | |
55 | | virtual String displayName() const { return _displayName; } |
56 | | virtual String name() const { return _displayName; } |
57 | | virtual bool isValid() const { return _isValid; } |
| 61 | |
| 62 | /** |
| 63 | * Creates a WindowsFilesystemNode for a given path. |
| 64 | * |
| 65 | * Examples: |
| 66 | * path=c:\foo\bar.txt, currentDir=false -> c:\foo\bar.txt |
| 67 | * path=c:\foo\bar.txt, currentDir=true -> current directory |
| 68 | * path=NULL, currentDir=true -> current directory |
| 69 | * |
| 70 | * @param path String with the path the new node should point to. |
| 71 | * @param currentDir if true, the path parameter will be ignored and the resulting node will point to the current directory. |
| 72 | */ |
| 73 | WindowsFilesystemNode(const String &path, const bool currentDir); |
| 74 | |
| 75 | virtual bool exists() const { return _access(_path.c_str(), F_OK) == 0; } |
| 76 | virtual String getDisplayName() const { return _displayName; } |
| 77 | virtual String getName() const { return _displayName; } |
| 78 | virtual String getPath() const { return _path; } |
58 | 79 | virtual bool isDirectory() const { return _isDirectory; } |
59 | | virtual String path() const { return _path; } |
| 80 | virtual bool isReadable() const { return _access(_path.c_str(), R_OK) == 0; } |
| 81 | virtual bool isValid() const { return _isValid; } |
| 82 | virtual bool isWritable() const { return _access(_path.c_str(), W_OK) == 0; } |
60 | 83 | |
61 | | virtual bool listDir(AbstractFSList &list, ListMode mode) const; |
62 | | virtual AbstractFilesystemNode *parent() const; |
63 | | virtual AbstractFilesystemNode *child(const String &n) const; |
| 84 | virtual AbstractFilesystemNode *getChild(const String &n) const; |
| 85 | virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const; |
| 86 | virtual AbstractFilesystemNode *getParent() const; |
64 | 87 | |
65 | 88 | private: |
66 | | static char *toAscii(TCHAR *x); |
67 | | static const TCHAR* toUnicode(const char *x); |
68 | | static void addFile (AbstractFSList &list, ListMode mode, const char *base, WIN32_FIND_DATA* find_data); |
| 89 | /** |
| 90 | * Adds a single WindowsFilesystemNode to a given list. |
| 91 | * This method is used by getChildren() to populate the directory entries list. |
| 92 | * |
| 93 | * @param list List to put the file entry node in. |
| 94 | * @param mode Mode to use while adding the file entry to the list. |
| 95 | * @param base String with the directory being listed. |
| 96 | * @param find_data Describes a file that the FindFirstFile, FindFirstFileEx, or FindNextFile functions find. |
| 97 | */ |
| 98 | static void addFile(AbstractFSList &list, ListMode mode, const char *base, WIN32_FIND_DATA* find_data); |
| 99 | |
| 100 | /** |
| 101 | * Converts a Unicode string to Ascii format. |
| 102 | * |
| 103 | * @param str String to convert from Unicode to Ascii. |
| 104 | * @return str in Ascii format. |
| 105 | */ |
| 106 | static char *toAscii(TCHAR *str); |
| 107 | |
| 108 | /** |
| 109 | * Converts an Ascii string to Unicode format. |
| 110 | * |
| 111 | * @param str String to convert from Ascii to Unicode. |
| 112 | * @return str in Unicode format. |
| 113 | */ |
| 114 | static const TCHAR* toUnicode(const char *str); |
69 | 115 | }; |
70 | 116 | |
71 | | |
| 117 | /** |
| 118 | * Returns the last component of a given path. |
| 119 | * |
| 120 | * Examples: |
| 121 | * c:\foo\bar.txt would return "\bar.txt" |
| 122 | * c:\foo\bar\ would return "\bar\" |
| 123 | * |
| 124 | * @param str Path to obtain the last component from. |
| 125 | * @return Pointer to the first char of the last component inside str. |
| 126 | */ |
72 | 127 | static const char *lastPathComponent(const Common::String &str) { |
73 | 128 | const char *start = str.c_str(); |
74 | 129 | const char *cur = start + str.size() - 2; |
… |
… |
|
80 | 135 | return cur + 1; |
81 | 136 | } |
82 | 137 | |
83 | | char* WindowsFilesystemNode::toAscii(TCHAR *x) { |
84 | | |
85 | | #ifndef UNICODE |
86 | | return (char*)x; |
87 | | #else |
88 | | static char asciiString[MAX_PATH]; |
89 | | WideCharToMultiByte(CP_ACP, 0, x, _tcslen(x) + 1, asciiString, sizeof(asciiString), NULL, NULL); |
90 | | return asciiString; |
91 | | #endif |
92 | | } |
93 | | |
94 | | const TCHAR* WindowsFilesystemNode::toUnicode(const char *x) { |
95 | | #ifndef UNICODE |
96 | | return (const TCHAR *)x; |
97 | | #else |
98 | | static TCHAR unicodeString[MAX_PATH]; |
99 | | MultiByteToWideChar(CP_ACP, 0, x, strlen(x) + 1, unicodeString, sizeof(unicodeString) / sizeof(TCHAR)); |
100 | | return unicodeString; |
101 | | #endif |
102 | | } |
103 | | |
104 | 138 | void WindowsFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const char *base, WIN32_FIND_DATA* find_data) { |
105 | 139 | WindowsFilesystemNode entry; |
106 | 140 | char *asciiName = toAscii(find_data->cFileName); |
… |
… |
|
128 | 162 | list.push_back(new WindowsFilesystemNode(entry)); |
129 | 163 | } |
130 | 164 | |
131 | | AbstractFilesystemNode *AbstractFilesystemNode::getCurrentDirectory() { |
132 | | char path[MAX_PATH]; |
133 | | GetCurrentDirectory(MAX_PATH, path); |
134 | | |
135 | | // Add a trailing slash, if necessary. |
136 | | if (path[0] != 0) { |
137 | | if (path[strlen(path) - 1] != '\\') |
138 | | strcat(path, "\\"); |
139 | | } |
140 | | |
141 | | return new WindowsFilesystemNode(path); |
| 165 | char* WindowsFilesystemNode::toAscii(TCHAR *str) { |
| 166 | #ifndef UNICODE |
| 167 | return (char*)str; |
| 168 | #else |
| 169 | static char asciiString[MAX_PATH]; |
| 170 | WideCharToMultiByte(CP_ACP, 0, str, _tcslen(str) + 1, asciiString, sizeof(asciiString), NULL, NULL); |
| 171 | return asciiString; |
| 172 | #endif |
142 | 173 | } |
143 | 174 | |
144 | | AbstractFilesystemNode *AbstractFilesystemNode::getRoot() { |
145 | | return new WindowsFilesystemNode(); |
146 | | } |
147 | | |
148 | | AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) { |
149 | | return new WindowsFilesystemNode(path); |
| 175 | const TCHAR* WindowsFilesystemNode::toUnicode(const char *str) { |
| 176 | #ifndef UNICODE |
| 177 | return (const TCHAR *)str; |
| 178 | #else |
| 179 | static TCHAR unicodeString[MAX_PATH]; |
| 180 | MultiByteToWideChar(CP_ACP, 0, str, strlen(str) + 1, unicodeString, sizeof(unicodeString) / sizeof(TCHAR)); |
| 181 | return unicodeString; |
| 182 | #endif |
150 | 183 | } |
151 | 184 | |
152 | 185 | WindowsFilesystemNode::WindowsFilesystemNode() { |
… |
… |
|
165 | 198 | #endif |
166 | 199 | } |
167 | 200 | |
168 | | WindowsFilesystemNode::WindowsFilesystemNode(const String &p) { |
169 | | assert(p.size() > 0); |
| 201 | WindowsFilesystemNode::WindowsFilesystemNode(const String &p, const bool currentDir) { |
| 202 | if (currentDir) { |
| 203 | char path[MAX_PATH]; |
| 204 | GetCurrentDirectory(MAX_PATH, path); |
170 | 205 | |
171 | | _path = p; |
| 206 | // Add a trailing slash, if necessary. |
| 207 | if (path[0] != 0) { |
| 208 | if (path[strlen(path) - 1] != '\\') |
| 209 | strcat(path, "\\"); |
| 210 | } |
| 211 | _path = path; |
| 212 | } |
| 213 | else { |
| 214 | assert(p.size() > 0); |
| 215 | _path = p; |
| 216 | } |
| 217 | |
172 | 218 | _displayName = lastPathComponent(_path); |
173 | 219 | |
174 | 220 | // Check whether it is a directory, and whether the file actually exists |
… |
… |
|
175 | 221 | DWORD fileAttribs = GetFileAttributes(toUnicode(_path.c_str())); |
176 | 222 | |
177 | 223 | if (fileAttribs == INVALID_FILE_ATTRIBUTES) { |
| 224 | _isDirectory = false; |
178 | 225 | _isValid = false; |
179 | | _isDirectory = false; |
180 | 226 | } else { |
| 227 | _isDirectory = ((fileAttribs & FILE_ATTRIBUTE_DIRECTORY) != 0); |
181 | 228 | _isValid = true; |
182 | | _isDirectory = ((fileAttribs & FILE_ATTRIBUTE_DIRECTORY) != 0); |
183 | 229 | } |
184 | 230 | _isPseudoRoot = false; |
185 | 231 | } |
… |
… |
|
184 | 230 | _isPseudoRoot = false; |
185 | 231 | } |
186 | 232 | |
187 | | bool WindowsFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const { |
| 233 | AbstractFilesystemNode *WindowsFilesystemNode::getChild(const String &n) const { |
| 234 | assert(_isDirectory); |
| 235 | |
| 236 | String newPath(_path); |
| 237 | if (_path.lastChar() != '\\') |
| 238 | newPath += '\\'; |
| 239 | newPath += n; |
| 240 | |
| 241 | // Check whether the directory actually exists |
| 242 | DWORD fileAttribs = GetFileAttributes(toUnicode(newPath.c_str())); |
| 243 | if (fileAttribs == INVALID_FILE_ATTRIBUTES) |
| 244 | return 0; |
| 245 | |
| 246 | return new WindowsFilesystemNode(newPath, false); |
| 247 | } |
| 248 | |
| 249 | bool WindowsFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const { |
188 | 250 | assert(_isDirectory); |
189 | 251 | |
| 252 | //TODO: honor the hidden flag |
| 253 | |
190 | 254 | if (_isPseudoRoot) { |
191 | 255 | #ifndef _WIN32_WCE |
192 | 256 | // Drives enumeration |
… |
… |
|
218 | 282 | sprintf(searchPath, "%s*", _path.c_str()); |
219 | 283 | |
220 | 284 | handle = FindFirstFile(toUnicode(searchPath), &desc); |
| 285 | |
221 | 286 | if (handle == INVALID_HANDLE_VALUE) |
222 | 287 | return false; |
| 288 | |
223 | 289 | addFile(myList, mode, _path.c_str(), &desc); |
| 290 | |
224 | 291 | while (FindNextFile(handle, &desc)) |
225 | 292 | addFile(myList, mode, _path.c_str(), &desc); |
226 | 293 | |
… |
… |
|
230 | 297 | return true; |
231 | 298 | } |
232 | 299 | |
233 | | AbstractFilesystemNode *WindowsFilesystemNode::parent() const { |
| 300 | AbstractFilesystemNode *WindowsFilesystemNode::getParent() const { |
234 | 301 | assert(_isValid || _isPseudoRoot); |
| 302 | |
235 | 303 | if (_isPseudoRoot) |
236 | 304 | return 0; |
| 305 | |
237 | 306 | WindowsFilesystemNode *p = new WindowsFilesystemNode(); |
238 | 307 | if (_path.size() > 3) { |
239 | 308 | const char *start = _path.c_str(); |
… |
… |
|
246 | 315 | p->_displayName = lastPathComponent(p->_path); |
247 | 316 | p->_isPseudoRoot = false; |
248 | 317 | } |
| 318 | |
249 | 319 | return p; |
250 | 320 | } |
251 | 321 | |
252 | | AbstractFilesystemNode *WindowsFilesystemNode::child(const String &n) const { |
253 | | assert(_isDirectory); |
254 | | String newPath(_path); |
255 | | if (_path.lastChar() != '\\') |
256 | | newPath += '\\'; |
257 | | newPath += n; |
258 | | |
259 | | // Check whether the directory actually exists |
260 | | DWORD fileAttribs = GetFileAttributes(toUnicode(newPath.c_str())); |
261 | | if (fileAttribs == INVALID_FILE_ATTRIBUTES) |
262 | | return 0; |
263 | | |
264 | | WindowsFilesystemNode *p = new WindowsFilesystemNode(newPath); |
265 | | return p; |
266 | | } |
267 | | |
268 | | #endif // WIN32 |
| 322 | #endif //#ifdef WIN32 |
-
|
|
|
114 | 114 | // Scan for all plugins in this directory |
115 | 115 | FilesystemNode dir(PLUGIN_DIRECTORY); |
116 | 116 | FSList files; |
117 | | if (!dir.listDir(files, FilesystemNode::kListFilesOnly)) { |
| 117 | if (!dir.getChildren(files, FilesystemNode::kListFilesOnly)) { |
118 | 118 | error("Couldn't open plugin directory '%s'", PLUGIN_DIRECTORY); |
119 | 119 | } |
120 | 120 | |
… |
… |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | for (FSList::const_iterator i = files.begin(); i != files.end(); ++i) { |
122 | | Common::String name(i->name()); |
| 122 | Common::String name(i->getName()); |
123 | 123 | if (name.hasPrefix(PLUGIN_PREFIX) && name.hasSuffix(PLUGIN_SUFFIX)) { |
124 | | pl.push_back(new DCPlugin(i->path())); |
| 124 | pl.push_back(new DCPlugin(i->getPath())); |
125 | 125 | } |
126 | 126 | } |
127 | 127 | |
-
|
|
|
107 | 107 | // Scan for all plugins in this directory |
108 | 108 | FilesystemNode dir(PLUGIN_DIRECTORY); |
109 | 109 | FSList files; |
110 | | if (!dir.listDir(files, FilesystemNode::kListFilesOnly)) { |
| 110 | if (!dir.getChildren(files, FilesystemNode::kListFilesOnly)) { |
111 | 111 | error("Couldn't open plugin directory '%s'", PLUGIN_DIRECTORY); |
112 | 112 | } |
113 | 113 | |
… |
… |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | for (FSList::const_iterator i = files.begin(); i != files.end(); ++i) { |
115 | | Common::String name(i->name()); |
| 115 | Common::String name(i->getName()); |
116 | 116 | if (name.hasPrefix(PLUGIN_PREFIX) && name.hasSuffix(PLUGIN_SUFFIX)) { |
117 | | pl.push_back(new POSIXPlugin(i->path())); |
| 117 | pl.push_back(new POSIXPlugin(i->getPath())); |
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
-
|
|
|
107 | 107 | // Scan for all plugins in this directory |
108 | 108 | FilesystemNode dir(PLUGIN_DIRECTORY); |
109 | 109 | FSList files; |
110 | | if (!dir.listDir(files, FilesystemNode::kListFilesOnly)) { |
| 110 | if (!dir.getChildren(files, FilesystemNode::kListFilesOnly)) { |
111 | 111 | error("Couldn't open plugin directory '%s'", PLUGIN_DIRECTORY); |
112 | 112 | } |
113 | 113 | |
… |
… |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | for (FSList::const_iterator i = files.begin(); i != files.end(); ++i) { |
115 | | Common::String name(i->name()); |
| 115 | Common::String name(i->getName()); |
116 | 116 | if (name.hasPrefix(PLUGIN_PREFIX) && name.hasSuffix(PLUGIN_SUFFIX)) { |
117 | | pl.push_back(new SDLPlugin(i->path())); |
| 117 | pl.push_back(new SDLPlugin(i->getPath())); |
118 | 118 | } |
119 | 119 | } |
120 | 120 | |
-
|
|
|
110 | 110 | // Scan for all plugins in this directory |
111 | 111 | FilesystemNode dir(PLUGIN_DIRECTORY); |
112 | 112 | FSList files; |
113 | | if (!dir.listDir(files, FilesystemNode::kListFilesOnly)) { |
| 113 | if (!dir.getChildren(files, FilesystemNode::kListFilesOnly)) { |
114 | 114 | error("Couldn't open plugin directory '%s'", PLUGIN_DIRECTORY); |
115 | 115 | } |
116 | 116 | |
… |
… |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | for (FSList::const_iterator i = files.begin(); i != files.end(); ++i) { |
118 | | Common::String name(i->name()); |
| 118 | Common::String name(i->getName()); |
119 | 119 | if (name.hasPrefix(PLUGIN_PREFIX) && name.hasSuffix(PLUGIN_SUFFIX)) { |
120 | | pl.push_back(new Win32Plugin(i->path())); |
| 120 | pl.push_back(new Win32Plugin(i->getPath())); |
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
-
|
|
|
28 | 28 | #include "common/stdafx.h" |
29 | 29 | #include "common/savefile.h" |
30 | 30 | #include "common/util.h" |
| 31 | #include "common/fs.h" |
| 32 | #include "common/file.h" |
31 | 33 | #include "backends/saves/default/default-saves.h" |
32 | 34 | #include "backends/saves/compressed/compressed-saves.h" |
33 | 35 | |
… |
… |
|
119 | 121 | // Ensure that the savepath exists and is writeable. If not, generate |
120 | 122 | // an appropriate error |
121 | 123 | const char *savePath = getSavePath(); |
| 124 | |
122 | 125 | #if defined(UNIX) || defined(__SYMBIAN32__) |
123 | 126 | struct stat sb; |
| 127 | clearError(); |
124 | 128 | |
125 | 129 | // Check whether the dir exists |
126 | 130 | if (stat(savePath, &sb) == -1) { |
… |
… |
|
126 | 130 | if (stat(savePath, &sb) == -1) { |
127 | 131 | // The dir does not exist, or stat failed for some other reason. |
128 | 132 | // If the problem was that the path pointed to nothing, try |
129 | | // to create the dir. |
130 | | if (errno == ENOENT) { |
| 133 | // to create the dir (ENOENT case). |
| 134 | switch (errno) { |
| 135 | case EACCES: |
| 136 | setError(SFM_DIR_ACCESS, Common::String("Search or write permission denied")); |
| 137 | break; |
| 138 | case ELOOP: |
| 139 | setError(SFM_DIR_LOOP, Common::String("Too many symbolic links encountered while traversing the path")); |
| 140 | break; |
| 141 | case ENAMETOOLONG: |
| 142 | setError(SFM_DIR_NAMETOOLONG, Common::String("The path name is too long")); |
| 143 | break; |
| 144 | case ENOENT: |
131 | 145 | if (mkdir(savePath, 0755) != 0) { |
132 | 146 | // mkdir could fail for various reasons: The parent dir doesn't exist, |
133 | 147 | // or is not writeable, the path could be completly bogus, etc. |
… |
… |
|
133 | 147 | // or is not writeable, the path could be completly bogus, etc. |
134 | 148 | warning("mkdir for '%s' failed!", savePath); |
135 | 149 | perror("mkdir"); |
136 | | // TODO: Specify an error code here so that callers can |
137 | | // determine what exactly went wrong. |
| 150 | |
| 151 | switch (errno) { |
| 152 | case EACCES: |
| 153 | setError(SFM_DIR_ACCESS, Common::String("Search or write permission denied")); |
| 154 | break; |
| 155 | case EMLINK: |
| 156 | setError(SFM_DIR_LINKMAX, Common::String("The link count of the parent directory would exceed {LINK_MAX}")); |
| 157 | break; |
| 158 | case ELOOP: |
| 159 | setError(SFM_DIR_LOOP, Common::String("Too many symbolic links encountered while traversing the path")); |
| 160 | break; |
| 161 | case ENAMETOOLONG: |
| 162 | setError(SFM_DIR_NAMETOOLONG, Common::String("The path name is too long")); |
| 163 | break; |
| 164 | case ENOENT: |
| 165 | setError(SFM_DIR_NOENT, Common::String("A component of the path path does not exist, or the path is an empty string")); |
| 166 | break; |
| 167 | case ENOTDIR: |
| 168 | setError(SFM_DIR_NOTDIR, Common::String("A component of the path prefix is not a directory")); |
| 169 | break; |
| 170 | case EROFS: |
| 171 | setError(SFM_DIR_ROFS, Common::String("The parent directory resides on a read-only file system")); |
| 172 | break; |
| 173 | } |
| 174 | |
138 | 175 | return 0; |
139 | 176 | } |
140 | | } else { |
141 | | // Unknown error, abort. |
142 | | // TODO: Specify an error code here so that callers can |
143 | | // determine what exactly went wrong. |
144 | | return 0; |
145 | | } |
| 177 | break; |
| 178 | case ENOTDIR: |
| 179 | setError(SFM_DIR_NOTDIR, Common::String("A component of the path prefix is not a directory")); |
| 180 | break; |
| 181 | } |
146 | 182 | } else { |
147 | | // So stat() succeeded. But is the path actually pointing to a |
148 | | // directory? |
| 183 | // So stat() succeeded. But is the path actually pointing to a directory? |
149 | 184 | if (!S_ISDIR(sb.st_mode)) { |
150 | | // TODO: Specify an error code here so that callers can |
151 | | // determine what exactly went wrong. |
| 185 | setError(SFM_DIR_NOTDIR, Common::String("The given savepath is not a directory")); |
| 186 | |
152 | 187 | return 0; |
153 | 188 | } |
154 | 189 | } |
… |
… |
|
163 | 198 | delete sf; |
164 | 199 | sf = 0; |
165 | 200 | } |
| 201 | |
166 | 202 | return wrapOutSaveFile(sf); |
167 | 203 | } |
168 | 204 | |
… |
… |
|
179 | 215 | return wrapInSaveFile(sf); |
180 | 216 | } |
181 | 217 | |
182 | | void DefaultSaveFileManager::listSavefiles(const char * /* prefix */, bool *marks, int num) { |
183 | | // TODO: Implement this properly, at least on systems that support |
184 | | // opendir/readdir. |
185 | | // Even better, replace this with a better design... |
186 | | memset(marks, true, num * sizeof(bool)); |
| 218 | bool DefaultSaveFileManager::removeSavefile(const char *filename) { |
| 219 | Common::File file; |
| 220 | FilesystemNode savePath(filename); |
| 221 | return file.remove(savePath); |
| 222 | } |
| 223 | |
| 224 | Common::StringList DefaultSaveFileManager::listSavefiles(const char *regex) { |
| 225 | FilesystemNode savePath(getSavePath()); |
| 226 | FSList savefiles; |
| 227 | Common::StringList results; |
| 228 | Common::String search(regex); |
| 229 | |
| 230 | if(savePath.lookupFile(savefiles, savePath, search, false, true)) { |
| 231 | for(FSList::const_iterator file = savefiles.begin(); file != savefiles.end(); file++) { |
| 232 | results.push_back(file->getPath()); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | return results; |
187 | 237 | } |
188 | 238 | |
189 | 239 | #endif // !defined(DISABLE_DEFAULT_SAVEFILEMANAGER) |
-
|
|
|
28 | 28 | |
29 | 29 | #include "common/stdafx.h" |
30 | 30 | #include "common/savefile.h" |
| 31 | #include "common/str.h" |
31 | 32 | |
32 | 33 | class DefaultSaveFileManager : public Common::SaveFileManager { |
33 | 34 | public: |
… |
… |
|
33 | 34 | public: |
34 | 35 | virtual Common::OutSaveFile *openForSaving(const char *filename); |
35 | 36 | virtual Common::InSaveFile *openForLoading(const char *filename); |
36 | | virtual void listSavefiles(const char * /* prefix */, bool *marks, int num); |
| 37 | virtual bool removeSavefile(const char *filename); |
| 38 | virtual Common::StringList listSavefiles(const char *regex); |
37 | 39 | }; |
38 | 40 | |
39 | 41 | #endif |
-
|
|
|
32 | 32 | |
33 | 33 | #include "common/config-manager.h" |
34 | 34 | #include "common/system.h" |
| 35 | #include "common/fs.h" |
35 | 36 | |
36 | 37 | #include "sound/mididrv.h" |
37 | 38 | #include "sound/mixer.h" |
… |
… |
|
48 | 49 | |
49 | 50 | #define DETECTOR_TESTING_HACK |
50 | 51 | |
51 | | #ifdef DETECTOR_TESTING_HACK |
52 | | #include "common/fs.h" |
53 | | #endif |
54 | | |
55 | 52 | namespace Base { |
56 | 53 | |
57 | 54 | static const char USAGE_STRING[] = |
… |
… |
|
313 | 310 | for (int i = 1; i < argc; ++i) { |
314 | 311 | s = argv[i]; |
315 | 312 | s2 = (i < argc-1) ? argv[i+1] : 0; |
316 | | |
| 313 | |
317 | 314 | if (s[0] != '-') { |
318 | 315 | // The argument doesn't start with a dash, so it's not an option. |
319 | 316 | // Hence it must be the target name. We currently enforce that |
… |
… |
|
390 | 387 | END_OPTION |
391 | 388 | |
392 | 389 | DO_OPTION('p', "path") |
393 | | // TODO: Verify whether the path is valid |
| 390 | FilesystemNode path(option); |
| 391 | if(!path.exists()) { |
| 392 | usage("Non-existent game path '%s'", option); |
| 393 | } else if(!path.isReadable()) { |
| 394 | usage("Non-readable game path '%s'", option); |
| 395 | } |
394 | 396 | END_OPTION |
395 | 397 | |
396 | 398 | DO_OPTION('q', "language") |
… |
… |
|
428 | 430 | END_OPTION |
429 | 431 | |
430 | 432 | DO_LONG_OPTION("soundfont") |
431 | | // TODO: Verify whether the path is valid |
| 433 | FilesystemNode path(option); |
| 434 | if(!path.exists()) { |
| 435 | usage("Non-existent soundfont path '%s'", option); |
| 436 | } else if(!path.isReadable()) { |
| 437 | usage("Non-readable soundfont path '%s'", option); |
| 438 | } |
432 | 439 | END_OPTION |
433 | 440 | |
434 | 441 | DO_LONG_OPTION_BOOL("disable-sdl-parachute") |
… |
… |
|
453 | 460 | END_OPTION |
454 | 461 | |
455 | 462 | DO_LONG_OPTION("savepath") |
456 | | // TODO: Verify whether the path is valid |
| 463 | FilesystemNode path(option); |
| 464 | if(!path.exists()) { |
| 465 | usage("Non-existent savegames path '%s'", option); |
| 466 | } else if(!path.isWritable()) { |
| 467 | usage("Non-writable savegames path '%s'", option); |
| 468 | } |
457 | 469 | END_OPTION |
458 | 470 | |
459 | 471 | DO_LONG_OPTION_INT("talkspeed") |
… |
… |
|
466 | 478 | END_OPTION |
467 | 479 | |
468 | 480 | DO_LONG_OPTION("themepath") |
469 | | // TODO: Verify whether the path is valid |
| 481 | FilesystemNode path(option); |
| 482 | if(!path.exists()) { |
| 483 | usage("Non-existent theme path '%s'", option); |
| 484 | } else if(!path.isReadable()) { |
| 485 | usage("Non-readable theme path '%s'", option); |
| 486 | } |
470 | 487 | END_OPTION |
471 | 488 | |
472 | 489 | DO_LONG_OPTION("target-md5") |
… |
… |
|
562 | 579 | |
563 | 580 | FilesystemNode dir(path); |
564 | 581 | FSList files; |
565 | | if (!dir.listDir(files, FilesystemNode::kListAll)) { |
| 582 | if (!dir.getChildren(files, FilesystemNode::kListAll)) { |
566 | 583 | printf(" ... invalid path, skipping\n"); |
567 | 584 | continue; |
568 | 585 | } |
… |
… |
|
673 | 690 | if (!settings.contains("savepath")) { |
674 | 691 | const char *dir = getenv("SCUMMVM_SAVEPATH"); |
675 | 692 | if (dir && *dir && strlen(dir) < MAXPATHLEN) { |
676 | | // TODO: Verify whether the path is valid |
677 | | settings["savepath"] = dir; |
| 693 | FilesystemNode saveDir(dir); |
| 694 | if(!saveDir.exists()) { |
| 695 | warning("Non-existent SCUMMVM_SAVEPATH save path. It will be ignored."); |
| 696 | } else if(!saveDir.isWritable()) { |
| 697 | warning("Non-writable SCUMMVM_SAVEPATH save path. It will be ignored."); |
| 698 | } else { |
| 699 | settings["savepath"] = dir; |
| 700 | } |
678 | 701 | } |
679 | 702 | } |
680 | 703 | #endif |
… |
… |
|
679 | 702 | } |
680 | 703 | #endif |
681 | 704 | |
682 | | |
683 | 705 | // Finally, store the command line settings into the config manager. |
684 | 706 | for (Common::StringMap::const_iterator x = settings.begin(); x != settings.end(); ++x) { |
685 | 707 | Common::String key(x->_key); |
-
|
|
|
276 | 276 | |
277 | 277 | FSList fslist; |
278 | 278 | FilesystemNode dir(ConfMan.get("path")); |
279 | | if (!dir.listDir(fslist, FilesystemNode::kListFilesOnly)) { |
| 279 | if (!dir.getChildren(fslist, FilesystemNode::kListFilesOnly)) { |
280 | 280 | return kInvalidPathError; |
281 | 281 | } |
282 | 282 | |
… |
… |
|
345 | 345 | // Get the information of the existing files |
346 | 346 | for (FSList::const_iterator file = fslist->begin(); file != fslist->end(); ++file) { |
347 | 347 | if (file->isDirectory()) continue; |
348 | | tstr = file->name(); |
| 348 | tstr = file->getName(); |
349 | 349 | tstr.toLowercase(); |
350 | 350 | |
351 | 351 | // Strip any trailing dot |
… |
… |
|
364 | 364 | |
365 | 365 | debug(3, "> %s: %s", tstr.c_str(), md5str); |
366 | 366 | |
367 | | if (testFile.open(file->path())) { |
| 367 | if (testFile.open(file->getPath())) { |
368 | 368 | filesSize[tstr] = (int32)testFile.size(); |
369 | 369 | testFile.close(); |
370 | 370 | } |
-
|
|
|
28 | 28 | #include "common/hashmap.h" |
29 | 29 | #include "common/util.h" |
30 | 30 | #include "common/hash-str.h" |
| 31 | #include <errno.h> |
31 | 32 | |
32 | 33 | #ifdef MACOSX |
33 | 34 | #include "CoreFoundation/CoreFoundation.h" |
… |
… |
|
226 | 227 | return; |
227 | 228 | |
228 | 229 | FSList fslist; |
229 | | if (!dir.listDir(fslist, FilesystemNode::kListAll)) { |
| 230 | if (!dir.getChildren(fslist, FilesystemNode::kListAll)) { |
230 | 231 | // Failed listing the contents of this node, so it is either not a |
231 | 232 | // directory, or just doesn't exist at all. |
232 | 233 | return; |
… |
… |
|
237 | 238 | |
238 | 239 | // Do not add directories multiple times, unless this time they are added |
239 | 240 | // with a bigger depth. |
240 | | const String &directory(dir.path()); |
| 241 | const String &directory(dir.getPath()); |
241 | 242 | if (_defaultDirectories->contains(directory) && (*_defaultDirectories)[directory] >= level) |
242 | 243 | return; |
243 | 244 | (*_defaultDirectories)[directory] = level; |
… |
… |
|
247 | 248 | |
248 | 249 | for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { |
249 | 250 | if (file->isDirectory()) { |
250 | | addDefaultDirectoryRecursive(file->path(), level - 1, prefix + file->name() + "/"); |
| 251 | addDefaultDirectoryRecursive(file->getPath(), level - 1, prefix + file->getName() + "/"); |
251 | 252 | } else { |
252 | 253 | String lfn(prefix); |
253 | | lfn += file->name(); |
| 254 | lfn += file->getName(); |
254 | 255 | lfn.toLowercase(); |
255 | 256 | if (!_filesMap->contains(lfn)) { |
256 | | (*_filesMap)[lfn] = file->path(); |
| 257 | (*_filesMap)[lfn] = file->getPath(); |
257 | 258 | } |
258 | 259 | } |
259 | 260 | } |
… |
… |
|
364 | 365 | bool File::open(const FilesystemNode &node, AccessMode mode) { |
365 | 366 | assert(mode == kFileReadMode || mode == kFileWriteMode); |
366 | 367 | |
367 | | if (!node.isValid()) { |
368 | | warning("File::open: Trying to open an invalid FilesystemNode object"); |
| 368 | if (!node.exists()) { |
| 369 | warning("File::open: Trying to open a FilesystemNode which does not exist"); |
369 | 370 | return false; |
370 | 371 | } else if (node.isDirectory()) { |
371 | 372 | warning("File::open: Trying to open a FilesystemNode which is a directory"); |
… |
… |
|
370 | 371 | } else if (node.isDirectory()) { |
371 | 372 | warning("File::open: Trying to open a FilesystemNode which is a directory"); |
372 | 373 | return false; |
373 | | } |
| 374 | } /*else if (!node.isReadable() && mode == kFileReadMode) { |
| 375 | warning("File::open: Trying to open an unreadable FilesystemNode object for reading"); |
| 376 | return false; |
| 377 | } else if (!node.isWritable() && mode == kFileWriteMode) { |
| 378 | warning("File::open: Trying to open an unwritable FilesystemNode object for writing"); |
| 379 | return false; |
| 380 | }*/ |
374 | 381 | |
375 | | String filename(node.name()); |
| 382 | String filename(node.getName()); |
376 | 383 | |
377 | 384 | if (_handle) { |
378 | 385 | error("File::open: This file object already is opened (%s), won't open '%s'", _name.c_str(), filename.c_str()); |
… |
… |
|
383 | 390 | |
384 | 391 | const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb"; |
385 | 392 | |
386 | | _handle = fopen(node.path().c_str(), modeStr); |
| 393 | _handle = fopen(node.getPath().c_str(), modeStr); |
387 | 394 | |
388 | 395 | if (_handle == NULL) { |
389 | 396 | if (mode == kFileReadMode) |
… |
… |
|
402 | 409 | return true; |
403 | 410 | } |
404 | 411 | |
| 412 | bool File::remove(const String &filename){ |
| 413 | if (remove(filename.c_str()) != 0) { |
| 414 | if(errno == EACCES) |
| 415 | ;//TODO: read-only file |
| 416 | if(errno == ENOENT) |
| 417 | ;//TODO: non-existent file |
| 418 | |
| 419 | return false; |
| 420 | } else { |
| 421 | return true; |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | bool File::remove(const FilesystemNode &node){ |
| 426 | if (remove(node.getPath()) != 0) { |
| 427 | if(errno == EACCES) |
| 428 | ;//TODO: read-only file |
| 429 | if(errno == ENOENT) |
| 430 | ;//TODO: non-existent file |
| 431 | |
| 432 | return false; |
| 433 | } else { |
| 434 | return true; |
| 435 | } |
| 436 | } |
| 437 | |
405 | 438 | bool File::exists(const String &filename) { |
406 | 439 | // First try to find the file it via a FilesystemNode (in case an absolute |
407 | 440 | // path was passed). But we only use this to filter out directories. |
… |
… |
|
406 | 439 | // First try to find the file it via a FilesystemNode (in case an absolute |
407 | 440 | // path was passed). But we only use this to filter out directories. |
408 | 441 | FilesystemNode file(filename); |
409 | | // FIXME: can't use isValid() here since at the time of writing |
410 | | // FilesystemNode is to be unable to find for example files |
411 | | // added in extrapath |
412 | | if (file.isDirectory()) |
413 | | return false; |
414 | | |
| 442 | |
| 443 | return (!file.isDirectory() && file.exists()); |
| 444 | |
| 445 | //***DEPRECATED COMMENTS BELOW, LEFT FOR DISCUSSION*** |
415 | 446 | // Next, try to locate the file by *opening* it in read mode. This has |
416 | 447 | // multiple effects: |
417 | 448 | // 1) It takes _filesMap and _defaultDirectories into consideration -> good |
-
|
|
|
52 | 52 | // code that accidentally copied File objects tended to break in strange |
53 | 53 | // ways. |
54 | 54 | File(const File &f); |
55 | | File &operator =(const File &f); |
| 55 | File &operator =(const File &f); |
56 | 56 | |
57 | 57 | public: |
58 | 58 | enum AccessMode { |
… |
… |
|
86 | 86 | |
87 | 87 | virtual void close(); |
88 | 88 | |
| 89 | virtual bool remove(const String &filename); |
| 90 | virtual bool remove(const FilesystemNode &node); |
| 91 | |
89 | 92 | /** |
90 | 93 | * Checks if the object opened a file successfully. |
91 | 94 | * |
-
|
|
|
23 | 23 | */ |
24 | 24 | |
25 | 25 | #include "common/stdafx.h" |
26 | | |
27 | | #include "backends/fs/abstract-fs.h" |
28 | 26 | #include "common/util.h" |
| 27 | #include "backends/fs/abstract-fs.h" |
| 28 | #include "backends/factories/fs-factory-maker.cpp" |
29 | 29 | |
| 30 | /* |
| 31 | * Simple DOS-style pattern matching function (understands * and ? like used in DOS). |
| 32 | * Taken from exult/files/listfiles.cc |
| 33 | */ |
| 34 | static bool matchString(const char *str, const char *pat) { |
| 35 | const char *p = 0; |
| 36 | const char *q = 0; |
| 37 | |
| 38 | for (;;) { |
| 39 | switch (*pat) { |
| 40 | case '*': |
| 41 | p = ++pat; |
| 42 | q = str; |
| 43 | break; |
30 | 44 | |
31 | | FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode) { |
32 | | _realNode = realNode; |
33 | | _refCount = new int(1); |
| 45 | default: |
| 46 | if (*pat != *str) { |
| 47 | if (p) { |
| 48 | pat = p; |
| 49 | str = ++q; |
| 50 | if(!*str) |
| 51 | return !*pat; |
| 52 | break; |
| 53 | } |
| 54 | else |
| 55 | return false; |
| 56 | } |
| 57 | // fallthrough |
| 58 | case '?': |
| 59 | if(!*str) |
| 60 | return !*pat; |
| 61 | pat++; |
| 62 | str++; |
| 63 | } |
| 64 | } |
34 | 65 | } |
35 | 66 | |
36 | 67 | FilesystemNode::FilesystemNode() { |
… |
… |
|
38 | 69 | _refCount = 0; |
39 | 70 | } |
40 | 71 | |
| 72 | FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode) { |
| 73 | _realNode = realNode; |
| 74 | _refCount = new int(1); |
| 75 | } |
| 76 | |
41 | 77 | FilesystemNode::FilesystemNode(const FilesystemNode &node) { |
42 | 78 | _realNode = node._realNode; |
43 | 79 | _refCount = node._refCount; |
… |
… |
|
46 | 82 | } |
47 | 83 | |
48 | 84 | FilesystemNode::FilesystemNode(const Common::String &p) { |
| 85 | AbstractFilesystemFactory *factory = FilesystemFactoryMaker::makeFactory(); |
| 86 | |
49 | 87 | if (p.empty() || p == ".") |
50 | | _realNode = AbstractFilesystemNode::getCurrentDirectory(); |
| 88 | _realNode = factory->makeCurrentDirectoryFileNode(); |
51 | 89 | else |
52 | | _realNode = AbstractFilesystemNode::getNodeForPath(p); |
| 90 | _realNode = factory->makeFileNodePath(p); |
53 | 91 | _refCount = new int(1); |
54 | 92 | } |
55 | 93 | |
… |
… |
|
57 | 95 | decRefCount(); |
58 | 96 | } |
59 | 97 | |
60 | | void FilesystemNode::decRefCount() { |
61 | | if (_refCount) { |
62 | | assert(*_refCount > 0); |
63 | | --(*_refCount); |
64 | | if (*_refCount == 0) { |
65 | | delete _refCount; |
66 | | delete _realNode; |
67 | | } |
68 | | } |
69 | | } |
70 | | |
71 | | FilesystemNode &FilesystemNode::operator =(const FilesystemNode &node) { |
| 98 | FilesystemNode &FilesystemNode::operator= (const FilesystemNode &node) { |
72 | 99 | if (node._refCount) |
73 | 100 | ++(*node._refCount); |
74 | 101 | |
… |
… |
|
80 | 107 | return *this; |
81 | 108 | } |
82 | 109 | |
83 | | bool FilesystemNode::isValid() const { |
84 | | if (_realNode == 0) |
| 110 | bool FilesystemNode::operator< (const FilesystemNode& node) const |
| 111 | { |
| 112 | if (isDirectory() && !node.isDirectory()) |
| 113 | return true; |
| 114 | if (!isDirectory() && node.isDirectory()) |
85 | 115 | return false; |
86 | | return _realNode->isValid(); |
| 116 | return scumm_stricmp(getDisplayName().c_str(), node.getDisplayName().c_str()) < 0; |
87 | 117 | } |
88 | 118 | |
89 | | FilesystemNode FilesystemNode::getParent() const { |
90 | | if (_realNode == 0) |
91 | | return *this; |
| 119 | void FilesystemNode::decRefCount() { |
| 120 | if (_refCount) { |
| 121 | assert(*_refCount > 0); |
| 122 | --(*_refCount); |
| 123 | if (*_refCount == 0) { |
| 124 | delete _refCount; |
| 125 | delete _realNode; |
| 126 | } |
| 127 | } |
| 128 | } |
92 | 129 | |
93 | | AbstractFilesystemNode *node = _realNode->parent(); |
94 | | if (node == 0) { |
95 | | return *this; |
96 | | } else { |
97 | | return FilesystemNode(node); |
98 | | } |
| 130 | bool FilesystemNode::exists() const { |
| 131 | if (_realNode == 0) |
| 132 | return false; |
| 133 | return _realNode->exists(); |
99 | 134 | } |
100 | 135 | |
101 | 136 | FilesystemNode FilesystemNode::getChild(const Common::String &n) const { |
… |
… |
|
103 | 138 | return *this; |
104 | 139 | |
105 | 140 | assert(_realNode->isDirectory()); |
106 | | AbstractFilesystemNode *node = _realNode->child(n); |
| 141 | AbstractFilesystemNode *node = _realNode->getChild(n); |
107 | 142 | return FilesystemNode(node); |
108 | 143 | } |
109 | 144 | |
110 | | bool FilesystemNode::listDir(FSList &fslist, ListMode mode) const { |
| 145 | bool FilesystemNode::getChildren(FSList &fslist, ListMode mode, bool hidden) const { |
111 | 146 | if (!_realNode || !_realNode->isDirectory()) |
112 | 147 | return false; |
113 | 148 | |
… |
… |
|
113 | 148 | |
114 | 149 | AbstractFSList tmp; |
115 | 150 | |
116 | | if (!_realNode->listDir(tmp, mode)) |
| 151 | if (!_realNode->getChildren(tmp, mode, hidden)) |
117 | 152 | return false; |
118 | 153 | |
119 | 154 | fslist.clear(); |
… |
… |
|
124 | 159 | return true; |
125 | 160 | } |
126 | 161 | |
| 162 | Common::String FilesystemNode::getDisplayName() const { |
| 163 | assert(_realNode); |
| 164 | return _realNode->getDisplayName(); |
| 165 | } |
| 166 | |
| 167 | Common::String FilesystemNode::getName() const { |
| 168 | assert(_realNode); |
| 169 | return _realNode->getName(); |
| 170 | } |
| 171 | |
| 172 | FilesystemNode FilesystemNode::getParent() const { |
| 173 | if (_realNode == 0) |
| 174 | return *this; |
| 175 | |
| 176 | AbstractFilesystemNode *node = _realNode->getParent(); |
| 177 | if (node == 0) { |
| 178 | return *this; |
| 179 | } else { |
| 180 | return FilesystemNode(node); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | Common::String FilesystemNode::getPath() const { |
| 185 | assert(_realNode); |
| 186 | return _realNode->getPath(); |
| 187 | } |
| 188 | |
127 | 189 | bool FilesystemNode::isDirectory() const { |
128 | 190 | if (_realNode == 0) |
129 | 191 | return false; |
… |
… |
|
130 | 192 | return _realNode->isDirectory(); |
131 | 193 | } |
132 | 194 | |
133 | | Common::String FilesystemNode::displayName() const { |
134 | | assert(_realNode); |
135 | | return _realNode->displayName(); |
| 195 | bool FilesystemNode::isReadable() const { |
| 196 | if (_realNode == 0) |
| 197 | return false; |
| 198 | return _realNode->isReadable(); |
136 | 199 | } |
137 | 200 | |
138 | | Common::String FilesystemNode::name() const { |
139 | | assert(_realNode); |
140 | | return _realNode->name(); |
| 201 | bool FilesystemNode::isWritable() const { |
| 202 | if (_realNode == 0) |
| 203 | return false; |
| 204 | return _realNode->isWritable(); |
141 | 205 | } |
142 | 206 | |
143 | | Common::String FilesystemNode::path() const { |
144 | | assert(_realNode); |
145 | | return _realNode->path(); |
| 207 | bool FilesystemNode::lookupFile(FSList &results, FSList &fslist, Common::String &filename, bool hidden, bool exhaustive) const |
| 208 | { |
| 209 | for(FSList::iterator entry = fslist.begin(); entry != fslist.end(); ++entry) |
| 210 | { |
| 211 | if(entry->isDirectory()) { |
| 212 | lookupFileRec(results, *entry, filename, hidden, exhaustive); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | //TODO: we would return true even if no matches were found, if the initial results list isn't empty |
| 217 | return ((results.size() > 0) ? true : false); |
146 | 218 | } |
147 | 219 | |
| 220 | bool FilesystemNode::lookupFile(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const |
| 221 | { |
| 222 | lookupFileRec(results, dir, filename, hidden, exhaustive); |
| 223 | |
| 224 | //TODO: we would return true even if no matches were found, if the initial results list isn't empty |
| 225 | return ((results.size() > 0) ? true : false); |
| 226 | } |
148 | 227 | |
149 | | bool FilesystemNode::operator< (const FilesystemNode& node) const |
| 228 | void FilesystemNode::lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const |
150 | 229 | { |
151 | | if (isDirectory() && !node.isDirectory()) |
152 | | return true; |
153 | | if (!isDirectory() && node.isDirectory()) |
154 | | return false; |
155 | | return scumm_stricmp(displayName().c_str(), node.displayName().c_str()) < 0; |
| 230 | FSList entries; |
| 231 | dir.getChildren(entries, FilesystemNode::kListAll, hidden); |
| 232 | |
| 233 | for(FSList::iterator entry = entries.begin(); entry != entries.end(); ++entry) |
| 234 | { |
| 235 | if(entry->isDirectory()) { |
| 236 | lookupFileRec(results, *entry, filename, hidden, exhaustive); |
| 237 | } else { |
| 238 | //TODO: here we assume all backends implement the lastPathComponent method. It is currently static, |
| 239 | // so it might be a good idea to include it inside the backend class. This would enforce its |
| 240 | // implementation by all ports. |
| 241 | if(matchString(lastPathComponent(entry->getPath()), filename.c_str())) { |
| 242 | results.push_back(*entry); |
| 243 | |
| 244 | if(!exhaustive) { |
| 245 | break; |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | } |
156 | 250 | } |
-
|
|
|
33 | 33 | class FilesystemNode; |
34 | 34 | class AbstractFilesystemNode; |
35 | 35 | |
36 | | |
37 | 36 | /** |
38 | 37 | * List of multiple file system nodes. E.g. the contents of a given directory. |
39 | 38 | * This is subclass instead of just a typedef so that we can use forward |
… |
… |
|
41 | 40 | */ |
42 | 41 | class FSList : public Common::Array<FilesystemNode> {}; |
43 | 42 | |
44 | | |
45 | 43 | /** |
46 | | * FilesystemNode provides an abstraction for file pathes, allowing for portable |
| 44 | * FilesystemNode provides an abstraction for file paths, allowing for portable |
47 | 45 | * file system browsing. To this ends, multiple or single roots have to be supported |
48 | 46 | * (compare Unix with a single root, Windows with multiple roots C:, D:, ...). |
49 | 47 | * |
… |
… |
|
67 | 65 | */ |
68 | 66 | class FilesystemNode { |
69 | 67 | private: |
| 68 | int *_refCount; |
70 | 69 | AbstractFilesystemNode *_realNode; |
71 | | int *_refCount; |
72 | | |
73 | 70 | FilesystemNode(AbstractFilesystemNode *realNode); |
74 | 71 | |
75 | 72 | public: |
… |
… |
|
113 | 110 | /** |
114 | 111 | * Copy operator. |
115 | 112 | */ |
116 | | FilesystemNode &operator =(const FilesystemNode &node); |
117 | | |
| 113 | FilesystemNode &operator= (const FilesystemNode &node); |
| 114 | |
118 | 115 | /** |
119 | | * Checks if the FilesystemNode is valid for any usage |
| 116 | * Compare the name of this node to the name of another. Directories |
| 117 | * go before normal files. |
120 | 118 | */ |
121 | | bool isValid() const; |
| 119 | bool operator< (const FilesystemNode& node) const; |
122 | 120 | |
123 | | /** |
124 | | * Get the parent node of this node. If this node has no parent node, |
125 | | * then it returns a duplicate of this node. |
| 121 | /* |
| 122 | * Indicates whether the object refered by this path exists in the filesystem or not. |
126 | 123 | */ |
127 | | FilesystemNode getParent() const; |
| 124 | virtual bool exists() const; |
128 | 125 | |
129 | 126 | /** |
130 | 127 | * Fetch a child node of this node, with the given name. Only valid for |
131 | | * directory nodes (an assertion is triggered otherwise). If no no child |
132 | | * node with the given name exists, an invalid node is returned. |
| 128 | * directory nodes (an assertion is triggered otherwise). |
| 129 | * If no child node with the given name exists, an invalid node is returned. |
133 | 130 | */ |
134 | 131 | FilesystemNode getChild(const Common::String &name) const; |
135 | | |
| 132 | |
136 | 133 | /** |
137 | 134 | * Return a list of child nodes of this directory node. If called on a node |
138 | 135 | * that does not represent a directory, false is returned. |
| 136 | * |
139 | 137 | * @return true if succesful, false otherwise (e.g. when the directory does not exist). |
140 | | * @todo Rename this to listChildren or getChildren. |
141 | | */ |
142 | | virtual bool listDir(FSList &fslist, ListMode mode = kListDirectoriesOnly) const; |
143 | | |
144 | | /** |
145 | | * Is this node pointing to a directory? |
146 | | * @todo Currently we assume that a valid node that is not a directory |
147 | | * automatically is a file (ignoring things like symlinks). That might |
148 | | * actually be OK... but we could still add an isFile method. Or even replace |
149 | | * isValid and isDirectory by a getType() method that can return values like |
150 | | * kDirNodeType, kFileNodeType, kInvalidNodeType. |
151 | 138 | */ |
152 | | virtual bool isDirectory() const; |
| 139 | virtual bool getChildren(FSList &fslist, ListMode mode = kListDirectoriesOnly, bool hidden = false) const; |
153 | 140 | |
154 | 141 | /** |
155 | 142 | * Return a human readable string for this node, usable for display (e.g. |
… |
… |
|
155 | 142 | * Return a human readable string for this node, usable for display (e.g. |
156 | 143 | * in the GUI code). Do *not* rely on it being usable for anything else, |
157 | 144 | * like constructing paths! |
| 145 | * |
158 | 146 | * @return the display name |
159 | 147 | */ |
160 | | virtual Common::String displayName() const; |
| 148 | virtual Common::String getDisplayName() const; |
161 | 149 | |
162 | 150 | /** |
163 | 151 | * Return a string representation of the name of the file. This is can be |
… |
… |
|
167 | 155 | * |
168 | 156 | * @return the file name |
169 | 157 | */ |
170 | | virtual Common::String name() const; |
| 158 | virtual Common::String getName() const; |
171 | 159 | |
172 | 160 | /** |
173 | 161 | * Return a string representation of the file which can be passed to fopen(), |
… |
… |
|
180 | 168 | * |
181 | 169 | * @return the 'path' represented by this filesystem node |
182 | 170 | */ |
183 | | virtual Common::String path() const; |
| 171 | virtual Common::String getPath() const; |
| 172 | |
| 173 | /** |
| 174 | * Get the parent node of this node. If this node has no parent node, |
| 175 | * then it returns a duplicate of this node. |
| 176 | */ |
| 177 | FilesystemNode getParent() const; |
184 | 178 | |
185 | 179 | /** |
186 | | * Compare the name of this node to the name of another. Directories |
187 | | * go before normal files. |
| 180 | * Indicates whether this path refers to a directory or not. |
| 181 | * |
| 182 | * @todo Currently we assume that a valid node that is not a directory |
| 183 | * automatically is a file (ignoring things like symlinks). That might |
| 184 | * actually be OK... but we could still add an isFile method. Or even replace |
| 185 | * isValid and isDirectory by a getType() method that can return values like |
| 186 | * kDirNodeType, kFileNodeType, kInvalidNodeType. |
188 | 187 | */ |
189 | | bool operator< (const FilesystemNode& node) const; |
| 188 | virtual bool isDirectory() const; |
| 189 | |
| 190 | /** |
| 191 | * Indicates whether this path can be read from or not. |
| 192 | */ |
| 193 | virtual bool isReadable() const; |
| 194 | |
| 195 | /** |
| 196 | * Indicates whether this path can be written to or not. |
| 197 | */ |
| 198 | virtual bool isWritable() const; |
| 199 | |
| 200 | /** |
| 201 | * Searches recursively for a filename inside the given directories. |
| 202 | * |
| 203 | * @param results List to put the matches in. |
| 204 | * @param fslist List of directories to search within. |
| 205 | * @param filename Name of the file to look for. |
| 206 | * @param hidden Whether to search hidden files or not. Default: false |
| 207 | * @param exhaustive Whether to continue searching after one match has been found. Default: false |
| 208 | * |
| 209 | * @return true if matches could be found, false otherwise. |
| 210 | */ |
| 211 | virtual bool lookupFile(FSList &results, FSList &fslist, Common::String &filename, bool hidden, bool exhaustive) const; |
| 212 | |
| 213 | /** |
| 214 | * Searches recursively for a filename inside the given directory. |
| 215 | * |
| 216 | * @param results List to put the matches in. |
| 217 | * @param FilesystemNode Directory to search within. |
| 218 | * @param filename Name of the file to look for. |
| 219 | * @param hidden Whether to search hidden files or not. Default: false |
| 220 | * @param exhaustive Whether to continue searching after one match has been found. Default: false |
| 221 | * |
| 222 | * @return true if matches could be found, false otherwise. |
| 223 | */ |
| 224 | virtual bool lookupFile(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const; |
190 | 225 | |
191 | 226 | protected: |
| 227 | /** |
| 228 | * Decreases the reference count to the FilesystemNode, and if necessary, |
| 229 | * deletes the corresponding underlying references. |
| 230 | */ |
192 | 231 | void decRefCount(); |
| 232 | |
| 233 | /** |
| 234 | * Searches recursively for a filename inside the given directory. |
| 235 | * |
| 236 | * @param results List to put the matches in. |
| 237 | * @param FilesystemNode Directory to search within. |
| 238 | * @param filename Name of the file to look for. |
| 239 | * @param hidden Whether to search hidden files or not. |
| 240 | * @param exhaustive Whether to continue searching after one match has been found. |
| 241 | */ |
| 242 | void lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const; |
193 | 243 | }; |
194 | 244 | |
195 | 245 | //} // End of namespace Common |
… |
… |
|
194 | 244 | |
195 | 245 | //} // End of namespace Common |
196 | 246 | |
197 | | #endif |
| 247 | #endif //COMMON_FS_H |
-
|
|
|
246 | 246 | } |
247 | 247 | |
248 | 248 | bool md5_file(const FilesystemNode &file, uint8 digest[16], uint32 length) { |
249 | | if (!file.isValid()) { |
250 | | warning("md5_file: using an invalid FilesystemNode"); |
| 249 | if(!file.exists()) { |
| 250 | warning("md5_file: using an inexistent FilesystemNode"); |
| 251 | return false; |
| 252 | } else if (!file.isReadable()) { |
| 253 | warning("md5_file: using an unreadable FilesystemNode"); |
251 | 254 | return false; |
252 | 255 | } else if (file.isDirectory()) { |
253 | | warning("md5_file: using a diretory FilesystemNode"); |
| 256 | warning("md5_file: using a directory FilesystemNode"); |
254 | 257 | return false; |
255 | 258 | } |
256 | 259 | |
257 | | return md5_file(file.path().c_str(), digest, length); |
| 260 | return md5_file(file.getPath().c_str(), digest, length); |
258 | 261 | } |
259 | 262 | |
260 | 263 | bool md5_file(const char *name, uint8 digest[16], uint32 length) { |
-
|
|
|
30 | 30 | #include "common/noncopyable.h" |
31 | 31 | #include "common/scummsys.h" |
32 | 32 | #include "common/stream.h" |
| 33 | #include "common/str.h" |
33 | 34 | |
34 | 35 | namespace Common { |
35 | 36 | |
… |
… |
|
77 | 78 | class SaveFileManager : NonCopyable { |
78 | 79 | |
79 | 80 | public: |
| 81 | enum SFMError { |
| 82 | SFM_NO_ERROR, //Default state, indicates no error has been recorded |
| 83 | SFM_DIR_ACCESS, //stat(), mkdir()::EACCES: Search or write permission denied |
| 84 | SFM_DIR_LINKMAX, //mkdir()::EMLINK: The link count of the parent directory would exceed {LINK_MAX} |
| 85 | SFM_DIR_LOOP, //stat(), mkdir()::ELOOP: Too many symbolic links encountered while traversing the path |
| 86 | SFM_DIR_NAMETOOLONG, //stat(), mkdir()::ENAMETOOLONG: The path name is too long |
| 87 | SFM_DIR_NOENT, //stat(), mkdir()::ENOENT: A component of the path path does not exist, or the path is an empty string |
| 88 | SFM_DIR_NOTDIR, //stat(), mkdir()::ENOTDIR: A component of the path prefix is not a directory |
| 89 | SFM_DIR_ROFS //mkdir()::EROFS: The parent directory resides on a read-only file system |
| 90 | }; |
| 91 | |
| 92 | protected: |
| 93 | SFMError _error; |
| 94 | String _errorDesc; |
| 95 | |
| 96 | public: |
80 | 97 | virtual ~SaveFileManager() {} |
81 | | |
| 98 | |
| 99 | /** |
| 100 | * Clears the last set error code and string. |
| 101 | */ |
| 102 | virtual void clearError() { _error = SFM_NO_ERROR; _errorDesc = ""; } |
| 103 | |
| 104 | /** |
| 105 | * Returns the last ocurred error code. If none ocurred, returns SFM_NO_ERROR. |
| 106 | * |
| 107 | * @return A SFMError indicating the type of the last error. |
| 108 | */ |
| 109 | virtual SFMError getError() { return _error; } |
| 110 | |
| 111 | /** |
| 112 | * Returns the last ocurred error description. If none ocurred, returns 0. |
| 113 | * |
| 114 | * @return A string describing the last error. |
| 115 | */ |
| 116 | virtual String getErrorDesc() { return _errorDesc; } |
| 117 | |
| 118 | /** |
| 119 | * Sets the last ocurred error. |
| 120 | * @param error Code identifying the last error. |
| 121 | * @param errorDesc String describing the last error. |
| 122 | */ |
| 123 | virtual void setError(SFMError error, String errorDesc) { _error = error; _errorDesc = errorDesc; } |
| 124 | |
82 | 125 | /** |
83 | 126 | * Open the file with name filename in the given directory for saving. |
84 | 127 | * @param filename the filename |
… |
… |
|
94 | 137 | virtual InSaveFile *openForLoading(const char *filename) = 0; |
95 | 138 | |
96 | 139 | /** |
97 | | * Request a list of available savegames with a given prefix. |
98 | | * TODO: Document this better! |
99 | | * TODO: Or even replace it with a better API. For example, one that |
100 | | * returns a list of strings for all present file names. |
| 140 | * Removes the given savefile from the filesystem. |
| 141 | * @param filename Filename path pointing to the savefile. |
| 142 | * @return true if no error ocurred. false otherwise. |
101 | 143 | */ |
102 | | virtual void listSavefiles(const char * /* prefix */, bool *marks, int num) = 0; |
| 144 | virtual bool removeSavefile(const char *filename) = 0; |
| 145 | |
| 146 | /** |
| 147 | * Request a list of available savegames with a given regex. |
| 148 | * @param regex Regular expression to match. Wildcards like * or ? are available. |
| 149 | * returns a list of strings for all present file names. |
| 150 | */ |
| 151 | virtual Common::StringList listSavefiles(const char *regex) = 0; |
103 | 152 | |
104 | 153 | /** |
105 | 154 | * Get the path to the save game directory. |
-
|
|
|
52 | 52 | FSList fslist; |
53 | 53 | FilesystemNode dir(ConfMan.get("path")); |
54 | 54 | |
55 | | if (!dir.listDir(fslist, FilesystemNode::kListFilesOnly)) { |
56 | | warning("AgiEngine: invalid game path '%s'", dir.path().c_str()); |
| 55 | if (!dir.getChildren(fslist, FilesystemNode::kListFilesOnly)) { |
| 56 | warning("AgiEngine: invalid game path '%s'", dir.getPath().c_str()); |
57 | 57 | return errInvalidAGIFile; |
58 | 58 | } |
59 | 59 | |
… |
… |
|
59 | 59 | |
60 | 60 | for (FSList::const_iterator file = fslist.begin(); |
61 | 61 | file != fslist.end() && !found; ++file) { |
62 | | Common::String f = file->name(); |
| 62 | Common::String f = file->getName(); |
63 | 63 | f.toLowercase(); |
64 | 64 | |
65 | 65 | if (f.hasSuffix("vol.0")) { |
-
|
|
|
1883 | 1883 | // First grab all filenames and at the same time count the number of *.wag files |
1884 | 1884 | for (FSList::const_iterator file = fslist->begin(); file != fslist->end(); ++file) { |
1885 | 1885 | if (file->isDirectory()) continue; |
1886 | | Common::String filename = file->name(); |
| 1886 | Common::String filename = file->getName(); |
1887 | 1887 | filename.toLowercase(); |
1888 | 1888 | allFiles[filename] = true; // Save the filename in a hash table |
1889 | 1889 | |
… |
… |
|
1889 | 1889 | |
1890 | 1890 | if (filename.hasSuffix(".wag")) { |
1891 | 1891 | // Save latest found *.wag file's path (Can be used to open the file, the name can't) |
1892 | | wagFilePath = file->path(); |
| 1892 | wagFilePath = file->getPath(); |
1893 | 1893 | wagFileCount++; // Count found *.wag files |
1894 | 1894 | } |
1895 | 1895 | } |
-
|
|
|
38 | 38 | |
39 | 39 | int AGOSEngine::countSaveGames() { |
40 | 40 | Common::InSaveFile *f; |
| 41 | Common::StringList filenames; |
41 | 42 | uint i = 1; |
| 43 | char slot[3]; |
| 44 | int slotNum; |
42 | 45 | bool marks[256]; |
43 | 46 | |
44 | 47 | char *prefix = genSaveName(998); |
45 | | prefix[strlen(prefix)-3] = '\0'; |
46 | | _saveFileMan->listSavefiles(prefix, marks, 256); |
| 48 | prefix[strlen(prefix)-3] = '*'; |
| 49 | prefix[strlen(prefix)-2] = '\0'; |
| 50 | memset(marks, false, 256 * sizeof(bool)); //assume no savegames for this title |
| 51 | filenames = _saveFileMan->listSavefiles(prefix); |
47 | 52 | |
| 53 | for(Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); file++){ |
| 54 | //Obtain the last 3 digits of the filename, since they correspond to the save slot |
| 55 | slot[0] = file->c_str()[file->size()-3]; |
| 56 | slot[1] = file->c_str()[file->size()-2]; |
| 57 | slot[2] = file->c_str()[file->size()-1]; |
| 58 | |
| 59 | slotNum = atoi(slot); |
| 60 | if(slotNum >= 0 && slotNum < 256) |
| 61 | marks[slotNum] = true; //mark this slot as valid |
| 62 | } |
| 63 | |
48 | 64 | while (i < 256) { |
49 | 65 | if (marks[i] && |
50 | 66 | (f = _saveFileMan->openForLoading(genSaveName(i)))) { |
… |
… |
|
53 | 69 | } else |
54 | 70 | break; |
55 | 71 | } |
| 72 | |
56 | 73 | return i; |
57 | 74 | } |
58 | 75 | |
-
|
|
|
82 | 82 | FSList fslist; |
83 | 83 | FilesystemNode dir(ConfMan.get("path")); |
84 | 84 | |
85 | | if (!dir.listDir(fslist, FilesystemNode::kListFilesOnly)) |
86 | | error("invalid game path '%s'", dir.path().c_str()); |
| 85 | if (!dir.getChildren(fslist, FilesystemNode::kListFilesOnly)) |
| 86 | error("invalid game path '%s'", dir.getPath().c_str()); |
87 | 87 | |
88 | 88 | if (_vm->game() == GI_KYRA1 && _vm->gameFlags().isTalkie) { |
89 | 89 | static const char *list[] = { |
… |
… |
|
96 | 96 | Common::for_each(_pakfiles.begin(), _pakfiles.end(), Common::bind2nd(Common::mem_fun(&ResourceFile::protect), true)); |
97 | 97 | } else { |
98 | 98 | for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { |
99 | | Common::String filename = file->name(); |
| 99 | Common::String filename = file->getName(); |
100 | 100 | filename.toUppercase(); |
101 | 101 | |
102 | 102 | // No real PAK file! |
… |
… |
|
104 | 104 | continue; |
105 | 105 | |
106 | 106 | if (filename.hasSuffix("PAK") || filename.hasSuffix("APK")) { |
107 | | if (!loadPakFile(file->name())) |
108 | | error("couldn't open pakfile '%s'", file->name().c_str()); |
| 107 | if (!loadPakFile(file->getName())) |
| 108 | error("couldn't open pakfile '%s'", file->getName().c_str()); |
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
-
|
|
|
73 | 73 | if (file->isDirectory()) { |
74 | 74 | continue; |
75 | 75 | } |
76 | | if (file->name().equalsIgnoreCase("queen.1") || file->name().equalsIgnoreCase("queen.1c")) { |
| 76 | if (file->getName().equalsIgnoreCase("queen.1") || file->getName().equalsIgnoreCase("queen.1c")) { |
77 | 77 | Common::File dataFile; |
78 | 78 | if (!dataFile.open(*file)) { |
79 | 79 | continue; |
… |
… |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | void QueenEngine::findGameStateDescriptions(char descriptions[100][32]) { |
320 | | char filename[20]; |
321 | | makeGameStateName(0, filename); |
322 | | filename[strlen(filename) - 2] = 0; |
| 320 | char prefix[20]; |
| 321 | makeGameStateName(0, prefix); |
| 322 | prefix[strlen(prefix) - 2] = '*'; |
| 323 | prefix[strlen(prefix) - 1] = 0; |
323 | 324 | bool marks[SAVESTATE_MAX_NUM]; |
324 | | _saveFileMan->listSavefiles(filename, marks, SAVESTATE_MAX_NUM); |
| 325 | char slot[2]; |
| 326 | int slotNum; |
| 327 | Common::StringList filenames; |
| 328 | |
| 329 | memset(marks, false, SAVESTATE_MAX_NUM * sizeof(bool)); //assume no savegames for this title |
| 330 | filenames = _saveFileMan->listSavefiles(prefix); |
| 331 | |
| 332 | for(Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); file++){ |
| 333 | //Obtain the last 2 digits of the filename, since they correspond to the save slot |
| 334 | slot[0] = file->c_str()[file->size()-2]; |
| 335 | slot[1] = file->c_str()[file->size()-1]; |
| 336 | |
| 337 | slotNum = atoi(slot); |
| 338 | if(slotNum >= 0 && slotNum < SAVESTATE_MAX_NUM) |
| 339 | marks[slotNum] = true; //mark this slot as valid |
| 340 | } |
| 341 | |
325 | 342 | for (int i = 0; i < SAVESTATE_MAX_NUM; ++i) { |
326 | 343 | if (marks[i]) { |
327 | 344 | GameStateHeader header; |
-
|
|
|
112 | 112 | } |
113 | 113 | |
114 | 114 | void SagaEngine::fillSaveList() { |
| 115 | assert(_saveMarks); |
| 116 | |
115 | 117 | int i; |
116 | 118 | Common::InSaveFile *in; |
| 119 | Common::StringList filenames; |
| 120 | char slot[2]; |
| 121 | int slotNum; |
117 | 122 | char *name; |
118 | 123 | |
119 | 124 | name = calcSaveFileName(MAX_SAVES); |
120 | | name[strlen(name) - 2] = 0; |
121 | | _saveFileMan->listSavefiles(name, _saveMarks, MAX_SAVES); |
122 | | |
| 125 | name[strlen(name) - 2] = '*'; |
| 126 | name[strlen(name) - 1] = 0; |
| 127 | |
| 128 | memset(_saveMarks, false, MAX_SAVES * sizeof(bool)); //assume no savegames for this title |
| 129 | filenames = _saveFileMan->listSavefiles(name); |
| 130 | |
| 131 | for(Common::StringList::iterator file = filenames.begin(); file != filenames.end(); file++){ |
| 132 | //Obtain the last 2 digits of the filename, since they correspond to the save slot |
| 133 | slot[0] = file->c_str()[file->size()-2]; |
| 134 | slot[1] = file->c_str()[file->size()-1]; |
| 135 | |
| 136 | slotNum = atoi(slot); |
| 137 | if(slotNum >= 0 && slotNum < MAX_SAVES) |
| 138 | _saveMarks[slotNum] = true; //mark this slot as valid |
| 139 | } |
| 140 | |
123 | 141 | _saveFilesMaxCount = 0; |
124 | 142 | for (i = 0; i < MAX_SAVES; i++) { |
125 | 143 | if (_saveMarks[i]) { |
-
|
|
|
18 | 18 | * along with this program; if not, write to the Free Software |
19 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
20 | 20 | * |
21 | | * $URL$ |
22 | | * $Id$ |
| 21 | * $URL:https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/branches/gsoc2007-fsnode/engines/scumm/detection.cpp $ |
| 22 | * $Id:detection.cpp 26949 2007-05-26 20:23:24Z david_corrales $ |
23 | 23 | * |
24 | 24 | */ |
25 | 25 | |
… |
… |
|
194 | 194 | // the first match is used. |
195 | 195 | static bool searchFSNode(const FSList &fslist, const Common::String &name, FilesystemNode &result) { |
196 | 196 | for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { |
197 | | if (!scumm_stricmp(file->name().c_str(), name.c_str())) { |
| 197 | if (!scumm_stricmp(file->getName().c_str(), name.c_str())) { |
198 | 198 | result = *file; |
199 | 199 | return true; |
200 | 200 | } |
… |
… |
|
220 | 220 | FSList tmpList; |
221 | 221 | if (searchFSNode(fslist, "RESOURCE", resDir) |
222 | 222 | && resDir.isDirectory() |
223 | | && resDir.listDir(tmpList, FilesystemNode::kListFilesOnly) |
| 223 | && resDir.getChildren(tmpList, FilesystemNode::kListFilesOnly) |
224 | 224 | && searchFSNode(tmpList, filename, langFile)) { |
225 | 225 | tmp.open(langFile); |
226 | 226 | } |
… |
… |
|
324 | 324 | DetectorDesc d; |
325 | 325 | d.node = *file; |
326 | 326 | d.md5Entry = 0; |
327 | | fileMD5Map[file->name()] = d; |
| 327 | fileMD5Map[file->getName()] = d; |
328 | 328 | } |
329 | 329 | } |
330 | 330 | |
… |
… |
|
451 | 451 | |
452 | 452 | Common::File tmp; |
453 | 453 | if (!tmp.open(d.node)) { |
454 | | warning("SCUMM detectGames: failed to open '%s' for read access", d.node.path().c_str()); |
| 454 | warning("SCUMM detectGames: failed to open '%s' for read access", d.node.getPath().c_str()); |
455 | 455 | return false; |
456 | 456 | } |
457 | 457 | |
… |
… |
|
755 | 755 | // Fetch the list of files in the current directory |
756 | 756 | FSList fslist; |
757 | 757 | FilesystemNode dir(ConfMan.get("path")); |
758 | | if (!dir.listDir(fslist, FilesystemNode::kListFilesOnly)) { |
| 758 | if (!dir.getChildren(fslist, FilesystemNode::kListFilesOnly)) { |
759 | 759 | return kInvalidPathError; |
760 | 760 | } |
761 | 761 | |
-
|
|
|
427 | 427 | #pragma mark - |
428 | 428 | |
429 | 429 | Common::StringList generateSavegameList(ScummEngine *scumm, bool saveMode) { |
430 | | // Get savegame names |
431 | | Common::StringList l; |
| 430 | // Get savegame descriptions |
| 431 | Common::StringList descriptions; |
432 | 432 | char name[32]; |
433 | | uint i = saveMode ? 1 : 0; |
| 433 | uint i = saveMode ? 1 : 0; //the autosave is on slot #0 |
434 | 434 | bool avail_saves[81]; |
435 | 435 | |
436 | 436 | scumm->listSavegames(avail_saves, ARRAYSIZE(avail_saves)); |
… |
… |
|
439 | 439 | scumm->getSavegameName(i, name); |
440 | 440 | else |
441 | 441 | name[0] = 0; |
442 | | l.push_back(name); |
| 442 | descriptions.push_back(name); |
443 | 443 | } |
444 | | |
445 | | return l; |
| 444 | |
| 445 | return descriptions; |
446 | 446 | } |
447 | 447 | |
448 | 448 | MainMenuDialog::MainMenuDialog(ScummEngine *scumm) |
-
|
|
|
384 | 384 | } |
385 | 385 | |
386 | 386 | void ScummEngine::listSavegames(bool *marks, int num) { |
| 387 | assert(marks); |
| 388 | |
387 | 389 | char prefix[256]; |
| 390 | char slot[2]; |
| 391 | int slotNum; |
| 392 | Common::StringList filenames; |
| 393 | |
388 | 394 | makeSavegameName(prefix, 99, false); |
389 | | prefix[strlen(prefix)-2] = 0; |
390 | | _saveFileMan->listSavefiles(prefix, marks, num); |
| 395 | prefix[strlen(prefix)-2] = '*'; |
| 396 | prefix[strlen(prefix)-1] = 0; |
| 397 | memset(marks, false, num * sizeof(bool)); //assume no savegames for this title |
| 398 | filenames = _saveFileMan->listSavefiles(prefix); |
| 399 | |
| 400 | for(Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); file++){ |
| 401 | //Obtain the last 2 digits of the filename, since they correspond to the save slot |
| 402 | slot[0] = file->c_str()[file->size()-2]; |
| 403 | slot[1] = file->c_str()[file->size()-1]; |
| 404 | |
| 405 | slotNum = atoi(slot); |
| 406 | if(slotNum >= 0 && slotNum < num) |
| 407 | marks[slotNum] = true; //mark this slot as valid |
| 408 | } |
391 | 409 | } |
392 | 410 | |
393 | 411 | bool ScummEngine::getSavegameName(int slot, char *desc) { |
-
|
|
|
124 | 124 | // Iterate over all files in the given directory |
125 | 125 | for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { |
126 | 126 | if (!file->isDirectory()) { |
127 | | const char *fileName = file->name().c_str(); |
| 127 | const char *fileName = file->getName().c_str(); |
128 | 128 | |
129 | 129 | if (0 == scumm_stricmp("sky.dsk", fileName)) { |
130 | 130 | Common::File dataDisk; |
131 | | if (dataDisk.open(file->path())) { |
| 131 | if (dataDisk.open(file->getPath())) { |
132 | 132 | hasSkyDsk = true; |
133 | 133 | dataDiskSize = dataDisk.size(); |
134 | 134 | } |
… |
… |
|
136 | 136 | |
137 | 137 | if (0 == scumm_stricmp("sky.dnr", fileName)) { |
138 | 138 | Common::File dinner; |
139 | | if (dinner.open(file->path())) { |
| 139 | if (dinner.open(file->getPath())) { |
140 | 140 | hasSkyDnr = true; |
141 | 141 | dinnerTableEntries = dinner.readUint32LE(); |
142 | 142 | } |
-
|
|
|
107 | 107 | void Sword1CheckDirectory(const FSList &fslist, bool *filesFound) { |
108 | 108 | for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { |
109 | 109 | if (!file->isDirectory()) { |
110 | | const char *fileName = file->name().c_str(); |
| 110 | const char *fileName = file->getName().c_str(); |
111 | 111 | for (int cnt = 0; cnt < NUM_FILES_TO_CHECK; cnt++) |
112 | 112 | if (scumm_stricmp(fileName, g_filesToCheck[cnt]) == 0) |
113 | 113 | filesFound[cnt] = true; |
… |
… |
|
113 | 113 | filesFound[cnt] = true; |
114 | 114 | } else { |
115 | 115 | for (int cnt = 0; cnt < ARRAYSIZE(g_dirNames); cnt++) |
116 | | if (scumm_stricmp(file->name().c_str(), g_dirNames[cnt]) == 0) { |
| 116 | if (scumm_stricmp(file->getName().c_str(), g_dirNames[cnt]) == 0) { |
117 | 117 | FSList fslist2; |
118 | | if (file->listDir(fslist2, FilesystemNode::kListFilesOnly)) |
| 118 | if (file->getChildren(fslist2, FilesystemNode::kListFilesOnly)) |
119 | 119 | Sword1CheckDirectory(fslist2, filesFound); |
120 | 120 | } |
121 | 121 | } |
-
|
|
|
101 | 101 | // Iterate over all files in the given directory |
102 | 102 | for (file = fslist.begin(); file != fslist.end(); ++file) { |
103 | 103 | if (!file->isDirectory()) { |
104 | | const char *fileName = file->name().c_str(); |
| 104 | const char *fileName = file->getName().c_str(); |
105 | 105 | |
106 | 106 | if (0 == scumm_stricmp(g->detectname, fileName)) { |
107 | 107 | // Match found, add to list of candidates, then abort inner loop. |
… |
… |
|
118 | 118 | // present e.g. if the user copied the data straight from CD. |
119 | 119 | for (file = fslist.begin(); file != fslist.end(); ++file) { |
120 | 120 | if (file->isDirectory()) { |
121 | | const char *fileName = file->name().c_str(); |
| 121 | const char *fileName = file->getName().c_str(); |
122 | 122 | |
123 | 123 | if (0 == scumm_stricmp("clusters", fileName)) { |
124 | 124 | FSList recList; |
125 | | if (file->listDir(recList, FilesystemNode::kListAll)) { |
| 125 | if (file->getChildren(recList, FilesystemNode::kListAll)) { |
126 | 126 | GameList recGames(Engine_SWORD2_detectGames(recList)); |
127 | 127 | if (!recGames.empty()) { |
128 | 128 | detectedGames.push_back(recGames); |
… |
… |
|
144 | 144 | |
145 | 145 | FSList fslist; |
146 | 146 | FilesystemNode dir(ConfMan.get("path")); |
147 | | if (!dir.listDir(fslist, FilesystemNode::kListAll)) { |
| 147 | if (!dir.getChildren(fslist, FilesystemNode::kListAll)) { |
148 | 148 | return kInvalidPathError; |
149 | 149 | } |
150 | 150 | |
-
|
|
|
400 | 400 | |
401 | 401 | void ToucheEngine::generateGameStateFileName(int num, char *dst, int len, bool prefixOnly) const { |
402 | 402 | if (prefixOnly) { |
403 | | snprintf(dst, len, "%s.", _targetName.c_str()); |
| 403 | snprintf(dst, len, "%s.*", _targetName.c_str()); |
404 | 404 | } else { |
405 | 405 | snprintf(dst, len, "%s.%d", _targetName.c_str(), num); |
406 | 406 | } |
-
|
|
|
370 | 370 | setupMenu(menuData.mode, &menuData); |
371 | 371 | curMode = menuData.mode; |
372 | 372 | if (menuData.mode == kMenuLoadStateMode || menuData.mode == kMenuSaveStateMode) { |
| 373 | assert(menuData.saveLoadMarks); |
| 374 | |
373 | 375 | char gameStateFileName[16]; |
374 | 376 | generateGameStateFileName(999, gameStateFileName, 15, true); |
375 | | _saveFileMan->listSavefiles(gameStateFileName, menuData.saveLoadMarks, 100); |
| 377 | char slot[2]; |
| 378 | int slotNum; |
| 379 | Common::StringList filenames; |
| 380 | |
| 381 | memset(menuData.saveLoadMarks, false, 100 * sizeof(bool)); //assume no savegames for this title |
| 382 | filenames = _saveFileMan->listSavefiles(gameStateFileName); |
| 383 | |
| 384 | for(Common::StringList::const_iterator file = filenames.begin(); file != filenames.end(); file++){ |
| 385 | //Obtain the last 1 or 2 digits of the filename, since they correspond to the save slot |
| 386 | //This engine can save games either with one or two digits, hence the additional if statement |
| 387 | slot[0] = file->c_str()[file->size()-2]; |
| 388 | slot[1] = file->c_str()[file->size()-1]; |
| 389 | |
| 390 | if(!atoi(&slot[0])){ |
| 391 | slotNum = atoi(&slot[1]); |
| 392 | } else { |
| 393 | slotNum = atoi(slot); |
| 394 | } |
| 395 | |
| 396 | if(slotNum >= 0 && slotNum < 100) |
| 397 | menuData.saveLoadMarks[slotNum] = true; //mark this slot as valid |
| 398 | } |
| 399 | |
376 | 400 | for (int i = 0; i < 100; ++i) { |
377 | 401 | menuData.saveLoadDescriptionsTable[i][0] = 0; |
378 | 402 | if (menuData.saveLoadMarks[i]) { |
-
|
|
|
28 | 28 | #include "gui/ListWidget.h" |
29 | 29 | |
30 | 30 | #include "common/config-manager.h" |
31 | | #include "common/fs.h" |
32 | 31 | #include "common/system.h" |
33 | 32 | #include "common/algorithm.h" |
34 | 33 | |
… |
… |
|
223 | 222 | |
224 | 223 | void BrowserDialog::updateListing() { |
225 | 224 | // Update the path display |
226 | | _currentPath->setLabel(_node.path()); |
| 225 | _currentPath->setLabel(_node.getPath()); |
227 | 226 | |
228 | 227 | // We memorize the last visited path. |
229 | | ConfMan.set("browser_lastpath", _node.path()); |
| 228 | ConfMan.set("browser_lastpath", _node.getPath()); |
230 | 229 | |
231 | 230 | // Read in the data from the file system |
232 | 231 | FilesystemNode::ListMode listMode = _isDirBrowser ? FilesystemNode::kListDirectoriesOnly |
… |
… |
|
231 | 230 | // Read in the data from the file system |
232 | 231 | FilesystemNode::ListMode listMode = _isDirBrowser ? FilesystemNode::kListDirectoriesOnly |
233 | 232 | : FilesystemNode::kListAll; |
234 | | if (!_node.listDir(_nodeContent, listMode)) { |
| 233 | if (!_node.getChildren(_nodeContent, listMode)) { |
235 | 234 | _nodeContent.clear(); |
236 | 235 | } else { |
237 | 236 | Common::sort(_nodeContent.begin(), _nodeContent.end()); |
… |
… |
|
241 | 240 | Common::StringList list; |
242 | 241 | for (FSList::iterator i = _nodeContent.begin(); i != _nodeContent.end(); ++i) { |
243 | 242 | if (!_isDirBrowser && i->isDirectory()) |
244 | | list.push_back(i->displayName() + "/"); |
| 243 | list.push_back(i->getDisplayName() + "/"); |
245 | 244 | else |
246 | | list.push_back(i->displayName()); |
| 245 | list.push_back(i->getDisplayName()); |
247 | 246 | } |
248 | 247 | _fileList->setList(list); |
249 | 248 | _fileList->scrollTo(0); |
-
|
|
|
394 | 394 | if (browser.runModal() > 0) { |
395 | 395 | // User made this choice... |
396 | 396 | FilesystemNode file(browser.getResult()); |
397 | | _soundFont->setLabel(file.path()); |
| 397 | _soundFont->setLabel(file.getPath()); |
398 | 398 | |
399 | | if (!file.path().empty() && (file.path() != "None")) |
| 399 | if (!file.getPath().empty() && (file.getPath() != "None")) |
400 | 400 | _soundFontClearButton->setEnabled(true); |
401 | 401 | else |
402 | 402 | _soundFontClearButton->setEnabled(false); |
… |
… |
|
417 | 417 | // done with optional specific gameid to pluginmgr detectgames? |
418 | 418 | // FSList files = dir.listDir(FilesystemNode::kListFilesOnly); |
419 | 419 | |
420 | | _gamePathWidget->setLabel(dir.path()); |
| 420 | _gamePathWidget->setLabel(dir.getPath()); |
421 | 421 | draw(); |
422 | 422 | } |
423 | 423 | draw(); |
… |
… |
|
430 | 430 | if (browser.runModal() > 0) { |
431 | 431 | // User made his choice... |
432 | 432 | FilesystemNode dir(browser.getResult()); |
433 | | _extraPathWidget->setLabel(dir.path()); |
| 433 | _extraPathWidget->setLabel(dir.getPath()); |
434 | 434 | draw(); |
435 | 435 | } |
436 | 436 | draw(); |
… |
… |
|
442 | 442 | if (browser.runModal() > 0) { |
443 | 443 | // User made his choice... |
444 | 444 | FilesystemNode dir(browser.getResult()); |
445 | | _savePathWidget->setLabel(dir.path()); |
| 445 | _savePathWidget->setLabel(dir.getPath()); |
446 | 446 | draw(); |
447 | 447 | } |
448 | 448 | draw(); |
… |
… |
|
654 | 654 | // User made his choice... |
655 | 655 | FilesystemNode dir(_browser->getResult()); |
656 | 656 | FSList files; |
657 | | if (!dir.listDir(files, FilesystemNode::kListAll)) { |
| 657 | if (!dir.getChildren(files, FilesystemNode::kListAll)) { |
658 | 658 | error("browser returned a node that is not a directory: '%s'", |
659 | | dir.path().c_str()); |
| 659 | dir.getPath().c_str()); |
660 | 660 | } |
661 | 661 | |
662 | 662 | // ...so let's determine a list of candidates, games that |
… |
… |
|
686 | 686 | GameDescriptor result = candidates[idx]; |
687 | 687 | |
688 | 688 | // TODO: Change the detectors to set "path" ! |
689 | | result["path"] = dir.path(); |
| 689 | result["path"] = dir.getPath(); |
690 | 690 | |
691 | 691 | Common::String domain = addGameToConf(result); |
692 | 692 | |
-
|
|
|
128 | 128 | FilesystemNode dir = _scanStack.pop(); |
129 | 129 | |
130 | 130 | FSList files; |
131 | | if (!dir.listDir(files, FilesystemNode::kListAll)) { |
| 131 | if (!dir.getChildren(files, FilesystemNode::kListAll)) { |
132 | 132 | error("browser returned a node that is not a directory: '%s'", |
133 | | dir.path().c_str()); |
| 133 | dir.getPath().c_str()); |
134 | 134 | } |
135 | 135 | |
136 | 136 | // Run the detector on the dir |
… |
… |
|
142 | 142 | // e.g. ask the user which one to pick (make sure to display the |
143 | 143 | // path, too). |
144 | 144 | GameDescriptor result = candidates[0]; |
145 | | result["path"] = dir.path(); |
| 145 | result["path"] = dir.getPath(); |
146 | 146 | |
147 | 147 | _games.push_back(result); |
148 | 148 | } |
-
|
|
|
27 | 27 | #include "gui/themebrowser.h" |
28 | 28 | #include "gui/chooser.h" |
29 | 29 | #include "gui/eval.h" |
| 30 | #include "gui/message.h" |
30 | 31 | #include "gui/newgui.h" |
31 | 32 | #include "gui/options.h" |
32 | 33 | #include "gui/PopUpWidget.h" |
… |
… |
|
813 | 814 | if (browser.runModal() > 0) { |
814 | 815 | // User made his choice... |
815 | 816 | FilesystemNode dir(browser.getResult()); |
816 | | _savePath->setLabel(dir.path()); |
| 817 | if(dir.isWritable()) |
| 818 | { |
| 819 | _savePath->setLabel(dir.getPath()); |
| 820 | } else { |
| 821 | MessageDialog error("The chosen directory cannot be written to. Please select another one."); |
| 822 | error.runModal(); |
| 823 | return; |
| 824 | } |
817 | 825 | draw(); |
818 | | // TODO - we should check if the directory is writeable before accepting it |
819 | 826 | } |
820 | 827 | break; |
821 | 828 | } |
… |
… |
|
824 | 831 | if (browser.runModal() > 0) { |
825 | 832 | // User made his choice... |
826 | 833 | FilesystemNode dir(browser.getResult()); |
827 | | _themePath->setLabel(dir.path()); |
| 834 | _themePath->setLabel(dir.getPath()); |
828 | 835 | draw(); |
829 | 836 | } |
830 | 837 | break; |
… |
… |
|
834 | 841 | if (browser.runModal() > 0) { |
835 | 842 | // User made his choice... |
836 | 843 | FilesystemNode dir(browser.getResult()); |
837 | | _extraPath->setLabel(dir.path()); |
| 844 | _extraPath->setLabel(dir.getPath()); |
838 | 845 | draw(); |
839 | 846 | } |
840 | 847 | break; |
… |
… |
|
844 | 851 | if (browser.runModal() > 0) { |
845 | 852 | // User made his choice... |
846 | 853 | FilesystemNode file(browser.getResult()); |
847 | | _soundFont->setLabel(file.path()); |
| 854 | _soundFont->setLabel(file.getPath()); |
848 | 855 | |
849 | | if (!file.path().empty() && (file.path() != "None")) |
| 856 | if (!file.getPath().empty() && (file.getPath() != "None")) |
850 | 857 | _soundFontClearButton->setEnabled(true); |
851 | 858 | else |
852 | 859 | _soundFontClearButton->setEnabled(false); |
-
|
|
|
27 | 27 | #include "gui/ListWidget.h" |
28 | 28 | #include "gui/widget.h" |
29 | 29 | #include "gui/theme.h" |
30 | | #include "common/fs.h" |
31 | 30 | |
32 | 31 | #ifdef MACOSX |
33 | 32 | #include "CoreFoundation/CoreFoundation.h" |
… |
… |
|
145 | 144 | |
146 | 145 | FilesystemNode node(dir); |
147 | 146 | |
148 | | if (!node.isValid()) |
| 147 | if (!node.exists() || !node.isReadable()) |
149 | 148 | return; |
150 | 149 | |
151 | 150 | FSList fslist; |
152 | | if (!node.listDir(fslist, FilesystemNode::kListAll)) |
| 151 | if (!node.getChildren(fslist, FilesystemNode::kListAll)) |
153 | 152 | return; |
154 | 153 | |
155 | 154 | for (FSList::const_iterator i = fslist.begin(); i != fslist.end(); ++i) { |
… |
… |
|
154 | 153 | |
155 | 154 | for (FSList::const_iterator i = fslist.begin(); i != fslist.end(); ++i) { |
156 | 155 | if (i->isDirectory()) { |
157 | | addDir(list, i->path(), level-1); |
| 156 | addDir(list, i->getPath(), level-1); |
158 | 157 | } else { |
159 | 158 | Entry th; |
160 | 159 | if (isTheme(*i, th)) { |
… |
… |
|
177 | 176 | Common::ConfigFile cfg; |
178 | 177 | Common::String type; |
179 | 178 | |
180 | | out.file = node.name(); |
| 179 | out.file = node.getName(); |
181 | 180 | for (int i = out.file.size()-1; out.file[i] != '.' && i > 0; --i) { |
182 | 181 | out.file.deleteLastChar(); |
183 | 182 | } |