mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-16 18:35:35 +08:00
Ref T401, crash info can be saved as file
This commit is contained in:
committed by
Mat Sutcliffe
parent
10fff29f97
commit
df3ac2b02d
@@ -8,6 +8,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "blackmisc/crashinfo.h"
|
#include "blackmisc/crashinfo.h"
|
||||||
|
#include "fileutils.h"
|
||||||
|
|
||||||
|
#include <QFile>
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
@@ -27,6 +30,11 @@ namespace BlackMisc
|
|||||||
m_info += u' ' % extraInfo;
|
m_info += u' ' % extraInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCrashInfo::setLogPathAndFileName(const QString &fileName)
|
||||||
|
{
|
||||||
|
m_logFileAndPath = fileName;
|
||||||
|
}
|
||||||
|
|
||||||
CVariant CCrashInfo::propertyByIndex(const CPropertyIndex &index) const
|
CVariant CCrashInfo::propertyByIndex(const CPropertyIndex &index) const
|
||||||
{
|
{
|
||||||
if (index.isMyself()) { return CVariant::from(*this); }
|
if (index.isMyself()) { return CVariant::from(*this); }
|
||||||
@@ -69,4 +77,18 @@ namespace BlackMisc
|
|||||||
default: return CValueObject::comparePropertyByIndex(index.copyFrontRemoved(), compareValue);
|
default: return CValueObject::comparePropertyByIndex(index.copyFrontRemoved(), compareValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCrashInfo::triggerWritingFile()
|
||||||
|
{
|
||||||
|
if (m_logFileAndPath.isEmpty()) { return; }
|
||||||
|
CFileUtils::writeStringToFileInBackground(summary(), m_logFileAndPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString CCrashInfo::summary() const
|
||||||
|
{
|
||||||
|
return (m_userName.isEmpty() ? QStringLiteral("") : u"user name: " % m_userName % u"\n") %
|
||||||
|
(m_simulatorString.isEmpty() ? QStringLiteral("") : u"simulator: " % m_simulatorString % u"\n") %
|
||||||
|
(m_flightNetwork.isEmpty() ? QStringLiteral("") : u"network: " % m_flightNetwork % u"\n") %
|
||||||
|
(m_info.isEmpty() ? QStringLiteral("") : u"info: " % m_info % u"\n");
|
||||||
|
}
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ namespace BlackMisc
|
|||||||
//! User name
|
//! User name
|
||||||
void setUserName(const QString &userName) { m_userName = userName; }
|
void setUserName(const QString &userName) { m_userName = userName; }
|
||||||
|
|
||||||
|
//! Any info available?
|
||||||
|
bool hasInfo() const { return !m_info.isEmpty(); }
|
||||||
|
|
||||||
//! Get the info
|
//! Get the info
|
||||||
const QString &getInfo() const { return m_info; }
|
const QString &getInfo() const { return m_info; }
|
||||||
|
|
||||||
@@ -62,6 +65,9 @@ namespace BlackMisc
|
|||||||
//! Append some info
|
//! Append some info
|
||||||
void appendInfo(const QString &extraInfo);
|
void appendInfo(const QString &extraInfo);
|
||||||
|
|
||||||
|
//! Set path and file name
|
||||||
|
void setLogPathAndFileName(const QString &fileName);
|
||||||
|
|
||||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||||
QString convertToQString(bool i18n = false) const;
|
QString convertToQString(bool i18n = false) const;
|
||||||
|
|
||||||
@@ -74,16 +80,26 @@ namespace BlackMisc
|
|||||||
//! \copydoc BlackMisc::Mixin::Index::comparePropertyByIndex
|
//! \copydoc BlackMisc::Mixin::Index::comparePropertyByIndex
|
||||||
int comparePropertyByIndex(const CPropertyIndex &index, const CCrashInfo &compareValue) const;
|
int comparePropertyByIndex(const CPropertyIndex &index, const CCrashInfo &compareValue) const;
|
||||||
|
|
||||||
|
//! Trigger writing this to file
|
||||||
|
void triggerWritingFile();
|
||||||
|
|
||||||
|
//! Summary
|
||||||
|
QString summary() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_userName;
|
QString m_userName;
|
||||||
QString m_info;
|
QString m_info;
|
||||||
QString m_simulatorString;
|
QString m_simulatorString;
|
||||||
QString m_flightNetwork;
|
QString m_flightNetwork;
|
||||||
|
QString m_logFileAndPath;
|
||||||
|
|
||||||
BLACK_METACLASS(
|
BLACK_METACLASS(
|
||||||
CCrashInfo,
|
CCrashInfo,
|
||||||
BLACK_METAMEMBER(userName),
|
BLACK_METAMEMBER(userName),
|
||||||
BLACK_METAMEMBER(info)
|
BLACK_METAMEMBER(info),
|
||||||
|
BLACK_METAMEMBER(simulatorString),
|
||||||
|
BLACK_METAMEMBER(flightNetwork),
|
||||||
|
BLACK_METAMEMBER(logFileAndPath)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -102,9 +102,9 @@ namespace BlackMisc
|
|||||||
bool CFileUtils::writeStringToFileInBackground(const QString &content, const QString &fileNameAndPath)
|
bool CFileUtils::writeStringToFileInBackground(const QString &content, const QString &fileNameAndPath)
|
||||||
{
|
{
|
||||||
if (fileNameAndPath.isEmpty()) { return false; }
|
if (fileNameAndPath.isEmpty()) { return false; }
|
||||||
CWorker *worker = BlackMisc::CWorker::fromTask(QCoreApplication::instance(), "writeStringToFileInBackground", [content, fileNameAndPath]()
|
CWorker *worker = CWorker::fromTask(QCoreApplication::instance(), "writeStringToFileInBackground", [content, fileNameAndPath]()
|
||||||
{
|
{
|
||||||
bool s = CFileUtils::writeStringToFile(content, fileNameAndPath);
|
const bool s = CFileUtils::writeStringToFile(content, fileNameAndPath);
|
||||||
Q_UNUSED(s);
|
Q_UNUSED(s);
|
||||||
});
|
});
|
||||||
return worker ? true : false;
|
return worker ? true : false;
|
||||||
|
|||||||
Reference in New Issue
Block a user