diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-17 01:02:09 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-17 01:02:09 +0100 |
commit | 8eb2bed0115b5f6884fe12ecda80974aa6c21761 (patch) | |
tree | ab9fde77789a8945655a6cb3d6f1981dbf9792a8 /src/core/resource | |
parent | 2edd0e40cd1afa9a422733b0a3b4babc064041b6 (diff) |
Improved auto-completion handling and error messages in ResourceRequest -- perform autocompletion if the mimetype is not known and not if no extension is given. People might have files that contain dots without having an actual extension.
Diffstat (limited to 'src/core/resource')
-rw-r--r-- | src/core/resource/ResourceRequest.cpp | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/src/core/resource/ResourceRequest.cpp b/src/core/resource/ResourceRequest.cpp index 0216388..79e1ff7 100644 --- a/src/core/resource/ResourceRequest.cpp +++ b/src/core/resource/ResourceRequest.cpp @@ -174,37 +174,42 @@ bool ResourceRequest::deduce(Registry ®istry, Logger &logger) resourceType = deduceResourceType(supportedTypes); } - // If the given file has no extension, try to complete it - std::string ext = Utils::extractFileExtension(path); - if (ext.empty()) { - std::vector<std::string> paths = - registry.autocompleteResource(path, resourceType, relativeTo); - if (paths.size() > 1U) { - // There are multiple possible files - // TODO: Select the one which matches the other parameters - logger.error(std::string("Resource \"") + path + - std::string("\" is ambiguous.")); - logger.note(std::string("Possibly referenced files are:"), - SourceLocation{}, MessageMode::NO_CONTEXT); - for (const auto &p : paths) { - logger.note(p, SourceLocation{}, MessageMode::NO_CONTEXT); - } - ok = false; - } else if (paths.size() == 1U) { - // Otherwise just copy the first resolved element - path = paths[0]; - } - } - // Try to deduce the mimetype if none was given if (mimetype.empty()) { mimetype = registry.getMimetypeForFilename(path); if (mimetype.empty()) { - logger.error(std::string("Resource \"") + path + - std::string( - "\" has an unknown file extension. Explicitly " - "specify a mimetype.")); - ok = false; + // Probably the file extension was not given -- autocomplete the + // extension and try again + std::vector<std::string> paths = + registry.autocompleteResource(path, resourceType, relativeTo); + if (paths.size() > 1U) { + // There are multiple possible files + // TODO: Select the one which matches the other parameters + logger.error(std::string("Resource \"") + path + + std::string("\" is ambiguous")); + logger.note(std::string("Possible resources are:"), + SourceLocation{}, MessageMode::NO_CONTEXT); + for (const auto &p : paths) { + logger.note(p, SourceLocation{}, MessageMode::NO_CONTEXT); + } + ok = false; + } else if (paths.size() == 1U) { + // Otherwise just copy the first resolved element + path = paths[0]; + mimetype = registry.getMimetypeForFilename(path); + if (mimetype.empty()) { + logger.error( + std::string("Resource \"") + path + + std::string( + "\" has an unknown file extension. Explicitly " + "specify a mimetype.")); + ok = false; + } + } else { + logger.error(std::string("Resource \"") + path + + std::string("\" not found")); + ok = false; + } } } |