mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-17 15:46:44 +00:00
Other: moved user folder paths functions to bridgepp.
This commit is contained in:
@ -34,7 +34,6 @@ else()
|
|||||||
message(STATUS "Bridge version is ${BRIDGE_APP_VERSION}")
|
message(STATUS "Bridge version is ${BRIDGE_APP_VERSION}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
configure_file(Version.h.in ${CMAKE_SOURCE_DIR}/Version.h)
|
|
||||||
if (APPLE) # On macOS, we have some Objective-C++ code in DockIcon to deal with the dock icon.
|
if (APPLE) # On macOS, we have some Objective-C++ code in DockIcon to deal with the dock icon.
|
||||||
enable_language(OBJC OBJCXX)
|
enable_language(OBJC OBJCXX)
|
||||||
endif()
|
endif()
|
||||||
@ -68,7 +67,7 @@ message(STATUS "Using Qt ${Qt6_VERSION}")
|
|||||||
#*****************************************************************************************************************************************************
|
#*****************************************************************************************************************************************************
|
||||||
|
|
||||||
|
|
||||||
configure_file(Version.h.in ${CMAKE_CURRENT_SOURCE_DIR}/Version.h)
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Version.h.in ${CMAKE_CURRENT_SOURCE_DIR}/Version.h)
|
||||||
|
|
||||||
if (NOT TARGET bridgepp)
|
if (NOT TARGET bridgepp)
|
||||||
add_subdirectory(../bridgepp bridgepp)
|
add_subdirectory(../bridgepp bridgepp)
|
||||||
@ -91,7 +90,7 @@ add_executable(bridge-gui
|
|||||||
QMLBackend.cpp QMLBackend.h
|
QMLBackend.cpp QMLBackend.h
|
||||||
UserList.cpp UserList.h
|
UserList.cpp UserList.h
|
||||||
${DOCK_ICON_SRC_FILE} DockIcon/DockIcon.h
|
${DOCK_ICON_SRC_FILE} DockIcon/DockIcon.h
|
||||||
UserDirectories.h)
|
)
|
||||||
|
|
||||||
target_precompile_headers(bridge-gui PRIVATE Pch.h)
|
target_precompile_headers(bridge-gui PRIVATE Pch.h)
|
||||||
target_include_directories(bridge-gui PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
target_include_directories(bridge-gui PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|||||||
@ -1,79 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by romain on 01/08/22.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef PROTON_BRIDGE_GUI_USERDIRECTORIES_H
|
|
||||||
#define PROTON_BRIDGE_GUI_USERDIRECTORIES_H
|
|
||||||
|
|
||||||
#include <bridgepp/Exception/Exception.h>
|
|
||||||
|
|
||||||
using namespace bridgepp;
|
|
||||||
|
|
||||||
namespace UserDirectories {
|
|
||||||
|
|
||||||
QString const configFolder = "protonmail/bridge";
|
|
||||||
|
|
||||||
//****************************************************************************************************************************************************
|
|
||||||
/// \return user configuration directory used by bridge (based on Golang OS/File's UserConfigDir).
|
|
||||||
//****************************************************************************************************************************************************
|
|
||||||
static const 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())
|
|
||||||
throw Exception("$HOME is not defined.");
|
|
||||||
dir += "/Library/Application Support";
|
|
||||||
#else
|
|
||||||
dir = qgetenv ("XDG_CONFIG_HOME");
|
|
||||||
if (dir.isEmpty())
|
|
||||||
dir = qgetenv ("HOME");
|
|
||||||
if (dir.isEmpty())
|
|
||||||
throw Exception("neither $XDG_CONFIG_HOME nor $HOME are defined");
|
|
||||||
dir += "/.config";
|
|
||||||
#endif
|
|
||||||
QString folder = dir + "/" + configFolder;
|
|
||||||
QDir().mkpath(folder);
|
|
||||||
|
|
||||||
return folder;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************************************************************************************
|
|
||||||
/// \return user configuration directory used by bridge (based on Golang OS/File's UserCacheDir).
|
|
||||||
//****************************************************************************************************************************************************
|
|
||||||
static const QString UserCacheDir()
|
|
||||||
{
|
|
||||||
QString dir;
|
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
dir = qgetenv ("LocalAppData");
|
|
||||||
if (dir.isEmpty())
|
|
||||||
throw Exception("%LocalAppData% is not defined.");
|
|
||||||
#elif defined(Q_OS_IOS) || defined(Q_OS_DARWIN)
|
|
||||||
dir = qgetenv ("HOME");
|
|
||||||
if (dir.isEmpty())
|
|
||||||
throw Exception("$HOME is not defined.");
|
|
||||||
dir += "/Library/Caches";
|
|
||||||
#else
|
|
||||||
dir = qgetenv ("XDG_CACHE_HOME");
|
|
||||||
if (dir.isEmpty())
|
|
||||||
dir = qgetenv ("HOME");
|
|
||||||
if (dir.isEmpty())
|
|
||||||
throw Exception("neither XDG_CACHE_HOME nor $HOME are defined");
|
|
||||||
dir += "/.cache";
|
|
||||||
#endif
|
|
||||||
QString folder = dir + "/" + configFolder;
|
|
||||||
QDir().mkpath(folder);
|
|
||||||
|
|
||||||
return folder;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif //PROTON_BRIDGE_GUI_USERDIRECTORIES_H
|
|
||||||
@ -19,8 +19,8 @@
|
|||||||
#include "QMLBackend.h"
|
#include "QMLBackend.h"
|
||||||
#include "BridgeMonitor.h"
|
#include "BridgeMonitor.h"
|
||||||
#include "Version.h"
|
#include "Version.h"
|
||||||
#include "UserDirectories.h"
|
|
||||||
#include <bridgepp/Log/Log.h>
|
#include <bridgepp/Log/Log.h>
|
||||||
|
#include <bridgepp/BridgeUtils.h>
|
||||||
#include <bridgepp/Exception/Exception.h>
|
#include <bridgepp/Exception/Exception.h>
|
||||||
|
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ void parseArguments(int argc, char *argv[], QStringList& args, QString& launcher
|
|||||||
// list from the original argc and argv values.
|
// list from the original argc and argv values.
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
QString const &arg = QString::fromLocal8Bit(argv[i]);
|
QString const &arg = QString::fromLocal8Bit(argv[i]);
|
||||||
// we can't use QCommandLineParser here since it will fails on unknown options.
|
// we can't use QCommandLineParser here since it will fail on unknown options.
|
||||||
// Arguments may contain some bridge flags.
|
// Arguments may contain some bridge flags.
|
||||||
if (arg == launcherFlag)
|
if (arg == launcherFlag)
|
||||||
{
|
{
|
||||||
@ -214,7 +214,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
Log &log = initLog();
|
Log &log = initLog();
|
||||||
|
|
||||||
QLockFile lock(UserDirectories::UserCacheDir() + "/" + bridgeLock);
|
QLockFile lock(bridgepp::userCacheDir() + "/" + bridgeLock);
|
||||||
if (!checkSingleInstance(lock))
|
if (!checkSingleInstance(lock))
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
|
|||||||
@ -23,6 +23,14 @@
|
|||||||
namespace bridgepp
|
namespace bridgepp
|
||||||
{
|
{
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
QString const configFolder = "protonmail/bridge";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//****************************************************************************************************************************************************
|
//****************************************************************************************************************************************************
|
||||||
/// \return user configuration directory used by bridge (based on Golang OS/File's UserConfigDir).
|
/// \return user configuration directory used by bridge (based on Golang OS/File's UserConfigDir).
|
||||||
//****************************************************************************************************************************************************
|
//****************************************************************************************************************************************************
|
||||||
@ -34,19 +42,51 @@ QString userConfigDir()
|
|||||||
if (dir.isEmpty())
|
if (dir.isEmpty())
|
||||||
throw Exception("%AppData% is not defined.");
|
throw Exception("%AppData% is not defined.");
|
||||||
#elif defined(Q_OS_IOS) || defined(Q_OS_DARWIN)
|
#elif defined(Q_OS_IOS) || defined(Q_OS_DARWIN)
|
||||||
dir = qgetenv("HOME");
|
dir = qgetenv ("HOME");
|
||||||
if (dir.isEmpty())
|
if (dir.isEmpty())
|
||||||
throw Exception("$HOME is not defined.");
|
throw Exception("$HOME is not defined.");
|
||||||
dir += "/Library/Application Support";
|
dir += "/Library/Application Support";
|
||||||
#else
|
#else
|
||||||
dir = qgetenv ("XDG_CONFIG_HOME");
|
dir = qgetenv ("XDG_CONFIG_HOME");
|
||||||
if (dir.isEmpty())
|
if (dir.isEmpty())
|
||||||
dir = qgetenv ("HOME");
|
dir = qgetenv ("HOME");
|
||||||
if (dir.isEmpty())
|
if (dir.isEmpty())
|
||||||
throw Exception("neither $XDG_CONFIG_HOME nor $HOME are defined");
|
throw Exception("neither $XDG_CONFIG_HOME nor $HOME are defined");
|
||||||
dir += "/.config";
|
dir += "/.config";
|
||||||
#endif
|
#endif
|
||||||
QString folder = dir + "/protonmail/bridge";
|
QString const folder = QDir(dir).absoluteFilePath(configFolder);
|
||||||
|
QDir().mkpath(folder);
|
||||||
|
|
||||||
|
return folder;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
/// \return user configuration directory used by bridge (based on Golang OS/File's UserCacheDir).
|
||||||
|
//****************************************************************************************************************************************************
|
||||||
|
QString userCacheDir()
|
||||||
|
{
|
||||||
|
QString dir;
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
dir = qgetenv ("LocalAppData");
|
||||||
|
if (dir.isEmpty())
|
||||||
|
throw Exception("%LocalAppData% is not defined.");
|
||||||
|
#elif defined(Q_OS_IOS) || defined(Q_OS_DARWIN)
|
||||||
|
dir = qgetenv ("HOME");
|
||||||
|
if (dir.isEmpty())
|
||||||
|
throw Exception("$HOME is not defined.");
|
||||||
|
dir += "/Library/Caches";
|
||||||
|
#else
|
||||||
|
dir = qgetenv ("XDG_CACHE_HOME");
|
||||||
|
if (dir.isEmpty())
|
||||||
|
dir = qgetenv ("HOME");
|
||||||
|
if (dir.isEmpty())
|
||||||
|
throw Exception("neither XDG_CACHE_HOME nor $HOME are defined");
|
||||||
|
dir += "/.cache";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QString const folder = QDir(dir).absoluteFilePath(configFolder);
|
||||||
QDir().mkpath(folder);
|
QDir().mkpath(folder);
|
||||||
|
|
||||||
return folder;
|
return folder;
|
||||||
|
|||||||
@ -24,6 +24,7 @@ namespace bridgepp {
|
|||||||
|
|
||||||
|
|
||||||
QString userConfigDir(); ///< Get the path of the user configuration folder.
|
QString userConfigDir(); ///< Get the path of the user configuration folder.
|
||||||
|
QString userCacheDir(); ///< Get the path of the user cache folder.
|
||||||
|
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user