//-------------------------------- bool Utils::directoryExists( const String &pathString ) { bool pathExists = false; #ifdef COLLADABU_OS_WIN SystemType type = getSystemType(); if( type != WINDOWS ) return false; const char* currentPath = _getcwd( 0, 0); const char* testPath = pathString.c_str(); pathExists = _chdir( testPath ) == 0; _chdir( currentPath ); return pathExists; #else SystemType type = getSystemType(); if( type != POSIX ) return false; struct stat st; if(stat(pathString.c_str(),&st) == 0) pathExists = true; #endif return pathExists; }
//-------------------------------- bool Utils::copyFile( const String &source, const String &destination ) { bool copystatus = false; #ifdef COLLADABU_OS_WIN SystemType type = getSystemType(); if( type != WINDOWS ) return false; char command[4097]; sprintf(command,"copy \"%s\" \"%s\"", source.c_str(), destination.c_str() ); size_t length = strlen(command); if( length > 4096) return false; int status = system(command); copystatus = (status == 0 ? true : false); #else SystemType type = getSystemType(); if( type != POSIX ) return false; char command[4097]; sprintf(command, "/bin/cp \"%s\" \"%s\"", source.c_str(), destination.c_str()); size_t length = strlen(command); if( length > 4096) return false; int status = system(command); copystatus = (status == 0 ? true : false); #endif return copystatus; }
//-------------------------------- bool Utils::copyFile( const String &source, const String &destination ) { bool pathExists = false; #ifdef COLLADABU_OS_WIN SystemType type = getSystemType(); if( type != WINDOWS ) return false; char command[4097]; sprintf(command,"copy \"%s\" \"%s\"", source.c_str(), destination.c_str() ); size_t length = strlen(command); if( length > 4096) return false; system(command); return true; #else SystemType type = getSystemType(); if( type != POSIX ) return false; //... #endif return pathExists; }
//-------------------------------- bool Utils::directoryExists( const WideString &pathString ) { bool pathExists = false; #ifdef COLLADABU_OS_WIN SystemType type = getSystemType(); if( type != WINDOWS ) return false; const wchar_t* currentPath = _wgetcwd( 0, 0); const wchar_t* testPath = pathString.c_str(); pathExists = _wchdir( testPath ) == 0; _wchdir( currentPath ); return pathExists; #else SystemType type = getSystemType(); if( type != POSIX ) return false; //... #endif return pathExists; }
//-------------------------------- bool Utils::createDirectoryIfNeeded( const String &pathString ) { bool pathExists = false; #ifdef COLLADABU_OS_WIN SystemType type = getSystemType(); if( type != WINDOWS ) return false; const char* currentPath = _getcwd( 0, 0); const char* testPath = pathString.c_str(); pathExists = _chdir( testPath ) == 0; if( !pathExists ) { _mkdir( testPath ); pathExists = _chdir( testPath ) == 0; } _chdir( currentPath ); #else SystemType type = getSystemType(); if( type != POSIX ) return false; const char* currentPath = getcwd( 0, 0); const char* testPath = pathString.c_str(); pathExists = chdir( testPath ) == 0; if( !pathExists ) { pathExists = mkdir(testPath, 0755) == false; } chdir( currentPath ); #endif return pathExists; }
//-------------------------------- bool Utils::directoryExists( const WideString &pathString ) { bool pathExists = false; SystemType type = getSystemType(); if( type != WINDOWS ) return false; const wchar_t* currentPath = _wgetcwd( 0, 0); const wchar_t* testPath = pathString.c_str(); pathExists = _wchdir( testPath ) == 0; _wchdir( currentPath ); return pathExists; }
//-------------------------------- bool Utils::deleteFile(const String &pathString) { SystemType type = getSystemType(); #ifdef COLLADABU_OS_WIN if (type != WINDOWS) return false; return DeleteFileA(pathString.c_str()) != FALSE; #else if (type != POSIX) return false; char command[4097]; sprintf(command, "rm -f \"%s\"", pathString.c_str()); int status = system(command); return status == 0; #endif }
//-------------------------------- bool Utils::createDirectoryRecursive( const String &pathString ) { if (pathString.length() == 0) return false; String path = pathString; if (path[path.length()-1] != '/' && path[path.length()-1] != '\\') path.push_back('\\'); std::list<String> paths; size_t offset = String::npos; while ((offset != 0) && (offset = pathString.find_last_of("/\\", offset)) != String::npos) { paths.push_front(pathString.substr(0, offset + 1)); if (offset !=0) --offset; } bool pathExists = true; SystemType type = getSystemType(); #ifdef COLLADABU_OS_WIN if( type != WINDOWS ) return false; const char* currentPath = _getcwd(0, 0); for (std::list<String>::const_iterator iPath = paths.begin(); iPath != paths.end(); ++iPath) { // if path exists if (_chdir((*iPath).c_str()) == 0) continue; // path does not exist, try to create it _mkdir((*iPath).c_str()); if (_chdir((*iPath).c_str()) != 0) { pathExists = false; break; } } // Restore current path _chdir(currentPath); #else if( type != POSIX ) return false; const char* currentPath = getcwd(0, 0); for (std::list<String>::const_iterator iPath = paths.begin(); iPath != paths.end(); ++iPath) { // if path exists if (chdir((*iPath).c_str()) == 0) continue; // path does not exist, try to create it mkdir((*iPath).c_str(), 0755); if (chdir((*iPath).c_str()) != 0) { pathExists = false; break; } } // Restore current path chdir(currentPath); #endif return pathExists; }
rspfRefPtr<rspfProperty> rspfNitfFileHeaderV2_X::getProperty(const rspfString& name)const { rspfRefPtr<rspfProperty> property = 0; if(name == FHDR_KW) { property = new rspfStringProperty(name, rspfString(theFileTypeVersion)); } else if(name == VERSION_KW) { property = new rspfStringProperty(name, rspfString(getVersion())); } else if(name == FILE_TYPE_KW) { property = new rspfStringProperty(name, "NITF"); } else if(name == CLEVEL_KW) { rspfNumericProperty* numericProperty = new rspfNumericProperty(name, getComplexityLevel(), 1, 99); numericProperty->setNumericType(rspfNumericProperty::rspfNumericPropertyType_INT); property = numericProperty; } else if(name == STYPE_KW) { property = new rspfStringProperty(name, getSystemType().trim()); } else if(name == OSTAID_KW) { property = new rspfStringProperty(name, getOriginatingStationId().trim()); } else if(name == FDT_KW) { property = new rspfStringProperty(name, getDate()); } else if(name == FTITLE_KW) { property = new rspfStringProperty(name, getTitle().trim()); } else if(name == FSCLAS_KW) { rspfStringProperty* stringProperty = new rspfStringProperty(name, getSecurityClassification().trim(), false); stringProperty->addConstraint(""); stringProperty->addConstraint("T"); stringProperty->addConstraint("S"); stringProperty->addConstraint("C"); stringProperty->addConstraint("R"); stringProperty->addConstraint("U"); property = stringProperty; } else if(name == FSCODE_KW) { property = new rspfStringProperty(name, getCodeWords().trim()); } else if(name == FSCTLH_KW) { property = new rspfStringProperty(name, getControlAndHandling().trim()); } else if(name == FSREL_KW) { property = new rspfStringProperty(name, getReleasingInstructions().trim()); } else if(name == FSCAUT_KW) { property = new rspfStringProperty(name, getClassificationAuthority().trim()); } else if(name == FSCTLN_KW) { property = new rspfStringProperty(name, getSecurityControlNumber().trim()); } else if(name == FSCOP_KW) { property = new rspfStringProperty(name, getCopyNumber().trim()); } else if(name == FSCPYS_KW) { property = new rspfStringProperty(name, getNumberOfCopies().trim()); } else if(name == ENCRYP_KW) { property = new rspfStringProperty(name, getEncryption().trim(), false); } else { property = rspfNitfFileHeader::getProperty(name).get(); } return property; }