mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 09:30:13 +03:00
Add a button to create a debug archive
This will harvest everything we might need for debugging purposes: * config file * sync journal dbs * log files Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
This commit is contained in:
parent
15d294e7fb
commit
8fb673457b
3 changed files with 103 additions and 2 deletions
|
@ -30,21 +30,102 @@
|
||||||
|
|
||||||
#include "ignorelisteditor.h"
|
#include "ignorelisteditor.h"
|
||||||
#include "common/utility.h"
|
#include "common/utility.h"
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include "legalnotice.h"
|
#include "legalnotice.h"
|
||||||
|
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QNetworkProxy>
|
#include <QNetworkProxy>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QScopedValueRollback>
|
#include <QScopedValueRollback>
|
||||||
|
|
||||||
|
#include <private/qzipwriter_p.h>
|
||||||
|
|
||||||
#define QTLEGACY (QT_VERSION < QT_VERSION_CHECK(5,9,0))
|
#define QTLEGACY (QT_VERSION < QT_VERSION_CHECK(5,9,0))
|
||||||
|
|
||||||
#if !(QTLEGACY)
|
#if !(QTLEGACY)
|
||||||
#include <QOperatingSystemVersion>
|
#include <QOperatingSystemVersion>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
struct ZipEntry {
|
||||||
|
QString localFilename;
|
||||||
|
QString zipFilename;
|
||||||
|
};
|
||||||
|
|
||||||
|
ZipEntry fileInfoToZipEntry(const QFileInfo &info)
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
info.absoluteFilePath(),
|
||||||
|
info.fileName()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
ZipEntry fileInfoToLogZipEntry(const QFileInfo &info)
|
||||||
|
{
|
||||||
|
auto entry = fileInfoToZipEntry(info);
|
||||||
|
entry.zipFilename.prepend(QStringLiteral("logs/"));
|
||||||
|
return entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZipEntry syncFolderToZipEntry(OCC::Folder *f)
|
||||||
|
{
|
||||||
|
const auto journalPath = f->journalDb()->databaseFilePath();
|
||||||
|
const auto journalInfo = QFileInfo(journalPath);
|
||||||
|
return fileInfoToZipEntry(journalInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
QVector<ZipEntry> createFileList()
|
||||||
|
{
|
||||||
|
auto list = QVector<ZipEntry>();
|
||||||
|
OCC::ConfigFile cfg;
|
||||||
|
|
||||||
|
list.append(fileInfoToZipEntry(QFileInfo(cfg.configFile())));
|
||||||
|
|
||||||
|
const auto logger = OCC::Logger::instance();
|
||||||
|
|
||||||
|
if (!logger->logDir().isEmpty()) {
|
||||||
|
list.append({QString(), QStringLiteral("logs")});
|
||||||
|
|
||||||
|
QDir dir(logger->logDir());
|
||||||
|
const auto infoList = dir.entryInfoList(QDir::Files);
|
||||||
|
std::transform(std::cbegin(infoList), std::cend(infoList),
|
||||||
|
std::back_inserter(list),
|
||||||
|
fileInfoToLogZipEntry);
|
||||||
|
} else if (!logger->logFile().isEmpty()) {
|
||||||
|
list.append(fileInfoToZipEntry(QFileInfo(logger->logFile())));
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto folders = OCC::FolderMan::instance()->map().values();
|
||||||
|
std::transform(std::cbegin(folders), std::cend(folders),
|
||||||
|
std::back_inserter(list),
|
||||||
|
syncFolderToZipEntry);
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
void createDebugArchive(const QString &filename)
|
||||||
|
{
|
||||||
|
const auto entries = createFileList();
|
||||||
|
|
||||||
|
QZipWriter zip(filename);
|
||||||
|
for (const auto &entry : entries) {
|
||||||
|
if (entry.localFilename.isEmpty()) {
|
||||||
|
zip.addDirectory(entry.zipFilename);
|
||||||
|
} else {
|
||||||
|
QFile file(entry.localFilename);
|
||||||
|
if (!file.open(QFile::ReadOnly)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
zip.addFile(entry.zipFilename, &file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace OCC {
|
namespace OCC {
|
||||||
|
|
||||||
GeneralSettings::GeneralSettings(QWidget *parent)
|
GeneralSettings::GeneralSettings(QWidget *parent)
|
||||||
|
@ -122,6 +203,7 @@ GeneralSettings::GeneralSettings(QWidget *parent)
|
||||||
_ui->monoIconsCheckBox->setVisible(Theme::instance()->monoIconsAvailable());
|
_ui->monoIconsCheckBox->setVisible(Theme::instance()->monoIconsAvailable());
|
||||||
|
|
||||||
connect(_ui->ignoredFilesButton, &QAbstractButton::clicked, this, &GeneralSettings::slotIgnoreFilesEditor);
|
connect(_ui->ignoredFilesButton, &QAbstractButton::clicked, this, &GeneralSettings::slotIgnoreFilesEditor);
|
||||||
|
connect(_ui->debugArchiveButton, &QAbstractButton::clicked, this, &GeneralSettings::slotCreateDebugArchive);
|
||||||
|
|
||||||
// accountAdded means the wizard was finished and the wizard might change some options.
|
// accountAdded means the wizard was finished and the wizard might change some options.
|
||||||
connect(AccountManager::instance(), &AccountManager::accountAdded, this, &GeneralSettings::loadMiscSettings);
|
connect(AccountManager::instance(), &AccountManager::accountAdded, this, &GeneralSettings::loadMiscSettings);
|
||||||
|
@ -260,6 +342,17 @@ void GeneralSettings::slotIgnoreFilesEditor()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GeneralSettings::slotCreateDebugArchive()
|
||||||
|
{
|
||||||
|
const auto filename = QFileDialog::getSaveFileName(this, tr("Create Debug Archive"), QString(), tr("Zip Archives") + " (*.zip)");
|
||||||
|
if (filename.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
createDebugArchive(filename);
|
||||||
|
QMessageBox::information(this, tr("Debug Archive Created"), tr("Debug archive is created at %1").arg(filename));
|
||||||
|
}
|
||||||
|
|
||||||
void GeneralSettings::slotShowLegalNotice()
|
void GeneralSettings::slotShowLegalNotice()
|
||||||
{
|
{
|
||||||
auto notice = new LegalNotice();
|
auto notice = new LegalNotice();
|
||||||
|
|
|
@ -48,6 +48,7 @@ private slots:
|
||||||
void slotToggleOptionalServerNotifications(bool);
|
void slotToggleOptionalServerNotifications(bool);
|
||||||
void slotShowInExplorerNavigationPane(bool);
|
void slotShowInExplorerNavigationPane(bool);
|
||||||
void slotIgnoreFilesEditor();
|
void slotIgnoreFilesEditor();
|
||||||
|
void slotCreateDebugArchive();
|
||||||
void loadMiscSettings();
|
void loadMiscSettings();
|
||||||
void slotShowLegalNotice();
|
void slotShowLegalNotice();
|
||||||
#if defined(BUILD_UPDATER)
|
#if defined(BUILD_UPDATER)
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>516</width>
|
<width>553</width>
|
||||||
<height>523</height>
|
<height>558</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -219,6 +219,13 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="debugArchiveButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Create Debug Archive...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer_4">
|
<spacer name="horizontalSpacer_4">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|
Loading…
Reference in a new issue