diff --git a/LatticeDehomogenization/src/ErrorCodes.h b/LatticeDehomogenization/src/ErrorCodes.h index f840f01cec18cba457e661f12a33eaec98a59d91..4bde0d116d422c9ebdcb2e964be313102614883e 100644 --- a/LatticeDehomogenization/src/ErrorCodes.h +++ b/LatticeDehomogenization/src/ErrorCodes.h @@ -7,15 +7,17 @@ enum ErrorCodes { NoError = 0, - FileNotFound, - CellSizeNotDefined, - StrutRadiusNotDefined, - CantDetermineLatticeType, - LatticeTypeNotDefined, + FileNotFound, DirectoryNotFound, InvalidExtension, + CellSizeNotDefined, StrutRadiusNotDefined, + + CantDetermineLatticeType, LatticeTypeNotDefined, + InvalidArgument, FailedToMergeCells, FailedToTrimLattice, LatticeIsNull, BoundingBoxIsNull, + + UnknownError, }; constexpr const char* errorcode2string(const ErrorCodes code) @@ -24,6 +26,8 @@ constexpr const char* errorcode2string(const ErrorCodes code) { case NoError: return "NO_ERROR"; case FileNotFound: return "FILE_NOT_FOUND"; + case DirectoryNotFound: return "DIRECTORY_NOT_FOUND"; + case InvalidExtension: return "INVALID_FILE_EXTENSION"; case CellSizeNotDefined: return "CELL_SIZE_NOT_DEFINED"; case StrutRadiusNotDefined: return "STRUT_RADIUS_NOT_DEFINED"; case CantDetermineLatticeType: return "CANT_DETERMINE_LATTICE_TYPE"; diff --git a/LatticeDehomogenization/src/inputParsing/ParseCommandLine.h b/LatticeDehomogenization/src/inputParsing/ParseCommandLine.h index 12987c975540a05475f2cd9769c99beab6b5a1e0..aa7aa527b8de5293019dd94d1935c3582a8adb17 100644 --- a/LatticeDehomogenization/src/inputParsing/ParseCommandLine.h +++ b/LatticeDehomogenization/src/inputParsing/ParseCommandLine.h @@ -2,6 +2,7 @@ #include <unordered_map> #include <unordered_set> #include <string> +#include <sys/stat.h> #include "ErrorCodes.h" @@ -21,6 +22,23 @@ private: std::vector<ErrorCodes> _errors; std::vector<std::string> _errorMsgs; + bool directoryExists(const std::string& filepath) + { + size_t directoryIdx = filepath.find_last_of('/'); + if (directoryIdx == std::string::npos) + directoryIdx = filepath.find_last_of('\\'); + + // Isnt a directory. Just a file name to be placed in current path + if (directoryIdx == std::string::npos) + return true; + + struct stat sb; + if (stat(filepath.substr(0, directoryIdx).c_str(), &sb) == 0) + return true; // Valid path + else + return false; // directory not found + } + private: static AcceptedKeys s_validKeys; @@ -44,6 +62,14 @@ public: _errorMsgs.emplace_back(key); } } + if (hasKey("input")) + { + if (!directoryExists(getValue("input"))) + { + _errors.emplace_back(ErrorCodes::DirectoryNotFound); + _errorMsgs.emplace_back(getValue("input")); + } + } } inline const std::string& getValue(const std::string& key) const