diff --git a/src/Base/FileInfo.cpp b/src/Base/FileInfo.cpp index 589a3f674f..c2b7b68d69 100644 --- a/src/Base/FileInfo.cpp +++ b/src/Base/FileInfo.cpp @@ -92,6 +92,9 @@ std::wstring ConvertToWideString(const std::string& string) wideCharString = NULL; return wideString; } +#define GetCurrentDir direct::_getcwd +#elif defined (FC_OS_LINUX) || defined(FC_OS_CYGWIN) || defined(FC_OS_MACOSX) || defined(FC_OS_BSD) +#define GetCurrentDir unistd::getcwd #endif @@ -225,7 +228,16 @@ std::string FileInfo::fileName () const std::string FileInfo::dirPath () const { - return FileName.substr(0,FileName.find_last_of('/')); + std::size_t last_pos; + std::string retval; + last_pos = FileName.find_last_of('/'); + if (last_pos != std::string::npos) { + retval = FileName.substr(0, last_pos); + } + else{ + retval = std::string(GetCurrentDir(NULL, 0)); + } + return retval; } std::string FileInfo::fileNamePure () const diff --git a/src/Mod/Mesh/App/Core/MeshIO.cpp b/src/Mod/Mesh/App/Core/MeshIO.cpp index 183188fb7a..25e3341b02 100644 --- a/src/Mod/Mesh/App/Core/MeshIO.cpp +++ b/src/Mod/Mesh/App/Core/MeshIO.cpp @@ -1515,52 +1515,52 @@ void MeshOutput::Transform(const Base::Matrix4D& mat) bool MeshOutput::SaveAny(const char* FileName, MeshIO::Format format) const { // ask for write permission - Base::FileInfo fi(FileName); - Base::FileInfo di(fi.dirPath().c_str()); - if ((fi.exists() && !fi.isWritable()) || !di.exists() || !di.isWritable()) + Base::FileInfo file(FileName); + Base::FileInfo directory(file.dirPath()); + if ((file.exists() && !file.isWritable()) || !directory.exists() || !directory.isWritable()) throw Base::FileException("No write permission for file",FileName); MeshIO::Format fileformat = format; if (fileformat == MeshIO::Undefined) { - if (fi.hasExtension("bms")) { + if (file.hasExtension("bms")) { fileformat = MeshIO::BMS; } - else if (fi.hasExtension("stl")) { + else if (file.hasExtension("stl")) { fileformat = MeshIO::BSTL; } - else if (fi.hasExtension("ast")) { + else if (file.hasExtension("ast")) { fileformat = MeshIO::ASTL; } - else if (fi.hasExtension("obj")) { + else if (file.hasExtension("obj")) { fileformat = MeshIO::OBJ; } - else if (fi.hasExtension("off")) { + else if (file.hasExtension("off")) { fileformat = MeshIO::OFF; } - else if (fi.hasExtension("ply")) { + else if (file.hasExtension("ply")) { fileformat = MeshIO::PLY; } - else if (fi.hasExtension("iv")) { + else if (file.hasExtension("iv")) { fileformat = MeshIO::IV; } - else if (fi.hasExtension("x3d")) { + else if (file.hasExtension("x3d")) { fileformat = MeshIO::X3D; } - else if (fi.hasExtension("py")) { + else if (file.hasExtension("py")) { fileformat = MeshIO::PY; } - else if (fi.hasExtension("wrl") || fi.hasExtension("vrml")) { + else if (file.hasExtension("wrl") || file.hasExtension("vrml")) { fileformat = MeshIO::VRML; } - else if (fi.hasExtension("wrz")) { + else if (file.hasExtension("wrz")) { fileformat = MeshIO::WRZ; } - else if (fi.hasExtension("nas") || fi.hasExtension("bdf")) { + else if (file.hasExtension("nas") || file.hasExtension("bdf")) { fileformat = MeshIO::NAS; } } - Base::ofstream str(fi, std::ios::out | std::ios::binary); + Base::ofstream str(file, std::ios::out | std::ios::binary); if (fileformat == MeshIO::BMS) { _rclMesh.Write(str);