34 #include <boost/version.hpp>
35 #include <boost/filesystem.hpp>
46 namespace bfs=boost::filesystem;
111 string stdCompleteFileName;
112 set<string> stdListOfFileNames;
113 set<string> stdListOfCompleteFileNames;
134 for(
int i=0; i<(int)
m_Files.Count(); i++) {
144 for(
int i=0; i<(int)
m_SubDirs.Count(); i++) {
158 if( bfs::exists( path ) )
162 bfs::directory_iterator end ;
163 for( bfs::directory_iterator iter(path) ; iter != end ; ++iter )
164 if ( bfs::is_directory( *iter ) )
168 #if BOOST_VERSION > 103500
170 #if BOOST_VERSION < 104800
171 moText pSubDirName( iter->path().filename().c_str() );
173 moText pSubDirName( iter->path().filename().string().c_str() );
176 moText pSubDirName( iter->path().leaf().c_str() );
179 moText pCompletePathSubdirName( iter->path().string().c_str() );
181 if (pSubDirName.Left(1) !=
"." ) {
193 #if BOOST_VERSION > 103500
196 #if BOOST_VERSION < 104800
197 moText pFileName( iter->path().filename().c_str() );
198 stdFileName = iter->path().filename().c_str();
200 moText pFileName( iter->path().filename().string().c_str() );
201 stdFileName = iter->path().filename().string().c_str();
206 moText pFileName( iter->path().leaf().c_str() );
208 stdFileName = iter->path().leaf().c_str();
212 moText pCompletePathFilename( iter->path().string().c_str() );
213 stdCompleteFileName = iter->path().string().c_str();
217 if (stdFileName!=
"Thumbs.db") {
218 stdListOfFileNames.insert(stdFileName);
219 stdListOfCompleteFileNames.insert(stdCompleteFileName);
233 moText pCompletePathFilename;
235 for(std::set<string>::iterator Name = stdListOfCompleteFileNames.begin() ; Name != stdListOfCompleteFileNames.end() ; ++Name)
239 pCompletePathFilename =
moText((
char*)comp.c_str());
245 pFile =
new moFile( pCompletePathFilename );
361 for(
int i=0; i<(int)
m_Files.Count(); i++) {
371 for(
int i=0; i<(int)
m_SubDirs.Count(); i++) {
496 if( bfs::exists( path ) )
500 bfs::directory_iterator end ;
501 for( bfs::directory_iterator iter(path) ; iter != end ; ++iter )
502 if ( bfs::is_directory( *iter ) )
511 #if BOOST_VERSION < 104300
512 moText pFileName( iter->path().leaf().c_str() );
513 moText pCompletePathFilename( iter->path().string().c_str() );
515 moText pFileName( iter->path().filename().string().c_str() );
516 moText pCompletePathFilename( iter->path().string().c_str() );
524 if (pFileName!=
moText(
"Thumbs.db")) {
526 bool founded =
false;
528 for(
int i=0; i<(int)
m_Files.Count(); i++) {
530 if (pFile->GetCompletePath()==pCompletePathFilename) {
538 pFile =
new moFile( pCompletePathFilename );
584 m_CompletePath =
moText(
"");
589 m_pBucketsPool = NULL;
609 if (m_bRemote && !m_pBucketsPool) {
613 return (m_pBucketsPool!=NULL);
618 if (m_bRemote && m_pBucketsPool) {
619 delete m_pBucketsPool;
620 m_pBucketsPool = NULL;
622 return (m_pBucketsPool==NULL);
628 m_bExists = bfs::exists((
char*)m_CompletePath);
629 }
catch(
const bfs::filesystem_error& e ) {
675 m_FileType = p_filetype;
686 return ( m_FileName + m_Extension );
693 m_CompletePath = p_completepath;
695 moText Left8 = m_CompletePath;
697 moText Left7 = m_CompletePath;
699 moText Left6 = m_CompletePath;
702 if (Left7==
moText(
"http://") ||
703 Left7==
moText(
"HTTP://")) {
704 m_Protocol =
moText(
"http://");
708 }
else if (Left8==
moText(
"https://") ||
709 Left8==
moText(
"HTTPS://")) {
710 m_Protocol =
moText(
"https://");
714 }
else if (Left6==
moText(
"ftp://") ||
715 Left6==
moText(
"FTP://")) {
716 m_Protocol =
moText(
"ftp://");
721 moTextArray FileNameA;
722 m_Protocol =
moText(
"file:///");
727 str = bfs::extension( (
char*)m_CompletePath );
730 m_Extension = str.c_str();
732 moText pathStart = m_CompletePath;
733 pathStart = pathStart.
SubText(0,0);
738 if (m_CompletePath.
Length()>0)
739 if ( pathStart == moSlash )
743 if ( m_Dirs.Count() > 0 ) {
745 m_FileName = m_Dirs[m_Dirs.Count()-1];
747 m_FileName = FileNameA[0];
748 m_Dirs.Remove(m_Dirs.Count()-1);
751 for(
MOuint d=0; d < m_Dirs.Count(); d++ ) {
752 if (m_Dirs[d]!=
"" && m_Dirs[d]!=
"/" && m_Dirs[d]!=
".")
753 m_Path+= m_Dirs[d] + moSlash;
760 m_CompletePath = m_Path + m_FileName + m_Extension;
762 m_bExists = bfs::exists((
char*)m_CompletePath);
765 path = m_CompletePath;
767 if (
Exists() && !bfs::is_directory(path)) m_FileSize = (long) bfs::file_size( path );
769 }
catch(
const bfs::filesystem_error& e ) {
784 return m_CompletePath;
790 moText absolutePath = m_CompletePath;
793 return m_CompletePath;
796 path = m_CompletePath;
800 bfs::path abspath = bfs::canonical( path );
801 absolutePath = (
char*)abspath.string().c_str();
803 }
catch(
const bfs::filesystem_error& e ) {
805 moDebugManager::Error(
"moFile::GetAbsolutePath failed for " + m_CompletePath +
" boost::filesystem error: " + e.what() );
821 if (m_Dirs.Count()>0) {
822 return m_Dirs[m_Dirs.Count()-1];
865 moFile pFileName(p_FileName);
869 if (
m_Files[i]->GetCompletePath() == p_FileName ) {
879 if (bWaitForDownload && pFile->
IsRemote()) {
892 moFile pFileName(p_FileName);
895 if (
Load(p_FileName) ) {
897 if (
m_Files[i]->GetCompletePath() == p_FileName ) {
922 if (bWaitForDownload && pDir->
IsRemote()) {
935 if (
Open(p_Path) ) {
950 char ownPth[MAX_PATH];
953 HMODULE hModule = GetModuleHandle(NULL);
957 GetModuleFileNameA( hModule, ownPth, (
sizeof(ownPth)));
963 return moText(
"[ WARNING -- function not implemented ]");
975 _getcwd( lbuf ,
sizeof( lbuf ) );
977 getcwd( lbuf ,
sizeof( lbuf ) );
993 bfs::create_directory( dirname );
1009 return bfs::exists((
char*)dirname);
1055 std::string name, new_name;
1061 bfs::copy_file(name, new_name);
1063 catch(
const std::exception & ex ) {
1076 std::string dsrc, ddst;
1079 bfs::path source = dsrc;
1080 bfs::path destination = ddst;
1086 !bfs::exists(source) ||
1087 !bfs::is_directory(source)
1090 std::cerr <<
"Source directory " << source.string()
1091 <<
" does not exist or is not a directory." <<
'\n'
1095 if(bfs::exists(destination))
1097 std::cerr <<
"Destination directory " << destination.string()
1098 <<
" already exists." <<
'\n'
1103 if(!bfs::create_directory(destination))
1105 std::cerr <<
"Unable to create destination directory"
1106 << destination.string() <<
'\n'
1111 catch(bfs::filesystem_error
const & e)
1113 std::cerr << e.what() <<
'\n';
1118 bfs::directory_iterator file(source);
1119 file != bfs::directory_iterator(); ++file
1124 bfs::path current(file->path());
1125 bfs::path destin(destination / current.filename());
1126 moText destinT = (
char*)destin.string().c_str();
1127 moText currentT = (
char*)current.string().c_str();
1128 if(bfs::is_directory(current))
1150 catch(bfs::filesystem_error
const & e)
1152 std:: cerr << e.what() <<
'\n';
virtual MOboolean Finish()
Finaliza el objeto, libera recursos.
static bool CopyFile(moText FileSrc, moText FileDst)
moText GetFullName()
Retreive full file name: return "myFileName" for "myFileName.txt".
moFile * GetFile(moText p_FileName)
void Error(moText p_text)
Anuncia y registra un error.
void SetName(const moText &p_name)
moTextArray Explode(char *separator) const
static bool FileExists(moText filename)
static moText GetWorkPath()
virtual MOboolean Init()
Inicializa el objeto.
static void Error(moText p_text)
Anuncia un error.
moDirectoryArray & GetSubDirs()
void SetResourceType(moResourceType p_restype)
moText GetFolderName()
Get path of file: return "XX/YY/PP" for "XX/YY/PP/myFileName.txt".
void SetType(moFileType p_filetype)
virtual MOboolean Init()
Inicializa el objeto.
moFile * Find(MOint index)
moText GetExtension()
Get absolute path and filename "/D/PP/myFileName.txt".
static bool CreateDirectory(moDirectory Dir)
void SetCompletePath(moText p_completepath)
static bool CopyDirectory(const moText &DirSrc, const moText &DirDst)
static moText GetExePath()
clase de para manejar textos
Dispositivo de entrada/salida, típicamente, interfaces humanas de IO y datos ( teclado, mouse, tableta, tcp, udp, serial )
moText GetPath()
Retreive full file name: return "myFileName.txt", extension is included.
moFileManager * m_pFileManager
virtual MOboolean Finish()
Finaliza el objeto, libera recursos.
moFileDate GetDate()
Return http:// | ftp:// | https:// | file:///.
moDefineDynamicArray(moFileArray) moDefineDynamicArray(moDirectoryArray) namespace bfs
Administrador de moBucket 's.
moDirectoryArray m_Directories
moDirectory * GetDirectory(moText p_Path)
moText GetCompletePath()
Get inmediate folder name: return "PP" for "PP/myFileName.txt".
void SetLabelName(const moText &p_labelname)
moTextArray m_DirNameArray
static moDebug * MODebug2
Clase de impresión de errores para depuración
MOboolean Load(moText p_FileName, MOboolean bWaitForDownload=false)
moText GetProtocol()
Get extension ".txt".
virtual MOboolean Finish()
MOboolean Open(moText p_Path, MOboolean bWaitForDownload=false)
moText GetAbsolutePath()
Get relative path and filename "PP/myFileName.txt".
moText0 & SubText(MOuint, MOuint)
void Message(moText p_text)
Anuncia un mensaje al usuario además de guardarlo en el log de texto.
static bool DirectoryExists(moText dirname)
void SetType(moMoldeoObjectType p_type)
MOboolean Open(moText p_CompletePath, moText p_Search="/*.*")
moDirectoryArray m_SubDirs