Commit fd42b7f4 by Maarten L. Hekkelman

search data_dir as well as cache_dir, for MacOS

parent edcea220
...@@ -3096,13 +3096,46 @@ void File::loadDictionary(const char* dict) ...@@ -3096,13 +3096,46 @@ void File::loadDictionary(const char* dict)
fs::path dict_name(dict); fs::path dict_name(dict);
auto data = loadResource(dict); auto data = loadResource(dict);
if (not data and dict_name.extension().string() != ".dic") if (not data and dict_name.extension().string() != ".dic")
data = loadResource(dict_name.parent_path() / (dict_name.filename().string() + ".dic")); data = loadResource(dict_name.parent_path() / (dict_name.filename().string() + ".dic"));
if (not data) if (data)
throw std::runtime_error("Dictionary not found or defined (" + dict_name.string() + ")"); loadDictionary(*data);
else
loadDictionary(*data); {
// might be a compressed dictionary on disk
fs::path p = dict;
p = p.parent_path() / (p.filename().string() + ".gz");
if (not fs::exists(p))
{
for (const char* dir: { CACHE_DIR, DATA_DIR })
{
auto p2 = fs::path(dir) / p;
if (fs::exists(p2))
{
swap(p, p2);
break;
}
}
}
if (fs::exists(p))
{
std::ifstream file(p, std::ios::binary);
if (not file.is_open())
throw std::runtime_error("Could not open dictionary (" + p.string() + ")");
io::filtering_stream<io::input> in;
in.push(io::gzip_decompressor());
in.push(file);
loadDictionary(in);
}
else
throw std::runtime_error("Dictionary not found or defined (" + dict_name.string() + ")");
}
} }
void File::loadDictionary(std::istream& is) void File::loadDictionary(std::istream& is)
......
...@@ -1187,7 +1187,7 @@ std::unique_ptr<std::istream> loadResource(std::filesystem::path name) ...@@ -1187,7 +1187,7 @@ std::unique_ptr<std::istream> loadResource(std::filesystem::path name)
if (fs::exists(p)) if (fs::exists(p))
{ {
std::unique_ptr<std::ifstream> file(new std::ifstream(p)); std::unique_ptr<std::ifstream> file(new std::ifstream(p, std::ios::binary));
if (file->is_open()) if (file->is_open())
result.reset(file.release()); result.reset(file.release());
} }
......
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