X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FTOOLSDS%2FSALOMEDS_Tool.cxx;h=2b61d3fddcb726106b06b87a1c5049cdbd34e6a6;hb=d8edd4804d9e6513a17c497c1a30326d4ba0d677;hp=9f9ffd6b74a608020b7b9cf4371d92fe228a0e7d;hpb=6fcebbb5046b69547c6e8cefd980efdc655cebad;p=modules%2Fkernel.git diff --git a/src/TOOLSDS/SALOMEDS_Tool.cxx b/src/TOOLSDS/SALOMEDS_Tool.cxx index 9f9ffd6b7..2b61d3fdd 100644 --- a/src/TOOLSDS/SALOMEDS_Tool.cxx +++ b/src/TOOLSDS/SALOMEDS_Tool.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -30,6 +30,7 @@ #include "utilities.h" #include "Basics_DirUtils.hxx" +#include "Basics_Utils.hxx" #ifndef WIN32 #include @@ -44,24 +45,13 @@ #include #include -#include #include #include CORBA_SERVER_HEADER(SALOMEDS_Attributes) bool Exists(const std::string thePath) { -#ifdef WIN32 - if ( GetFileAttributes ( thePath.c_str() ) == 0xFFFFFFFF ) { - if ( GetLastError () == ERROR_FILE_NOT_FOUND ) { - return false; - } - } -#else - int status = access ( thePath.c_str() , F_OK ); - if (status != 0) return false; -#endif - return true; + return Kernel_Utils::IsExists(thePath); } @@ -132,18 +122,24 @@ std::string SALOMEDS_Tool::GetTmpDir() // purpose : Removes files listed in theFileList //============================================================================ void SALOMEDS_Tool::RemoveTemporaryFiles(const std::string& theDirectory, - const std::list& theFiles, + const ListOfFiles& theFiles, const bool IsDirDeleted) { std::string aDirName = theDirectory; - for(std::list::const_iterator it = theFiles.begin(); it != theFiles.end(); it++) { + size_t i, aLength = theFiles.size(); + for(i=1; i<=aLength; i++) { std::string aFile(aDirName); - aFile += *it; + aFile += theFiles[i-1]; if(!Exists(aFile)) continue; #ifdef WIN32 - DeleteFile(aFile.c_str()); +#if defined(UNICODE) + std::wstring aFileToDelete = Kernel_Utils::utf8_decode_s(aFile); +#else + std::string aFileToDelete = aFile; +#endif + DeleteFile(aFileToDelete.c_str()); #else unlink(aFile.c_str()); #endif @@ -152,7 +148,12 @@ void SALOMEDS_Tool::RemoveTemporaryFiles(const std::string& theDirectory, if(IsDirDeleted) { if(Exists(aDirName)) { #ifdef WIN32 - RemoveDirectory(aDirName.c_str()); +#if defined(UNICODE) + std::wstring aDirToDelete = Kernel_Utils::utf8_decode_s(aDirName); +#else + std::string aDirToDelete = aDirName; +#endif + RemoveDirectory(aDirToDelete.c_str()); #else rmdir(aDirName.c_str()); #endif @@ -169,11 +170,11 @@ namespace { SALOMEDS::TMPFile* PutFilesToStream(const std::string& theFromDirectory, - const std::list& theFiles, - const std::list& theFileNames, + const std::vector& theFiles, + const std::vector& theFileNames, const int theNamesOnly) { - int i = 0, aLength = theFiles.size(); + int i, aLength = (int)theFiles.size(); //!< TODO: conversion from size_t to int if(aLength == 0) return (new SALOMEDS::TMPFile); @@ -189,25 +190,27 @@ namespace //Determine the required size of the buffer - std::list::const_iterator it_files = theFiles.begin(); - std::list::const_iterator it_names = theFileNames.begin(); - for(; it_files != theFiles.end(); it_files++, it_names++, i++) { + for(i=0; iseekg(0, std::ios::beg); - aFile->read((char *)(aBuffer + aCurrentPos), aFileSize[i]); + aFile->read((char *)(aBuffer + aCurrentPos), aFileSize[i]); aFile->close(); delete(aFile); aCurrentPos += aFileSize[i]; @@ -280,17 +286,17 @@ namespace SALOMEDS::TMPFile* SALOMEDS_Tool::PutFilesToStream(const std::string& theFromDirectory, - const std::list& theFiles, + const ListOfFiles& theFiles, const int theNamesOnly) { - std::list aFileNames(theFiles); + ListOfFiles aFileNames(theFiles); return ::PutFilesToStream(theFromDirectory,theFiles,aFileNames,theNamesOnly); } SALOMEDS::TMPFile* -SALOMEDS_Tool::PutFilesToStream(const std::list& theFiles, - const std::list& theFileNames) +SALOMEDS_Tool::PutFilesToStream(const ListOfFiles& theFiles, + const ListOfFiles& theFileNames) { return ::PutFilesToStream("",theFiles,theFileNames,0); } @@ -299,19 +305,18 @@ SALOMEDS_Tool::PutFilesToStream(const std::list& theFiles, // function : PutStreamToFile // purpose : converts the stream "theStream" to the files //============================================================================ -std::list +SALOMEDS_Tool::ListOfFiles SALOMEDS_Tool::PutStreamToFiles(const SALOMEDS::TMPFile& theStream, const std::string& theToDirectory, const int theNamesOnly) { - std::list aFiles; + ListOfFiles aFiles; if(theStream.length() == 0) return aFiles; //Get a temporary directory for saving a file std::string aTmpDir = theToDirectory; - unsigned char *aBuffer = (unsigned char*)theStream.NP_data(); if(aBuffer == NULL) @@ -323,6 +328,8 @@ SALOMEDS_Tool::PutStreamToFiles(const SALOMEDS::TMPFile& theStream, //Copy the number of files in the stream memcpy(&aNbFiles, aBuffer, sizeof(int)); + aFiles.reserve(aNbFiles); + for(i=0; i 0) { + size_t pos = aPath.rfind('/'); + if(pos != std::string::npos) { aPath = aPath.substr(pos+1, aPath.size()); isFound = true; } if(!isFound) { pos = aPath.rfind('\\'); - if(pos > 0) { + if(pos != std::string::npos) { aPath = aPath.substr(pos+1, aPath.size()); isFound = true; } } if(!isFound) { pos = aPath.rfind('|'); - if(pos > 0) aPath = aPath.substr(pos+1, aPath.size()); + if(pos != std::string::npos) aPath = aPath.substr(pos+1, aPath.size()); } pos = aPath.rfind('.'); - if(pos > 0) aPath = aPath.substr(0, pos); //Remove extension + if(pos != std::string::npos) aPath = aPath.substr(0, pos); //Remove extension return aPath; } @@ -401,18 +412,18 @@ std::string SALOMEDS_Tool::GetNameFromPath(const std::string& thePath) { std::string SALOMEDS_Tool::GetDirFromPath(const std::string& thePath) { if (thePath.empty()) return ""; - int pos = thePath.rfind('/'); + size_t pos = thePath.rfind('/'); std::string path; - if(pos > 0) { + if(pos != std::string::npos) { path = thePath.substr(0, pos+1); } if(path.empty()) { pos = thePath.rfind('\\'); - if(pos > 0) path = thePath.substr(0, pos+1); + if(pos != std::string::npos) path = thePath.substr(0, pos+1); } if(path.empty()) { pos = thePath.rfind('|'); - if(pos > 0) path = thePath.substr(0, pos+1); + if(pos != std::string::npos) path = thePath.substr(0, pos+1); } if(path.empty()) { path = thePath+"/"; @@ -422,7 +433,7 @@ std::string SALOMEDS_Tool::GetDirFromPath(const std::string& thePath) { if(path.size() == 2 && path[1] == ':') path +='\\'; #endif - for(int i = 0, len = path.size(); i