forked from Silverfish/proton-bridge
Other: C++ Code reformat.
This commit is contained in:
@ -21,8 +21,7 @@
|
||||
#include <random>
|
||||
|
||||
|
||||
namespace bridgepp
|
||||
{
|
||||
namespace bridgepp {
|
||||
|
||||
|
||||
namespace {
|
||||
@ -56,8 +55,7 @@ QStringList const lastNames {
|
||||
//****************************************************************************************************************************************************
|
||||
/// \brief Return the 64 bit Mersenne twister random number generator.
|
||||
//****************************************************************************************************************************************************
|
||||
std::mt19937_64& rng()
|
||||
{
|
||||
std::mt19937_64 &rng() {
|
||||
// Do not use for crypto. std::random_device is not good enough.
|
||||
static std::mt19937_64 generator = std::mt19937_64(std::random_device()());
|
||||
return generator;
|
||||
@ -70,17 +68,17 @@ std::mt19937_64& rng()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return user configuration directory used by bridge (based on Golang OS/File's UserConfigDir).
|
||||
//****************************************************************************************************************************************************
|
||||
QString userConfigDir()
|
||||
{
|
||||
QString userConfigDir() {
|
||||
QString dir;
|
||||
#ifdef Q_OS_WIN
|
||||
dir = qgetenv ("AppData");
|
||||
if (dir.isEmpty())
|
||||
throw Exception("%AppData% is not defined.");
|
||||
#elif defined(Q_OS_IOS) || defined(Q_OS_DARWIN)
|
||||
dir = qgetenv ("HOME");
|
||||
if (dir.isEmpty())
|
||||
dir = qgetenv("HOME");
|
||||
if (dir.isEmpty()) {
|
||||
throw Exception("$HOME is not defined.");
|
||||
}
|
||||
dir += "/Library/Application Support";
|
||||
#else
|
||||
dir = qgetenv ("XDG_CONFIG_HOME");
|
||||
@ -102,8 +100,7 @@ QString userConfigDir()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return user cache directory used by bridge (based on Golang OS/File's UserCacheDir).
|
||||
//****************************************************************************************************************************************************
|
||||
QString userCacheDir()
|
||||
{
|
||||
QString userCacheDir() {
|
||||
QString dir;
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
@ -111,9 +108,10 @@ QString userCacheDir()
|
||||
if (dir.isEmpty())
|
||||
throw Exception("%LocalAppData% is not defined.");
|
||||
#elif defined(Q_OS_IOS) || defined(Q_OS_DARWIN)
|
||||
dir = qgetenv ("HOME");
|
||||
if (dir.isEmpty())
|
||||
dir = qgetenv("HOME");
|
||||
if (dir.isEmpty()) {
|
||||
throw Exception("$HOME is not defined.");
|
||||
}
|
||||
dir += "/Library/Caches";
|
||||
#else
|
||||
dir = qgetenv ("XDG_CACHE_HOME");
|
||||
@ -132,11 +130,11 @@ QString userCacheDir()
|
||||
return folder;
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return user data directory used by bridge (based on Golang OS/File's UserDataDir).
|
||||
//****************************************************************************************************************************************************
|
||||
QString userDataDir()
|
||||
{
|
||||
QString userDataDir() {
|
||||
QString folder;
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
@ -157,21 +155,21 @@ QString userDataDir()
|
||||
return folder;
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return user logs directory used by bridge.
|
||||
//****************************************************************************************************************************************************
|
||||
QString userLogsDir()
|
||||
{
|
||||
QString userLogsDir() {
|
||||
QString const path = QDir(userDataDir()).absoluteFilePath("logs");
|
||||
QDir().mkpath(path);
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return sentry cache directory used by bridge.
|
||||
//****************************************************************************************************************************************************
|
||||
QString sentryCacheDir()
|
||||
{
|
||||
QString sentryCacheDir() {
|
||||
QString const path = QDir(userDataDir()).absoluteFilePath("sentry_cache");
|
||||
QDir().mkpath(path);
|
||||
return path;
|
||||
@ -181,8 +179,7 @@ QString sentryCacheDir()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The value GOOS would return for the current platform.
|
||||
//****************************************************************************************************************************************************
|
||||
QString goos()
|
||||
{
|
||||
QString goos() {
|
||||
#if defined(Q_OS_DARWIN)
|
||||
return "darwin";
|
||||
#elif defined(Q_OS_WINDOWS)
|
||||
@ -198,8 +195,7 @@ QString goos()
|
||||
///
|
||||
/// \return a random number in the range [0, n-1]
|
||||
//****************************************************************************************************************************************************
|
||||
qint64 randN(qint64 n)
|
||||
{
|
||||
qint64 randN(qint64 n) {
|
||||
QMutexLocker locker(&rngMutex);
|
||||
return (n > 0) ? std::uniform_int_distribution<qint64>(0, n - 1)(rng()) : 0;
|
||||
}
|
||||
@ -208,8 +204,7 @@ qint64 randN(qint64 n)
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return A random first name.
|
||||
//****************************************************************************************************************************************************
|
||||
QString randomFirstName()
|
||||
{
|
||||
QString randomFirstName() {
|
||||
return firstNames[randN(firstNames.size())];
|
||||
}
|
||||
|
||||
@ -217,8 +212,7 @@ QString randomFirstName()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return A random last name.
|
||||
//****************************************************************************************************************************************************
|
||||
QString randomLastName()
|
||||
{
|
||||
QString randomLastName() {
|
||||
return lastNames[randN(lastNames.size())];
|
||||
}
|
||||
|
||||
@ -226,15 +220,14 @@ QString randomLastName()
|
||||
//****************************************************************************************************************************************************
|
||||
//
|
||||
//****************************************************************************************************************************************************
|
||||
SPUser randomUser()
|
||||
{
|
||||
SPUser randomUser() {
|
||||
SPUser user = User::newUser(nullptr);
|
||||
user->setID(QUuid::createUuid().toString());
|
||||
QString const firstName = randomFirstName();
|
||||
QString const lastName = randomLastName();
|
||||
QString const username = QString("%1.%2").arg(firstName.toLower(), lastName.toLower());
|
||||
user->setUsername(username);
|
||||
user->setAddresses(QStringList() << (username + "@proton.me") << (username + "@protonmail.com") );
|
||||
user->setAddresses(QStringList() << (username + "@proton.me") << (username + "@protonmail.com"));
|
||||
user->setPassword(QUuid().createUuid().toString(QUuid::StringFormat::WithoutBraces).left(20));
|
||||
user->setAvatarText(firstName.left(1) + lastName.left(1));
|
||||
user->setState(UserState::Connected);
|
||||
@ -249,14 +242,15 @@ SPUser randomUser()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return The OS the application is running on.
|
||||
//****************************************************************************************************************************************************
|
||||
OS os()
|
||||
{
|
||||
OS os() {
|
||||
QString const osStr = QSysInfo::productType();
|
||||
if ((osStr == "macos") || (osStr == "osx")) // Qt < 5 returns "osx", Qt6 returns "macos".
|
||||
if ((osStr == "macos") || (osStr == "osx")) { // Qt < 5 returns "osx", Qt6 returns "macos".
|
||||
return OS::MacOS;
|
||||
}
|
||||
|
||||
if (osStr == "windows")
|
||||
if (osStr == "windows") {
|
||||
return OS::Windows;
|
||||
}
|
||||
|
||||
return OS::Linux;
|
||||
}
|
||||
@ -265,8 +259,7 @@ OS os()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return true if and only if the application is currently running on Linux.
|
||||
//****************************************************************************************************************************************************
|
||||
bool onLinux()
|
||||
{
|
||||
bool onLinux() {
|
||||
return OS::Linux == os();
|
||||
}
|
||||
|
||||
@ -274,8 +267,7 @@ bool onLinux()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return true if and only if the application is currently running on MacOS.
|
||||
//****************************************************************************************************************************************************
|
||||
bool onMacOS()
|
||||
{
|
||||
bool onMacOS() {
|
||||
return OS::MacOS == os();
|
||||
}
|
||||
|
||||
@ -283,8 +275,7 @@ bool onMacOS()
|
||||
//****************************************************************************************************************************************************
|
||||
/// \return true if and only if the application is currently running on Windows.
|
||||
//****************************************************************************************************************************************************
|
||||
bool onWindows()
|
||||
{
|
||||
bool onWindows() {
|
||||
return OS::Windows == os();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user