184 lines
4.3 KiB
C++
184 lines
4.3 KiB
C++
/*
|
|
This file is part of Telegram Desktop,
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
For license and copyright information please follow this link:
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
*/
|
|
#include "export/output/export_output_both.h"
|
|
|
|
#include "export/output/export_output_result.h"
|
|
#include "export/data/export_data_types.h"
|
|
#include "core/utils.h"
|
|
|
|
#include <QtCore/QDateTime>
|
|
#include <QtCore/QJsonDocument>
|
|
#include <QtCore/QJsonObject>
|
|
#include <QtCore/QJsonArray>
|
|
#include <QtCore/QJsonValue>
|
|
|
|
namespace Export {
|
|
namespace Output {
|
|
|
|
Result BothWriter::start(
|
|
const Settings &settings,
|
|
const Environment &environment,
|
|
Stats *stats) {
|
|
Expects(settings.path.endsWith('/'));
|
|
|
|
_settings = base::duplicate(settings);
|
|
_environment = environment;
|
|
_stats = stats;
|
|
if (_settings.onlySinglePeer()) {
|
|
return Result::Success();
|
|
}
|
|
|
|
// init json
|
|
Settings jsonSettings(settings);
|
|
jsonSettings.path += "json/";
|
|
jsonSettings.format = Format::Json;
|
|
jsonW = std::make_unique<JsonWriter>();
|
|
Result jres = jsonW->start(jsonSettings, environment, stats);
|
|
if(!jres) {
|
|
return jres;
|
|
}
|
|
|
|
// html json
|
|
Settings htmlSettings(settings);
|
|
htmlSettings.path += "html/";
|
|
htmlSettings.format = Format::Html;
|
|
htmlW = std::make_unique<HtmlWriter>();
|
|
Result hres = htmlW->start(htmlSettings, environment, stats);
|
|
|
|
return hres;
|
|
}
|
|
|
|
Result BothWriter::writePersonal(const Data::PersonalInfo &data) {
|
|
Expects(jsonW != nullptr);
|
|
Expects(htmlW != nullptr);
|
|
|
|
Result r = jsonW->writePersonal(data);
|
|
if(!r) return r;
|
|
return htmlW->writePersonal(data);
|
|
}
|
|
|
|
Result BothWriter::writeUserpicsStart(const Data::UserpicsInfo &data) {
|
|
Expects(jsonW != nullptr);
|
|
Expects(htmlW != nullptr);
|
|
|
|
Result r = jsonW->writeUserpicsStart(data);
|
|
if(!r) return r;
|
|
return htmlW->writeUserpicsStart(data);
|
|
}
|
|
|
|
Result BothWriter::writeUserpicsSlice(const Data::UserpicsSlice &data) {
|
|
Expects(jsonW != nullptr);
|
|
Expects(htmlW != nullptr);
|
|
Expects(!data.list.empty());
|
|
|
|
Result r = jsonW->writeUserpicsSlice(data);
|
|
if(!r) return r;
|
|
return htmlW->writeUserpicsSlice(data);
|
|
}
|
|
|
|
Result BothWriter::writeUserpicsEnd() {
|
|
Expects(jsonW != nullptr);
|
|
Expects(htmlW != nullptr);
|
|
|
|
Result r = jsonW->writeUserpicsEnd();
|
|
if(!r) return r;
|
|
return htmlW->writeUserpicsEnd();
|
|
}
|
|
|
|
Result BothWriter::writeContactsList(const Data::ContactsList &data) {
|
|
Expects(jsonW != nullptr);
|
|
Expects(htmlW != nullptr);
|
|
|
|
Result r = jsonW->writeContactsList(data);
|
|
if(!r) return r;
|
|
return htmlW->writeContactsList(data);
|
|
}
|
|
|
|
Result BothWriter::writeSessionsList(const Data::SessionsList &data) {
|
|
Expects(jsonW != nullptr);
|
|
Expects(htmlW != nullptr);
|
|
|
|
Result r = jsonW->writeSessionsList(data);
|
|
if(!r) return r;
|
|
return htmlW->writeSessionsList(data);
|
|
}
|
|
|
|
Result BothWriter::writeOtherData(const Data::File &data) {
|
|
Expects(data.skipReason == Data::File::SkipReason::None);
|
|
Expects(!data.relativePath.isEmpty());
|
|
|
|
Expects(jsonW != nullptr);
|
|
Expects(htmlW != nullptr);
|
|
|
|
Result r = jsonW->writeOtherData(data);
|
|
if(!r) return r;
|
|
return htmlW->writeOtherData(data);
|
|
}
|
|
|
|
Result BothWriter::writeDialogsStart(const Data::DialogsInfo &data) {
|
|
Expects(jsonW != nullptr);
|
|
Expects(htmlW != nullptr);
|
|
|
|
Result r = jsonW->writeDialogsStart(data);
|
|
if(!r) return r;
|
|
return htmlW->writeDialogsStart(data);
|
|
}
|
|
|
|
Result BothWriter::writeDialogStart(const Data::DialogInfo &data) {
|
|
Expects(jsonW != nullptr);
|
|
Expects(htmlW != nullptr);
|
|
|
|
Result r = jsonW->writeDialogStart(data);
|
|
if(!r) return r;
|
|
return htmlW->writeDialogStart(data);
|
|
}
|
|
|
|
Result BothWriter::writeDialogSlice(const Data::MessagesSlice &data) {
|
|
Expects(jsonW != nullptr);
|
|
Expects(htmlW != nullptr);
|
|
|
|
Result r = jsonW->writeDialogSlice(data);
|
|
if(!r) return r;
|
|
return htmlW->writeDialogSlice(data);
|
|
}
|
|
|
|
Result BothWriter::writeDialogEnd() {
|
|
Expects(jsonW != nullptr);
|
|
Expects(htmlW != nullptr);
|
|
|
|
Result r = jsonW->writeDialogEnd();
|
|
if(!r) return r;
|
|
return htmlW->writeDialogEnd();
|
|
}
|
|
|
|
Result BothWriter::writeDialogsEnd() {
|
|
Expects(jsonW != nullptr);
|
|
Expects(htmlW != nullptr);
|
|
|
|
Result r = jsonW->writeDialogsEnd();
|
|
if(!r) return r;
|
|
return htmlW->writeDialogsEnd();
|
|
}
|
|
|
|
Result BothWriter::finish() {
|
|
Expects(jsonW != nullptr);
|
|
Expects(htmlW != nullptr);
|
|
|
|
Result r = jsonW->finish();
|
|
if(!r) return r;
|
|
return htmlW->finish();
|
|
}
|
|
|
|
QString BothWriter::mainFilePath() {
|
|
return _settings.path;
|
|
}
|
|
|
|
|
|
} // namespace Output
|
|
} // namespace Export
|