Iss asset with model added

This commit is contained in:
Your Name
2020-01-30 18:15:38 -05:00
parent 826caf6954
commit b05df8778e
4 changed files with 219 additions and 36 deletions

View File

@@ -43,8 +43,10 @@ namespace {
constexpr const char* KeyIdentifier = "Identifier";
constexpr const char* KeyOverride = "Override";
constexpr const char* KeyUseHash = "UseHash";
constexpr const char* KeyFilename = "Filename";
constexpr const char* TempSuffix = ".tmp";
constexpr const char* ext = ".txt";
} // namespace
namespace openspace {
@@ -90,6 +92,13 @@ documentation::Documentation UrlSynchronization::Documentation() {
"circumstances. If this is not desired, the URLSynchronization use the "
"bare directory name alone if this value is 'false'. If this value is "
"'false', the identifier has to be specified."
},
{
KeyFilename,
new StringVerifier,
Optional::Yes,
"Optional to provide filename to override the one which is automatically "
"created from the url. "
}
}
};
@@ -117,6 +126,14 @@ UrlSynchronization::UrlSynchronization(const ghoul::Dictionary& dict,
}
}
if (dict.hasValue<std::string>(KeyFilename)) {
_filename = dict.value<std::string>(KeyFilename);
std::size_t foundExt = _filename.find(ext);
if (foundExt == std::string::npos) {
_filename += ext;
}
}
bool useHash = true;
if (dict.hasValue<bool>(KeyUseHash)) {
useHash = dict.value<bool>(KeyUseHash);
@@ -181,11 +198,21 @@ void UrlSynchronization::start() {
std::vector<std::unique_ptr<AsyncHttpFileDownload>> downloads;
for (const std::string& url : _urls) {
const size_t lastSlash = url.find_last_of('/');
const std::string filename = url.substr(lastSlash + 1);
if (_filename.empty()) {
const size_t lastSlash = url.find_last_of('/');
std::string lastPartOfUrl = url.substr(lastSlash + 1);
lastPartOfUrl.erase(std::remove(lastPartOfUrl.begin(), lastPartOfUrl.end(), '?'), lastPartOfUrl.end());
std::size_t foundExt = lastPartOfUrl.find(ext);
if (foundExt == std::string::npos) {
lastPartOfUrl += ext;
}
_filename = lastPartOfUrl;
}
std::string fileDestination = directory() +
ghoul::filesystem::FileSystem::PathSeparator + filename + TempSuffix;
ghoul::filesystem::FileSystem::PathSeparator + _filename + TempSuffix;
std::unique_ptr<AsyncHttpFileDownload> download =
std::make_unique<AsyncHttpFileDownload>(