Ticket #8715: gsoc-fsnode trunk (rev 1).patch

File gsoc-fsnode trunk (rev 1).patch, 220.1 KB (added by SF/david_corrales, 13 years ago)

Revised GSoC-fsnode to trunk patch

  • home/david/Projects/scummvm/backends/fs/abstract-fs-factory.h

    Property changes on: /home/david/Projects/scummvm
    ___________________________________________________________________
    Name: svn:ignore
       - config.log
    scummvm
    scummvm-static
    config.h
    config.mk
    .gdb_history
    dumps
    Credits.rtf
    *.mshark
    
       + config.log
    scummvm
    scummvm-static
    config.h
    config.mk
    .gdb_history
    dumps
    Credits.rtf
    *.mshark
    reconf.sh
    
    
     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#ifndef ABSTRACT_FILESYSTEM_FACTORY_H
     26#define ABSTRACT_FILESYSTEM_FACTORY_H
     27
     28#include "common/str.h"
     29#include "backends/fs/abstract-fs.h"
     30
     31/**
     32 * Creates concrete FilesystemNode objects depending on the current architecture.
     33 */
     34class AbstractFilesystemFactory {
     35public:
     36        typedef Common::String String;
     37       
     38        /**
     39         * Destructor.
     40         */
     41        virtual ~AbstractFilesystemFactory() {}
     42       
     43        /**
     44         * Returns a node representing the "current directory".
     45         * If your system does not support this concept, you can either try to
     46         * emulate it or simply return some "sensible" default directory node,
     47         * e.g. the same value as getRoot() returns.
     48         */
     49        virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const = 0;
     50       
     51        /**
     52         * Construct a node based on a path; the path is in the same format as it
     53         * would be for calls to fopen().
     54         *
     55         * Furthermore getNodeForPath(oldNode.path()) should create a new node
     56         * identical to oldNode. Hence, we can use the "path" value for persistent
     57         * storage e.g. in the config file.
     58         *
     59         * @param path The path string to create a FilesystemNode for.
     60         */
     61        virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const = 0;
     62       
     63        /**
     64         * Returns a special node representing the filesystem root.
     65         * The starting point for any file system browsing.
     66         *
     67         * On Unix, this will be simply the node for / (the root directory).
     68         * On Windows, it will be a special node which "contains" all drives (C:, D:, E:).
     69         */
     70        virtual AbstractFilesystemNode *makeRootFileNode() const = 0;
     71};
     72
     73#endif /*ABSTRACT_FILESYSTEM_FACTORY_H*/
  • home/david/Projects/scummvm/backends/fs/abstract-fs.h

    Property changes on: /home/david/Projects/scummvm/backends/fs/abstract-fs-factory.h
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    Name: svn:keywords
       + Date Rev Author URL Id
    Name: svn:mime-type
       + text/plain
    
     
    2727
    2828#include "common/array.h"
    2929#include "common/str.h"
    30 
    3130#include "common/fs.h"
    3231
    3332class AbstractFilesystemNode;
     
    4746        friend class FilesystemNode;
    4847        typedef Common::String String;
    4948        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       
    5750        /**
    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
    5952         * exists, returns 0. When called on a non-directory node, it should
    6053         * handle this gracefully by returning 0.
    6154         *
     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         *
    6262         * @note Handling calls on non-dir nodes gracefully makes it possible to
    6363         * 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.
    6466         */
    65         virtual AbstractFilesystemNode *child(const String &name) const = 0;
    66 
     67        virtual AbstractFilesystemNode *getChild(const String &name) const = 0;
    6768
    6869        /**
    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.
    7372         */
    74         static AbstractFilesystemNode *getRoot();
     73        virtual AbstractFilesystemNode *getParent() const = 0;
    7574
     75public:
    7676        /**
    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 referred by this path exists in the filesystem or not.
    8183         */
    82         static AbstractFilesystemNode *getCurrentDirectory();
    83 
     84        virtual bool exists() const = 0;
    8485
    8586        /**
    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).
    9895         */
    99         static AbstractFilesystemNode *getNodeForPath(const String &path);
     96        virtual bool getChildren(AbstractFSList &list, ListMode mode, bool hidden) const = 0;
    10097
    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(); }
    104104
    105         virtual String name() const = 0;
     105        /**
     106         * Returns a string with an architecture dependent path description.
     107         */
     108        virtual String getName() const = 0;
    106109       
    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         */
    112118        virtual bool isDirectory() const = 0;
    113119       
    114120        /**
    115          * Return the 'path' of the current node, usable in fopen(). See also
    116          * the static getNodeForPath() method.
     121         * Indicates whether the object referred by this path can be read from or not.
     122         *
     123         * If the path refers to a directory, readability implies being able to read
     124         * and list the directory entries.
     125         *
     126         * If the path refers to a file, readability implies being able to read the
     127         * contents of the file.
     128         *
     129         * @return bool true if the object can be read, false otherwise.
    117130         */
    118         virtual String path() const = 0;
    119         virtual bool listDir(AbstractFSList &list, ListMode mode) const = 0;
    120 
     131        virtual bool isReadable() const = 0;
     132       
     133        /**
     134         * Indicates whether the object referred by this path can be written to or not.
     135         *
     136         * If the path refers to a directory, writability implies being able to modify
     137         * the directory entry (i.e. rename the directory, remove it or write files inside of it).
     138         *
     139         * If the path refers to a file, writability implies being able to write data
     140         * to the file.
     141         *
     142         * @return bool true if the object can be written to, false otherwise.
     143         */
     144        virtual bool isWritable() const = 0;
    121145
    122146        /* TODO:
    123         bool exists();
    124 
    125         bool isDirectory();
    126147        bool isFile();
    127 
    128         bool isReadable();
    129         bool isWriteable();
    130148        */
    131149};
    132150
    133 
    134 #endif
     151#endif //BACKENDS_ABSTRACT_FS_H
  • home/david/Projects/scummvm/backends/fs/amigaos4/amigaos4-fs-factory.cpp

     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#include "backends/fs/amigaos4/amigaos4-fs-factory.h"
     26#include "backends/fs/amigaos4/amigaos4-fs.cpp"
     27
     28DECLARE_SINGLETON(AmigaOSFilesystemFactory);
     29
     30AbstractFilesystemNode *AmigaOSFilesystemFactory::makeRootFileNode() const {
     31        return new AmigaOSFilesystemNode();
     32}
     33
     34AbstractFilesystemNode *AmigaOSFilesystemFactory::makeCurrentDirectoryFileNode() const {
     35        return new AmigaOSFilesystemNode();
     36}
     37
     38AbstractFilesystemNode *AmigaOSFilesystemFactory::makeFileNodePath(const String &path) const {
     39        return new AmigaOSFilesystemNode(path);
     40}
  • home/david/Projects/scummvm/backends/fs/amigaos4/amigaos4-fs-factory.h

    Property changes on: /home/david/Projects/scummvm/backends/fs/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/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#ifndef AMIGAOS_FILESYSTEM_FACTORY_H
     26#define AMIGAOS_FILESYSTEM_FACTORY_H
     27
     28#include "common/singleton.h"
     29#include "backends/fs/abstract-fs-factory.h"
     30
     31/**
     32 * Creates AmigaOSFilesystemNode objects.
     33 *
     34 * Parts of this class are documented in the base interface class, AbstractFilesystemFactory.
     35 */
     36class AmigaOSFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<AmigaOSFilesystemFactory> {
     37public:
     38        typedef Common::String String;
     39               
     40        virtual AbstractFilesystemNode *makeRootFileNode() const;
     41        virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const;
     42        virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const;
     43       
     44protected:
     45        AmigaOSFilesystemFactory() {};
     46               
     47private:
     48        friend class Common::Singleton<SingletonBaseType>;
     49};
     50
     51#endif /*AMIGAOS_FILESYSTEM_FACTORY_H*/
  • home/david/Projects/scummvm/backends/fs/amigaos4/amigaos4-fs.cpp

    Property changes on: /home/david/Projects/scummvm/backends/fs/amigaos4/amigaos4-fs-factory.h
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    Name: svn:keywords
       + Date Rev Author URL Id
    Name: svn:mime-type
       + text/plain
    
     
    3838#include <common/stdafx.h>
    3939
    4040#include "common/util.h"
    41 
    4241#include "engines/engine.h"
    4342#include "backends/fs/abstract-fs.h"
    4443
     
    4544#define ENTER() /* debug(6, "Enter") */
    4645#define LEAVE() /* debug(6, "Leave") */
    4746
    48 
    4947const uint32 kExAllBufferSize = 40960; // TODO: is this okay for sure?
    5048
     49/**
     50 * Implementation of the ScummVM file system API.
     51 *
     52 * Parts of this class are documented in the base interface class, AbstractFilesystemNode.
     53 */
    5154class AmigaOSFilesystemNode : public AbstractFilesystemNode {
    52         protected:
    53                 BPTR _pFileLock;
    54                 String _sDisplayName;
    55                 bool _bIsDirectory;
    56                 bool _bIsValid;
    57                 String _sPath;
     55protected:
     56        BPTR _pFileLock;
     57        String _sDisplayName;
     58        String _sPath;
     59        bool _bIsDirectory;
     60        bool _bIsValid;
    5861
    59         public:
    60                 AmigaOSFilesystemNode();
    61                 AmigaOSFilesystemNode(BPTR pLock, const char *pDisplayName = 0);
    62                 AmigaOSFilesystemNode(const String &p);
     62public:
     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);
    6379
    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();
    6891
    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;
    79109};
    80110
    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 
    93111AmigaOSFilesystemNode::AmigaOSFilesystemNode() {
    94112        ENTER();
    95113        _sDisplayName = "Available Disks";
     
    100118        LEAVE();
    101119}
    102120
    103 
    104121AmigaOSFilesystemNode::AmigaOSFilesystemNode(const String &p) {
    105122        ENTER();
    106123
     
    150167                                const char c = _sPath.lastChar();
    151168                                if (c != '/' && c != ':')
    152169                                        _sPath += '/';
    153 
    154170                        }
    155171                        else {
    156172                                //_bIsDirectory = false;
     
    170186        int bufSize = MAXPATHLEN;
    171187        _pFileLock = 0;
    172188
    173         while (1) {
     189        while (true) {
    174190                char *n = new char[bufSize];
    175191                if (IDOS->NameFromLock(pLock, (STRPTR)n, bufSize) != DOSFALSE) {
    176192                        _sPath = n;
     
    186202                        delete [] n;
    187203                        return;
    188204                }
     205               
    189206                bufSize *= 2;
    190207                delete [] n;
    191208        }
     
    238255        LEAVE();
    239256}
    240257
    241 bool AmigaOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const {
     258AbstractFilesystemNode *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
     282bool AmigaOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
    242283        ENTER();
    243284
     285        //TODO: honor the hidden flag
     286
    244287        if (!_bIsValid) {
    245288                debug(6, "Invalid node");
    246289                LEAVE();
     
    308351        }
    309352
    310353        LEAVE();
     354       
    311355        return true;
    312356}
    313357
    314 AbstractFilesystemNode *AmigaOSFilesystemNode::parent() const {
     358AbstractFilesystemNode *AmigaOSFilesystemNode::getParent() const {
    315359        ENTER();
    316360
    317361        if (!_bIsDirectory) {
     
    337381                node = new AmigaOSFilesystemNode();
    338382
    339383        LEAVE();
     384       
    340385        return node;
    341386}
    342387
    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 
    369388AbstractFSList AmigaOSFilesystemNode::listVolumes()     const {
    370389        ENTER();
    371390
     
    431450        IDOS->UnLockDosList(kLockFlags);
    432451
    433452        LEAVE();
     453       
    434454        return myList;
    435455}
    436456
    437 #endif
     457#endif //defined(__amigaos4__)
  • home/david/Projects/scummvm/backends/fs/dc/dc-fs.cpp

     
    2525#if defined(__DC__)
    2626
    2727#include "common/stdafx.h"
    28 
    2928#include "backends/fs/abstract-fs.h"
    3029
    3130#include <ronin/cdfs.h>
     
    3231#include <stdio.h>
    3332#include <unistd.h>
    3433
    35 /*
    36  * Implementation of the ScummVM file system API based on ronin.
     34/**
     35 * Implementation of the ScummVM file system API based on Ronin.
     36 *
     37 * Parts of this class are documented in the base interface class, AbstractFilesystemNode.
    3738 */
    38 
    3939class RoninCDFilesystemNode : public AbstractFilesystemNode {
    4040protected:
    4141        String _displayName;
     42        String _path;
    4243        bool _isDirectory;
    4344        bool _isValid;
    44         String _path;
    4545
    4646public:
     47        /**
     48         * Creates a RoninCDFilesystemNode with the root node as path.
     49         */
    4750        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         */
    4858        RoninCDFilesystemNode(const String &path, bool verify);
    4959
    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
    5266        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
    5568
    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;
    5972};
    6073
    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 */
    6284static const char *lastPathComponent(const Common::String &str) {
    6385        const char *start = str.c_str();
    6486        const char *cur = start + str.size() - 2;
     
    7092        return cur + 1;
    7193}
    7294
    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 
    8995RoninCDFilesystemNode::RoninCDFilesystemNode() {
    9096        // The root dir.
    9197        _path = "/";
     
    118124        }
    119125}
    120126
    121 bool RoninCDFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const {
     127AbstractFilesystemNode *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
     140bool RoninCDFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
    122141        assert(_isDirectory);
     142       
     143        //TODO: honor the hidden flag
     144       
    123145        DIR *dirp = opendir(_path.c_str());
    124 
    125146        struct dirent *dp;
    126147
    127148        if (dirp == NULL)
     
    150171
    151172                if (entry._isDirectory)
    152173                        entry._path += "/";
     174                       
    153175                myList.push_back(new RoninCDFilesystemNode(entry));
    154176        }
    155177        closedir(dirp);
     178       
    156179        return true;
    157180}
    158181
    159 AbstractFilesystemNode *RoninCDFilesystemNode::parent() const {
     182AbstractFilesystemNode *RoninCDFilesystemNode::getParent() const {
    160183        if (_path == "/")
    161184                return 0;
    162185
     
    163186        const char *start = _path.c_str();
    164187        const char *end = lastPathComponent(_path);
    165188
    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);
    182190}
    183191
    184192#endif // defined(__DC__)
  • home/david/Projects/scummvm/backends/fs/dc/ronincd-fs-factory.cpp

     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#include "backends/fs/dc/ronincd-fs-factory.h"
     26#include "backends/fs/dc/dc-fs.cpp"
     27
     28DECLARE_SINGLETON(RoninCDFilesystemFactory);
     29
     30AbstractFilesystemNode *RoninCDFilesystemFactory::makeRootFileNode() const {
     31        return new RoninCDFilesystemNode();
     32}
     33
     34AbstractFilesystemNode *RoninCDFilesystemFactory::makeCurrentDirectoryFileNode() const {
     35        return new RoninCDFilesystemNode();
     36}
     37
     38AbstractFilesystemNode *RoninCDFilesystemFactory::makeFileNodePath(const String &path) const {
     39        return new RoninCDFilesystemNode(path, true);
     40}
  • home/david/Projects/scummvm/backends/fs/dc/ronincd-fs-factory.h

    Property changes on: /home/david/Projects/scummvm/backends/fs/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/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#ifndef RONINCD_FILESYSTEM_FACTORY_H
     26#define RONINCD_FILESYSTEM_FACTORY_H
     27
     28#include "common/singleton.h"
     29#include "backends/fs/abstract-fs-factory.h"
     30
     31/**
     32 * Creates RoninCDFilesystemNode objects.
     33 *
     34 * Parts of this class are documented in the base interface class, AbstractFilesystemFactory.
     35 */
     36class RoninCDFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<RoninCDFilesystemFactory> {
     37public:
     38        typedef Common::String String;
     39               
     40        virtual AbstractFilesystemNode *makeRootFileNode() const;
     41        virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const;
     42        virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const;
     43       
     44protected:
     45        RoninCDFilesystemFactory() {};
     46               
     47private:
     48        friend class Common::Singleton<SingletonBaseType>;
     49};
     50
     51#endif /*RONINCD_FILESYSTEM_FACTORY_H*/
  • home/david/Projects/scummvm/backends/fs/ds/ds-fs-factory.cpp

    Property changes on: /home/david/Projects/scummvm/backends/fs/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/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#include "backends/fs/ds/ds-fs-factory.h"
     26#include "backends/fs/ds/ds-fs.cpp"
     27#include "dsmain.h" //for the isGBAMPAvailable() function
     28
     29DECLARE_SINGLETON(DSFilesystemFactory);
     30
     31AbstractFilesystemNode *DSFilesystemFactory::makeRootFileNode() const {
     32        if (DS::isGBAMPAvailable()) {
     33                return new DS::GBAMPFileSystemNode();
     34        } else {
     35                return new DS::DSFileSystemNode();
     36        }
     37}
     38
     39AbstractFilesystemNode *DSFilesystemFactory::makeCurrentDirectoryFileNode() const {
     40        if (DS::isGBAMPAvailable()) {
     41                return new DS::GBAMPFileSystemNode();
     42        } else {
     43                return new DS::DSFileSystemNode();
     44        }
     45}
     46
     47AbstractFilesystemNode *DSFilesystemFactory::makeFileNodePath(const String &path) const {
     48        if (DS::isGBAMPAvailable()) {
     49                return new DS::GBAMPFileSystemNode(path);
     50        } else {
     51                return new DS::DSFileSystemNode(path);
     52        }
     53}
  • home/david/Projects/scummvm/backends/fs/ds/ds-fs-factory.h

    Property changes on: /home/david/Projects/scummvm/backends/fs/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/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#ifndef DS_FILESYSTEM_FACTORY_H
     26#define DS_FILESYSTEM_FACTORY_H
     27
     28#include "common/singleton.h"
     29#include "backends/fs/abstract-fs-factory.h"
     30
     31/**
     32 * Creates DSFilesystemNode objects.
     33 *
     34 * Parts of this class are documented in the base interface class, AbstractFilesystemFactory.
     35 */
     36class DSFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<DSFilesystemFactory> {   
     37public:
     38        typedef Common::String String;
     39               
     40        virtual AbstractFilesystemNode *makeRootFileNode() const;
     41        virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const;
     42        virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const;
     43       
     44protected:
     45        DSFilesystemFactory() {};
     46               
     47private:
     48        friend class Common::Singleton<SingletonBaseType>;
     49};
     50
     51#endif /*DS_FILESYSTEM_FACTORY_H*/
  • home/david/Projects/scummvm/backends/fs/ds/ds-fs.cpp

    Property changes on: /home/david/Projects/scummvm/backends/fs/ds/ds-fs-factory.h
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    Name: svn:keywords
       + Date Rev Author URL Id
    Name: svn:mime-type
       + text/plain
    
     
    2020 *
    2121 */
    2222
    23 
    2423#include "stdafx.h"
    2524#include "str.h"
    26 #include "fs.h"
    2725#include "common/util.h"
    2826//#include <NDS/ARM9/console.h> //basic print funcionality
    2927#include "ds-fs.h"
     
    3028#include "dsmain.h"
    3129#include "gba_nds_fat.h"
    3230
    33 
    3431namespace DS {
    3532
    36 
    37 
    38 
    3933//////////////////////////////////////////////////////////////
    40 // DSFileSystemNode - Flash ROM file system using Zip files
     34// DSFileSystemNode - Flash ROM file system using Zip files //
    4135//////////////////////////////////////////////////////////////
    4236
    4337ZipFile*        DSFileSystemNode::_zipFile = NULL;
     
    6660        char disp[128];
    6761        char* pathStr = (char *) path.c_str();
    6862       
    69        
    7063        int lastSlash = 3;
    7164        for (int r = 0; r < (int) strlen(pathStr) - 1; r++) {
    7265                if (path[r] == '\\') {
     
    8174//      _isValid = true;
    8275//      _isDirectory = false;
    8376
    84 
    85 
    8677        if (!strncmp(pathStr, "ds:/", 4)) {
    8778                pathStr += 4;
    8879        }
     
    8778                pathStr += 4;
    8879        }
    8980       
    90 
    9181        if (*pathStr == '\0') {
    9282                _isValid = true;
    9383                _isDirectory = true;
     
    130120}
    131121
    132122DSFileSystemNode::DSFileSystemNode(const DSFileSystemNode* node) {
    133 
     123        //TODO: not implemented?
    134124}
    135125
    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 {
     126AbstractFilesystemNode *DSFileSystemNode::getChild(const Common::String& n) const {
    162127        if (_path.lastChar() == '\\') {
    163128                return new DSFileSystemNode(_path + n);
    164129        } else {
     
    168133        return NULL;
    169134}
    170135
    171 
    172 bool DSFileSystemNode::listDir(AbstractFSList &dirList, ListMode mode) const {
     136bool DSFileSystemNode::getChildren(AbstractFSList &dirList, ListMode mode, bool hidden) const {
    173137//      consolePrintf("Listdir\n");
    174 
    175        
    176138//      consolePrintf("Directory\n");
    177139
    178        
     140        //TODO: honor the hidden flag
     141
    179142        char temp[128];
    180143        strcpy(temp, _path.c_str());
    181144
     
    190153/*                      // This is the root dir, so add the RAM folder
    191154                        DSFileSystemNode* dsfsn = new DSFileSystemNode("ds:/ram");
    192155                        dsfsn->_isDirectory = true;
    193                         dirList->push_back(wrap(dsfsn));*/
     156                        dirList->push_back(wrap(dsfsn));
     157*/
    194158                }
    195159        } else {
    196160                _zipFile->changeDirectory(temp);
     
    196160                _zipFile->changeDirectory(temp);
    197161        }
    198162       
    199        
    200        
    201163        if (_zipFile->restartFile()) {
    202164                do {
    203165                        char n[128];   
     
    218180        return true;
    219181}
    220182
     183AbstractFilesystemNode* 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                }
    221196
     197                p = new DSFileSystemNode(String(path, lastSlash));
     198                ((DSFileSystemNode *) (p))->_isDirectory = true;
     199        } else {
     200                p = new DSFileSystemNode();
     201        }
    222202
     203        return p;
     204}
    223205
    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//////////////////////////////////////////////////////////////////////////
    227209
    228210GBAMPFileSystemNode::GBAMPFileSystemNode() {
    229211        _displayName = "mp:/";
     
    290272
    291273
    292274GBAMPFileSystemNode::GBAMPFileSystemNode(const GBAMPFileSystemNode* node) {
    293 
     275        //TODO: not implemented?
    294276}
    295277
    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 {
     278AbstractFilesystemNode *GBAMPFileSystemNode::getChild(const Common::String& n) const {
    322279        if (_path.lastChar() == '\\') {
    323280                return new DSFileSystemNode(_path + n);
    324281        } else {
     
    328285        return NULL;
    329286}
    330287
    331 bool GBAMPFileSystemNode::listDir(AbstractFSList& dirList, ListMode mode) const {
     288bool GBAMPFileSystemNode::getChildren(AbstractFSList& dirList, ListMode mode, bool hidden) const {
    332289//      consolePrintf("Listdir\n");
    333290
     291        //TODO: honor the hidden flag
     292
    334293        enum { TYPE_NO_MORE = 0, TYPE_FILE = 1, TYPE_DIR = 2 };
    335294       
    336295        char temp[128], fname[128], *path, *pathTemp;
     
    346305                pathTemp++;
    347306        }
    348307
    349 
    350308//      consolePrintf("This dir: %s\n", path);
    351309        FAT_chdir(path);
    352310       
     
    369327//                              dsfsn->_isDirectory = entryType == DIR;
    370328                                dirList.push_back((dsfsn));
    371329                        }
    372                
    373                
    374330                } else {
    375331//                      consolePrintf("Skipping %s\n", fname);
    376332                }
     
    385341        return true;
    386342}
    387343
     344AbstractFilesystemNode* 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}
    388366
    389367// Stdio replacements
    390368#define MAX_FILE_HANDLES 32
     
    393371DS::fileHandle handle[MAX_FILE_HANDLES];
    394372
    395373FILE* std_fopen(const char* name, const char* mode) {
    396 
    397        
    398 
    399374        if (!inited) {
    400375                for (int r = 0; r < MAX_FILE_HANDLES; r++) {
    401376                        handle[r].used = false;
     
    403378                inited = true;
    404379                currentDir[0] = '\0';
    405380        }
    406 
    407 
    408        
    409381       
    410382        char* realName = (char *) name;
    411383       
     
    413385        if ((name[0] == 'd') && (name[1] == 's') && (name[2] == ':') && (name[3] == '/')) {
    414386                realName += 4;
    415387        }
    416 
     388       
    417389        if ((name[0] == 'm') && (name[1] == 'p') && (name[2] == ':') && (name[3] == '/')) {
    418390                realName += 4;
    419391        }
     
    421393//      consolePrintf("Open file:");
    422394//      consolePrintf("'%s', [%s]", realName, mode);
    423395
    424 
    425396        if (DS::isGBAMPAvailable()) {
    426397                FAT_chdir("/");
    427398               
     
    443414               
    444415                return (FILE *) result;
    445416        }
    446 
    447417       
    448418        // Fail to open file for writing.  It's in ROM!
    449 
     419       
    450420        // Allocate a file handle
    451421        int r = 0;
    452422        while (handle[r].used) r++;
     
    459429                handle[r].sramFile = (DSSaveFile *) DSSaveFileManager::instance()->openSavefile(realName, false);
    460430        }
    461431
    462        
    463432        if (handle[r].sramFile) {
    464433                handle[r].used = true;
    465434                handle[r].pos = 0;
     
    513482                return NULL;
    514483        }
    515484}
     485
    516486void std_fclose(FILE* handle) {
    517487
    518488        if (DS::isGBAMPAvailable()) {
     
    528498}
    529499
    530500size_t std_fread(const void* ptr, size_t size, size_t numItems, FILE* handle) {
    531 
    532501//      consolePrintf("fread %d,%d %d ", size, numItems, ptr);
    533        
    534        
    535502
    536503        if (DS::isGBAMPAvailable()) {
    537        
    538                
    539504                int bytes = FAT_fread((void *) ptr, size, numItems, (FAT_FILE *) handle);
    540505                if (!std_feof(handle)) {
    541506                        return numItems;
     
    560525               
    561526                }
    562527               
    563                 return item;*/
    564 
    565 
     528                return item;
     529*/
    566530                int items = 0;
    567531       
    568532                //for (int r = 0; r < numItems; r++) {
     
    567531       
    568532                //for (int r = 0; r < numItems; r++) {
    569533                        if (!std_feof(handle)) {
    570                                
    571 
    572                                
    573534/*                              for (int t = 0; t < size; t++) {
    574535                                        if (feof(handle)) eof = true;
    575536                                        *(((char *) (ptr)) + r * size + t) = getc(handle);
     
    576537                                }*/
    577538                                int left = size * numItems;
    578539                                int bytesRead = -1;
     540                               
    579541                                while ((left > 0) && (!FAT_feof((FAT_FILE *) handle))) {
    580542                                        int amount = left > 8192? 8192: left;
    581543//                                      do {
     
    580542                                        int amount = left > 8192? 8192: left;
    581543//                                      do {
    582544                                                bytesRead = FAT_fread((void *) ptr, 1, amount, (FAT_FILE *) handle);
    583         /*                                      if (bytesRead == 0) {
     545/*                                              if (bytesRead == 0) {
    584546                                                        consolePrintf("Pos:%d items:%d num:%d amount:%d read:%d\n", ftell(handle), items, numItems, amount, bytesRead);
    585547                                                        left++;
    586548                                                       
     
    592554                                                        fread(ptr, 1024, 1, handle);
    593555                                                        swiWaitForVBlank();
    594556                                                        //while (true);
    595                                                 }*/
    596                                         //} while (bytesRead == 0);
     557                                                }
     558
     559                                        } while (bytesRead == 0);
     560*/
    597561                                        left -= bytesRead;
    598562                                        ptr = ((char *) (ptr)) + bytesRead;                             
    599563                                }
     
    599563                                }
    600564                               
    601565                                items = numItems - (left / size);
    602                                
    603                        
    604                
    605                                
     566
    606567//                              FAT_fread((void *) ptr, size, 1, ((int) (handle)) - 1);
    607         //                      ptr = ((char *) (ptr)) + size;
    608                                
     568//                              ptr = ((char *) (ptr)) + size; 
    609569                        }
    610                 //}
     570//              }
    611571               
    612572//              consolePrintf("...done %d \n", items)
    613573
     
    612572//              consolePrintf("...done %d \n", items)
    613573
    614574                return items;
    615                
    616575        }
    617576       
    618577        if (handle->sramFile) {
     
    630589                return bytes / size;
    631590        }
    632591
    633 
    634592        if (handle->pos + size * numItems > handle->size) {
    635593                numItems = (handle->size - handle->pos) / size;
    636594                if (numItems < 0) numItems = 0;
     
    639597//      consolePrintf("read %d  ", size * numItems);
    640598
    641599        memcpy((void *) ptr, handle->data + handle->pos, size * numItems);
    642 
    643600        handle->pos += size * numItems;
    644601
    645        
    646602        return numItems;
    647603}
    648604
     
    657613        //consolePrintf("fwrite size=%d\n", size * numItems);
    658614
    659615        if (DS::isGBAMPAvailable()) {
    660 
    661616                FAT_fwrite(((char *) (ptr)), size, numItems, (FAT_FILE *) handle);
    662617                return numItems;
    663618               
     
    675630                return numItems;
    676631        }
    677632
    678 
    679633        if (handle->sramFile) {
    680634                handle->sramFile->write(ptr, size);
    681635                return size;
     
    704658}
    705659
    706660void std_fflush(FILE* handle) {
     661        //FIXME: not implemented?
    707662//      consolePrintf("fflush ");
    708663}
    709664
     
    711666//      consolePrintf("fgets file=%d ", file);
    712667       
    713668        if (DS::isGBAMPAvailable()) {
    714                
    715669                char* s = str;
    716670                while ((*s++ = std_getc(file)) >= 32) {
    717671//                      consolePrintf("%d ", *s);
     
    723677                return str;
    724678        }
    725679       
    726        
    727680        if (file->sramFile) {
    728681                file->pos--;
    729682                int p = -1;
     
    743696}
    744697
    745698long int std_ftell(FILE* handle) {
    746 
    747699        if (DS::isGBAMPAvailable()) {
    748700                return FAT_ftell((FAT_FILE *) handle);
    749701        }
     
    758710                return FAT_fseek((FAT_FILE *) handle, offset, whence);
    759711        }
    760712
    761 
    762713        switch (whence) {
    763                 case SEEK_CUR: {
     714                case SEEK_CUR:
    764715                        handle->pos += offset;
    765716                        break;
    766                 }
    767                
    768                 case SEEK_SET: {
     717                case SEEK_SET:
    769718                        handle->pos = offset;
    770719                        break;
    771                 }
    772                
    773                 case SEEK_END: {
     720                case SEEK_END:
    774721                        handle->pos = handle->size + offset;
    775722                        break;
    776                 }
    777                
    778                 default: {
     723                default:
    779724                        handle->pos = offset;
    780725                        break;
    781                 }
    782                
    783726        }
    784727       
    785728        return 0;
     
    786729}
    787730
    788731void std_clearerr(FILE* handle) {
     732        //FIXME: not implemented?
    789733//      consolePrintf("clearerr ");
    790734}
    791735
     
    790734}
    791735
    792736int std_getc(FILE* handle) {
    793 
    794737        if (DS::isGBAMPAvailable()) {
    795738                char c;
    796739                FAT_fread(&c, 1, 1, (FAT_FILE *) handle);
     
    852795}
    853796
    854797} // 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 }
  • home/david/Projects/scummvm/backends/fs/ds/ds-fs.h

     
    2323#ifndef _DS_FS_H
    2424#define _DS_FS_H
    2525
    26 
    27 
    2826//#include <NDS/ARM9/console.h>
    2927#include "fs.h"
    3028#include "zipreader.h"
     
    3230#include "scummconsole.h"
    3331#include "gba_nds_fat.h"
    3432#include "backends/fs/abstract-fs.h"
    35 //#include "backends/fs/fs.h"
    3633
    3734namespace DS {
    3835
     
    3734namespace DS {
    3835
    3936/**
     37 * Implementation of the ScummVM file system API.
    4038 * 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.
    4141 */
    4242class DSFileSystemNode : public AbstractFilesystemNode {
    4343protected:
    44         static ZipFile* _zipFile;
    45 
    4644        typedef class Common::String String;
    4745
     46        static ZipFile* _zipFile;
     47
    4848        String _displayName;
     49        String _path;
    4950        bool _isDirectory;
    5051        bool _isValid;
    51         String _path;
    5252        int _refCountVal;
    5353       
    5454public:
     55        /**
     56         * Creates a DSFilesystemNode with the root node as path.
     57         */
    5558        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         */
    5665        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         */
    5873        DSFileSystemNode(const String& path, bool isDir);
    5974       
    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; }
    6384        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
    6588       
    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         */
    6892        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         */
    70101        static ZipFile* getZip() { return _zipFile; }
    71102};
    72103
    73 
    74 /**
     104 /**
     105 * Implementation of the ScummVM file system API.
    75106 * 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.
    76109 */
    77110class GBAMPFileSystemNode : public AbstractFilesystemNode {
    78111protected:
     
    79112        typedef class Common::String String;
    80113
    81114        String _displayName;
     115        String _path;
    82116        bool _isDirectory;
    83117        bool _isValid;
    84         String _path;
    85        
    86118        int _refCountVal;
    87119       
    88120public:
     121        /**
     122         * Creates a GBAMPFilesystemNode with the root node as path.
     123         */
    89124        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         */
    90131        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         */
    91139        GBAMPFileSystemNode(const String &path, bool isDirectory);
     140       
     141        /**
     142         * Copy constructor.
     143         */
    92144        GBAMPFileSystemNode(const GBAMPFileSystemNode *node);
    93145
    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
    96154       
    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         */
    102158        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;
    105162};
    106163
    107 
    108 
    109 
    110164struct fileHandle {
    111165        int pos;
    112166        bool used;
     
    116170        DSSaveFile* sramFile;
    117171};
    118172
    119 
    120173#undef stderr
    121174#undef stdout
    122175#undef stdin
     
    140193void    std_cwd(char* dir);
    141194void    std_fflush(FILE* handle);
    142195
    143 }
     196} //namespace DS
    144197
    145 #endif
     198#endif //_DS_FS_H
  • home/david/Projects/scummvm/backends/fs/fs-factory-maker.cpp

     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#include "backends/fs/abstract-fs-factory.h"
     26
     27/*
     28 * All the following includes choose, at compile time, which specific backend will be used
     29 * during the execution of the ScummVM.
     30 *
     31 * It has to be done this way because not all the necessary libraries will be available in
     32 * all build environments. Additionally, this results in smaller binaries.
     33 */
     34#if defined(__amigaos4__)
     35        #include "backends/fs/amigaos4/amigaos4-fs-factory.cpp"
     36#elif defined(__DC__)
     37        #include "backends/fs/dc/ronincd-fs-factory.cpp"
     38#elif defined(__DS__)
     39        #include "backends/fs/ds/ds-fs-factory.cpp"
     40#elif defined(__GP32__)
     41        #include "backends/fs/gp32/gp32-fs-factory.cpp"
     42#elif defined(__MORPHOS__)
     43        #include "backends/fs/morphos/abox-fs-factory.cpp"
     44#elif defined(PALMOS_MODE)
     45        #include "backends/fs/palmos/palmos-fs-factory.cpp"
     46#elif defined(__PLAYSTATION2__)
     47        #include "backends/fs/ps2/ps2-fs-factory.cpp"
     48#elif defined(__PSP__)
     49        #include "backends/fs/psp/psp-fs-factory.cpp"
     50#elif defined(__SYMBIAN32__)
     51        #include "backends/fs/symbian/symbian-fs-factory.cpp"
     52#elif defined(UNIX)
     53        #include "backends/fs/posix/posix-fs-factory.cpp"
     54#elif defined(WIN32)
     55        #include "backends/fs/windows/windows-fs-factory.cpp"
     56#endif
     57
     58/**
     59 * Creates concrete FilesystemFactory objects depending on the current architecture.
     60 *
     61 * @return AbstractFilesystemFactory* The specific factory for the current architecture.
     62 */
     63static AbstractFilesystemFactory *makeFSFactory() {
     64        #if defined(__amigaos4__)
     65                return &AmigaOSFilesystemFactory::instance();
     66        #elif defined(__DC__)
     67                return &RoninCDFilesystemFactory::instance();
     68        #elif defined(__DS__)
     69                return &DSFilesystemFactory::instance();
     70        #elif defined(__GP32__)
     71                return &GP32FilesystemFactory::instance();
     72        #elif defined(__MORPHOS__)
     73                return &ABoxFilesystemFactory::instance();
     74        #elif defined(PALMOS_MODE)
     75                return &PalmOSFilesystemFactory::instance();
     76        #elif defined(__PLAYSTATION2__)
     77                return &Ps2FilesystemFactory::instance();
     78        #elif defined(__PSP__)
     79                return &PSPFilesystemFactory::instance();
     80        #elif defined(__SYMBIAN32__)
     81                return &SymbianFilesystemFactory::instance();
     82        #elif defined(UNIX)
     83                return &POSIXFilesystemFactory::instance();
     84        #elif defined(WIN32)
     85                return &WindowsFilesystemFactory::instance();
     86        #endif
     87}
  • home/david/Projects/scummvm/backends/fs/gp32/gp32-fs-factory.cpp

    Property changes on: /home/david/Projects/scummvm/backends/fs/fs-factory-maker.cpp
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    Name: svn:keywords
       + Date Rev Author URL Id
    Name: svn:mime-type
       + text/plain
    
     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#include "backends/fs/gp32/gp32-fs-factory.h"
     26#include "backends/fs/gp32/gp32-fs.cpp"
     27
     28DECLARE_SINGLETON(GP32FilesystemFactory);
     29
     30AbstractFilesystemNode *GP32FilesystemFactory::makeRootFileNode() const {
     31        return new GP32FilesystemNode();
     32}
     33
     34AbstractFilesystemNode *GP32FilesystemFactory::makeCurrentDirectoryFileNode() const {
     35        return new GP32FilesystemNode();
     36}
     37
     38AbstractFilesystemNode *GP32FilesystemFactory::makeFileNodePath(const String &path) const {
     39        return new GP32FilesystemNode(path);
     40}
  • home/david/Projects/scummvm/backends/fs/gp32/gp32-fs-factory.h

    Property changes on: /home/david/Projects/scummvm/backends/fs/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/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#ifndef GP32_FILESYSTEM_FACTORY_H
     26#define GP32_FILESYSTEM_FACTORY_H
     27
     28#include "common/singleton.h"
     29#include "backends/fs/abstract-fs-factory.h"
     30
     31/**
     32 * Creates GP32FilesystemNode objects.
     33 *
     34 * Parts of this class are documented in the base interface class, AbstractFilesystemFactory.
     35 */
     36class GP32FilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<GP32FilesystemFactory> {       
     37public:
     38        typedef Common::String String;
     39               
     40        virtual AbstractFilesystemNode *makeRootFileNode() const;
     41        virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const;
     42        virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const;
     43       
     44protected:
     45        GP32FilesystemFactory() {};
     46               
     47private:
     48        friend class Common::Singleton<SingletonBaseType>;
     49};
     50
     51#endif /*GP32_FILESYSTEM_FACTORY_H*/
  • home/david/Projects/scummvm/backends/fs/gp32/gp32-fs.cpp

    Property changes on: /home/david/Projects/scummvm/backends/fs/gp32/gp32-fs-factory.h
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    Name: svn:keywords
       + Date Rev Author URL Id
    Name: svn:mime-type
       + text/plain
    
     
    2424 */
    2525
    2626#include "stdafx.h"
     27#include "backends/fs/abstract-fs.h"
    2728
    28 #include "backends/fs/abstract-fs.h"
     29#define MAX_PATH_SIZE 256
    2930
     31/**
     32 * Implementation of the ScummVM file system API.
     33 *
     34 * Parts of this class are documented in the base interface class, AbstractFilesystemNode.
     35 */
    3036class GP32FilesystemNode : public AbstractFilesystemNode {
    3137protected:
    3238        String _displayName;
     39        String _path;
    3340        bool _isDirectory;
    3441        bool _isRoot;
    35         String _path;
    3642
    3743public:
     44        /**
     45         * Creates a GP32FilesystemNode with the root node as path.
     46         */
    3847        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         */
    3954        GP32FilesystemNode(const String &path);
    4055
    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; }
    4361        // 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
    4564        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
    4866
    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;
    5270};
    5371
    54 #define MAX_PATH_SIZE 256
    55 
    5672const char gpRootPath[] = "gp:\\";
    5773//char gpCurrentPath[MAX_PATH_SIZE] = "gp:\\";          // must end with '\'
    5874
     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 */
     85static 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 */
    59102int gpMakePath(const char *path, char *convPath) {
    60103        // copy root or current directory
    61104        const char *p;
     
    106149        return 0;
    107150}
    108151
    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 
    121152GP32FilesystemNode::GP32FilesystemNode() {
    122153        _isDirectory = true;
    123154        _isRoot = true;
     
    132163        gpMakePath(path.c_str(), convPath);
    133164
    134165        _path = convPath;
    135 
    136166        pos = convPath;
     167       
    137168        while (*pos)
    138169                if (*pos++ == '\\')
    139170                        dsplName = pos;
     
    150181        _isDirectory = true;
    151182}
    152183
    153 bool GP32FilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const {
     184AbstractFilesystemNode *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.
    154187        assert(_isDirectory);
     188       
     189        String newPath(_path);
     190        if (_path.lastChar() != '\\')
     191                newPath += '\\';
     192        newPath += n;
     193
     194        return new GP32FilesystemNode(newPath);
     195}
     196
     197bool GP32FilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
     198        assert(_isDirectory);
     199
     200        //TODO: honor the hidden flag
    155201
    156202        GPDIRENTRY dirEntry;
    157203        GPFILEATTR attr;
    158 
    159204        GP32FilesystemNode entry;
    160 
    161205        uint32 read;
    162206
    163207        if (mode == FilesystemNode::kListAll)
     
    168212        int startIdx = 0; // current file
    169213        String listDir(_path);
    170214        //listDir += "/";
     215       
    171216        while (GpDirEnumList(listDir.c_str(), startIdx++, 1, &dirEntry, &read)  == SM_OK) {
    172217                if (dirEntry.name[0] == '.')
    173218                        continue;
     219                       
    174220                entry._displayName = dirEntry.name;
    175221                entry._path = _path;
    176222                entry._path += dirEntry.name;
     
    194240        return true;
    195241}
    196242
    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 {
     243AbstractFilesystemNode *GP32FilesystemNode::getParent() const {
    209244        if(_isRoot)
    210245                return 0;
    211246
     
    218253
    219254        return p;
    220255}
    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 }
  • home/david/Projects/scummvm/backends/fs/morphos/abox-fs-factory.cpp

     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#include "backends/fs/morphos/abox-fs-factory.h"
     26#include "backends/fs/morphos/abox-fs.cpp"
     27
     28DECLARE_SINGLETON(ABoxFilesystemFactory);
     29
     30AbstractFilesystemNode *ABoxFilesystemFactory::makeRootFileNode() const {
     31        return new ABoxFilesystemNode();
     32}
     33
     34AbstractFilesystemNode *ABoxFilesystemFactory::makeCurrentDirectoryFileNode() const {
     35        return new ABoxFilesystemNode();
     36}
     37
     38AbstractFilesystemNode *ABoxFilesystemFactory::makeFileNodePath(const String &path) const {
     39        return new ABoxFilesystemNode(path);
     40}
  • home/david/Projects/scummvm/backends/fs/morphos/abox-fs-factory.h

    Property changes on: /home/david/Projects/scummvm/backends/fs/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/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#ifndef ABOX_FILESYSTEM_FACTORY_H
     26#define ABOX_FILESYSTEM_FACTORY_H
     27
     28#include "common/singleton.h"
     29#include "backends/fs/abstract-fs-factory.h"
     30
     31/**
     32 * Creates ABoxFilesystemNode objects.
     33 *
     34 * Parts of this class are documented in the base interface class, AbstractFilesystemFactory.
     35 */
     36class ABoxFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<ABoxFilesystemFactory> {       
     37public:
     38        typedef Common::String String;
     39               
     40        virtual AbstractFilesystemNode *makeRootFileNode() const;
     41        virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const;
     42        virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const;
     43       
     44protected:
     45        ABoxFilesystemFactory() {};
     46               
     47private:
     48        friend class Common::Singleton<SingletonBaseType>;
     49};
     50
     51#endif /*ABOX_FILESYSTEM_FACTORY_H*/
  • home/david/Projects/scummvm/backends/fs/morphos/abox-fs.cpp

    Property changes on: /home/david/Projects/scummvm/backends/fs/morphos/abox-fs-factory.h
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    Name: svn:keywords
       + Date Rev Author URL Id
    Name: svn:mime-type
       + text/plain
    
     
    3535#include "base/engine.h"
    3636#include "backends/fs/abstract-fs.h"
    3737
    38 /*
     38/**
    3939 * 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.
    4042 */
    41 
    4243class ABoxFilesystemNode : public AbstractFilesystemNode {
    43         protected:
    44                 BPTR _lock;
    45                 String _displayName;
    46                 bool _isDirectory;
    47                 bool _isValid;
    48                 String _path;
     44protected:
     45        BPTR _lock;
     46        String _displayName;
     47        String _path;
     48        bool _isDirectory;
     49        bool _isValid;
    4950
    50         public:
    51                 ABoxFilesystemNode();
    52                 ABoxFilesystemNode(BPTR lock, CONST_STRPTR display_name = NULL);
    53                 ABoxFilesystemNode(const String &p);
    54                 ABoxFilesystemNode(const ABoxFilesystemNode &node);
     51public:
     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);
    5573
    56                 ~ABoxFilesystemNode();
     74        /**
     75         * Destructor.
     76         */
     77        ~ABoxFilesystemNode();
    5778
    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();
    6896};
    6997
    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 
    8498ABoxFilesystemNode::ABoxFilesystemNode()
    8599{
    86100        _displayName = "Mounted Volumes";
     
    90104        _lock = NULL;
    91105}
    92106
    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 
    144107ABoxFilesystemNode::ABoxFilesystemNode(const String &p) {
    145108        int len = 0, offset = p.size();
    146109
     
    168131        }
    169132
    170133        // Check whether the node exists and if it is a directory
    171 
    172134        BPTR pLock = Lock((STRPTR)_path.c_str(), SHARED_LOCK);
    173135        if (pLock)
    174136        {
     
    198160        FreeDosObject(DOS_FIB, fib);
    199161}
    200162
     163ABoxFilesystemNode::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
    201215ABoxFilesystemNode::ABoxFilesystemNode(const ABoxFilesystemNode& node)
    202216{
    203217        _displayName = node._displayName;
     
    216230        }
    217231}
    218232
    219 bool ABoxFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const
     233AbstractFilesystemNode *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
     253bool ABoxFilesystemNode::getChildren(AbstractFSList &list, ListMode mode, bool hidden) const
    220254{
     255        //TODO: honor the hidden flag
     256       
    221257        if (!_isValid)
    222258        {
    223259                debug(6, "listDir() called on invalid node");
     
    232268        if (_lock == NULL)
    233269        {
    234270                /* This is the root node */
    235                 myList = listRoot();
     271                list = getRootChildren();
    236272                return true;
    237273        }
    238274
     
    266302                                        if (entry)
    267303                                        {
    268304                                                if (entry->isValid())
    269                                                         myList.push_back(entry);
     305                                                        list.push_back(entry);
    270306                                                else
    271307                                                        delete entry;
    272308                                        }
     
    284320        return true;
    285321}
    286322
    287 AbstractFilesystemNode *ABoxFilesystemNode::parent() const
     323AbstractFilesystemNode *ABoxFilesystemNode::getParent() const
    288324{
    289325        AbstractFilesystemNode *node = NULL;
    290326
     
    309345        return node;
    310346}
    311347
    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()
     348AbstractFSList ABoxFilesystemNode::getRootChildren()
    333349{
    334         AbstractFSList myList;
     350        AbstractFSList list;
    335351        DosList *dosList;
    336352        CONST ULONG lockDosListFlags = LDF_READ | LDF_VOLUMES;
    337353        char name[256];
     
    339355        dosList = LockDosList(lockDosListFlags);
    340356        if (dosList == NULL)
    341357        {
    342                 return myList;
     358                return list;
    343359        }
    344360
    345361        dosList = NextDosEntry(dosList, LDF_VOLUMES);
     
    345361        dosList = NextDosEntry(dosList, LDF_VOLUMES);
    346362        while (dosList)
    347363        {
    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
    351367                        )
    352368                {
    353369                        ABoxFilesystemNode *entry;
     
    365381                                if (entry)
    366382                                {
    367383                                        if (entry->isValid())
    368                                                 myList.push_back(entry);
     384                                                list.push_back(entry);
    369385                                        else
    370386                                                delete entry;
    371387                                }
     
    377393
    378394        UnLockDosList(lockDosListFlags);
    379395
    380         return myList;
     396        return list;
    381397}
    382398
    383399#endif // defined(__MORPHOS__)
    384 
    385 
  • home/david/Projects/scummvm/backends/fs/palmos/palmos-fs-factory.cpp

     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#include "backends/fs/palmos/palmos-fs-factory.h"
     26#include "backends/fs/palmos/palmos-fs.cpp"
     27
     28DECLARE_SINGLETON(PalmOSFilesystemFactory);
     29
     30AbstractFilesystemNode *PalmOSFilesystemFactory::makeRootFileNode() const {
     31        return new PalmOSFilesystemNode();
     32}
     33
     34AbstractFilesystemNode *PalmOSFilesystemFactory::makeCurrentDirectoryFileNode() const {
     35        return new PalmOSFilesystemNode();
     36}
     37
     38AbstractFilesystemNode *PalmOSFilesystemFactory::makeFileNodePath(const String &path) const {
     39        return new PalmOSFilesystemNode(path);
     40}
  • home/david/Projects/scummvm/backends/fs/palmos/palmos-fs-factory.h

    Property changes on: /home/david/Projects/scummvm/backends/fs/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/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#ifndef PALMOS_FILESYSTEM_FACTORY_H
     26#define PALMOS_FILESYSTEM_FACTORY_H
     27
     28#include "common/singleton.h"
     29#include "backends/fs/abstract-fs-factory.h"
     30
     31/**
     32 * Creates PalmOSFilesystemNode objects.
     33 *
     34 * Parts of this class are documented in the base interface class, AbstractFilesystemFactory.
     35 */
     36class PalmOSFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<PalmOSFilesystemFactory> {   
     37public:
     38        typedef Common::String String;
     39               
     40        virtual AbstractFilesystemNode *makeRootFileNode() const;
     41        virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const;
     42        virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const;
     43       
     44protected:
     45        PalmOSFilesystemFactory() {};
     46               
     47private:
     48        friend class Common::Singleton<SingletonBaseType>;
     49};
     50
     51#endif /*PALMOS_FILESYSTEM_FACTORY_H*/
  • home/david/Projects/scummvm/backends/fs/palmos/palmos-fs.cpp

    Property changes on: /home/david/Projects/scummvm/backends/fs/palmos/palmos-fs-factory.h
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    Name: svn:keywords
       + Date Rev Author URL Id
    Name: svn:mime-type
       + text/plain
    
     
    3030#include "common/stdafx.h"
    3131#include "backends/fs/abstract-fs.h"
    3232
    33 /*
     33/**
    3434 * 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.
    3537 */
    36 
    3738class PalmOSFilesystemNode : public AbstractFilesystemNode {
    3839protected:
    3940        String _displayName;
     41        String _path;
    4042        bool _isDirectory;
    4143        bool _isValid;
    4244        bool _isPseudoRoot;
    43         String _path;
    4445       
    4546public:
     47        /**
     48         * Creates a PalmOSFilesystemNode with the root node as path.
     49         */
    4650        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         */
    4757        PalmOSFilesystemNode(const String &p);
    4858
    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
    5165        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
    5467
    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;
    5871
    5972private:
    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);
    6183};
    6284
     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 */
    6395static const char *lastPathComponent(const Common::String &str) {
    6496        const char *start = str.c_str();
    6597        const char *cur = start + str.size() - 2;
     
    95127        list.push_back(new PalmOSFilesystemNode(entry));
    96128}
    97129
    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 
    111130PalmOSFilesystemNode::PalmOSFilesystemNode() {
    112131        _isDirectory = true;
    113132        _displayName = "Root";
     
    122141
    123142        UInt32 attr;
    124143        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);
    128147                VFSFileClose(handle);
    129148        }
    130149
    131         if (e) {
     150        if (error) {
    132151                _isValid = false;
    133152                _isDirectory = false;
    134153
     
    139158        _isPseudoRoot = false;
    140159}
    141160
    142 bool PalmOSFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const {
    143         Err e;
     161AbstractFilesystemNode *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
     184bool PalmOSFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
     185        //TODO: honor the hidden flag
     186       
     187        Err error;
    144188        Char nameP[256];
    145189        FileInfoType desc;
    146190        FileRef handle;
     
    148192
    149193        desc.nameP = nameP;
    150194        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);
    152196
    153         if (e)
     197        if (error)
    154198                return false;
    155199       
    156200        while(dirIterator != expIteratorStop) {
    157                 e = VFSDirEntryEnumerate(handle, &dirIterator, &desc);
    158                 if (!e) {
     201                error = VFSDirEntryEnumerate(handle, &dirIterator, &desc);
     202                if (!error) {
    159203                        addFile(myList, mode, _path.c_str(), &desc);
    160204                }
    161205        }
     
    165209        return true;
    166210}
    167211
    168 
    169 AbstractFilesystemNode *PalmOSFilesystemNode::parent() const {
     212AbstractFilesystemNode *PalmOSFilesystemNode::getParent() const {
    170213        PalmOSFilesystemNode *p = 0;
    171214       
    172215        if (!_isPseudoRoot) {
     
    180223                p->_displayName = lastPathComponent(p->_path);
    181224                p->_isPseudoRoot =(p->_path == "/");
    182225        }
    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;
    200226       
    201         e = VFSFileGetAttributes(handle, &attr);
    202         VFSFileClose(handle);
    203 
    204         if (e || !(attr & vfsFileAttrDirectory))
    205                 return 0;
    206 
    207         PalmOSFilesystemNode *p = new PalmOSFilesystemNode(newPath);
    208227        return p;
    209228}
    210229
  • home/david/Projects/scummvm/backends/fs/posix/posix-fs-factory.cpp

     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#include "backends/fs/posix/posix-fs-factory.h"
     26#include "backends/fs/posix/posix-fs.cpp"
     27
     28DECLARE_SINGLETON(POSIXFilesystemFactory);
     29
     30AbstractFilesystemNode *POSIXFilesystemFactory::makeRootFileNode() const {
     31        return new POSIXFilesystemNode();
     32}
     33
     34AbstractFilesystemNode *POSIXFilesystemFactory::makeCurrentDirectoryFileNode() const {
     35        char buf[MAXPATHLEN];
     36        getcwd(buf, MAXPATHLEN);
     37        return new POSIXFilesystemNode(buf, true);
     38}
     39
     40AbstractFilesystemNode *POSIXFilesystemFactory::makeFileNodePath(const String &path) const {
     41        return new POSIXFilesystemNode(path, true);
     42}
  • home/david/Projects/scummvm/backends/fs/posix/posix-fs-factory.h

    Property changes on: /home/david/Projects/scummvm/backends/fs/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/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#ifndef POSIX_FILESYSTEM_FACTORY_H
     26#define POSIX_FILESYSTEM_FACTORY_H
     27
     28#include "common/singleton.h"
     29#include "backends/fs/abstract-fs-factory.h"
     30
     31/**
     32 * Creates POSIXFilesystemNode objects.
     33 *
     34 * Parts of this class are documented in the base interface class, AbstractFilesystemFactory.
     35 */
     36class POSIXFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<POSIXFilesystemFactory> {
     37public:
     38        typedef Common::String String;
     39               
     40        virtual AbstractFilesystemNode *makeRootFileNode() const;
     41        virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const;
     42        virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const;
     43       
     44protected:
     45        POSIXFilesystemFactory() {};
     46               
     47private:
     48        friend class Common::Singleton<SingletonBaseType>;
     49};
     50
     51#endif /*POSIX_FILESYSTEM_FACTORY_H*/
  • home/david/Projects/scummvm/backends/fs/posix/posix-fs.cpp

    Property changes on: /home/david/Projects/scummvm/backends/fs/posix/posix-fs-factory.h
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    Name: svn:keywords
       + Date Rev Author URL Id
    Name: svn:mime-type
       + text/plain
    
     
    2525#if defined(UNIX)
    2626
    2727#include "common/stdafx.h"
    28 
    2928#include "backends/fs/abstract-fs.h"
    3029
    3130#ifdef MACOSX
     
    3736#include <stdio.h>
    3837#include <unistd.h>
    3938
    40 /*
     39/**
    4140 * Implementation of the ScummVM file system API based on POSIX.
     41 *
     42 * Parts of this class are documented in the base interface class, AbstractFilesystemNode.
    4243 */
    43 
    4444class POSIXFilesystemNode : public AbstractFilesystemNode {
    4545protected:
    4646        String _displayName;
     47        String _path;
    4748        bool _isDirectory;
    4849        bool _isValid;
    49         String _path;
    5050
    5151public:
     52        /**
     53         * Creates a POSIXFilesystemNode with the root node as path.
     54         */
    5255        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         */
    5363        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; }
    5869        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       
     77private:
     78        /**
     79         * Tests and sets the _isValid and _isDirectory flags, using the stat() function.
     80         */
     81        virtual void setFlags();
    6482};
    6583
    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 */
    6794static const char *lastPathComponent(const Common::String &str) {
    6895        const char *start = str.c_str();
    6996        const char *cur = start + str.size() - 2;
     
    75102        return cur + 1;
    76103}
    77104
    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);
     105void POSIXFilesystemNode::setFlags() {
     106        struct stat st;
     107       
     108        _isValid = (0 == stat(_path.c_str(), &st));
     109        _isDirectory = _isValid ? S_ISDIR(st.st_mode) : false;
    90110}
    91111
    92112POSIXFilesystemNode::POSIXFilesystemNode() {
     
    123143
    124144        _path = p;
    125145        _displayName = lastPathComponent(_path);
    126         _isValid = true;
    127         _isDirectory = true;
    128146
    129147        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();
    133149        }
    134150}
    135151
    136 bool POSIXFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const {
     152AbstractFilesystemNode *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
     165bool POSIXFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
    137166        assert(_isDirectory);
     167       
    138168        DIR *dirp = opendir(_path.c_str());
    139 
    140169        struct dirent *dp;
    141170
    142171        if (dirp == NULL)
     
    142171        if (dirp == NULL)
    143172                return false;
    144173
    145         // ... loop over dir entries using readdir
     174        // loop over dir entries using readdir
    146175        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) {
    149178                        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                }
    150184
    151185                String newPath(_path);
    152186                if (newPath.lastChar() != '/')
     
    156190                POSIXFilesystemNode entry(newPath, false);
    157191
    158192#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();
    165201#else
    166202                if (dp->d_type == DT_UNKNOWN) {
    167203                        // 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();
    171205                } else {
    172206                        entry._isValid = (dp->d_type == DT_DIR) || (dp->d_type == DT_REG) || (dp->d_type == DT_LNK);
    173207                        if (dp->d_type == DT_LNK) {
     
    194228
    195229                if (entry._isDirectory)
    196230                        entry._path += "/";
     231                       
    197232                myList.push_back(new POSIXFilesystemNode(entry));
    198233        }
    199234        closedir(dirp);
     235       
    200236        return true;
    201237}
    202238
    203 AbstractFilesystemNode *POSIXFilesystemNode::parent() const {
     239AbstractFilesystemNode *POSIXFilesystemNode::getParent() const {
    204240        if (_path == "/")
    205241                return 0;
    206242
     
    207243        const char *start = _path.c_str();
    208244        const char *end = lastPathComponent(_path);
    209245
    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);
    226247}
    227248
    228 #endif // defined(UNIX)
     249#endif //#if defined(UNIX)
  • home/david/Projects/scummvm/backends/fs/ps2/ps2-fs-factory.cpp

     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#include "backends/fs/ps2/ps2-fs-factory.h"
     26#include "backends/fs/ps2/ps2-fs.cpp"
     27
     28DECLARE_SINGLETON(Ps2FilesystemFactory);
     29
     30AbstractFilesystemNode *Ps2FilesystemFactory::makeRootFileNode() const {
     31        return new Ps2FilesystemNode();
     32}
     33
     34AbstractFilesystemNode *Ps2FilesystemFactory::makeCurrentDirectoryFileNode() const {
     35        return new Ps2FilesystemNode();
     36}
     37
     38AbstractFilesystemNode *Ps2FilesystemFactory::makeFileNodePath(const String &path) const {
     39        return new Ps2FilesystemNode(path);
     40}
  • home/david/Projects/scummvm/backends/fs/ps2/ps2-fs-factory.h

    Property changes on: /home/david/Projects/scummvm/backends/fs/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/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#ifndef PS2_FILESYSTEM_FACTORY_H
     26#define PS2_FILESYSTEM_FACTORY_H
     27
     28#include "common/singleton.h"
     29#include "backends/fs/abstract-fs-factory.h"
     30
     31/**
     32 * Creates PS2FilesystemNode objects.
     33 *
     34 * Parts of this class are documented in the base interface class, AbstractFilesystemFactory.
     35 */
     36class Ps2FilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<Ps2FilesystemFactory> {
     37public:
     38        typedef Common::String String;
     39               
     40        virtual AbstractFilesystemNode *makeRootFileNode() const;
     41        virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const;
     42        virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const;
     43       
     44protected:
     45        Ps2FilesystemFactory() {};
     46               
     47private:
     48        friend class Common::Singleton<SingletonBaseType>;
     49};
     50
     51#endif /*PS2_FILESYSTEM_FACTORY_H*/
  • home/david/Projects/scummvm/backends/fs/ps2/ps2-fs.cpp

    Property changes on: /home/david/Projects/scummvm/backends/fs/ps2/ps2-fs-factory.h
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    Name: svn:keywords
       + Date Rev Author URL Id
    Name: svn:mime-type
       + text/plain
    
     
    3232extern AsyncFio fio;
    3333extern OSystem_PS2 *g_systemPs2;
    3434
     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 */
    3540class Ps2FilesystemNode : public AbstractFilesystemNode {
    3641protected:
    3742        String _displayName;
     43        String _path;
    3844        bool _isDirectory;
    3945        bool _isRoot;
    40         String _path;
    4146
    4247public:
    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         */
    4463        Ps2FilesystemNode(const Ps2FilesystemNode *node);
    45         Ps2FilesystemNode(const String &path);
    4664
    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; }
    5069        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
    5273
    53         //virtual FSList listDir(ListMode) const;
    54         virtual bool listDir(AbstractFSList &list, ListMode mode) const;
    55         virtual AbstractFilesystemNode *parent() const;
    5674        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;
    5878};
    5979
    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) {
     80Ps2FilesystemNode::Ps2FilesystemNode() {
    7381        _isDirectory = true;
    7482        _isRoot = true;
    7583        _displayName = "PlayStation 2";
     
    108116        _isRoot = node->_isRoot;
    109117}
    110118
    111 bool Ps2FilesystemNode::listDir(AbstractFSList &list, ListMode mode) const {
     119AbstractFilesystemNode *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
     153bool Ps2FilesystemNode::getChildren(AbstractFSList &list, ListMode mode, bool hidden) const {
     154        //TODO: honor the hidden flag
     155       
    112156        if (!_isDirectory)
    113157                return false;
    114158
     
    135179        } else {
    136180                char listDir[256];
    137181                int fd;
     182               
    138183                if (_path.lastChar() == '/')
    139184                        fd = fio.dopen(_path.c_str());
    140185                else {
     
    173218        }
    174219}
    175220
    176 AbstractFilesystemNode *Ps2FilesystemNode::parent() const {
     221AbstractFilesystemNode *Ps2FilesystemNode::getParent() const {
    177222        if (_isRoot)
    178223                return new Ps2FilesystemNode(this);
    179224
     
    191236        else
    192237                return new Ps2FilesystemNode();
    193238}
    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 }
  • home/david/Projects/scummvm/backends/fs/psp/psp-fs-factory.cpp

     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#include "backends/fs/psp/psp-fs-factory.h"
     26#include "backends/fs/psp/psp_fs.cpp"
     27
     28DECLARE_SINGLETON(PSPFilesystemFactory);
     29
     30AbstractFilesystemNode *PSPFilesystemFactory::makeRootFileNode() const {
     31        return new PSPFilesystemNode();
     32}
     33
     34AbstractFilesystemNode *PSPFilesystemFactory::makeCurrentDirectoryFileNode() const {
     35        return new PSPFilesystemNode();
     36}
     37
     38AbstractFilesystemNode *PSPFilesystemFactory::makeFileNodePath(const String &path) const {
     39        return new PSPFilesystemNode(path, true);
     40}
  • home/david/Projects/scummvm/backends/fs/psp/psp-fs-factory.h

    Property changes on: /home/david/Projects/scummvm/backends/fs/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/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#ifndef PSP_FILESYSTEM_FACTORY_H
     26#define PSP_FILESYSTEM_FACTORY_H
     27
     28#include "common/singleton.h"
     29#include "backends/fs/abstract-fs-factory.h"
     30
     31/**
     32 * Creates PSPFilesystemNode objects.
     33 *
     34 * Parts of this class are documented in the base interface class, AbstractFilesystemFactory.
     35 */
     36class PSPFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<PSPFilesystemFactory> {
     37public:
     38        typedef Common::String String;
     39               
     40        virtual AbstractFilesystemNode *makeRootFileNode() const;
     41        virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const;
     42        virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const;
     43       
     44protected:
     45        PSPFilesystemFactory() {};
     46               
     47private:
     48        friend class Common::Singleton<SingletonBaseType>;
     49};
     50
     51#endif /*PSP_FILESYSTEM_FACTORY_H*/
  • home/david/Projects/scummvm/backends/fs/psp/psp_fs.cpp

    Property changes on: /home/david/Projects/scummvm/backends/fs/psp/psp-fs-factory.h
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    Name: svn:keywords
       + Date Rev Author URL Id
    Name: svn:mime-type
       + text/plain
    
     
    2323 */
    2424
    2525#ifdef __PSP__
     26
    2627#include "engines/engine.h"
    27 
    2828#include "backends/fs/abstract-fs.h"
    2929
    3030#include <sys/stat.h>
     
    3232
    3333#define ROOT_PATH       "ms0:/"
    3434
    35 
    36 /*
     35/**
    3736 * 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.
    3839 */
    39 
    4040class PSPFilesystemNode : public AbstractFilesystemNode {
    4141protected:
    4242        String _displayName;
     43        String _path;
    4344        bool _isDirectory;
    4445        bool _isValid;
    45         String _path;
    4646       
    4747public:
     48        /**
     49         * Creates a PSPFilesystemNode with the root node as path.
     50         */
    4851        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         */
    4959        PSPFilesystemNode(const Common::String &p, bool verify);
    5060
    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
    5367        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
    5669
    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;
    6073};
    6174
    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 */
     85static const char *lastPathComponent(const Common::String &str) {
     86        const char *start = str.c_str();
     87        const char *cur = start + str.size() - 2;
    6588
    66 AbstractFilesystemNode *AbstractFilesystemNode::getRoot() {
    67         return new PSPFilesystemNode();
     89        while (cur >= start && *cur != '/') {
     90                --cur;
     91        }
     92
     93        return cur + 1;
    6894}
    6995
    7096PSPFilesystemNode::PSPFilesystemNode() {
     
    89115        }       
    90116}
    91117
    92 AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) {
    93         return new PSPFilesystemNode(path, true);
     118AbstractFilesystemNode *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);
    94129}
    95130
     131bool PSPFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
     132        assert(_isDirectory);
    96133
    97 bool PSPFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const {
    98         assert(_isDirectory);
     134        //TODO: honor the hidden flag
    99135
    100136        int dfd  = sceIoDopen(_path.c_str());
    101137        if (dfd > 0) {
     
    133169        }
    134170}
    135171
    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 {
     172AbstractFilesystemNode *PSPFilesystemNode::getParent() const {
    148173        assert(_isValid);
    149174       
    150175        if (_path == ROOT_PATH)
     
    153178        const char *start = _path.c_str();
    154179        const char *end = lastPathComponent(_path);
    155180       
    156         PSPFilesystemNode *p = new PSPFilesystemNode(String(start, end - start), false);
    157        
    158         return p;
     181        return new PSPFilesystemNode(String(start, end - start), false);
    159182}
    160183
    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__
  • home/david/Projects/scummvm/backends/fs/symbian/symbian-fs-factory.cpp

     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#include "backends/fs/symbian/symbian-fs-factory.h"
     26#include "backends/fs/symbian/symbian-fs.cpp"
     27
     28DECLARE_SINGLETON(SymbianFilesystemFactory);
     29
     30AbstractFilesystemNode *SymbianFilesystemFactory::makeRootFileNode() const {
     31        return new SymbianFilesystemNode(true);
     32}
     33
     34AbstractFilesystemNode *SymbianFilesystemFactory::makeCurrentDirectoryFileNode() const {
     35        char path[MAXPATHLEN];
     36        getcwd(path, MAXPATHLEN);
     37        return new SymbianFilesystemNode(path);
     38}
     39
     40AbstractFilesystemNode *SymbianFilesystemFactory::makeFileNodePath(const String &path) const {
     41        return new SymbianFilesystemNode(path);
     42}
  • home/david/Projects/scummvm/backends/fs/symbian/symbian-fs-factory.h

    Property changes on: /home/david/Projects/scummvm/backends/fs/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/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#ifndef SYMBIAN_FILESYSTEM_FACTORY_H
     26#define SYMBIAN_FILESYSTEM_FACTORY_H
     27
     28#include "common/singleton.h"
     29#include "backends/fs/abstract-fs-factory.h"
     30
     31/**
     32 * Creates SymbianFilesystemNode objects.
     33 *
     34 * Parts of this class are documented in the base interface class, AbstractFilesystemFactory.
     35 */
     36class SymbianFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<SymbianFilesystemFactory> {
     37public:
     38        typedef Common::String String;
     39               
     40        virtual AbstractFilesystemNode *makeRootFileNode() const;
     41        virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const;
     42        virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const;
     43       
     44protected:
     45        SymbianFilesystemFactory() {};
     46               
     47private:
     48        friend class Common::Singleton<SingletonBaseType>;
     49};
     50
     51#endif /*SYMBIAN_FILESYSTEM_FACTORY_H*/
  • home/david/Projects/scummvm/backends/fs/symbian/symbian-fs.cpp

    Property changes on: /home/david/Projects/scummvm/backends/fs/symbian/symbian-fs-factory.h
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    Name: svn:keywords
       + Date Rev Author URL Id
    Name: svn:mime-type
       + text/plain
    
     
    3131#include <f32file.h>
    3232#include <bautils.h>
    3333
    34 /*
     34/**
    3535 * Implementation of the ScummVM file system API based on POSIX.
     36 *
     37 * Parts of this class are documented in the base interface class, AbstractFilesystemNode.
    3638 */
    37 
    3839class SymbianFilesystemNode : public AbstractFilesystemNode {
    3940protected:
    4041        String _displayName;
     42        String _path;
    4143        bool _isDirectory;
    4244        bool _isValid;
    43         String _path;
    4445        bool _isPseudoRoot;
    4546
    4647public:
     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         */
    4753        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         */
    4860        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
    5168        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
    5470
    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;
    5874};
    5975
    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 */
    6186static const char *lastPathComponent(const Common::String &str) {
    6287        const char *start = str.c_str();
    6388        const char *cur = start + str.size() - 2;
     
    6994        return cur + 1;
    7095}
    7196
     97/**
     98 * Fixes the path by changing all slashes to backslashes.
     99 *
     100 * @param path String with the path to be fixed.
     101 */
    72102static void fixFilePath(Common::String& path) {
    73103        TInt len = path.size();
    74104       
     
    79109        }
    80110}
    81111
    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 
    96112SymbianFilesystemNode::SymbianFilesystemNode(bool aIsRoot) {
    97113        _path = "";
    98114        _isValid = true;
     
    128144        }
    129145}
    130146
    131 bool SymbianFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const {
     147AbstractFilesystemNode *SymbianFilesystemNode::getChild(const String &n) const {
    132148        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
     166bool SymbianFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
     167        assert(_isDirectory);
     168
     169        //TODO: honor the hidden flag
    133170
    134171        if (_isPseudoRoot) {
    135172                // Drives enumeration
     
    199236                        }
    200237                        CleanupStack::PopAndDestroy(dirPtr);
    201238                }
    202 
    203239        }
     240       
    204241        return true;
    205242}
    206243
    207 AbstractFilesystemNode *SymbianFilesystemNode::parent() const {
     244AbstractFilesystemNode *SymbianFilesystemNode::getParent() const {
    208245        SymbianFilesystemNode *p =NULL;
    209246
    210247        // Root node is its own parent. Still we can't just return this
     
    210247        // Root node is its own parent. Still we can't just return this
    211248        // as the GUI code will call delete on the old node.
    212249        if (!_isPseudoRoot && _path.size() > 3) {
    213                 p=new SymbianFilesystemNode(false);
     250                p = new SymbianFilesystemNode(false);
    214251                const char *start = _path.c_str();
    215252                const char *end = lastPathComponent(_path);
    216253
     
    221258        }
    222259        else
    223260        {
    224                 p=new SymbianFilesystemNode(true);
     261                p = new SymbianFilesystemNode(true);
    225262        }
    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       
    246264        return p;
    247265}
    248266
    249 #endif // defined(__SYMBIAN32__)
     267#endif //#if defined (__SYMBIAN32__)
  • home/david/Projects/scummvm/backends/fs/windows/windows-fs-factory.cpp

     
     1/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#include "backends/fs/windows/windows-fs-factory.h"
     26#include "backends/fs/windows/windows-fs.cpp"
     27
     28DECLARE_SINGLETON(WindowsFilesystemFactory);
     29
     30AbstractFilesystemNode *WindowsFilesystemFactory::makeRootFileNode() const {
     31        return new WindowsFilesystemNode();
     32}
     33
     34AbstractFilesystemNode *WindowsFilesystemFactory::makeCurrentDirectoryFileNode() const {
     35        return new WindowsFilesystemNode("", true);
     36}
     37
     38AbstractFilesystemNode *WindowsFilesystemFactory::makeFileNodePath(const String &path) const {
     39        return new WindowsFilesystemNode(path, false);
     40}
  • home/david/Projects/scummvm/backends/fs/windows/windows-fs-factory.h

    Property changes on: /home/david/Projects/scummvm/backends/fs/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/* ScummVM - Graphic Adventure Engine
     2 *
     3 * ScummVM is the legal property of its developers, whose names
     4 * are too numerous to list here. Please refer to the COPYRIGHT
     5 * file distributed with this source distribution.
     6 *
     7 * This program is free software; you can redistribute it and/or
     8 * modify it under the terms of the GNU General Public License
     9 * as published by the Free Software Foundation; either version 2
     10 * of the License, or (at your option) any later version.
     11 *
     12 * This program is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with this program; if not, write to the Free Software
     19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
     20 *
     21 * $URL:  $
     22 * $Id:  $
     23 */
     24
     25#ifndef WINDOWS_FILESYSTEM_FACTORY_H
     26#define WINDOWS_FILESYSTEM_FACTORY_H
     27
     28#include "common/singleton.h"
     29#include "backends/fs/abstract-fs-factory.h"
     30
     31/**
     32 * Creates WindowsFilesystemNode objects.
     33 *
     34 * Parts of this class are documented in the base interface class, AbstractFilesystemFactory.
     35 */
     36class WindowsFilesystemFactory : public AbstractFilesystemFactory, public Common::Singleton<WindowsFilesystemFactory> {
     37public:
     38        typedef Common::String String;
     39       
     40        virtual AbstractFilesystemNode *makeRootFileNode() const;
     41        virtual AbstractFilesystemNode *makeCurrentDirectoryFileNode() const;
     42        virtual AbstractFilesystemNode *makeFileNodePath(const String &path) const;
     43       
     44protected:
     45        WindowsFilesystemFactory() {};
     46               
     47private:
     48        friend class Common::Singleton<SingletonBaseType>;
     49};
     50
     51#endif /*WINDOWS_FILESYSTEM_FACTORY_H*/
  • home/david/Projects/scummvm/backends/fs/windows/windows-fs.cpp

    Property changes on: /home/david/Projects/scummvm/backends/fs/windows/windows-fs-factory.h
    ___________________________________________________________________
    Name: svn:eol-style
       + native
    Name: svn:keywords
       + Date Rev Author URL Id
    Name: svn:mime-type
       + text/plain
    
     
    2929#endif
    3030#include "common/stdafx.h"
    3131#include "backends/fs/abstract-fs.h"
     32#include <io.h>
    3233#include <stdio.h>
    3334#include <stdlib.h>
    3435#ifndef _WIN32_WCE
     
    3637#endif
    3738#include <tchar.h>
    3839
    39 /*
     40/**
    4041 * 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.
    4144 */
    42 
    4345class WindowsFilesystemNode : public AbstractFilesystemNode {
    4446protected:
    4547        String _displayName;
     48        String _path;
    4649        bool _isDirectory;
    47         bool _isValid;
    4850        bool _isPseudoRoot;
    49         String _path;
     51        bool _isValid;
    5052
    5153public:
     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         */
    5260        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; }
    5879        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; }
    6083
    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;
    6487
    6588private:
    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);
    69115};
    70116
    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 */
    72127static const char *lastPathComponent(const Common::String &str) {
    73128        const char *start = str.c_str();
    74129        const char *cur = start + str.size() - 2;
     
    80135        return cur + 1;
    81136}
    82137
    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 
    104138void WindowsFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const char *base, WIN32_FIND_DATA* find_data) {
    105139        WindowsFilesystemNode entry;
    106140        char *asciiName = toAscii(find_data->cFileName);
     
    128162        list.push_back(new WindowsFilesystemNode(entry));
    129163}
    130164
    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);
     165char* 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
    142173}
    143174
    144 AbstractFilesystemNode *AbstractFilesystemNode::getRoot() {
    145         return new WindowsFilesystemNode();
    146 }
    147 
    148 AbstractFilesystemNode *AbstractFilesystemNode::getNodeForPath(const String &path) {
    149         return new WindowsFilesystemNode(path);
     175const 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
    150183}
    151184
    152185WindowsFilesystemNode::WindowsFilesystemNode() {
     
    165198#endif
    166199}
    167200
    168 WindowsFilesystemNode::WindowsFilesystemNode(const String &p) {
    169         assert(p.size() > 0);
     201WindowsFilesystemNode::WindowsFilesystemNode(const String &p, const bool currentDir) {
     202        if (currentDir) {
     203                char path[MAX_PATH];
     204                GetCurrentDirectory(MAX_PATH, path);
    170205
    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       
    172218        _displayName = lastPathComponent(_path);
    173219
    174220        // Check whether it is a directory, and whether the file actually exists
     
    175221        DWORD fileAttribs = GetFileAttributes(toUnicode(_path.c_str()));
    176222
    177223        if (fileAttribs == INVALID_FILE_ATTRIBUTES) {
     224                _isDirectory = false;
    178225                _isValid = false;
    179                 _isDirectory = false;
    180226        } else {
     227                _isDirectory = ((fileAttribs & FILE_ATTRIBUTE_DIRECTORY) != 0);
    181228                _isValid = true;
    182                 _isDirectory = ((fileAttribs & FILE_ATTRIBUTE_DIRECTORY) != 0);
    183229        }
    184230        _isPseudoRoot = false;
    185231}
     
    184230        _isPseudoRoot = false;
    185231}
    186232
    187 bool WindowsFilesystemNode::listDir(AbstractFSList &myList, ListMode mode) const {
     233AbstractFilesystemNode *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
     249bool WindowsFilesystemNode::getChildren(AbstractFSList &myList, ListMode mode, bool hidden) const {
    188250        assert(_isDirectory);
    189251
     252        //TODO: honor the hidden flag
     253
    190254        if (_isPseudoRoot) {
    191255#ifndef _WIN32_WCE
    192256                // Drives enumeration
     
    218282                sprintf(searchPath, "%s*", _path.c_str());
    219283
    220284                handle = FindFirstFile(toUnicode(searchPath), &desc);
     285               
    221286                if (handle == INVALID_HANDLE_VALUE)
    222287                        return false;
     288                       
    223289                addFile(myList, mode, _path.c_str(), &desc);
     290               
    224291                while (FindNextFile(handle, &desc))
    225292                        addFile(myList, mode, _path.c_str(), &desc);
    226293
     
    230297        return true;
    231298}
    232299
    233 AbstractFilesystemNode *WindowsFilesystemNode::parent() const {
     300AbstractFilesystemNode *WindowsFilesystemNode::getParent() const {
    234301        assert(_isValid || _isPseudoRoot);
     302       
    235303        if (_isPseudoRoot)
    236304                return 0;
     305               
    237306        WindowsFilesystemNode *p = new WindowsFilesystemNode();
    238307        if (_path.size() > 3) {
    239308                const char *start = _path.c_str();
     
    246315                p->_displayName = lastPathComponent(p->_path);
    247316                p->_isPseudoRoot = false;
    248317        }
     318       
    249319        return p;
    250320}
    251321
    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
  • home/david/Projects/scummvm/backends/plugins/dc/dc-provider.cpp

     
    114114        // Scan for all plugins in this directory
    115115        FilesystemNode dir(PLUGIN_DIRECTORY);
    116116        FSList files;
    117         if (!dir.listDir(files, FilesystemNode::kListFilesOnly)) {
     117        if (!dir.getChildren(files, FilesystemNode::kListFilesOnly)) {
    118118                error("Couldn't open plugin directory '%s'", PLUGIN_DIRECTORY);
    119119        }
    120120
     
    119119        }
    120120
    121121        for (FSList::const_iterator i = files.begin(); i != files.end(); ++i) {
    122                 Common::String name(i->name());
     122                Common::String name(i->getName());
    123123                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()));
    125125                }
    126126        }
    127127       
  • home/david/Projects/scummvm/backends/plugins/posix/posix-provider.cpp

     
    107107        // Scan for all plugins in this directory
    108108        FilesystemNode dir(PLUGIN_DIRECTORY);
    109109        FSList files;
    110         if (!dir.listDir(files, FilesystemNode::kListFilesOnly)) {
     110        if (!dir.getChildren(files, FilesystemNode::kListFilesOnly)) {
    111111                error("Couldn't open plugin directory '%s'", PLUGIN_DIRECTORY);
    112112        }
    113113
     
    112112        }
    113113
    114114        for (FSList::const_iterator i = files.begin(); i != files.end(); ++i) {
    115                 Common::String name(i->name());
     115                Common::String name(i->getName());
    116116                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()));
    118118                }
    119119        }
    120120       
  • home/david/Projects/scummvm/backends/plugins/sdl/sdl-provider.cpp

     
    107107        // Scan for all plugins in this directory
    108108        FilesystemNode dir(PLUGIN_DIRECTORY);
    109109        FSList files;
    110         if (!dir.listDir(files, FilesystemNode::kListFilesOnly)) {
     110        if (!dir.getChildren(files, FilesystemNode::kListFilesOnly)) {
    111111                error("Couldn't open plugin directory '%s'", PLUGIN_DIRECTORY);
    112112        }
    113113
     
    112112        }
    113113
    114114        for (FSList::const_iterator i = files.begin(); i != files.end(); ++i) {
    115                 Common::String name(i->name());
     115                Common::String name(i->getName());
    116116                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()));
    118118                }
    119119        }
    120120       
  • home/david/Projects/scummvm/backends/plugins/win32/win32-provider.cpp

     
    110110        // Scan for all plugins in this directory
    111111        FilesystemNode dir(PLUGIN_DIRECTORY);
    112112        FSList files;
    113         if (!dir.listDir(files, FilesystemNode::kListFilesOnly)) {
     113        if (!dir.getChildren(files, FilesystemNode::kListFilesOnly)) {
    114114                error("Couldn't open plugin directory '%s'", PLUGIN_DIRECTORY);
    115115        }
    116116
     
    115115        }
    116116
    117117        for (FSList::const_iterator i = files.begin(); i != files.end(); ++i) {
    118                 Common::String name(i->name());
     118                Common::String name(i->getName());
    119119                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()));
    121121                }
    122122        }
    123123       
  • home/david/Projects/scummvm/backends/saves/default/default-saves.cpp

     
    2828#include "common/stdafx.h"
    2929#include "common/savefile.h"
    3030#include "common/util.h"
     31#include "common/fs.h"
     32#include "common/file.h"
    3133#include "backends/saves/default/default-saves.h"
    3234#include "backends/saves/compressed/compressed-saves.h"
    3335
     
    8688        }
    8789};
    8890
    89 
    9091static void join_paths(const char *filename, const char *directory,
    9192                                                                 char *buf, int bufsize) {
    9293        buf[bufsize-1] = '\0';
     
    113114        strncat(buf, filename, bufsize-1);
    114115}
    115116
     117Common::StringList DefaultSaveFileManager::listSavefiles(const char *regex) {
     118        FilesystemNode savePath(getSavePath());
     119        FSList savefiles;
     120        Common::StringList results;
     121        Common::String search(regex);
     122       
     123        if (savePath.lookupFile(savefiles, savePath, search, false, true)) {
     124                for (FSList::const_iterator file = savefiles.begin(); file != savefiles.end(); file++) {
     125                        results.push_back(file->getPath());
     126                }
     127        }
     128                               
     129        return results;
     130}
     131
     132Common::InSaveFile *DefaultSaveFileManager::openForLoading(const char *filename) {
     133        char buf[256];
     134        join_paths(filename, getSavePath(), buf, sizeof(buf));
     135
     136        StdioSaveFile *sf = new StdioSaveFile(buf, false);
     137
     138        if (!sf->isOpen()) {
     139                delete sf;
     140                sf = 0;
     141        }
     142        return wrapInSaveFile(sf);
     143}
     144
    116145Common::OutSaveFile *DefaultSaveFileManager::openForSaving(const char *filename) {
    117146        char buf[256];
    118147
     
    119148        // Ensure that the savepath exists and is writeable. If not, generate
    120149        // an appropriate error
    121150        const char *savePath = getSavePath();
     151       
    122152#if defined(UNIX) || defined(__SYMBIAN32__)
    123153        struct stat sb;
     154        clearError();
    124155       
    125156        // Check whether the dir exists
    126157        if (stat(savePath, &sb) == -1) {
     
    126157        if (stat(savePath, &sb) == -1) {
    127158                // The dir does not exist, or stat failed for some other reason.
    128159                // If the problem was that the path pointed to nothing, try
    129                 // to create the dir.
    130                 if (errno == ENOENT) {
     160                // to create the dir (ENOENT case).
     161                switch (errno) {
     162                case EACCES:
     163                        setError(SFM_DIR_ACCESS, Common::String("Search or write permission denied"));
     164                        break;
     165                case ELOOP:
     166                        setError(SFM_DIR_LOOP, Common::String("Too many symbolic links encountered while traversing the path"));
     167                        break;
     168                case ENAMETOOLONG:
     169                        setError(SFM_DIR_NAMETOOLONG, Common::String("The path name is too long"));
     170                        break;
     171                case ENOENT:
    131172                        if (mkdir(savePath, 0755) != 0) {
    132173                                // mkdir could fail for various reasons: The parent dir doesn't exist,
    133174                                // or is not writeable, the path could be completly bogus, etc.
     
    133174                                // or is not writeable, the path could be completly bogus, etc.
    134175                                warning("mkdir for '%s' failed!", savePath);
    135176                                perror("mkdir");
    136                                 // TODO: Specify an error code here so that callers can
    137                                 // determine what exactly went wrong.
     177                               
     178                                switch (errno) {
     179                                case EACCES:
     180                                        setError(SFM_DIR_ACCESS, Common::String("Search or write permission denied"));
     181                                        break;
     182                                case EMLINK:
     183                                        setError(SFM_DIR_LINKMAX, Common::String("The link count of the parent directory would exceed {LINK_MAX}"));
     184                                        break;
     185                                case ELOOP:
     186                                        setError(SFM_DIR_LOOP, Common::String("Too many symbolic links encountered while traversing the path"));
     187                                        break;
     188                                case ENAMETOOLONG:
     189                                        setError(SFM_DIR_NAMETOOLONG, Common::String("The path name is too long"));
     190                                        break;
     191                                case ENOENT:
     192                                        setError(SFM_DIR_NOENT, Common::String("A component of the path path does not exist, or the path is an empty string"));
     193                                        break;
     194                                case ENOTDIR:
     195                                        setError(SFM_DIR_NOTDIR, Common::String("A component of the path prefix is not a directory"));
     196                                        break;
     197                                case EROFS:
     198                                        setError(SFM_DIR_ROFS, Common::String("The parent directory resides on a read-only file system"));
     199                                        break;
     200                                }
     201                               
    138202                                return 0;
    139203                        }
    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                 }
     204                        break;
     205                case ENOTDIR:
     206                        setError(SFM_DIR_NOTDIR, Common::String("A component of the path prefix is not a directory"));
     207                        break;
     208                }
    146209        } else {
    147                 // So stat() succeeded. But is the path actually pointing to a
    148                 // directory?
     210                // So stat() succeeded. But is the path actually pointing to a directory?
    149211                if (!S_ISDIR(sb.st_mode)) {
    150                         // TODO: Specify an error code here so that callers can
    151                         // determine what exactly went wrong.
     212                        setError(SFM_DIR_NOTDIR, Common::String("The given savepath is not a directory"));
     213                       
    152214                        return 0;
    153215                }
    154216        }
     
    163225                delete sf;
    164226                sf = 0;
    165227        }
     228       
    166229        return wrapOutSaveFile(sf);
    167230}
    168231
    169 Common::InSaveFile *DefaultSaveFileManager::openForLoading(const char *filename) {
    170         char buf[256];
    171         join_paths(filename, getSavePath(), buf, sizeof(buf));
    172 
    173         StdioSaveFile *sf = new StdioSaveFile(buf, false);
    174 
    175         if (!sf->isOpen()) {
    176                 delete sf;
    177                 sf = 0;
    178         }
    179         return wrapInSaveFile(sf);
    180 }
    181 
    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));
     232bool DefaultSaveFileManager::removeSavefile(const char *filename) {
     233        Common::File file;
     234        FilesystemNode savePath(filename);
     235        return file.remove(savePath);
    187236}
    188237
    189238#endif // !defined(DISABLE_DEFAULT_SAVEFILEMANAGER)
  • home/david/Projects/scummvm/backends/saves/default/default-saves.h

     
    2828
    2929#include "common/stdafx.h"
    3030#include "common/savefile.h"
     31#include "common/str.h"
    3132
    3233class DefaultSaveFileManager : public Common::SaveFileManager {
    3334public:
     35        virtual Common::StringList listSavefiles(const char *regex);
     36        virtual Common::InSaveFile *openForLoading(const char *filename);
    3437        virtual Common::OutSaveFile *openForSaving(const char *filename);
    35         virtual Common::InSaveFile *openForLoading(const char *filename);
    36         virtual void listSavefiles(const char * /* prefix */, bool *marks, int num);
     38        virtual bool removeSavefile(const char *filename);
    3739};
    3840
    3941#endif
  • home/david/Projects/scummvm/base/commandLine.cpp

     
    3232
    3333#include "common/config-manager.h"
    3434#include "common/system.h"
     35#include "common/fs.h"
    3536
    3637#include "sound/mididrv.h"
    3738#include "sound/mixer.h"
     
    4849
    4950#define DETECTOR_TESTING_HACK
    5051
    51 #ifdef DETECTOR_TESTING_HACK
    52 #include "common/fs.h"
    53 #endif
    54 
    5552namespace Base {
    5653
    5754static const char USAGE_STRING[] =
     
    313310        for (int i = 1; i < argc; ++i) {
    314311                s = argv[i];
    315312                s2 = (i < argc-1) ? argv[i+1] : 0;
    316 
     313               
    317314                if (s[0] != '-') {
    318315                        // The argument doesn't start with a dash, so it's not an option.
    319316                        // Hence it must be the target name. We currently enforce that
     
    390387                        END_OPTION
    391388
    392389                        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                                }
    394396                        END_OPTION
    395397
    396398                        DO_OPTION('q', "language")
     
    428430                        END_OPTION
    429431
    430432                        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                                }
    432439                        END_OPTION
    433440
    434441                        DO_LONG_OPTION_BOOL("disable-sdl-parachute")
     
    453460                        END_OPTION
    454461
    455462                        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                                }
    457469                        END_OPTION
    458470
    459471                        DO_LONG_OPTION_INT("talkspeed")
     
    466478                        END_OPTION
    467479
    468480                        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                                }
    470487                        END_OPTION
    471488
    472489                        DO_LONG_OPTION("target-md5")
     
    562579               
    563580                FilesystemNode dir(path);
    564581                FSList files;
    565                 if (!dir.listDir(files, FilesystemNode::kListAll)) {
     582                if (!dir.getChildren(files, FilesystemNode::kListAll)) {
    566583                        printf(" ... invalid path, skipping\n");
    567584                        continue;
    568585                }
     
    673690        if (!settings.contains("savepath")) {
    674691                const char *dir = getenv("SCUMMVM_SAVEPATH");
    675692                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                        }
    678701                }
    679702        }
    680703#endif
     
    679702        }
    680703#endif
    681704
    682 
    683705        // Finally, store the command line settings into the config manager.
    684706        for (Common::StringMap::const_iterator x = settings.begin(); x != settings.end(); ++x) {
    685707                Common::String key(x->_key);
  • home/david/Projects/scummvm/common/advancedDetector.cpp

     
    276276
    277277        FSList fslist;
    278278        FilesystemNode dir(ConfMan.get("path"));
    279         if (!dir.listDir(fslist, FilesystemNode::kListFilesOnly)) {
     279        if (!dir.getChildren(fslist, FilesystemNode::kListFilesOnly)) {
    280280                return kInvalidPathError;
    281281        }
    282282
     
    345345                // Get the information of the existing files
    346346                for (FSList::const_iterator file = fslist->begin(); file != fslist->end(); ++file) {
    347347                        if (file->isDirectory()) continue;
    348                         tstr = file->name();
     348                        tstr = file->getName();
    349349                        tstr.toLowercase();
    350350
    351351                        // Strip any trailing dot
     
    364364
    365365                        debug(3, "> %s: %s", tstr.c_str(), md5str);
    366366
    367                         if (testFile.open(file->path())) {
     367                        if (testFile.open(file->getPath())) {
    368368                                filesSize[tstr] = (int32)testFile.size();
    369369                                testFile.close();
    370370                        }
  • home/david/Projects/scummvm/common/file.cpp

     
    2828#include "common/hashmap.h"
    2929#include "common/util.h"
    3030#include "common/hash-str.h"
     31#include <errno.h>
    3132
    3233#ifdef MACOSX
    3334#include "CoreFoundation/CoreFoundation.h"
     
    226227                return;
    227228
    228229        FSList fslist;
    229         if (!dir.listDir(fslist, FilesystemNode::kListAll)) {
     230        if (!dir.getChildren(fslist, FilesystemNode::kListAll)) {
    230231                // Failed listing the contents of this node, so it is either not a
    231232                // directory, or just doesn't exist at all.
    232233                return;
     
    237238
    238239        // Do not add directories multiple times, unless this time they are added
    239240        // with a bigger depth.
    240         const String &directory(dir.path());
     241        const String &directory(dir.getPath());
    241242        if (_defaultDirectories->contains(directory) && (*_defaultDirectories)[directory] >= level)
    242243                return;
    243244        (*_defaultDirectories)[directory] = level;
     
    247248
    248249        for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
    249250                if (file->isDirectory()) {
    250                         addDefaultDirectoryRecursive(file->path(), level - 1, prefix + file->name() + "/");
     251                        addDefaultDirectoryRecursive(file->getPath(), level - 1, prefix + file->getName() + "/");
    251252                } else {
    252253                        String lfn(prefix);
    253                         lfn += file->name();
     254                        lfn += file->getName();
    254255                        lfn.toLowercase();
    255256                        if (!_filesMap->contains(lfn)) {
    256                                 (*_filesMap)[lfn] = file->path();
     257                                (*_filesMap)[lfn] = file->getPath();
    257258                        }
    258259                }
    259260        }
     
    364365bool File::open(const FilesystemNode &node, AccessMode mode) {
    365366        assert(mode == kFileReadMode || mode == kFileWriteMode);
    366367
    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");
    369370                return false;
    370371        } else if (node.isDirectory()) {
    371372                warning("File::open: Trying to open a FilesystemNode which is a directory");
     
    370371        } else if (node.isDirectory()) {
    371372                warning("File::open: Trying to open a FilesystemNode which is a directory");
    372373                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        }*/
    374381
    375         String filename(node.name());
     382        String filename(node.getName());
    376383
    377384        if (_handle) {
    378385                error("File::open: This file object already is opened (%s), won't open '%s'", _name.c_str(), filename.c_str());
     
    383390
    384391        const char *modeStr = (mode == kFileReadMode) ? "rb" : "wb";
    385392
    386         _handle = fopen(node.path().c_str(), modeStr);
     393        _handle = fopen(node.getPath().c_str(), modeStr);
    387394
    388395        if (_handle == NULL) {
    389396                if (mode == kFileReadMode)
     
    402409        return true;
    403410}
    404411
     412bool 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
     425bool 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
    405438bool File::exists(const String &filename) {
    406439        // First try to find the file it via a FilesystemNode (in case an absolute
    407440        // path was passed). But we only use this to filter out directories.
     
    406439        // First try to find the file it via a FilesystemNode (in case an absolute
    407440        // path was passed). But we only use this to filter out directories.
    408441        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***
    415446        // Next, try to locate the file by *opening* it in read mode. This has
    416447        // multiple effects:
    417448        // 1) It takes _filesMap and _defaultDirectories into consideration -> good
  • home/david/Projects/scummvm/common/file.h

     
    5252        // code that accidentally copied File objects tended to break in strange
    5353        // ways.
    5454        File(const File &f);
    55         File &operator  =(const File &f);
     55        File &operator =(const File &f);
    5656
    5757public:
    5858        enum AccessMode {
     
    8686
    8787        virtual void close();
    8888
     89        virtual bool remove(const String &filename);
     90        virtual bool remove(const FilesystemNode &node);
     91       
    8992        /**
    9093         * Checks if the object opened a file successfully.
    9194         *
  • home/david/Projects/scummvm/common/fs.cpp

     
    2323 */
    2424
    2525#include "common/stdafx.h"
    26 
     26#include "common/util.h"
    2727#include "backends/fs/abstract-fs.h"
    28 #include "common/util.h"
     28#include "backends/fs/fs-factory-maker.cpp"
    2929
     30/*
     31 * Simple DOS-style pattern matching function (understands * and ? like used in DOS).
     32 * Taken from exult/files/listfiles.cc
     33 */
     34static 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;
    3044
    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        }
    3465}
    3566
    3667FilesystemNode::FilesystemNode() {
     
    3869        _refCount = 0;
    3970}
    4071
     72FilesystemNode::FilesystemNode(AbstractFilesystemNode *realNode) {
     73        _realNode = realNode;
     74        _refCount = new int(1);
     75}
     76
    4177FilesystemNode::FilesystemNode(const FilesystemNode &node) {
    4278        _realNode = node._realNode;
    4379        _refCount = node._refCount;
     
    4682}
    4783
    4884FilesystemNode::FilesystemNode(const Common::String &p) {
     85        AbstractFilesystemFactory *factory = makeFSFactory();
     86       
    4987        if (p.empty() || p == ".")
    50                 _realNode = AbstractFilesystemNode::getCurrentDirectory();
     88                _realNode = factory->makeCurrentDirectoryFileNode();
    5189        else
    52                 _realNode = AbstractFilesystemNode::getNodeForPath(p);
     90                _realNode = factory->makeFileNodePath(p);
    5391        _refCount = new int(1);
    5492}
    5593
     
    5795        decRefCount();
    5896}
    5997
    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) {
     98FilesystemNode &FilesystemNode::operator= (const FilesystemNode &node) {
    7299        if (node._refCount)
    73100                ++(*node._refCount);
    74101
     
    80107        return *this;
    81108}
    82109
    83 bool FilesystemNode::isValid() const {
    84         if (_realNode == 0)
     110bool FilesystemNode::operator<(const FilesystemNode& node) const
     111{
     112        if (isDirectory() && !node.isDirectory())
     113                return true;
     114        if (!isDirectory() && node.isDirectory())
    85115                return false;
    86         return _realNode->isValid();
     116       
     117        return scumm_stricmp(getDisplayName().c_str(), node.getDisplayName().c_str()) < 0;
    87118}
    88119
    89 FilesystemNode FilesystemNode::getParent() const {
    90         if (_realNode == 0)
    91                 return *this;
    92 
    93         AbstractFilesystemNode *node = _realNode->parent();
    94         if (node == 0) {
    95                 return *this;
    96         } else {
    97                 return FilesystemNode(node);
     120void FilesystemNode::decRefCount() {
     121        if (_refCount) {
     122                assert(*_refCount > 0);
     123                --(*_refCount);
     124                if (*_refCount == 0) {
     125                        delete _refCount;
     126                        delete _realNode;
     127                }
    98128        }
    99129}
    100130
     131bool FilesystemNode::exists() const {
     132        if (_realNode == 0)
     133                return false;
     134       
     135        return _realNode->exists();
     136}
     137
    101138FilesystemNode FilesystemNode::getChild(const Common::String &n) const {
    102139        if (_realNode == 0)
    103140                return *this;
     
    103140                return *this;
    104141
    105142        assert(_realNode->isDirectory());
    106         AbstractFilesystemNode *node = _realNode->child(n);
     143        AbstractFilesystemNode *node = _realNode->getChild(n);
    107144        return FilesystemNode(node);
    108145}
    109146
    110 bool FilesystemNode::listDir(FSList &fslist, ListMode mode) const {
     147bool FilesystemNode::getChildren(FSList &fslist, ListMode mode, bool hidden) const {
    111148        if (!_realNode || !_realNode->isDirectory())
    112149                return false;
    113150
     
    113150
    114151        AbstractFSList tmp;
    115152       
    116         if (!_realNode->listDir(tmp, mode))
     153        if (!_realNode->getChildren(tmp, mode, hidden))
    117154                return false;
    118155       
    119156        fslist.clear();
     
    124161        return true;
    125162}
    126163
     164Common::String FilesystemNode::getDisplayName() const {
     165        assert(_realNode);
     166        return _realNode->getDisplayName();
     167}
     168
     169Common::String FilesystemNode::getName() const {
     170        assert(_realNode);
     171        return _realNode->getName();
     172}
     173
     174FilesystemNode FilesystemNode::getParent() const {
     175        if (_realNode == 0)
     176                return *this;
     177
     178        AbstractFilesystemNode *node = _realNode->getParent();
     179        if (node == 0) {
     180                return *this;
     181        } else {
     182                return FilesystemNode(node);
     183        }
     184}
     185
     186Common::String FilesystemNode::getPath() const {
     187        assert(_realNode);
     188        return _realNode->getPath();
     189}
     190
    127191bool FilesystemNode::isDirectory() const {
    128192        if (_realNode == 0)
    129193                return false;
     194       
    130195        return _realNode->isDirectory();
    131196}
    132197
    133 Common::String FilesystemNode::displayName() const {
    134         assert(_realNode);
    135         return _realNode->displayName();
     198bool FilesystemNode::isReadable() const {
     199        if (_realNode == 0)
     200                return false;
     201       
     202        return _realNode->isReadable();
    136203}
    137204
    138 Common::String FilesystemNode::name() const {
    139         assert(_realNode);
    140         return _realNode->name();
     205bool FilesystemNode::isWritable() const {
     206        if (_realNode == 0)
     207                return false;
     208       
     209        return _realNode->isWritable();
    141210}
    142211
    143 Common::String FilesystemNode::path() const {
    144         assert(_realNode);
    145         return _realNode->path();
     212bool FilesystemNode::lookupFile(FSList &results, FSList &fslist, Common::String &filename, bool hidden, bool exhaustive) const
     213{
     214        int matches = 0;
     215       
     216        for (FSList::iterator entry = fslist.begin(); entry != fslist.end(); ++entry) {
     217                if (entry->isDirectory()) {
     218                        matches += lookupFileRec(results, *entry, filename, hidden, exhaustive);
     219                }
     220        }
     221
     222        return ((matches > 0) ? true : false);
    146223}
    147224
    148 
    149 bool FilesystemNode::operator< (const FilesystemNode& node) const
     225bool FilesystemNode::lookupFile(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const
    150226{
    151         if (isDirectory() && !node.isDirectory())
    152                 return true;
    153         if (!isDirectory() && node.isDirectory())
     227        int matches;
     228       
     229        if (!dir.isDirectory())
    154230                return false;
    155         return scumm_stricmp(displayName().c_str(), node.displayName().c_str()) < 0;
     231               
     232        matches = lookupFileRec(results, dir, filename, hidden, exhaustive);
     233       
     234        return ((matches > 0) ? true : false);
     235}
     236
     237int FilesystemNode::lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const
     238{
     239        FSList entries;
     240        FSList children;
     241        int matches = 0;
     242        dir.getChildren(entries, FilesystemNode::kListAll, hidden);
     243       
     244        //Breadth search (entries in the same level)
     245        for (FSList::iterator entry = entries.begin(); entry != entries.end(); ++entry) {
     246                if (entry->isDirectory()) {
     247                        children.push_back(*entry);
     248                } else {
     249                        //TODO: here we assume all backends implement the lastPathComponent method. It is currently static,
     250                        //              so it might be a good idea to include it inside the backend class. This would enforce its
     251                        //              implementation by all ports.
     252                        if (matchString(lastPathComponent(entry->getPath()), filename.c_str())) {
     253                                results.push_back(*entry);
     254                                matches++;
     255                               
     256                                if (!exhaustive)
     257                                        break;
     258                        }
     259                }
     260        }
     261       
     262        //Depth search (entries in lower levels)
     263        for (FSList::iterator child = children.begin(); child != children.end(); ++child) {
     264                matches += lookupFileRec(results, *child, filename, hidden, exhaustive);
     265        }
     266       
     267        return matches;
    156268}
  • home/david/Projects/scummvm/common/fs.h

     
    3333class FilesystemNode;
    3434class AbstractFilesystemNode;
    3535
    36 
    3736/**
    3837 * List of multiple file system nodes. E.g. the contents of a given directory.
    3938 * This is subclass instead of just a typedef so that we can use forward
     
    4140 */
    4241class FSList : public Common::Array<FilesystemNode> {};
    4342
    44 
    4543/**
    46  * FilesystemNode provides an abstraction for file pathes, allowing for portable
     44 * FilesystemNode provides an abstraction for file paths, allowing for portable
    4745 * file system browsing. To this ends, multiple or single roots have to be supported
    4846 * (compare Unix with a single root, Windows with multiple roots C:, D:, ...).
    4947 *
     
    6462 * paths (MacOS 9 doesn't even have the notion of a "current directory").
    6563 * And if we ever want to support devices with no FS in the classical sense (Palm...),
    6664 * we can build upon this.
     65 *
     66 * This class acts as a wrapper around the AbstractFilesystemNode class defined in backends/fs.
    6767 */
    6868class FilesystemNode {
    6969private:
     70        int *_refCount;
    7071        AbstractFilesystemNode *_realNode;
    71         int *_refCount;
    72 
    7372        FilesystemNode(AbstractFilesystemNode *realNode);
    7473
    7574public:
     
    8382        };
    8483
    8584        /**
    86          * Create a new invalid FilesystemNode. In other words, isValid() for that
    87          * node returns false, and if you try to get it's path, an assert is
    88          * triggered.
     85         * Create a new pathless FilesystemNode. Since there's no path associated
     86         * with this node, path-related operations (i.e. exists(), isDirectory(),
     87         * getPath()) will always return false or raise an assertion.
    8988         */
    9089        FilesystemNode();
    9190
     
    113112        /**
    114113         * Copy operator.
    115114         */
    116         FilesystemNode &operator  =(const FilesystemNode &node);
    117 
     115        FilesystemNode &operator= (const FilesystemNode &node);
     116       
    118117        /**
    119          * Checks if the FilesystemNode is valid for any usage
     118         * Compare the name of this node to the name of another. Directories
     119         * go before normal files.
    120120         */
    121         bool isValid() const;
     121        bool operator<(const FilesystemNode& node) const;
    122122
    123123        /**
    124          * Get the parent node of this node. If this node has no parent node,
    125          * then it returns a duplicate of this node.
     124         * Indicates whether the object referred by this path exists in the filesystem or not.
     125         *
     126         * @return bool true if the path exists, false otherwise.
    126127         */
    127         FilesystemNode getParent() const;
     128        virtual bool exists() const;
    128129
    129130        /**
    130131         * 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.
     132         * directory nodes (an assertion is triggered otherwise).
     133         * If no child node with the given name exists, an invalid node is returned.
    133134         */
    134135        FilesystemNode getChild(const Common::String &name) const;
    135 
     136       
    136137        /**
    137138         * Return a list of child nodes of this directory node. If called on a node
    138139         * that does not represent a directory, false is returned.
     140         *
    139141         * @return true if succesful, false otherwise (e.g. when the directory does not exist).
    140          * @todo Rename this to listChildren or getChildren.
    141142         */
    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          */
    152         virtual bool isDirectory() const;
     143        virtual bool getChildren(FSList &fslist, ListMode mode = kListDirectoriesOnly, bool hidden = false) const;     
    153144
    154145        /**
    155146         * Return a human readable string for this node, usable for display (e.g.
     
    155146         * Return a human readable string for this node, usable for display (e.g.
    156147         * in the GUI code). Do *not* rely on it being usable for anything else,
    157148         * like constructing paths!
     149         *
    158150         * @return the display name
    159151         */
    160         virtual Common::String displayName() const;
     152        virtual Common::String getDisplayName() const;
    161153
    162154        /**
    163155         * Return a string representation of the name of the file. This is can be
     
    167159         *
    168160         * @return the file name
    169161         */
    170         virtual Common::String name() const;
     162        virtual Common::String getName() const;
    171163
    172164        /**
    173165         * Return a string representation of the file which can be passed to fopen(),
     
    180172         *
    181173         * @return the 'path' represented by this filesystem node
    182174         */
    183         virtual Common::String path() const;
     175        virtual Common::String getPath() const;
     176       
     177        /**
     178         * Get the parent node of this node. If this node has no parent node,
     179         * then it returns a duplicate of this node.
     180         */
     181        FilesystemNode getParent() const;
    184182
    185183        /**
    186          * Compare the name of this node to the name of another. Directories
    187          * go before normal files.
     184         * Indicates whether the path refers to a directory or not.
     185         *
     186         * @todo Currently we assume that a node that is not a directory
     187         * automatically is a file (ignoring things like symlinks or pipes).
     188         * That might actually be OK... but we could still add an isFile method.
     189         * Or even replace isDirectory by a getType() method that can return values like
     190         * kDirNodeType, kFileNodeType, kInvalidNodeType.
     191         */
     192        virtual bool isDirectory() const;
     193       
     194        /**
     195         * Indicates whether the object referred by this path can be read from or not.
     196         *
     197         * If the path refers to a directory, readability implies being able to read
     198         * and list the directory entries.
     199         *
     200         * If the path refers to a file, readability implies being able to read the
     201         * contents of the file.
     202         *
     203         * @return bool true if the object can be read, false otherwise.
     204         */
     205        virtual bool isReadable() const;
     206       
     207        /**
     208         * Indicates whether the object referred by this path can be written to or not.
     209         *
     210         * If the path refers to a directory, writability implies being able to modify
     211         * the directory entry (i.e. rename the directory, remove it or write files inside of it).
     212         *
     213         * If the path refers to a file, writability implies being able to write data
     214         * to the file.
     215         *
     216         * @return bool true if the object can be written to, false otherwise.
     217         */
     218        virtual bool isWritable() const;
     219       
     220        /**
     221         * Searches recursively for a filename inside the given directories.
     222         *
     223         * For each directory in the directory list a breadth-first search is performed,
     224         * that is, the current directory entries are scanned before going into subdirectories.
     225         *
     226         * @param results List to put the matches in.
     227         * @param fslist List of directories to search within.
     228         * @param filename Name of the file to look for.
     229         * @param hidden Whether to search hidden files or not.
     230         * @param exhaustive Whether to continue searching after one match has been found.
     231         *
     232         * @return true if matches could be found, false otherwise.
    188233         */
    189         bool operator< (const FilesystemNode& node) const;
     234        virtual bool lookupFile(FSList &results, FSList &fslist, Common::String &filename, bool hidden, bool exhaustive) const;
     235       
     236        /**
     237         * Searches recursively for a filename inside the given directory.
     238         *
     239         * The search is performed breadth-first, that is, the current directory entries
     240         * are scanned before going into subdirectories.
     241         *
     242         * @param results List to put the matches in.
     243         * @param FilesystemNode Directory to search within.
     244         * @param filename Name of the file to look for.
     245         * @param hidden Whether to search hidden files or not.
     246         * @param exhaustive Whether to continue searching after one match has been found.
     247         *
     248         * @return true if matches could be found, false otherwise.
     249         */
     250        virtual bool lookupFile(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const;
    190251
    191252protected:
     253        /**
     254         * Decreases the reference count to the FilesystemNode, and if necessary,
     255         * deletes the corresponding underlying references.
     256         */
    192257        void decRefCount();
     258       
     259        /**
     260         * Searches recursively for a filename inside the given directory.
     261         *
     262         * The search is performed breadth-first, that is, the current directory entries
     263         * are scanned before going into subdirectories.
     264         *
     265         * @param results List to put the matches in.
     266         * @param FilesystemNode Directory to search within.
     267         * @param filename Name of the file to look for.
     268         * @param hidden Whether to search hidden files or not.
     269         * @param exhaustive Whether to continue searching after one match has been found.
     270         *
     271         * @return The number of matches found.
     272         */
     273        int lookupFileRec(FSList &results, FilesystemNode &dir, Common::String &filename, bool hidden, bool exhaustive) const;
    193274};
    194275
    195276//} // End of namespace Common
     
    194275
    195276//} // End of namespace Common
    196277
    197 #endif
     278#endif //COMMON_FS_H
  • home/david/Projects/scummvm/common/md5.cpp

     
    246246}
    247247
    248248bool 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");
    251254                return false;
    252255        } else if (file.isDirectory()) {
    253                 warning("md5_file: using a diretory FilesystemNode");
     256                warning("md5_file: using a directory FilesystemNode");
    254257                return false;
    255258        }
    256259
    257         return md5_file(file.path().c_str(), digest, length);
     260        return md5_file(file.getPath().c_str(), digest, length);
    258261}
    259262
    260263bool md5_file(const char *name, uint8 digest[16], uint32 length) {
  • home/david/Projects/scummvm/common/savefile.h

     
    3030#include "common/noncopyable.h"
    3131#include "common/scummsys.h"
    3232#include "common/stream.h"
     33#include "common/str.h"
    3334
    3435namespace Common {
    3536
     
    7778class SaveFileManager : NonCopyable {
    7879
    7980public:
     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       
     92protected:
     93        SFMError _error;
     94        String _errorDesc;
     95       
     96public:
    8097        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       
    82125        /**
    83126         * Open the file with name filename in the given directory for saving.
    84127         * @param filename      the filename
     
    94137        virtual InSaveFile *openForLoading(const char *filename) = 0;
    95138
    96139        /**
    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.
    101143         */
    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;
    103152
    104153        /**
    105154         * Get the path to the save game directory.
  • home/david/Projects/scummvm/engines/agi/agi_v3.cpp

     
    5252        FSList fslist;
    5353        FilesystemNode dir(ConfMan.get("path"));
    5454
    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());
    5757                return errInvalidAGIFile;
    5858        }
    5959
     
    5959
    6060        for (FSList::const_iterator file = fslist.begin();
    6161            file != fslist.end() && !found; ++file) {
    62                 Common::String f = file->name();
     62                Common::String f = file->getName();
    6363                f.toLowercase();
    6464
    6565                if (f.hasSuffix("vol.0")) {
  • home/david/Projects/scummvm/engines/agi/detection.cpp

     
    18831883        // First grab all filenames and at the same time count the number of *.wag files
    18841884        for (FSList::const_iterator file = fslist->begin(); file != fslist->end(); ++file) {
    18851885                if (file->isDirectory()) continue;
    1886                 Common::String filename = file->name();
     1886                Common::String filename = file->getName();
    18871887                filename.toLowercase();
    18881888                allFiles[filename] = true; // Save the filename in a hash table
    18891889               
     
    18891889               
    18901890                if (filename.hasSuffix(".wag")) {
    18911891                        // 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();
    18931893                        wagFileCount++; // Count found *.wag files
    18941894                }
    18951895        }
  • home/david/Projects/scummvm/engines/agi/sound.cpp

     
    121121bool IIgsEnvelope::read(Common::SeekableReadStream &stream) {
    122122        for (int segNum = 0; segNum < ENVELOPE_SEGMENT_COUNT; segNum++) {
    123123                seg[segNum].bp  = stream.readByte();
    124                 seg[segNum].inc = stream.readUint16LE();
     124                seg[segNum].inc = stream.readUint16BE();
    125125        }
    126126        return !stream.ioFailed();
    127127}
     
    138138        mode    = (packedModeByte >> 1) & 3; // Bits 1-2
    139139        halt    = (packedModeByte & 1) != 0; // Bit 0 (Converted to boolean)
    140140
    141         relPitch = stream.readUint16LE();
     141        relPitch = stream.readUint16BE();
    142142
    143143        // Zero the wave address if we want to ignore the wave address info
    144144        if (ignoreAddr)
     
    264264
    265265static int playing;
    266266static ChannelInfo chn[NUM_CHANNELS];
    267 static IIgsChannelInfo IIgsChannel;
    268267static int endflag = -1;
    269268static int playingSound = -1;
    270269static uint8 env;
     
    347346        _vm->_game.sounds[resnum]->play();
    348347        playingSound = resnum;
    349348
    350         debugC(3, kDebugLevelSound, "startSound(resnum = %d, flag = %d)", resnum, flag);
    351 
    352349        switch (type) {
    353         case AGI_SOUND_SAMPLE: {
    354                 IIgsChannelInfo &chn = IIgsChannel;
    355                 IIgsSample *sampleRes = (IIgsSample *) _vm->_game.sounds[playingSound];
    356                 const IIgsWaveInfo &waveInfo = chn.ins.oscList(0).waves[0];
    357                 const IIgsSampleHeader &header = sampleRes->getHeader();
    358 
    359                 chn.ins     = header.instrument;
    360                 chn.sample  = sampleRes->getSample() + waveInfo.addr;
    361                 chn.pos     = intToFrac(0);
    362                 chn.posAdd  = intToFrac(0);
    363                 chn.note    = intToFrac(header.pitch) + doubleToFrac(waveInfo.relPitch/256.0);
    364                 chn.startEnvVol = intToFrac(0);
    365                 chn.chanVol = intToFrac(header.volume);
    366                 chn.envVol  = chn.startEnvVol;
    367                 chn.vol     = doubleToFrac(fracToDouble(chn.envVol) * fracToDouble(chn.chanVol) / 127.0);
    368                 chn.envSeg  = intToFrac(0);
    369                 chn.loop    = (waveInfo.mode == OSC_MODE_LOOP);
    370                 chn.size    = waveInfo.size - waveInfo.addr;
    371                 chn.end     = false;
     350#if 0
     351        case AGI_SOUND_SAMPLE:
     352                debugC(3, kDebugLevelSound, "IIGS sample");
     353                smp = (struct SoundIIgsSample *)_vm->_game.sounds[resnum].rdata;
     354                for (i = 0; i < NUM_CHANNELS; i++) {
     355                        chn[i].type = type;
     356                        chn[i].flags = 0;
     357                        chn[i].ins = (int16 *)&_vm->_game.sounds[resnum].rdata[54];
     358                        chn[i].size = ((int)smp->sizeHi << 8) + smp->sizeLo;
     359                        chn[i].ptr = &playSample[i];
     360                        chn[i].timer = 0;
     361                        chn[i].vol = 0;
     362                        chn[i].end = 0;
     363                }
    372364                break;
    373         }
    374 #if 0
    375365        case AGI_SOUND_MIDI:
    376366                debugC(3, kDebugLevelSound, "IIGS MIDI sequence");
    377367
     
    420410        int i;
    421411
    422412        endflag = -1;
    423         if (_vm->_soundemu != SOUND_EMU_APPLE2GS) {
    424                 for (i = 0; i < NUM_CHANNELS; i++)
    425                         stopNote(i);
    426         }
     413        for (i = 0; i < NUM_CHANNELS; i++)
     414                stopNote(i);
    427415
    428416        if (playingSound != -1) {
    429417                _vm->_game.sounds[playingSound]->stop();
    430                
    431                 if (_vm->_soundemu == SOUND_EMU_APPLE2GS) {
    432                         IIgsChannel.end     = true;
    433                         IIgsChannel.chanVol = intToFrac(0);
    434                 }
    435 
    436418                playingSound = -1;
    437419        }
    438420}
     
    581563}
    582564
    583565void SoundMgr::playSampleSound() {
    584         if (_vm->_soundemu != SOUND_EMU_APPLE2GS) {
    585                 warning("Trying to play a sample but not using Apple IIGS sound emulation mode");
    586                 return;
    587         }
    588 
    589         if (playingSound != -1)
    590                 playing = !IIgsChannel.end;
     566        playNote(0, 11025 * 10, 200);
     567        playing = 1;
    591568}
    592569
    593570void SoundMgr::playAgiSound() {
     
    635612        if (endflag == -1)
    636613                return;
    637614
    638         if (_vm->_soundemu == SOUND_EMU_APPLE2GS) {
    639                 if (playingSound != -1) {
    640                         if (_vm->_game.sounds[playingSound]->type() == AGI_SOUND_MIDI) {
    641                                 /* play_midi_sound (); */
    642                                 //warning("playSound: Trying to play an Apple IIGS MIDI sound. Not yet implemented!");
    643                                 playing = 0;
    644                         } else if (_vm->_game.sounds[playingSound]->type() == AGI_SOUND_SAMPLE) {
    645                                 //debugC(3, kDebugLevelSound, "playSound: Trying to play an Apple IIGS sample");
    646                                 playSampleSound();
    647                         }
    648                 }
    649         } else {
    650                 //debugC(3, kDebugLevelSound, "playSound: Trying to play a PCjr 4-channel sound");
     615        if (chn[0].type == AGI_SOUND_MIDI) {
     616                /* play_midi_sound (); */
     617                playing = 0;
     618        } else if (chn[0].type == AGI_SOUND_SAMPLE) {
     619                playSampleSound();
     620        } else
    651621                playAgiSound();
    652         }
    653622
    654623        if (!playing) {
    655                 if (_vm->_soundemu != SOUND_EMU_APPLE2GS) {
    656                         for (i = 0; i < NUM_CHANNELS; chn[i++].vol = 0);
    657                 }
     624                for (i = 0; i < NUM_CHANNELS; chn[i++].vol = 0);
    658625
    659626                if (endflag != -1)
    660627                        _vm->setflag(endflag, true);
     
    673640
    674641        memset(sndBuffer, 0, BUFFER_SIZE << 1);
    675642
    676         // Handle Apple IIGS sound mixing here
    677         if (_vm->_soundemu == SOUND_EMU_APPLE2GS && playing && playingSound != -1) {
    678                 IIgsChannelInfo &chn = IIgsChannel;
    679                 IIgsWaveInfo &waveInfo = chn.ins.oscList(0).waves[0];
    680 
    681                 //uint period = noteToPeriod(fracToInt(chn.note + FRAC_HALF));
    682                 //chn.posAdd = ((frac_t) (118600 * 4 / period)) << (FRAC_BITS - 8);
    683 
    684                 // Hertz (number of vibrations a second) = 6.875 x 2 ^ ( ( 3 + MIDI_Pitch ) / 12 )
    685                 // From http://www.musicmasterworks.com/WhereMathMeetsMusic.html
    686                 //double hertz = 6.875 * pow(SEMITONE, 3 + fracToDouble(chn.note));
    687                 //double hertz = 8.175798915644 * pow(SEMITONE, fracToDouble(chn.note));
    688                 // double step = getRate() / hertz;
    689                 // chn.posAdd = doubleToFrac(step);
    690                
    691                 // Frequency multiplier was 1076.0 based on tests made with MESS 0.117.
    692                 // Tests made with KEGS32 averaged the multiplier to around 1045.