better path handling
parent
211f17aa98
commit
92a627986f
|
@ -89,16 +89,16 @@ public:
|
|||
|
||||
/// Set the current directory by stripping away the last component
|
||||
inline void setCurrentDirectoryFromFile(const std::string &cwd) {
|
||||
m_currentDirectory = pathFromFile(cwd);
|
||||
m_currentDirectory = getParentDirectory(cwd);
|
||||
}
|
||||
|
||||
/// Adds a path while stripping away the last component
|
||||
inline void addPathFromFile(const std::string &path) {
|
||||
addPath(pathFromFile(path));
|
||||
addPath(getParentDirectory(path));
|
||||
}
|
||||
|
||||
/// Strip the last component from a path
|
||||
inline std::string pathFromFile(const std::string &path) const {
|
||||
inline std::string getParentDirectory(const std::string &path) const {
|
||||
std::vector<std::string> components = tokenize(path, "/\\");
|
||||
if (components.size() == 1)
|
||||
return ".";
|
||||
|
@ -112,6 +112,11 @@ public:
|
|||
return newPath;
|
||||
}
|
||||
|
||||
/// Return the last component of a path
|
||||
inline std::string getChild(const std::string &path) const {
|
||||
std::vector<std::string> components = tokenize(path, "/\\");
|
||||
return components[components.size()-1];
|
||||
}
|
||||
|
||||
/// Try to resolve a path to an existing file
|
||||
inline std::string resolve(const std::string &path) const {
|
||||
|
|
|
@ -287,7 +287,7 @@ int ubi_main(int argc, char **argv) {
|
|||
|
||||
int jobIdx = 0;
|
||||
for (int i=optind; i<argc; ++i) {
|
||||
std::string inputFile = argv[i], filePath = resolver->pathFromFile(inputFile);
|
||||
std::string inputFile = argv[i], filePath = resolver->getParentDirectory(inputFile);
|
||||
if (!resolver->contains(filePath))
|
||||
resolver->addPath(filePath);
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ void ImportDialog::accept() {
|
|||
dialog->show();
|
||||
progressBar->show();
|
||||
|
||||
std::string filePath = m_resolver->pathFromFile(sourceFile.toStdString());
|
||||
std::string filePath = m_resolver->getParentDirectory(sourceFile.toStdString());
|
||||
if (!m_resolver->contains(filePath))
|
||||
m_resolver->addPath(filePath);
|
||||
|
||||
|
|
|
@ -578,7 +578,7 @@ void MainWindow::onClearRecent() {
|
|||
SceneContext *MainWindow::loadScene(const QString &qFileName) {
|
||||
ref<FileResolver> resolver = FileResolver::getInstance();
|
||||
std::string filename = resolver->resolveAbsolute(qFileName.toStdString());
|
||||
std::string filePath = resolver->pathFromFile(filename);
|
||||
std::string filePath = resolver->getParentDirectory(filename);
|
||||
ref<FileResolver> newResolver = resolver->clone();
|
||||
if (!newResolver->contains(filePath))
|
||||
newResolver->addPath(filePath);
|
||||
|
|
|
@ -35,13 +35,15 @@ public:
|
|||
};
|
||||
|
||||
WavefrontOBJ(const Properties &props) : Shape(props) {
|
||||
m_name = FileResolver::getInstance()->resolve(props.getString("filename"));
|
||||
ref<FileResolver> fresolver = FileResolver::getInstance();
|
||||
std::string path = fresolver->resolve(props.getString("filename"));
|
||||
m_name = fresolver->getChild(path);
|
||||
|
||||
/* Load the geometry */
|
||||
Log(EInfo, "Loading geometry from \"%s\" ..", m_name.c_str());
|
||||
std::ifstream is(m_name.c_str());
|
||||
Log(EInfo, "Loading geometry from \"%s\" ..", path.c_str());
|
||||
std::ifstream is(path.c_str());
|
||||
if (is.bad() || is.fail())
|
||||
Log(EError, "Geometry file '%s' not found!", m_name.c_str());
|
||||
Log(EError, "Geometry file '%s' not found!", path.c_str());
|
||||
|
||||
std::string buf;
|
||||
std::vector<Point> vertices;
|
||||
|
|
Loading…
Reference in New Issue