Commit a5f61664 by Maarten L. Hekkelman

locating resources that might be protected

parent 501050e5
...@@ -1220,42 +1220,47 @@ void addFileResource(const std::string &name, std::filesystem::path dataFile) ...@@ -1220,42 +1220,47 @@ void addFileResource(const std::string &name, std::filesystem::path dataFile)
std::unique_ptr<std::istream> loadResource(std::filesystem::path name) std::unique_ptr<std::istream> loadResource(std::filesystem::path name)
{ {
std::unique_ptr<std::istream> result; std::unique_ptr<std::istream> result;
std::error_code ec;
fs::path p = name; fs::path p = name;
if (gLocalResources.count(name.string())) if (gLocalResources.count(name.string()))
{ {
std::unique_ptr<std::ifstream> file(new std::ifstream(gLocalResources[name.string()], std::ios::binary)); try
if (file->is_open()) {
result.reset(file.release()); std::unique_ptr<std::ifstream> file(new std::ifstream(gLocalResources[name.string()], std::ios::binary));
if (file->is_open())
result.reset(file.release());
}
catch (...) {}
} }
if (not result and not fs::exists(p) and not gDataDir.empty()) if (not result and (not fs::exists(p, ec) or ec) and not gDataDir.empty())
p = gDataDir / name; p = gDataDir / name;
#if defined(CACHE_DIR) #if defined(CACHE_DIR)
if (not result and not fs::exists(p)) if (not result and (not fs::exists(p, ec) or ec))
{ {
auto p2 = fs::path(CACHE_DIR) / p; auto p2 = fs::path(CACHE_DIR) / p;
if (fs::exists(p2)) if (fs::exists(p2, ec) and not ec)
swap(p, p2); swap(p, p2);
} }
#endif #endif
#if defined(DATA_DIR) #if defined(DATA_DIR)
if (not result and not fs::exists(p)) if (not result and (not fs::exists(p, ec) or ec))
{ {
auto p2 = fs::path(DATA_DIR) / p; auto p2 = fs::path(DATA_DIR) / p;
if (fs::exists(p2)) if (fs::exists(p2, ec) and not ec)
swap(p, p2); swap(p, p2);
} }
#endif #endif
#if defined(CCP4) and CCP4 #if defined(CCP4) and CCP4
if (not result and not fs::exists(p)) if (not result and (not fs::exists(p, ec) or ec))
{ {
const char* CCP4_DIR = getenv("CCP4"); const char* CCP4_DIR = getenv("CCP4");
if (CCP4_DIR != nullptr and fs::exists(CCP4_DIR)) if (CCP4_DIR != nullptr and fs::exists(CCP4_DIR, ec) and not ec)
{ {
auto p2 = fs::path(DATA_DIR) / p; auto p2 = fs::path(DATA_DIR) / p;
if (fs::exists(p2)) if (fs::exists(p2))
...@@ -1264,11 +1269,15 @@ std::unique_ptr<std::istream> loadResource(std::filesystem::path name) ...@@ -1264,11 +1269,15 @@ std::unique_ptr<std::istream> loadResource(std::filesystem::path name)
} }
#endif #endif
if (not result and fs::exists(p)) if (not result and fs::exists(p, ec) and not ec)
{ {
std::unique_ptr<std::ifstream> file(new std::ifstream(p, std::ios::binary)); try
if (file->is_open()) {
result.reset(file.release()); std::unique_ptr<std::ifstream> file(new std::ifstream(p, std::ios::binary));
if (file->is_open())
result.reset(file.release());
}
catch (...) {}
} }
if (not result and gResourceData) if (not result and gResourceData)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment