tDirectories Class Reference

#include <tDirectories.h>

List of all members.

Public Types

enum  { eGetFilesAllFiles = 0, eGetFilesFilesOnly = 1, eGetFilesDirsOnly = 2 }

Static Public Member Functions

static const tPathData ()
static const tPathMusic ()
static const tPathConfig ()
static const tPathVar ()
static const tPathScreenshot ()
static const tPathResourceResource ()
static const tPathScripts ()
static void SetData (const tString &dir)
static void SetUserData (const tString &dir)
static void SetConfig (const tString &dir)
static void SetUserConfig (const tString &dir)
static void SetVar (const tString &dir)
static void SetScreenshot (const tString &dir)
static void SetResource (const tString &dir)
static void SetAutoResource (const tString &dir)
static void SetIncludedResource (const tString &dir)
static void GetFiles (const tString &dir, const tString &fileSpec, tArray< tString > &files, int flag=eGetFilesAllFiles)
static bool FileMatchesWildcard (const char *str, const char *pattern, bool ignoreCase=true)
static tStringFileNameToMenuName (const char *fileName, tString &menuName)
static void GetSpecList (const tString &fileSpec, tArray< tString > &specList)
static void SortFiles (tArray< tString > &files)


Detailed Description

Definition at line 87 of file tDirectories.h.


Member Enumeration Documentation

anonymous enum

Enumerator:
eGetFilesAllFiles 
eGetFilesFilesOnly 
eGetFilesDirsOnly 

Definition at line 90 of file tDirectories.h.


Member Function Documentation

const tPath & tDirectories::Data (  )  [static]

Definition at line 882 of file tDirectories.cpp.

Referenced by _wrap_TDirectories_data(), eSoundMixer::Init(), tLocaleItem::Load(), eWavData::Load(), gCycleVisuals::LoadModelSafe(), tPlayList::LoadPlaylist(), eSoundMixer::LoadPlaylist(), main(), rFontContainer::New(), rModel::rModel(), se_rubyEval(), se_SoundInit(), sky_select(), st_LoadConfig(), and st_PrintPathInfo().

00883 {
00884     return st_Data;
00885 }

Here is the caller graph for this function:

const tPath & tDirectories::Music (  )  [static]

Definition at line 887 of file tDirectories.cpp.

Referenced by _wrap_TDirectories_music().

00888 {
00889     return st_Music;
00890 }

Here is the caller graph for this function:

const tPath & tDirectories::Config (  )  [static]

Definition at line 892 of file tDirectories.cpp.

Referenced by _wrap_TDirectories_config(), gServerFavorites::AlternativesMenu(), nServerInfo::GetMasters(), gAICharacter::LoadAll(), main(), st_Include(), st_LoadConfig(), st_PrintPathInfo(), and gGame::StateUpdate().

00893 {
00894     return st_Config;
00895 }

Here is the caller graph for this function:

const tPath & tDirectories::Var (  )  [static]

Definition at line 902 of file tDirectories.cpp.

Referenced by _wrap_TDirectories_var(), nServerInfo::GetFromMaster(), uMenuItemStringWithHistory::history_t::history_t(), main(), tStatFile::open(), nServerInfo::Save(), nMachinePersistor::SaveMachines(), st_Include(), st_LoadConfig(), st_PrintPathInfo(), st_SaveConfig(), and gGame::StateUpdate().

00903 {
00904     return st_Var;
00905 }

Here is the caller graph for this function:

const tPath & tDirectories::Screenshot (  )  [static]

Definition at line 907 of file tDirectories.cpp.

Referenced by _wrap_TDirectories_screenshot(), make_screenshot(), and st_PrintPathInfo().

00908 {
00909     return st_Screenshot;
00910 }

Here is the caller graph for this function:

const tPathResource & tDirectories::Resource (  )  [static]

Definition at line 912 of file tDirectories.cpp.

Referenced by _wrap_TDirectories_resource(), tResourceManager::locateResource(), st_PrintPathInfo(), and tXmlParserNamespace::tXmlParser::ValidateXml().

00913 {
00914     return st_Resource;
00915 }

Here is the caller graph for this function:

const tPath & tDirectories::Scripts (  )  [static]

Definition at line 897 of file tDirectories.cpp.

Referenced by _wrap_TDirectories_scripts().

00898 {
00899     return st_Scripts;
00900 }

Here is the caller graph for this function:

void tDirectories::SetData ( const tString dir  )  [static]

Definition at line 918 of file tDirectories.cpp.

References st_DataDir.

Referenced by _wrap_TDirectories_set_data().

00919 {
00920     st_DataDir = dir;
00921 }

Here is the caller graph for this function:

void tDirectories::SetUserData ( const tString dir  )  [static]

Definition at line 924 of file tDirectories.cpp.

References st_UserDataDir.

Referenced by _wrap_TDirectories_set_user_data().

00925 {
00926     st_UserDataDir = dir;
00927 }

Here is the caller graph for this function:

void tDirectories::SetConfig ( const tString dir  )  [static]

Definition at line 930 of file tDirectories.cpp.

References st_ConfigDir.

Referenced by _wrap_TDirectories_set_config().

00931 {
00932     st_ConfigDir = dir;
00933 }

Here is the caller graph for this function:

void tDirectories::SetUserConfig ( const tString dir  )  [static]

Definition at line 936 of file tDirectories.cpp.

References st_UserConfigDir.

Referenced by _wrap_TDirectories_set_user_config().

00937 {
00938     st_UserConfigDir = dir;
00939 }

Here is the caller graph for this function:

void tDirectories::SetVar ( const tString dir  )  [static]

Definition at line 942 of file tDirectories.cpp.

References st_VarDir.

Referenced by _wrap_TDirectories_set_var().

00943 {
00944     st_VarDir = dir;
00945 }

Here is the caller graph for this function:

void tDirectories::SetScreenshot ( const tString dir  )  [static]

Definition at line 948 of file tDirectories.cpp.

References st_ScreenshotDir.

Referenced by _wrap_TDirectories_set_screenshot().

00948                                                      {
00949     st_ScreenshotDir = dir;
00950 }

Here is the caller graph for this function:

void tDirectories::SetResource ( const tString dir  )  [static]

Definition at line 952 of file tDirectories.cpp.

References st_ResourceDir.

Referenced by _wrap_TDirectories_set_resource().

00952                                                    {
00953     st_ResourceDir = dir;
00954 }

Here is the caller graph for this function:

void tDirectories::SetAutoResource ( const tString dir  )  [static]

Definition at line 956 of file tDirectories.cpp.

References st_AutoResourceDir.

Referenced by _wrap_TDirectories_set_auto_resource().

00956                                                        {
00957     st_AutoResourceDir = dir;
00958 }

Here is the caller graph for this function:

void tDirectories::SetIncludedResource ( const tString dir  )  [static]

Definition at line 960 of file tDirectories.cpp.

References st_IncludedResourceDir.

Referenced by _wrap_TDirectories_set_included_resource().

00960                                                            {
00961     st_IncludedResourceDir = dir;
00962 }

Here is the caller graph for this function:

void tDirectories::GetFiles ( const tString dir,
const tString fileSpec,
tArray< tString > &  files,
int  flag = eGetFilesAllFiles 
) [static]

Definition at line 1061 of file tDirectories.cpp.

References closedir(), dirent::d_name, eGetFilesDirsOnly, eGetFilesFilesOnly, FileMatchesWildcard(), GetSpecList(), GrowingArrayBase::Len(), tString::Len(), NULL, opendir(), pos, readdir(), tArray< T, MALLOC >::SetLen(), and SortFiles().

Referenced by _wrap_TDirectories_get_files__SWIG_0(), and _wrap_TDirectories_get_files__SWIG_1().

01063 {
01064     tArray<tString> specList;
01065     long pos = 0;
01066     struct stat statbuf;
01067     tString temp;
01068     bool bDir = false;
01069 
01070     files.SetLen( 0 );
01071 
01072     // Check for multiple file specs
01073     GetSpecList( fileSpec, specList );
01074 
01075     DIR *dirp;
01076     struct dirent *entry;
01077 
01078     dirp = opendir( dir );
01079 
01080     if ( dirp != NULL )
01081     {
01082         while ( ( entry = readdir( dirp ) ) != NULL )
01083         {
01084             // Ignore "." and ".." entries
01085             if ( entry->d_name[0] != '.' )
01086             {
01087                 // Build path.  Make sure dir ends with a '/' or '\'.
01088                 temp = dir;
01089                 if ( ( dir.Len() > 1 ) && ( dir[ dir.Len() - 2 ] != '/' && dir[ dir.Len() - 2 ] != '\\' ) )
01090                 {
01091                     temp += "/";
01092                 }
01093                 temp += entry->d_name;
01094 
01095                 // Is the entry a directory?
01096                 bDir = false;
01097                 if ( stat( temp, &statbuf ) == 0 )
01098                 {
01099                     if( statbuf.st_mode & S_IFDIR )
01100                     {
01101                         bDir = true;
01102                         // Don't add directories when flag = 1
01103                         if ( flag == eGetFilesFilesOnly )
01104                             continue;
01105                     }
01106                     else
01107                     {
01108                         // Don't add files when flag = 2
01109                         if ( flag == eGetFilesDirsOnly )
01110                             continue;
01111                     }
01112                 }
01113 
01114                 // If the entry matches a file spec add it to the list
01115                 for ( int i = 0; i < specList.Len(); i++ )
01116                 {
01117                     if ( FileMatchesWildcard( entry->d_name, specList( i ), true ) )
01118                     {
01119                         files[ pos ] = entry->d_name;
01120                         if ( bDir )
01121                             files[ pos ] += "/";
01122                         pos++;
01123                         break;
01124                     }
01125                 }
01126             }
01127         }
01128 
01129         closedir( dirp );
01130     }
01131 
01132     // Sort the list of files
01133     SortFiles( files );
01134 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool tDirectories::FileMatchesWildcard ( const char *  str,
const char *  pattern,
bool  ignoreCase = true 
) [static]

Definition at line 988 of file tDirectories.cpp.

References c.

Referenced by _wrap_TDirectories_file_matches_wildcard__SWIG_0(), _wrap_TDirectories_file_matches_wildcard__SWIG_1(), and GetFiles().

00990 {
00991     int c;
00992 
00993     while (*pattern)
00994     {
00995         if (!*str && *pattern != '*')
00996             return false;
00997 
00998         switch (c = *pattern++)
00999         {
01000 
01001         case '*':
01002             while (*pattern == '*')
01003                 pattern++;
01004 
01005             if (!*pattern)
01006                 return true;
01007 
01008             if (*pattern != '?' && *pattern != '\\')
01009             {
01010                 if (ignoreCase)
01011                 {
01012                     while (*str && tolower(*pattern) != tolower(*str) )
01013                         str++;
01014                 }
01015                 else
01016                 {
01017                     while (*str && *pattern != *str )
01018                         str++;
01019                 }
01020             }
01021 
01022             while (*str)
01023             {
01024                 if (FileMatchesWildcard(str, pattern, ignoreCase))
01025                     return true;
01026                 str++;
01027             }
01028             return false;
01029 
01030         case '?':
01031             if (*str)
01032                 break;
01033             return false;
01034 
01035         case '\\':
01036             if (*pattern)
01037                 c = *pattern++;
01038 
01039         default:
01040             if (ignoreCase)
01041             {
01042                 if (tolower(c) != tolower(*str))
01043                     return false;
01044             }
01045             else
01046             {
01047                 if (c != *str)
01048                     return false;
01049             }
01050             break;
01051 
01052         }
01053         str++;
01054     }
01055 
01056     return !*str;
01057 }

Here is the caller graph for this function:

tString & tDirectories::FileNameToMenuName ( const char *  fileName,
tString menuName 
) [static]

Definition at line 1137 of file tDirectories.cpp.

Referenced by _wrap_TDirectories_file_name_to_menu_name().

01138 {
01139     char szBuf[256];
01140     int i = 0;
01141 
01142     // copy string to buffer for manipulation
01143     memset( szBuf, 0, sizeof( szBuf ) );
01144     strncpy( szBuf, fileName, sizeof( szBuf ) - 1 );
01145 
01146     // skip translation strings
01147     if ( szBuf[0] != '$' )
01148     {
01149         // strip extension
01150         for ( i = strlen(szBuf); i >= 0; i-- )
01151         {
01152             if ( szBuf[i] == '.' )
01153             {
01154                 szBuf[i] = '\0';
01155             }
01156         }
01157 
01158         // replace underscores with spaces
01159         for ( i = 0; (unsigned)i < strlen(szBuf); i++ )
01160         {
01161             if ( szBuf[i] == '_' )
01162             {
01163                 szBuf[i] = ' ';
01164             }
01165         }
01166     }
01167 
01168     menuName = szBuf;
01169 
01170     return menuName;
01171 }

Here is the caller graph for this function:

void tDirectories::GetSpecList ( const tString fileSpec,
tArray< tString > &  specList 
) [static]

Definition at line 1174 of file tDirectories.cpp.

References NULL, pos, and tArray< T, MALLOC >::SetLen().

Referenced by _wrap_TDirectories_get_spec_list(), and GetFiles().

01175 {
01176     char szBuf[256];
01177     char szSep[] = ";";
01178     char *token = NULL;
01179     long pos = 0;
01180 
01181     specList.SetLen( 0 );
01182 
01183     // Check for multiple file specs
01184     memset( szBuf, 0, sizeof( szBuf ) );
01185     strncpy( szBuf, (const char *) fileSpec, sizeof( szBuf ) - 1 );
01186     token = strtok( szBuf, szSep );
01187     while( token != NULL )
01188     {
01189         specList[ pos++ ] = token;
01190         token = strtok( NULL, szSep );
01191     }
01192 }

Here is the call graph for this function:

Here is the caller graph for this function:

void tDirectories::SortFiles ( tArray< tString > &  files  )  [static]

Definition at line 1208 of file tDirectories.cpp.

References GrowingArrayBase::Len(), pos, and tStringLessThan().

Referenced by _wrap_TDirectories_sort_files(), and GetFiles().

01209 {
01210     tString temp;
01211     long pos = 0;
01212 
01213     // bubble sort for now
01214     for ( pos = 0; pos < files.Len() - 1; pos ++ )
01215     {
01216         for ( long pos2 = pos + 1; pos2 < files.Len(); pos2++ )
01217         {
01218             //if ( strcmp( (const char *) files( pos2 ), (const char *) files( pos ) ) < 0 )
01219             if ( tStringLessThan( files( pos2 ), files( pos ) ) )
01220             {
01221                 temp = files( pos );
01222                 files( pos ) = files( pos2 );
01223                 files( pos2 ) = temp;
01224             }
01225         }
01226     }
01227 }

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:56:20 2008 for Armagetron Advanced by  doxygen 1.5.4