mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-05-25 01:31:24 -04:00
Formatting the code.
This commit is contained in:
parent
74efc57369
commit
8324d03f0a
294 changed files with 3796 additions and 3740 deletions
|
@ -18,43 +18,45 @@
|
|||
|
||||
#include "HostInstaller.h"
|
||||
#include "config-keepassx.h"
|
||||
#include <QCoreApplication>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QStandardPaths>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QCoreApplication>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QMessageBox>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QStandardPaths>
|
||||
|
||||
const QString HostInstaller::HOST_NAME = "org.keepassxc.keepassxc_browser";
|
||||
const QStringList HostInstaller::ALLOWED_ORIGINS = QStringList()
|
||||
<< "chrome-extension://iopaggbpplllidnfmcghoonnokmjoicf/"
|
||||
<< "chrome-extension://oboonakemofpalcgghocfoadofidjkkk/";
|
||||
<< "chrome-extension://iopaggbpplllidnfmcghoonnokmjoicf/"
|
||||
<< "chrome-extension://oboonakemofpalcgghocfoadofidjkkk/";
|
||||
|
||||
const QStringList HostInstaller::ALLOWED_EXTENSIONS = QStringList()
|
||||
<< "keepassxc-browser@keepassxc.org";
|
||||
const QStringList HostInstaller::ALLOWED_EXTENSIONS = QStringList() << "keepassxc-browser@keepassxc.org";
|
||||
|
||||
#if defined(Q_OS_OSX)
|
||||
const QString HostInstaller::TARGET_DIR_CHROME = "/Library/Application Support/Google/Chrome/NativeMessagingHosts";
|
||||
const QString HostInstaller::TARGET_DIR_CHROMIUM = "/Library/Application Support/Chromium/NativeMessagingHosts";
|
||||
const QString HostInstaller::TARGET_DIR_FIREFOX = "/Library/Application Support/Mozilla/NativeMessagingHosts";
|
||||
const QString HostInstaller::TARGET_DIR_VIVALDI = "/Library/Application Support/Vivaldi/NativeMessagingHosts";
|
||||
const QString HostInstaller::TARGET_DIR_CHROME = "/Library/Application Support/Google/Chrome/NativeMessagingHosts";
|
||||
const QString HostInstaller::TARGET_DIR_CHROMIUM = "/Library/Application Support/Chromium/NativeMessagingHosts";
|
||||
const QString HostInstaller::TARGET_DIR_FIREFOX = "/Library/Application Support/Mozilla/NativeMessagingHosts";
|
||||
const QString HostInstaller::TARGET_DIR_VIVALDI = "/Library/Application Support/Vivaldi/NativeMessagingHosts";
|
||||
#elif defined(Q_OS_LINUX)
|
||||
const QString HostInstaller::TARGET_DIR_CHROME = "/.config/google-chrome/NativeMessagingHosts";
|
||||
const QString HostInstaller::TARGET_DIR_CHROMIUM = "/.config/chromium/NativeMessagingHosts";
|
||||
const QString HostInstaller::TARGET_DIR_FIREFOX = "/.mozilla/native-messaging-hosts";
|
||||
const QString HostInstaller::TARGET_DIR_VIVALDI = "/.config/vivaldi/NativeMessagingHosts";
|
||||
const QString HostInstaller::TARGET_DIR_CHROME = "/.config/google-chrome/NativeMessagingHosts";
|
||||
const QString HostInstaller::TARGET_DIR_CHROMIUM = "/.config/chromium/NativeMessagingHosts";
|
||||
const QString HostInstaller::TARGET_DIR_FIREFOX = "/.mozilla/native-messaging-hosts";
|
||||
const QString HostInstaller::TARGET_DIR_VIVALDI = "/.config/vivaldi/NativeMessagingHosts";
|
||||
#elif defined(Q_OS_WIN)
|
||||
const QString HostInstaller::TARGET_DIR_CHROME = "HKEY_CURRENT_USER\\Software\\Google\\Chrome\\NativeMessagingHosts\\" + HostInstaller::HOST_NAME;
|
||||
const QString HostInstaller::TARGET_DIR_CHROMIUM = "HKEY_CURRENT_USER\\Software\\Chromium\\NativeMessagingHosts\\" + HostInstaller::HOST_NAME;
|
||||
const QString HostInstaller::TARGET_DIR_FIREFOX = "HKEY_CURRENT_USER\\Software\\Mozilla\\NativeMessagingHosts\\" + HostInstaller::HOST_NAME;
|
||||
const QString HostInstaller::TARGET_DIR_VIVALDI = "HKEY_CURRENT_USER\\Software\\Vivaldi\\NativeMessagingHosts\\" + HostInstaller::HOST_NAME;
|
||||
const QString HostInstaller::TARGET_DIR_CHROME =
|
||||
"HKEY_CURRENT_USER\\Software\\Google\\Chrome\\NativeMessagingHosts\\" + HostInstaller::HOST_NAME;
|
||||
const QString HostInstaller::TARGET_DIR_CHROMIUM =
|
||||
"HKEY_CURRENT_USER\\Software\\Chromium\\NativeMessagingHosts\\" + HostInstaller::HOST_NAME;
|
||||
const QString HostInstaller::TARGET_DIR_FIREFOX =
|
||||
"HKEY_CURRENT_USER\\Software\\Mozilla\\NativeMessagingHosts\\" + HostInstaller::HOST_NAME;
|
||||
const QString HostInstaller::TARGET_DIR_VIVALDI =
|
||||
"HKEY_CURRENT_USER\\Software\\Vivaldi\\NativeMessagingHosts\\" + HostInstaller::HOST_NAME;
|
||||
#endif
|
||||
|
||||
HostInstaller::HostInstaller()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool HostInstaller::checkIfInstalled(SupportedBrowsers browser)
|
||||
|
@ -68,34 +70,39 @@ bool HostInstaller::checkIfInstalled(SupportedBrowsers browser)
|
|||
#endif
|
||||
}
|
||||
|
||||
void HostInstaller::installBrowser(SupportedBrowsers browser, const bool& enabled, const bool& proxy, const QString& location)
|
||||
void HostInstaller::installBrowser(SupportedBrowsers browser,
|
||||
const bool& enabled,
|
||||
const bool& proxy,
|
||||
const QString& location)
|
||||
{
|
||||
if (enabled) {
|
||||
#ifdef Q_OS_WIN
|
||||
// Create a registry key
|
||||
QSettings settings(getTargetPath(browser), QSettings::NativeFormat);
|
||||
if (!registryEntryFound(settings)) {
|
||||
settings.setValue("Default", getPath(browser));
|
||||
}
|
||||
#endif
|
||||
// Always create the script file
|
||||
QJsonObject script = constructFile(browser, proxy, location);
|
||||
if (!saveFile(browser, script)) {
|
||||
QMessageBox::critical(0, tr("KeePassXC: Cannot save file!"),
|
||||
tr("Cannot save the native messaging script file."), QMessageBox::Ok);
|
||||
}
|
||||
} else {
|
||||
// Remove the script file
|
||||
QString fileName = getPath(browser);
|
||||
QFile::remove(fileName);
|
||||
#ifdef Q_OS_WIN
|
||||
// Remove the registry entry
|
||||
QSettings settings(getTargetPath(browser), QSettings::NativeFormat);
|
||||
if (registryEntryFound(settings)) {
|
||||
settings.remove("Default");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef Q_OS_WIN
|
||||
// Create a registry key
|
||||
QSettings settings(getTargetPath(browser), QSettings::NativeFormat);
|
||||
if (!registryEntryFound(settings)) {
|
||||
settings.setValue("Default", getPath(browser));
|
||||
}
|
||||
#endif
|
||||
// Always create the script file
|
||||
QJsonObject script = constructFile(browser, proxy, location);
|
||||
if (!saveFile(browser, script)) {
|
||||
QMessageBox::critical(0,
|
||||
tr("KeePassXC: Cannot save file!"),
|
||||
tr("Cannot save the native messaging script file."),
|
||||
QMessageBox::Ok);
|
||||
}
|
||||
} else {
|
||||
// Remove the script file
|
||||
QString fileName = getPath(browser);
|
||||
QFile::remove(fileName);
|
||||
#ifdef Q_OS_WIN
|
||||
// Remove the registry entry
|
||||
QSettings settings(getTargetPath(browser), QSettings::NativeFormat);
|
||||
if (registryEntryFound(settings)) {
|
||||
settings.remove("Default");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void HostInstaller::updateBinaryPaths(const bool& proxy, const QString& location)
|
||||
|
@ -110,22 +117,32 @@ void HostInstaller::updateBinaryPaths(const bool& proxy, const QString& location
|
|||
QString HostInstaller::getTargetPath(SupportedBrowsers browser) const
|
||||
{
|
||||
switch (browser) {
|
||||
case SupportedBrowsers::CHROME: return HostInstaller::TARGET_DIR_CHROME;
|
||||
case SupportedBrowsers::CHROMIUM: return HostInstaller::TARGET_DIR_CHROMIUM;
|
||||
case SupportedBrowsers::FIREFOX: return HostInstaller::TARGET_DIR_FIREFOX;
|
||||
case SupportedBrowsers::VIVALDI: return HostInstaller::TARGET_DIR_VIVALDI;
|
||||
default: return QString();
|
||||
case SupportedBrowsers::CHROME:
|
||||
return HostInstaller::TARGET_DIR_CHROME;
|
||||
case SupportedBrowsers::CHROMIUM:
|
||||
return HostInstaller::TARGET_DIR_CHROMIUM;
|
||||
case SupportedBrowsers::FIREFOX:
|
||||
return HostInstaller::TARGET_DIR_FIREFOX;
|
||||
case SupportedBrowsers::VIVALDI:
|
||||
return HostInstaller::TARGET_DIR_VIVALDI;
|
||||
default:
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
|
||||
QString HostInstaller::getBrowserName(SupportedBrowsers browser) const
|
||||
{
|
||||
switch (browser) {
|
||||
case SupportedBrowsers::CHROME: return "chrome";
|
||||
case SupportedBrowsers::CHROMIUM: return "chromium";
|
||||
case SupportedBrowsers::FIREFOX: return "firefox";
|
||||
case SupportedBrowsers::VIVALDI: return "vivaldi";
|
||||
default: return QString();
|
||||
case SupportedBrowsers::CHROME:
|
||||
return "chrome";
|
||||
case SupportedBrowsers::CHROMIUM:
|
||||
return "chromium";
|
||||
case SupportedBrowsers::FIREFOX:
|
||||
return "firefox";
|
||||
case SupportedBrowsers::VIVALDI:
|
||||
return "vivaldi";
|
||||
default:
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,7 +159,7 @@ QString HostInstaller::getPath(SupportedBrowsers browser) const
|
|||
}
|
||||
|
||||
QString winPath = QString("%1/%2_%3.json").arg(userPath, HostInstaller::HOST_NAME, getBrowserName(browser));
|
||||
winPath.replace("/","\\");
|
||||
winPath.replace("/", "\\");
|
||||
return winPath;
|
||||
#else
|
||||
QString path = getTargetPath(browser);
|
||||
|
@ -184,16 +201,16 @@ QJsonObject HostInstaller::constructFile(SupportedBrowsers browser, const bool&
|
|||
path = QFileInfo(QCoreApplication::applicationFilePath()).absoluteFilePath();
|
||||
}
|
||||
#ifdef Q_OS_WIN
|
||||
path.replace("/","\\");
|
||||
path.replace("/", "\\");
|
||||
#endif
|
||||
|
||||
#endif // #ifdef KEEPASSXC_DIST_APPIMAGE
|
||||
#endif // #ifdef KEEPASSXC_DIST_APPIMAGE
|
||||
|
||||
QJsonObject script;
|
||||
script["name"] = HostInstaller::HOST_NAME;
|
||||
script["description"] = "KeePassXC integration with native messaging support";
|
||||
script["path"] = path;
|
||||
script["type"] = "stdio";
|
||||
script["name"] = HostInstaller::HOST_NAME;
|
||||
script["description"] = "KeePassXC integration with native messaging support";
|
||||
script["path"] = path;
|
||||
script["type"] = "stdio";
|
||||
|
||||
QJsonArray arr;
|
||||
if (browser == SupportedBrowsers::FIREFOX) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue