diff --git a/src/archiver.cpp b/src/archiver.cpp index b62fc24d5689d7b8e978747a7bb010cd7cb1b739..01f015488f78ff2c541c51b1b3eecfd151287c6f 100644 --- a/src/archiver.cpp +++ b/src/archiver.cpp @@ -227,7 +227,7 @@ compress(const std::string& str) void compressGzip(const std::string& str, const std::string& path) { - auto fi = gzopen(path.c_str(), "wb"); + auto fi = openGzip(path, "wb"); gzwrite(fi, str.data(), str.size()); gzclose(fi); } @@ -236,7 +236,7 @@ std::vector<uint8_t> decompressGzip(const std::string& path) { std::vector<uint8_t> out; - auto fi = gzopen(path.c_str(),"rb"); + auto fi = openGzip(path, "rb"); gzrewind(fi); while (not gzeof(fi)) { std::array<uint8_t, 32768> outbuffer; @@ -294,4 +294,14 @@ decompress(const std::vector<uint8_t>& str) return out; } +gzFile +openGzip(const std::string& path, const char *mode) +{ +#ifdef _WIN32 + return gzopen_w(jami::to_wstring(path).c_str(), mode); +#else + return gzopen(path.c_str(), mode); +#endif +} + }} // namespace jami::archiver diff --git a/src/archiver.h b/src/archiver.h index b6aabc1535950ec6d182af895ceac078968f4fae..13e5b6f7c0c3569aa1ab2d7b24dc1840770788cc 100644 --- a/src/archiver.h +++ b/src/archiver.h @@ -26,6 +26,8 @@ #include <vector> #include <map> +typedef struct gzFile_s *gzFile; + namespace jami { /** @@ -74,6 +76,11 @@ void compressGzip(const std::string& str, const std::string& path); */ std::vector<uint8_t> decompressGzip(const std::string& path); +/** + * Open Gzip file (uses wide string version of gzopen on windows) + */ +gzFile openGzip(const std::string& path, const char *mode); + } } // namespace jami diff --git a/src/manager.cpp b/src/manager.cpp index 644108eec5bb1256006132493931a685f1e15053..169b7d1ba268314e789a649fabc3f20e3f8b49ab 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -441,6 +441,7 @@ Manager::ManagerPimpl::parseConfiguration() try { std::ifstream file = fileutils::ifstream(path_); YAML::Node parsedFile = YAML::Load(file); + file.close(); const int error_count = base_.loadAccountMap(parsedFile); if (error_count > 0) { @@ -449,6 +450,7 @@ Manager::ManagerPimpl::parseConfiguration() } } catch (const YAML::BadFile &e) { JAMI_WARN("Could not open configuration file"); + result = false; } return result; @@ -2859,6 +2861,7 @@ Manager::loadAccountMap(const YAML::Node& node) if (auto a = accountFactory.createAccount(JamiAccount::ACCOUNT_TYPE, dir)) { std::ifstream file = fileutils::ifstream(configFile); YAML::Node parsedConfig = YAML::Load(file); + file.close(); a->unserialize(parsedConfig); } } catch (const std::exception& e) { diff --git a/src/string_utils.h b/src/string_utils.h index 3f0e85fc9b2956f717332e09cfd35e9e9db8a203..50f8b9097e5b911292ffbc4456bf1a3b2d7320f4 100644 --- a/src/string_utils.h +++ b/src/string_utils.h @@ -42,7 +42,7 @@ std::string to_string(double value); #ifdef _WIN32 std::wstring to_wstring(const std::string& str, int codePage = CP_UTF8); -std::string to_string(const std::wstring& wstr, int codePage = CP_ACP); +std::string to_string(const std::wstring& wstr, int codePage = CP_UTF8); std::string bstrToStdString(BSTR bstr); #endif