Skip to content
Snippets Groups Projects
Commit d7cdd90f authored by Thomas Feuvrier's avatar Thomas Feuvrier
Browse files

Modifications de l'appel aux fonctions systeme (opendir, etc...) pour etre portable sur Windows.

parent 665cf327
Branches
Tags
No related merge requests found
......@@ -17,6 +17,26 @@
=========================================================================*/
#include "otbSystem.h"
#include <string.h> // strdup
#if defined(WIN32) || defined(WIN32CE)
/*=====================================================================
WIN32 / MSVC++ implementation
*====================================================================*/
#ifndef WIN32CE
# include <io.h>
#else
# include <wce_io.h>
#endif
#else
/*=====================================================================
POSIX (Unix) implementation
*====================================================================*/
#include <sys/types.h>
#include <dirent.h>
#endif
namespace otb
{
......@@ -57,4 +77,84 @@ System::GetRootName( const std::string& filename )
return( filename );
}
#if defined(WIN32) || defined(WIN32CE)
/*=====================================================================
WIN32 / MSVC++ implementation
*====================================================================*/
std::vector<std::string> System::Readdir(std::string pszPath)
{
struct _finddata_t c_file;
long hFile;
std::vector<std::string> listFileFind;
std::string pszFileSpec;
std::string path(pszPath);
if (pszPath.empty() == true)
path = ".";
pszFileSpec = path + "\\*.*";
if ( (hFile = _findfirst( pszFileSpec.c_str(), &c_file )) != -1L )
{
do
{
listFileFind.push_back(c_file.name);
} while( _findnext( hFile, &c_file ) == 0 );
_findclose( hFile );
}
return listFileFind;
}
#else
/*=====================================================================
POSIX (Unix) implementation
*====================================================================*/
/**
* Read names in a directory.
*
* This function abstracts access to directory contains. It returns a
* list of strings containing the names of files, and directories in this
* directory. The resulting string list becomes the responsibility of the
* application and should be freed with CSLDestroy() when no longer needed.
*
* Note that no error is issued via CPLError() if the directory path is
* invalid, though NULL is returned.
*
* @param pszPath the relative, or absolute path of a directory to read.
* @return The list of entries in the directory, or NULL if the directory
* doesn't exist.
*/
std::vector<std::string> System::Readdir(std::string pszPath)
{
DIR *hDir;
std::vector<std::string> listFileFind;
struct dirent *psDirEntry;
std::string path(pszPath);
if (pszPath.empty() == true)
path = ".";
if ( (hDir = opendir(path.c_str())) != NULL )
{
while( (psDirEntry = readdir(hDir)) != NULL )
{
listFileFind.push_back(psDirEntry->d_name);
}
closedir( hDir );
}
return listFileFind;
}
#endif
}
......@@ -19,6 +19,7 @@
#define _otbSystem_h
#include <string>
#include <vector>
namespace otb
{
......@@ -42,6 +43,8 @@ public:
/** Get the root name */
static std::string GetRootName( const std::string& filename );
/** Get list of file find in a directory */
static std::vector<std::string> System::Readdir(std::string pszPath);
};
} // namespace otb
......
......@@ -38,13 +38,15 @@
#include "itkMetaDataObject.h"
#include <sys/types.h>
/*#include <sys/types.h>
#include <dirent.h>
*/
// ROMAIN : Modification for VC++
#ifdef _MSC_VER
/*#ifdef _MSC_VER
#define strcasecmp stricmp // _MICROSOFT_ VC++
#endif
*/
#include "otbSystem.h"
......@@ -92,8 +94,8 @@ GDALImageIO::~GDALImageIO()
bool GDALImageIO::GetGdalReadImageFileName( const char * filename, std::string & GdalFileName )
{
DIR *ptr_repertoire;
struct dirent *cr_readdir;
// DIR *ptr_repertoire;
// struct dirent *cr_readdir;
// std::string str_debut("DAT");
std::vector<std::string> listFileSearch;
listFileSearch.push_back("DAT_01.001");// RADARSAT ou SAR_ERS2
......@@ -104,7 +106,27 @@ bool GDALImageIO::GetGdalReadImageFileName( const char * filename, std::string &
bool fic_trouve(false);
// Si c'est un rpertoire, on regarde le contenu pour voir si c'est pas du RADARSAT, ERS
ptr_repertoire = opendir(filename);
std::vector<std::string> listFileFind;
listFileFind = System::Readdir(std::string (filename));
if( listFileFind.empty() == false )
{
int cpt(0);
while ( (cpt < listFileFind.size()) && (fic_trouve==false) )
{
str_FileName = std::string(listFileFind[cpt]);
for(int i = 0 ; i < listFileSearch.size() ; i++)
{
if(str_FileName.compare(listFileSearch[i]) == 0)
{
GdalFileName = std::string(filename)+listFileSearch[i];
fic_trouve=true;
}
}
cpt++;
}
/* ptr_repertoire = opendir(filename);
if (ptr_repertoire != NULL)
{
while ((cr_readdir=readdir(ptr_repertoire))!=NULL && (fic_trouve==false) )
......@@ -129,6 +151,7 @@ bool GDALImageIO::GetGdalReadImageFileName( const char * filename, std::string &
// fic_trouve=true;
//}
}
*/
}
else
{
......@@ -150,7 +173,7 @@ bool GDALImageIO::GetGdalReadImageFileName( const char * filename, std::string &
}
otbMsgDevMacro(<<"lFileNameGdal : "<<GdalFileName.c_str());
otbMsgDevMacro(<<"fic_trouve : "<<fic_trouve);
closedir(ptr_repertoire);
// closedir(ptr_repertoire);
return( fic_trouve );
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment