FIXE: Linux/Windows compilation : revert the code of the 'void dir(...)' function for windows with using conditional compilation.

This commit is contained in:
liria 2013-06-08 15:38:04 +02:00
parent 4cc48daadd
commit f03dfb40de

View file

@ -35,10 +35,11 @@
#include "nel/3d/scene_group.h" #include "nel/3d/scene_group.h"
// #include <windows.h>
#include <dirent.h> /* Pour l'utilisation des dossiers */ #include <dirent.h>
#ifndef WIN32 #ifdef NL_OS_WINDOWS
#include <windows.h>
#else
#include <sys/types.h> #include <sys/types.h>
#endif #endif
#include <unistd.h> /* getcwd,chdir -- replacement for getCurDiretory & setCurDirectory on windows */ #include <unistd.h> /* getcwd,chdir -- replacement for getCurDiretory & setCurDirectory on windows */
@ -133,8 +134,31 @@ struct CZoneLimits
}; };
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
#ifdef NL_OS_WINDOWS // win32 code
void dir (const string &sFilter, vector<string> &sAllFiles, bool bFullPath)
{
WIN32_FIND_DATA findData;
HANDLE hFind;
char sCurDir[MAX_PATH];
sAllFiles.clear ();
GetCurrentDirectory (MAX_PATH, sCurDir);
hFind = FindFirstFile (sFilter.c_str(), &findData);
while (hFind != INVALID_HANDLE_VALUE)
{
DWORD res = GetFileAttributes(findData.cFileName);
if (res != INVALID_FILE_ATTRIBUTES && !(res&FILE_ATTRIBUTE_DIRECTORY))
{
if (bFullPath)
sAllFiles.push_back(string(sCurDir) + "\\" + findData.cFileName);
else
sAllFiles.push_back(findData.cFileName);
}
if (FindNextFile (hFind, &findData) == 0)
break;
}
FindClose (hFind);
}
#else // posix version of the void dir(...) function.
void dir (const string &sFilter, vector<string> &sAllFiles, bool bFullPath) void dir (const string &sFilter, vector<string> &sAllFiles, bool bFullPath)
{ {
char sCurDir[MAX_PATH]; char sCurDir[MAX_PATH];
@ -157,7 +181,6 @@ void dir (const string &sFilter, vector<string> &sAllFiles, bool bFullPath)
find(sFilter)!= std::string::npos ) find(sFilter)!= std::string::npos )
{ {
if (bFullPath) if (bFullPath)
// on windows should we use "\\"
sAllFiles.push_back(string(sCurDir) + "/" + sFileName); sAllFiles.push_back(string(sCurDir) + "/" + sFileName);
else else
sAllFiles.push_back(sFileName); sAllFiles.push_back(sFileName);
@ -167,8 +190,7 @@ void dir (const string &sFilter, vector<string> &sAllFiles, bool bFullPath)
} }
closedir(dp); closedir(dp);
} }
#endif // endif posix version of "void dir(...)"
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
CZoneRegion *loadLand (const string &filename) CZoneRegion *loadLand (const string &filename)
@ -402,7 +424,11 @@ int main(int nNbArg, char**ppArgs)
// Get all files // Get all files
vector<string> vAllFiles; vector<string> vAllFiles;
chdir (options.InputIGDir.c_str()); chdir (options.InputIGDir.c_str());
#ifdef NL_OS_WINDOWS
dir ("*.ig", vAllFiles, false);
#else // posix version
dir (".ig", vAllFiles, false); dir (".ig", vAllFiles, false);
#endif
chdir (sCurDir); chdir (sCurDir);
for (uint32 i = 0; i < vAllFiles.size(); ++i) for (uint32 i = 0; i < vAllFiles.size(); ++i)