From ba5b6ca75187e18942c463f7300b49061ebdc183 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sun, 25 Mar 2012 14:24:51 +0000 Subject: A globally-accessible OS-independent GetDirectoryContents() function for listing all objects in a folder as an AStringList git-svn-id: http://mc-server.googlecode.com/svn/trunk@433 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cFileFormatUpdater.cpp | 58 ++++--------------------------------------- 1 file changed, 5 insertions(+), 53 deletions(-) (limited to 'source/cFileFormatUpdater.cpp') diff --git a/source/cFileFormatUpdater.cpp b/source/cFileFormatUpdater.cpp index d17a35bb0..b58239eb2 100644 --- a/source/cFileFormatUpdater.cpp +++ b/source/cFileFormatUpdater.cpp @@ -12,13 +12,6 @@ -typedef std::list< std::string > StringList; -StringList GetDirectoryContents( const char* a_Directory ); - - - - - void cFileFormatUpdater::UpdateFileFormat() { UpdatePlayersOfWorld("world"); @@ -31,13 +24,13 @@ void cFileFormatUpdater::UpdateFileFormat() // Convert player .bin files to JSON void cFileFormatUpdater::UpdatePlayersOfWorld( const char* a_WorldName ) { - std::string PlayerDir = std::string( a_WorldName ) + "/player/"; + AString PlayerDir = AString( a_WorldName ) + "/player/"; - StringList AllFiles = GetDirectoryContents( PlayerDir.c_str() ); - for( StringList::iterator itr = AllFiles.begin(); itr != AllFiles.end(); ++itr ) + AStringList AllFiles = GetDirectoryContents( PlayerDir.c_str() ); + for (AStringList::iterator itr = AllFiles.begin(); itr != AllFiles.end(); ++itr ) { - std::string & FileName = *itr; - if( FileName.rfind(".bin") != std::string::npos ) // Get only the files ending in .bin + AString & FileName = *itr; + if (FileName.rfind(".bin") != AString::npos) // Get only the files ending in .bin { PlayerBINtoJSON( (PlayerDir + FileName).c_str() ); } @@ -148,44 +141,3 @@ void cFileFormatUpdater::PlayerBINtoJSON( const char* a_FileName ) - -// Helper function -StringList GetDirectoryContents( const char* a_Directory ) -{ - StringList AllFiles; -#ifdef _WIN32 - std::string FileFilter = std::string( a_Directory ) + "*.*"; - HANDLE hFind; - WIN32_FIND_DATA FindFileData; - - if( ( hFind = FindFirstFile(FileFilter.c_str(), &FindFileData) ) != INVALID_HANDLE_VALUE) - { - do - { - AllFiles.push_back( FindFileData.cFileName ); - } while( FindNextFile(hFind, &FindFileData) ); - FindClose(hFind); - } -#else - DIR *dp; - struct dirent *dirp; - if( (dp = opendir( a_Directory ) ) == NULL) - { - LOGERROR("Error (%i) opening %s\n", errno, a_Directory ); - } - else - { - while ((dirp = readdir(dp)) != NULL) - { - AllFiles.push_back( dirp->d_name ); - } - closedir(dp); - } -#endif - - return AllFiles; -} - - - - -- cgit v1.2.3