Skip to content

Commit

Permalink
Add export to JSON.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jun 21, 2018
1 parent d056c00 commit b5a65a4
Show file tree
Hide file tree
Showing 6 changed files with 952 additions and 14 deletions.
17 changes: 6 additions & 11 deletions Telegram/SourceFiles/export/export_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,11 @@ void Controller::startExport(const Settings &settings) {
}

bool Controller::normalizePath() {
const auto check = [&] {
return QDir().mkpath(_settings.path);
};
QDir folder(_settings.path);
const auto path = folder.absolutePath();
_settings.path = path.endsWith('/') ? path : (path + '/');
if (!folder.exists()) {
return check();
return true;
}
const auto mode = QDir::AllEntries | QDir::NoDotAndDotDot;
const auto list = folder.entryInfoList(mode);
Expand All @@ -260,7 +257,7 @@ bool Controller::normalizePath() {
++index;
}
_settings.path += add(index) + '/';
return check();
return true;
}

void Controller::fillExportSteps() {
Expand Down Expand Up @@ -336,12 +333,7 @@ void Controller::cancelExportFast() {
}

void Controller::exportNext() {
if (!++_stepIndex) {
if (ioCatchError(_writer->start(_settings, &_stats))) {
return;
}
}
if (_stepIndex >= _steps.size()) {
if (++_stepIndex >= _steps.size()) {
if (ioCatchError(_writer->finish())) {
return;
}
Expand Down Expand Up @@ -370,6 +362,9 @@ void Controller::initialize() {
setState(stateInitializing());

_api.startExport(_settings, &_stats, [=](ApiWrap::StartInfo info) {
if (ioCatchError(_writer->start(_settings, &_stats))) {
return;
}
fillSubstepsInSteps(info);
exportNext();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ For license and copyright information please follow this link:
#include "export/output/export_output_abstract.h"

#include "export/output/export_output_text.h"
#include "export/output/export_output_json.h"

namespace Export {
namespace Output {

std::unique_ptr<AbstractWriter> CreateWriter(Format format) {
return std::make_unique<TextWriter>();
return std::make_unique<JsonWriter>();
}

} // namespace Output
Expand Down
Loading

0 comments on commit b5a65a4

Please sign in to comment.