Commit cbc8c720 authored by Ronan Abhamon's avatar Ronan Abhamon

fix(src/app/Paths): fix style with uncrustify

parent 3aec3dc4
...@@ -29,22 +29,19 @@ ...@@ -29,22 +29,19 @@
#include "Paths.hpp" #include "Paths.hpp"
// =============================================================================
using namespace std;
#define PATH_AVATARS "/avatars/" #define PATH_AVATARS "/avatars/"
#define PATH_CAPTURES "/captures/" #define PATH_CAPTURES "/captures/"
#define PATH_LOGS "/logs/" #define PATH_LOGS "/logs/"
#define PATH_THUMBNAILS "/thumbnails/" #define PATH_THUMBNAILS "/thumbnails/"
#define PATH_USER_CERTIFICATES "/usr-crt/"
#define PATH_CONFIG "/linphonerc"
#define PATH_CALL_HISTORY_LIST "/call-history.db" #define PATH_CALL_HISTORY_LIST "/call-history.db"
#define PATH_CONFIG "/linphonerc"
#define PATH_FRIENDS_LIST "/friends.db" #define PATH_FRIENDS_LIST "/friends.db"
#define PATH_MESSAGE_HISTORY_LIST "/message-history.db" #define PATH_MESSAGE_HISTORY_LIST "/message-history.db"
#define PATH_ZRTP_SECRETS "/zidcache" #define PATH_ZRTP_SECRETS "/zidcache"
#define PATH_USER_CERTIFICATES "/usr-crt/"
using namespace std;
// ============================================================================= // =============================================================================
...@@ -55,14 +52,15 @@ inline bool directoryPathExists (const QString &path) { ...@@ -55,14 +52,15 @@ inline bool directoryPathExists (const QString &path) {
inline bool filePathExists (const QString &path) { inline bool filePathExists (const QString &path) {
QFileInfo info(path); QFileInfo info(path);
if (!directoryPathExists(info.path())) return false; if (!directoryPathExists(info.path()))
return false;
QFile file(path); QFile file(path);
return file.exists(); return file.exists();
} }
inline bool filePathExists (const string &path) { inline bool filePathExists (const string &path) {
return filePathExists(Utils::linphoneStringToQString(path)); return filePathExists(Utils::linphoneStringToQString(path));
} }
inline void ensureDirectoryPathExists (const QString &path) { inline void ensureDirectoryPathExists (const QString &path) {
...@@ -91,11 +89,10 @@ inline string getFilePath (const QString &filename) { ...@@ -91,11 +89,10 @@ inline string getFilePath (const QString &filename) {
} }
static QString getAppConfigFilepath () { static QString getAppConfigFilepath () {
if (QSysInfo::productType() == "macos") { if (QSysInfo::productType() == "macos")
return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_CONFIG; return QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + PATH_CONFIG;
} else {
return QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + PATH_CONFIG; return QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + PATH_CONFIG;
}
} }
static QString getAppCallHistoryFilepath () { static QString getAppCallHistoryFilepath () {
...@@ -120,10 +117,10 @@ string Paths::getCallHistoryFilepath () { ...@@ -120,10 +117,10 @@ string Paths::getCallHistoryFilepath () {
return getFilePath(getAppCallHistoryFilepath()); return getFilePath(getAppCallHistoryFilepath());
} }
string Paths::getConfigFilepath (const QString &configPath) { string Paths::getConfigFilepath (const QString &config_path) {
if (!configPath.isEmpty()) { if (!config_path.isEmpty())
return getFilePath(QFileInfo(configPath).absoluteFilePath()); return getFilePath(QFileInfo(config_path).absoluteFilePath());
}
return getFilePath(getAppConfigFilepath()); return getFilePath(getAppConfigFilepath());
} }
...@@ -157,53 +154,61 @@ string Paths::getUserCertificatesDirpath () { ...@@ -157,53 +154,61 @@ string Paths::getUserCertificatesDirpath () {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
static void migrateFile (const QString &oldPath, const QString &newPath) { static void migrateFile (const QString &old_path, const QString &new_path) {
QFileInfo info(newPath); QFileInfo info(new_path);
ensureDirectoryPathExists(info.path()); ensureDirectoryPathExists(info.path());
if (QFile::copy(oldPath, newPath)) {
QFile::remove(oldPath); if (QFile::copy(old_path, new_path)) {
qInfo() << "Migrated" << oldPath << "to" << newPath; QFile::remove(old_path);
qInfo() << "Migrated" << old_path << "to" << new_path;
} else { } else {
qWarning() << "Failed migration of" << oldPath << "to" << newPath; qWarning() << "Failed migration of" << old_path << "to" << new_path;
} }
} }
static void migrateConfigurationFile (const QString &oldPath, const QString &newPath) { static void migrateConfigurationFile (const QString &old_path, const QString &new_path) {
QFileInfo info(newPath); QFileInfo info(new_path);
ensureDirectoryPathExists(info.path()); ensureDirectoryPathExists(info.path());
if (QFile::copy(oldPath, newPath)) {
QFile oldFile(oldPath); if (QFile::copy(old_path, new_path)) {
if (oldFile.open(QIODevice::WriteOnly)) { QFile old_file(old_path);
QTextStream stream(&oldFile); if (old_file.open(QIODevice::WriteOnly)) {
stream << "This file has been migrated to " << newPath; QTextStream stream(&old_file);
stream << "This file has been migrated to " << new_path;
} }
QFile::setPermissions(oldPath, QFileDevice::ReadOwner);
qInfo() << "Migrated" << oldPath << "to" << newPath; QFile::setPermissions(old_path, QFileDevice::ReadOwner);
qInfo() << "Migrated" << old_path << "to" << new_path;
} else { } else {
qWarning() << "Failed migration of" << oldPath << "to" << newPath; qWarning() << "Failed migration of" << old_path << "to" << new_path;
} }
} }
void Paths::migrate () { void Paths::migrate () {
QString newPath; QString new_path = getAppConfigFilepath();
QString oldPath; QString old_base_dir = QSysInfo::productType() == "windows"
QString oldBaseDir; ? QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)
: QStandardPaths::writableLocation(QStandardPaths::HomeLocation);
QString old_path = old_base_dir + "/.linphonerc";
if (QSysInfo::productType() == "windows") { if (!filePathExists(new_path) && filePathExists(old_path))
oldBaseDir = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation); migrateConfigurationFile(old_path, new_path);
} else {
oldBaseDir = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); new_path = getAppCallHistoryFilepath();
} old_path = old_base_dir + "/.linphone-call-history.db";
newPath = getAppConfigFilepath();
oldPath = oldBaseDir + "/.linphonerc"; if (!filePathExists(new_path) && filePathExists(old_path))
if (!filePathExists(newPath) && filePathExists(oldPath)) migrateConfigurationFile(oldPath, newPath); migrateFile(old_path, new_path);
newPath = getAppCallHistoryFilepath();
oldPath = oldBaseDir + "/.linphone-call-history.db"; new_path = getAppFriendsFilepath();
if (!filePathExists(newPath) && filePathExists(oldPath)) migrateFile(oldPath, newPath); old_path = old_base_dir + "/.linphone-friends.db";
newPath = getAppFriendsFilepath();
oldPath = oldBaseDir + "/.linphone-friends.db"; if (!filePathExists(new_path) && filePathExists(old_path))
if (!filePathExists(newPath) && filePathExists(oldPath)) migrateFile(oldPath, newPath); migrateFile(old_path, new_path);
newPath = getAppMessageHistoryFilepath();
oldPath = oldBaseDir + "/.linphone-history.db"; new_path = getAppMessageHistoryFilepath();
if (!filePathExists(newPath) && filePathExists(oldPath)) migrateFile(oldPath, newPath); old_path = old_base_dir + "/.linphone-history.db";
if (!filePathExists(new_path) && filePathExists(old_path))
migrateFile(old_path, new_path);
} }
...@@ -24,22 +24,24 @@ ...@@ -24,22 +24,24 @@
#define PATHS_H_ #define PATHS_H_
#include <string> #include <string>
#include <QString> #include <QString>
// ============================================================================= // =============================================================================
namespace Paths { namespace Paths {
std::string getAvatarsDirpath (); std::string getAvatarsDirpath ();
std::string getCallHistoryFilepath ();
std::string getConfigFilepath (const QString &configPath = QString());
std::string getFriendsListFilepath ();
std::string getCapturesDirpath (); std::string getCapturesDirpath ();
std::string getLogsDirpath (); std::string getLogsDirpath ();
std::string getMessageHistoryFilepath ();
std::string getThumbnailsDirpath (); std::string getThumbnailsDirpath ();
std::string getZrtpSecretsFilepath ();
std::string getUserCertificatesDirpath (); std::string getUserCertificatesDirpath ();
std::string getCallHistoryFilepath ();
std::string getConfigFilepath (const QString &config_path = QString());
std::string getFriendsListFilepath ();
std::string getMessageHistoryFilepath ();
std::string getZrtpSecretsFilepath ();
void migrate (); void migrate ();
} }
......
...@@ -37,7 +37,7 @@ CoreManager *CoreManager::m_instance = nullptr; ...@@ -37,7 +37,7 @@ CoreManager *CoreManager::m_instance = nullptr;
CoreManager::CoreManager (QObject *parent, const QString &config_path) : QObject(parent), m_handlers(make_shared<CoreHandlers>()) { CoreManager::CoreManager (QObject *parent, const QString &config_path) : QObject(parent), m_handlers(make_shared<CoreHandlers>()) {
// TODO: activate migration when ready to switch to this new version // TODO: activate migration when ready to switch to this new version
//Paths::migrate(); // Paths::migrate();
setResourcesPaths(); setResourcesPaths();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment