diff --git a/src/control/settings/MetadataManager.cpp b/src/control/settings/MetadataManager.cpp index dd1113f7..fb6374b1 100644 --- a/src/control/settings/MetadataManager.cpp +++ b/src/control/settings/MetadataManager.cpp @@ -140,7 +140,7 @@ MetadataEntry MetadataManager::loadMetadataFile(string path, string file) ifstream infile(path.c_str()); string time = file.substr(0, file.size() - 9); - entry.time = std::stol(time); + entry.time = strtoll(time.c_str(), NULL, 10); if (!getline(infile, line)) { @@ -165,7 +165,6 @@ MetadataEntry MetadataManager::loadMetadataFile(string path, string file) entry.path = line; - if (!getline(infile, line)) { deleteMetadataFile(path); @@ -180,15 +179,7 @@ MetadataEntry MetadataManager::loadMetadataFile(string path, string file) return entry; } - try - { - entry.page = std::stoi(line.substr(5)); - } - catch (const std::exception& e) - { - // Return invalid entry - return entry; - } + entry.page = strtoll(line.substr(5).c_str(), NULL, 10); if (!getline(infile, line)) { @@ -204,7 +195,7 @@ MetadataEntry MetadataManager::loadMetadataFile(string path, string file) return entry; } - entry.zoom = std::stod(line.substr(5)); + entry.zoom = strtod(line.substr(5).c_str(), NULL); entry.valid = true; return entry; diff --git a/src/control/xojfile/LoadHandler.cpp b/src/control/xojfile/LoadHandler.cpp index 84334e19..20d1454e 100644 --- a/src/control/xojfile/LoadHandler.cpp +++ b/src/control/xojfile/LoadHandler.cpp @@ -5,6 +5,7 @@ #include "LoadHandlerHelper.h" #include +#include #include #include @@ -116,7 +117,7 @@ bool LoadHandler::openFile(string filename) XOJ_CHECK_TYPE(LoadHandler); this->filename = filename; - this->fp = gzopen(filename.c_str(), "r"); + this->fp = GzUtil::openPath(filename, "r"); if (!this->fp) { this->lastError = FS(_F("Could not open file: \"{1}\"") % filename); diff --git a/src/gui/toolbarMenubar/model/ToolbarColorNames.cpp b/src/gui/toolbarMenubar/model/ToolbarColorNames.cpp index 8d473d7b..ebdbc73e 100644 --- a/src/gui/toolbarMenubar/model/ToolbarColorNames.cpp +++ b/src/gui/toolbarMenubar/model/ToolbarColorNames.cpp @@ -4,11 +4,7 @@ #include #include -#include -#include -#include -using std::cout; -using std::endl; +#include ToolbarColorNames::ToolbarColorNames() { @@ -70,9 +66,15 @@ void ToolbarColorNames::saveFile(const string file) gsize len = 0; char* data = g_key_file_to_data(this->config, &len, NULL); - std::ofstream f(file, std::fstream::out); - f << data; - f.close(); + FILE* fp = g_fopen(file.c_str(), "wb"); + if (!fp) + { + g_error("Could not save color file «%s»", file.c_str()); + return; + } + + fwrite(data, len, 1, fp); + fclose(fp); g_free(data); } diff --git a/src/util/GzUtil.cpp b/src/util/GzUtil.cpp new file mode 100644 index 00000000..4bac46d8 --- /dev/null +++ b/src/util/GzUtil.cpp @@ -0,0 +1,14 @@ +#include "GzUtil.h" + +gzFile GzUtil::openPath(Path path, string flags) +{ +#ifdef WIN32 + wchar_t* wfilename = (wchar_t*)g_utf8_to_utf16(path.c_str(), -1, NULL, NULL, NULL); + gzFile fp = gzopen_w(wfilename, flags.c_str()); + g_free(wfilename); + + return fp; +#else + return gzopen(path.c_str(), flags.c_str()); +#endif +} diff --git a/src/util/GzUtil.h b/src/util/GzUtil.h new file mode 100644 index 00000000..0c0e4133 --- /dev/null +++ b/src/util/GzUtil.h @@ -0,0 +1,26 @@ +/* + * Xournal++ + * + * Gzip Helper + * + * @author Xournal++ Team + * https://github.com/xournalpp/xournalpp + * + * @license GNU GPLv2 or later + */ + +#pragma once + +#include "Path.h" +#include + +class GzUtil +{ +private: + GzUtil(); + virtual ~GzUtil(); + +public: + static gzFile openPath(Path path, string flags); +}; + diff --git a/src/util/OutputStream.cpp b/src/util/OutputStream.cpp index 3d3ab5fa..234c5280 100644 --- a/src/util/OutputStream.cpp +++ b/src/util/OutputStream.cpp @@ -1,5 +1,6 @@ #include "OutputStream.h" +#include "GzUtil.h" #include #include @@ -29,7 +30,7 @@ GzOutputStream::GzOutputStream(Path filename) this->fp = NULL; this->filename = filename; - this->fp = gzopen(filename.c_str(), "w"); + this->fp = GzUtil::openPath(filename, "w"); if (this->fp == NULL) { this->error = FS(_F("Error opening file: \"{1}\"") % filename.str()); diff --git a/src/util/XojPreviewExtractor.cpp b/src/util/XojPreviewExtractor.cpp index 99d89b20..6f4d90e9 100644 --- a/src/util/XojPreviewExtractor.cpp +++ b/src/util/XojPreviewExtractor.cpp @@ -4,6 +4,8 @@ #include #include +#include + const char* TAG_PREVIEW_NAME = "preview"; const int TAG_PREVIEW_NAME_LEN = strlen(TAG_PREVIEW_NAME); const char* TAG_PAGE_NAME = "page"; @@ -109,7 +111,7 @@ PreviewExtractResult XojPreviewExtractor::readFile(Path file) return PREVIEW_RESULT_BAD_FILE_EXTENSION; } - gzFile fp = gzopen(file.c_str(), "r"); + gzFile fp = GzUtil::openPath(file, "r"); if (!fp) { return PREVIEW_RESULT_COULD_NOT_OPEN_FILE; diff --git a/src/xoj-preview-extractor/CMakeLists.txt b/src/xoj-preview-extractor/CMakeLists.txt index 731a5b95..527727b6 100644 --- a/src/xoj-preview-extractor/CMakeLists.txt +++ b/src/xoj-preview-extractor/CMakeLists.txt @@ -7,6 +7,7 @@ endif () add_executable (xournal-thumbnailer xournal-thumbnailer.cpp + "${PROJECT_SOURCE_DIR}/src/util/GzUtil.cpp" "${PROJECT_SOURCE_DIR}/src/util/Path.cpp" "${PROJECT_SOURCE_DIR}/src/util/PlaceholderString.cpp" "${PROJECT_SOURCE_DIR}/src/util/StringUtils.cpp"