D:/Zythum/DinoKod/Common/Directory.cpp

00001 #include <windows.h>
00002 #include "Common/Ini.h"
00003 #include "Common/Directory.h"
00004 
00005 KDirectory      g_Directory;
00006 
00007 #define KPATHINIFILENAME                "Path.ini"
00008 
00009 //---------------------------------------------------------------------------------------------------------------------
00010 KDirectory::KDirectory()
00011 {
00012         char    pCurDir[1024];
00013         GetCurrentDirectory( sizeof( pCurDir ), pCurDir );
00014         for( s32 i = 0; i < (s32)strlen( pCurDir ); i ++ )
00015                 if( pCurDir[i] == '\\' )
00016                         pCurDir[i] = '/';
00017 
00018         m_sCurrentDirectory = pCurDir;
00019         m_sCurrentDirectory += "/";
00020 
00021         AddFile( KStr( KPATHINIFILENAME ) );
00022 }
00023 
00024 //---------------------------------------------------------------------------------------------------------------------
00025 KDirectory::~KDirectory()
00026 {
00027         RemoveFile( KStr( KPATHINIFILENAME ) );
00028         m_IniList.Clear();
00029 }
00030 
00031 //---------------------------------------------------------------------------------------------------------------------
00032 bool KDirectory::AddFile( KStr& sFileName )
00033 {
00034         KDirectoryFile*         pDirectoryFile = m_IniList.GetFirst();
00035         
00036         // Verifie qu'un fichier similaire n'existe pas déja
00037         while( pDirectoryFile )
00038         {
00039                 if( pDirectoryFile->m_sFileName == sFileName )
00040                         return false;
00041 
00042                 pDirectoryFile = m_IniList.GetNext( pDirectoryFile );
00043         }
00044 
00045         // Ajouter le fichier .ini
00046         pDirectoryFile = new KDirectoryFile( sFileName );
00047         m_IniList.Add( pDirectoryFile );
00048 
00049         return true;
00050 }
00051 
00052 //---------------------------------------------------------------------------------------------------------------------
00053 bool KDirectory::RemoveFile( KStr& sFileName )
00054 {
00055         KDirectoryFile*         pDirectoryFile = m_IniList.GetFirst();
00056 
00057         // Recherche le fichier .ini
00058         while( pDirectoryFile )
00059         {
00060                 if( pDirectoryFile->m_sFileName == sFileName )
00061                 {
00062                         // Supprimer le fichier .ini
00063                         m_IniList.Remove( pDirectoryFile );
00064                         Deletep( pDirectoryFile );
00065                         return true;
00066                 }
00067 
00068                 pDirectoryFile = m_IniList.GetNext( pDirectoryFile );
00069         }
00070         
00071         return false;
00072 }
00073 
00074 //---------------------------------------------------------------------------------------------------------------------
00075 KStr KDirectory::GetPath( KStr& sDirectory, s32 nPath )
00076 {
00077         KStr    sPath;
00078 
00079         KDirectoryFile* pDirectoryFile = m_IniList.GetFirst();
00080 
00081         for( s32 i = 0; i < nPath; i ++ )
00082                 pDirectoryFile = m_IniList.GetNext( pDirectoryFile );
00083 
00084         if( pDirectoryFile )
00085         {
00086                 char    pCurDir[1024];
00087                 GetCurrentDirectory( sizeof( pCurDir ), pCurDir );
00088                 sPath = m_sCurrentDirectory;
00089                 sPath += pDirectoryFile->m_pIni->ReadString( "PATH", sDirectory, "/" );
00090         }
00091 
00092         return sPath;
00093 }

Generated on Sun Mar 25 20:02:10 2007 for Zythum Project by  doxygen 1.5.1-p1