00001 00012 /*************************************************************************** 00013 * Copyright (C) 2007 by Jan Koci * 00014 * honza.koci@email.cz * 00015 * http://kengine.sourceforge.net/tutorial/ 00016 * * 00017 * This program is free software; you can redistribute it and/or modify * 00018 * it under the terms of the GNU General Public License as published by * 00019 * the Free Software Foundation; either version 2 of the License, or * 00020 * (at your option) any later version. * 00021 * * 00022 * This program is distributed in the hope that it will be useful, * 00023 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00025 * GNU General Public License for more details. * 00026 * * 00027 * You should have received a copy of the GNU General Public License * 00028 * along with this program; if not, write to the * 00029 * Free Software Foundation, Inc., * 00030 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00031 ***************************************************************************/ 00032 00033 #include "K3dDir.h" 00034 00035 K3dDir::K3dDir(K3dGameData *_pGameData) 00036 { 00037 m_pGameData = _pGameData; 00038 // Set this class to the global game data 00039 m_pGameData->SetDir(this); 00040 } 00041 K3dDir::~K3dDir() 00042 { 00043 } 00044 00047 bool K3dDir::CreateDirectory(const char* _strDir) 00048 { 00049 if((mkdir(_strDir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) == 0) 00050 { 00051 return true; 00052 } 00053 return false; 00054 } 00055 00058 bool K3dDir::OpenDirectory(const char* _strDir) 00059 { 00060 // Clear previous file array 00061 m_tDirFileArray.clear(); 00062 m_pDir=opendir(_strDir); 00063 if (!m_pDir) 00064 { 00065 cerr << "opendir() failure; terminating" << endl; 00066 return false; 00067 } 00068 errno=0; 00069 while ((m_ptEnt=readdir(m_pDir))) 00070 { 00071 // Add new file 00072 m_tDirFileArray.push_back(m_ptEnt->d_name); 00073 } 00074 if (errno) 00075 { 00076 cerr << "readdir() failure; terminating" << endl; 00077 return false; 00078 } 00079 closedir(m_pDir); 00080 // Sort alphabetically directory array 00081 sort( m_tDirFileArray.begin(), m_tDirFileArray.end()); 00082 return true; 00083 }