Merge pull request #635 from andreasb242/new-path

New path
presentation
andreasb242 7 years ago committed by GitHub
commit 2b29bb1343
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      src/control/settings/MetadataManager.cpp
  2. 3
      src/control/xojfile/LoadHandler.cpp
  3. 18
      src/gui/toolbarMenubar/model/ToolbarColorNames.cpp
  4. 14
      src/util/GzUtil.cpp
  5. 26
      src/util/GzUtil.h
  6. 3
      src/util/OutputStream.cpp
  7. 4
      src/util/XojPreviewExtractor.cpp
  8. 1
      src/xoj-preview-extractor/CMakeLists.txt

@ -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;

@ -5,6 +5,7 @@
#include "LoadHandlerHelper.h"
#include <config.h>
#include <GzUtil.h>
#include <i18n.h>
#include <glib/gstdio.h>
@ -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);

@ -4,11 +4,7 @@
#include <i18n.h>
#include <StringUtils.h>
#include <stdio.h>
#include <fstream>
#include <iostream>
using std::cout;
using std::endl;
#include <glib/gstdio.h>
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);
}

@ -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
}

@ -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 <zlib.h>
class GzUtil
{
private:
GzUtil();
virtual ~GzUtil();
public:
static gzFile openPath(Path path, string flags);
};

@ -1,5 +1,6 @@
#include "OutputStream.h"
#include "GzUtil.h"
#include <i18n.h>
#include <stdlib.h>
@ -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());

@ -4,6 +4,8 @@
#include <zlib.h>
#include <string.h>
#include <GzUtil.h>
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;

@ -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"

Loading…
Cancel
Save