src/tools/tDirectories.h

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 Copyright (C) 2004  Armagetron Advanced Team (http://sourceforge.net/projects/armagetronad/) 
00008 
00009 **************************************************************************
00010 
00011 This program is free software; you can redistribute it and/or
00012 modify it under the terms of the GNU General Public License
00013 as published by the Free Software Foundation; either version 2
00014 of the License, or (at your option) any later version.
00015 
00016 This program is distributed in the hope that it will be useful,
00017 but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 GNU General Public License for more details.
00020 
00021 You should have received a copy of the GNU General Public License
00022 along with this program; if not, write to the Free Software
00023 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00024   
00025 ***************************************************************************
00026 
00027 */
00028 
00029 #ifndef ArmageTron_tDirectories_H
00030 #define ArmageTron_tDirectories_H
00031 
00032 #include <fstream>
00033 #include "tArray.h"
00034 #include "tString.h"
00035 
00036 class tPath
00037 {
00038 public:
00039     bool Open    ( std::ifstream& f,
00040                    const char* filename   ) const; // opens a file to read
00041 
00042     bool Open    ( std::ofstream& f,
00043                    const char* filename,
00044                    std::ios::openmode mode = std::ios::out,
00045                    bool sensitive = false ) const; // opens a file to write
00046 
00047     bool Open    ( std::fstream& f,
00048                    const char* filename   ) const; // let's read and write at the same time shall we?
00049 
00050     tString GetReadPath   ( const char* filename   ) const; // finds the full path to a file to read
00051     tString GetWritePath  ( const char* filename   ) const; // finds the full path to a file to write
00052     static bool IsValidPath( char const * filename ); 
00053 
00054     tString GetPaths(void) const; 
00055 
00056     tPath(){};
00057     virtual ~tPath(){};
00058 protected:
00059     virtual void    Paths ( tArray< tString >& paths ) const = 0;  // maximum priority
00060 };
00061 
00062 class tPathResource: public tPath {
00063 public:
00064     tString GetWritePath(const char *filename) const;
00065     static tString GetDirPath(); 
00066 private:
00067     void Paths(tArray< tString >& paths) const;
00068 };
00069 
00070 class tPathScripts: public tPath {
00071 public:
00072     static tString GetDirPath(); 
00073 private:
00074     void Paths ( tArray< tString >& paths ) const;
00075 };
00076 
00077 #ifdef DEDICATED
00078 class tPathWebroot: public tPath
00079 {
00080 public:
00081     static tString GetDirPath();
00082 private:
00083     void Paths ( tArray< tString >& paths ) const;
00084 };
00085 #endif
00086 
00087 class tDirectories
00088 {
00089 public:
00090     enum { eGetFilesAllFiles = 0, eGetFilesFilesOnly = 1, eGetFilesDirsOnly = 2 };
00091 
00092     static const tPath& Data();              // directory for game data
00093     static const tPath& Music();             // directory for game music
00094     static const tPath& Config();            // directory for static configuration files
00095     static const tPath& Var();               // directory for dynamic logs and highscores
00096     static const tPath& Screenshot();        // directory for screenshots
00097     static const tPathResource& Resource();  // directory for resources
00098     static const tPath& Scripts();
00099 
00100 #ifdef DEDICATED    
00101     static const tPathWebroot& Webroot();    // directory for webroot of embedded web server
00102 #endif
00103 
00104     static void SetData( const tString& dir );       // set location of data directory
00105     static void SetUserData( const tString& dir );   // set location of user data directory
00106     static void SetConfig( const tString& dir );     // set location of config directory
00107     static void SetUserConfig( const tString& dir ); // set location of user config directory
00108     static void SetVar( const tString& dir );        // set location of var directory
00109     static void SetScreenshot( const tString& dir ); // set location of screenshot directory
00110     static void SetResource( const tString& dir );
00111     static void SetAutoResource( const tString& dir );
00112     static void SetIncludedResource( const tString& dir );
00113 
00114     // get a list of files for a directory
00115     // flag: 0=files+dirs, 1=files, 2=dirs
00116     static void GetFiles( const tString& dir, const tString& fileSpec,
00117                           tArray< tString >& files, int flag = eGetFilesAllFiles );
00118 
00119     // check if a file name matches a wildcard (* and ? are valid wild cards)
00120     static bool FileMatchesWildcard( const char *str, const char *pattern,
00121                                      bool ignoreCase = true );
00122 
00123     // convert a file name to a menu name (strip extension, replace '_' with ' ')
00124     static tString& FileNameToMenuName( const char* fileName, tString& menuName );
00125 
00126     // split the file spec into a list
00127     static void GetSpecList( const tString& fileSpec, tArray< tString >& specList );
00128 
00129     // sort the list of files
00130     static void SortFiles( tArray< tString >& files );
00131 };
00132 
00133 #endif

Generated on Sat Mar 15 22:56:00 2008 for Armagetron Advanced by  doxygen 1.5.4