Back to index

supertuxkart  0.5+dfsg1
file_manager.hpp
Go to the documentation of this file.
00001 //  $Id: file_manager.hpp 2111 2008-05-31 07:04:30Z cosmosninja $
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2004 Steve Baker <sjbaker1@airmail.net>
00005 //
00006 //  This program is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU General Public License
00008 //  as published by the Free Software Foundation; either version 2
00009 //  of the License, or (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program; if not, write to the Free Software
00018 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020 #ifndef HEADER_FILE_MANAGER_H
00021 #define HEADER_FILE_MANAGER_H
00022 
00023 #include <string>
00024 #include <vector>
00025 #include <set>
00026 #include "callback_manager.hpp"
00027 
00028 class FileManager 
00029 {
00030 private:
00031     bool                        m_is_full_path;
00032     std::string                 m_root_dir;
00033     std::vector<std::string>    m_texture_search_path,
00034                                 m_model_search_path,
00035                                 m_music_search_path;
00036     bool findFile               (std::string& full_path,
00037                                  const std::string& fname, 
00038                                  const std::vector<std::string>& search_path) const;
00039 public:
00040     FileManager();
00041     ~FileManager();
00042 
00043     std::string getHomeDir       () const;
00044     std::string getTrackDir      () const;
00045     std::string getKartDir       () const;
00046     std::string getHerringDir    () const;
00047     std::string getTranslationDir() const;
00048     std::vector<std::string>getMusicDirs() const;
00049     std::string getTextureFile   (const std::string& fname) const;
00050     std::string getKartFile      (const std::string& fname,
00051                                   const std::string& kart="") const;
00052     std::string getTrackFile     (const std::string& fname, 
00053                                   const std::string& track="") const;
00054     std::string getConfigFile    (const std::string& fname) const;
00055     std::string getHighscoreFile (const std::string& fname) const;
00056     std::string getLogFile       (const std::string& fname) const;
00057     std::string getHerringFile   (const std::string& fname) const;
00058     std::string getMusicFile     (const std::string& fname) const;
00059     std::string getSFXFile       (const std::string& fname) const;
00060     std::string getFontFile      (const std::string& fname) const;
00061     std::string getModelFile     (const std::string& fname) const;
00062 #ifdef HAVE_GHOST_REPLAY
00063     std::string getReplayFile    (const std::string& fname) const;
00064 #endif
00065 
00066     void listFiles(std::set<std::string>& result, const std::string& dir,
00067                    bool is_full_path=false, bool make_full_path=false)
00068         const;
00069 
00070     void       pushTextureSearchPath(const std::string& path) 
00071                                     { m_texture_search_path.push_back(path);}
00072     void       pushModelSearchPath  (const std::string& path)
00073                                     { m_model_search_path.push_back(path);  }
00074     void       pushMusicSearchPath  (const std::string& path)
00075                                     { m_music_search_path.push_back(path);  }
00076     void       popTextureSearchPath () {m_texture_search_path.pop_back();   }
00077     void       popModelSearchPath   () {m_model_search_path.pop_back();     }
00078     void       popMusicSearchPath   () {m_music_search_path.pop_back();     }
00079     void       initConfigDir();
00080 private:
00081     void         makePath     (std::string& path, const std::string& dir, 
00082                                const std::string& fname) const;
00083 };
00084 
00085 extern FileManager* file_manager;
00086 
00087 #endif
00088