build: split user and data folder, moving user data to Application Support on Mac

This commit is contained in:
Eberhard Graether
2016-02-16 16:44:42 +01:00
parent 89b8d51ab8
commit 86cf1ee62d
51 changed files with 176 additions and 1809 deletions
+48 -17
View File
@@ -1,8 +1,15 @@
#include "utility/AppPath.h"
#include <memory>
#include <QApplication>
#include "utility/logging/ConsoleLogger.h"
#include "utility/logging/FileLogger.h"
#include "utility/logging/LogManager.h"
#include "utility/StandardHeaderDetection.h"
#include "utility/ResourcePaths.h"
#include "utility/UserPaths.h"
#include "utility/Version.h"
#include "Application.h"
@@ -17,10 +24,10 @@
#include "qt/window/QtSplashScreen.h"
#include "version.h"
#include "utility/solution/SolutionParserVisualStudio.h"
#include "settings/ProjectSettings.h"
void init()
{
std::shared_ptr<ConsoleLogger> consoleLogger = std::make_shared<ConsoleLogger>();
@@ -29,60 +36,84 @@ void init()
std::shared_ptr<FileLogger> fileLogger = std::make_shared<FileLogger>();
fileLogger->setLogLevel(Logger::LOG_ALL);
FileLogger::setFilePath(logPath);
FileLogger::setFilePath(UserPaths::getLogPath());
LogManager::getInstance()->addLogger(fileLogger);
utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".otf");
}
QMainWindow* getMainWindow()
{
QWidgetList widgets = qApp->topLevelWidgets();
for (QWidgetList::iterator i = widgets.begin(); i != widgets.end(); ++i)
if ((*i)->objectName() == "MainWindow")
return (QMainWindow*) (*i);
return NULL;
}
int main(int argc, char *argv[])
{
QApplication::setApplicationName("Coati");
Version version = Version::fromString(GIT_VERSION_NUMBER);
QApplication::setApplicationVersion(version.toDisplayString().c_str());
setup(argc, argv);
QtApplication qtApp(argc, argv);
QApplication::setApplicationName("Coati");
QApplication::setApplicationVersion(version.toDisplayString().c_str());
qtApp.setAttribute(Qt::AA_UseHighDpiPixmaps);
QPixmap whitePixmap(500, 500);
whitePixmap.fill(Qt::white);
QtSplashScreen* splash = new QtSplashScreen(whitePixmap, Qt::WindowStaysOnTopHint);
QtSplashScreen* splash = new QtSplashScreen();
splash->setMessage("Loading UI");
splash->setVersion(version.toDisplayString().c_str());
// QTimer* timer = new QTimer(splash);
// QObject::connect(timer, SIGNAL(timeout()), splash, SLOT(animate()));
// timer->start(150);
splash->exec(qtApp);
qtApp.processEvents();
init();
QtCommandLineParser commandLineParser;
commandLineParser.setup();
commandLineParser.process(qtApp);
qtApp.processEvents();
QtViewFactory viewFactory;
QtNetworkFactory networkFactory;
std::shared_ptr<Application> app = Application::create(version, &viewFactory, &networkFactory);
QtMainWindow::setWindowSettingsPath(windowSettingsPath);
Application::setAppSettingsPath(appSettingsPath);
if(AppPath::getAppPath().empty())
if (AppPath::getAppPath().empty())
{
AppPath::setAppPath(QCoreApplication::applicationDirPath().toStdString());
}
if(ApplicationSettings::getInstance()->getHeaderSearchPaths().empty())
{
StandardHeaderDetection headerDetection;
headerDetection.detectHeaders();
ApplicationSettings::getInstance()->setHeaderSearchPaths(headerDetection.getDefaultHeaderPaths());
}
splash->setMessage("Checking License");
LicenseChecker checker;
std::shared_ptr<Application> app = Application::create(version, &viewFactory, &networkFactory);
checker.setApp(app.get());
splash->setMessage("Parse Commandline Arguments");
commandLineParser.parseCommandline();
qtApp.processEvents();
splash->setMessage("Done");
if (splash)
{
delete splash;
}
commandLineParser.parseCommandline();
return qtApp.exec();
}
+3 -9
View File
@@ -5,6 +5,7 @@
#include "utility/messaging/type/MessageActivateNodes.h"
#include "utility/messaging/type/MessageStatus.h"
#include "utility/scheduling/TaskScheduler.h"
#include "utility/UserPaths.h"
#include "utility/Version.h"
#include "component/view/GraphViewStyle.h"
@@ -15,8 +16,6 @@
#include "settings/ApplicationSettings.h"
#include "settings/ColorScheme.h"
std::string Application::m_appSettingsPath = "data/ApplicationSettings.xml";
std::shared_ptr<Application> Application::create(
const Version& version, ViewFactory* viewFactory, NetworkFactory* networkFactory
){
@@ -53,7 +52,7 @@ std::shared_ptr<Application> Application::create(
void Application::loadSettings()
{
ApplicationSettings::getInstance()->load(FilePath(m_appSettingsPath));
ApplicationSettings::getInstance()->load(FilePath(UserPaths::getAppSettingsPath()));
ColorScheme::getInstance()->load(ApplicationSettings::getInstance()->getColorSchemePath());
GraphViewStyle::loadStyleSettings();
@@ -114,11 +113,6 @@ void Application::showLicenseScreen()
m_mainView->showLicenseScreen();
}
void Application::setAppSettingsPath(const std::string& appSettingsPath)
{
m_appSettingsPath = appSettingsPath;
}
void Application::handleMessage(MessageActivateWindow* message)
{
m_mainView->activateWindow();
@@ -187,5 +181,5 @@ void Application::updateRecentProjects(const FilePath& projectSettingsFilePath)
}
appSettings->setRecentProjects(recentProjects);
appSettings->save(m_appSettingsPath);
appSettings->save(UserPaths::getAppSettingsPath());
}
-4
View File
@@ -37,8 +37,6 @@ public:
void saveProject(const FilePath& projectSettingsFilePath);
void showLicenseScreen();
static void setAppSettingsPath(const std::string& appSettingsPath);
private:
Application();
@@ -59,8 +57,6 @@ private:
std::shared_ptr<ComponentManager> m_componentManager;
std::shared_ptr<IDECommunicationController> m_ideCommunicationController;
static std::string m_appSettingsPath;
};
#endif // APPLICATION_H
+2
View File
@@ -294,6 +294,8 @@ add_files(
utility/TimePoint.cpp
utility/TimePoint.h
utility/types.h
utility/UserPaths.cpp
utility/UserPaths.h
utility/utility.cpp
utility/utility.h
utility/utilityString.cpp
-2
View File
@@ -3,8 +3,6 @@
#include <string>
// #include "src\lib_gui\includes.h"
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
+28
View File
@@ -0,0 +1,28 @@
#include "utility/UserPaths.h"
std::string UserPaths::s_userDataPath = "user/";
std::string UserPaths::getUserDataPath()
{
return s_userDataPath;
}
void UserPaths::setUserDataPath(const std::string& path)
{
s_userDataPath = path;
}
std::string UserPaths::getAppSettingsPath()
{
return getUserDataPath() + "ApplicationSettings.xml";
}
std::string UserPaths::getWindowSettingsPath()
{
return getUserDataPath() + "window_settings.ini";
}
std::string UserPaths::getLogPath()
{
return getUserDataPath() + "log/";
}
+20
View File
@@ -0,0 +1,20 @@
#ifndef USER_PATHS_H
#define USER_PATHS_H
#include <string>
class UserPaths
{
public:
static std::string getUserDataPath();
static void setUserDataPath(const std::string& path);
static std::string getAppSettingsPath();
static std::string getWindowSettingsPath();
static std::string getLogPath();
private:
static std::string s_userDataPath;
};
#endif // USER_PATHS_H
@@ -1,12 +1,13 @@
#ifndef INCLUDES_DEFAULT_H
#define INCLUDES_DEFAULT_H
static std::string appSettingsPath = "data/ApplicationSettings.xml";
static std::string windowSettingsPath = "data/window_settings.ini";
static std::string logPath = "data/log/";
#include "utility/UserPaths.h"
void setup(int argc, char *argv[])
{
std::string userdir(std::getenv("HOME"));
userdir.append("/.config/coati/");
UserPaths::setUserDataPath(userdir);
}
#endif // INCLUDES_DEFAULT_H
+19 -3
View File
@@ -4,10 +4,10 @@
#include <CoreFoundation/CoreFoundation.h>
#include <QApplication>
#include <QDir>
#include <QStandardPaths>
static std::string appSettingsPath = "data/ApplicationSettings.xml";
static std::string windowSettingsPath = "data/window_settings.ini";
static std::string logPath = "data/log/";
#include "qt/utility/utilityQt.h"
#include "utility/UserPaths.h"
void setup(int argc, char *argv[])
{
@@ -47,6 +47,22 @@ void setup(int argc, char *argv[])
// printf("after change, libraryPaths=(%s)\n", QCoreApplication::libraryPaths().join(",").toUtf8().data());
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Makes the mac bundle copy the user files to the Application Support folder
QString dataPath = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
QDir dataDir(dataPath);
if (!dataDir.exists())
{
dataDir.mkpath(dataPath);
}
utility::copyNewFilesFromDirectory(QString::fromStdString(UserPaths::getUserDataPath()), dataPath);
UserPaths::setUserDataPath(dataPath.toStdString() + "/");
// ----------------------------------------------------------------------------
}
#endif // INCLUDES_MAC_H
@@ -5,21 +5,15 @@
#include "vld.h"
// #define DEPLOY
#include "utility/UserPaths.h"
#ifdef DEPLOY
static std::string appSettingsPath = std::string(std::getenv("APPDATA")) + "/../local/Coati Software/Coati/ApplicationSettings.xml";
static std::string windowSettingsPath = std::string(std::getenv("APPDATA")) + "/../local/Coati Software/Coati/window_settings.ini";
static std::string logPath = std::string(std::getenv("APPDATA")) + "/../local/Coati Software/Coati/log/";
#else
static std::string appSettingsPath = "data/ApplicationSettings.xml";
static std::string windowSettingsPath = "data/window_settings.ini";
static std::string logPath = "data/log/";
#endif
// #define DEPLOY
void setup(int argc, char *argv[])
{
#ifdef DEPLOY
UserPaths::setUserDataPath(std::getenv("APPDATA")) + "/../local/Coati Software/Coati/");
#endif
}
#endif // INCLUDES_WINDOWS_H
+26
View File
@@ -2,6 +2,7 @@
#include <set>
#include <QDir>
#include <QFile>
#include <QFontDatabase>
#include <QPainter>
@@ -150,4 +151,29 @@ namespace utility
painter.drawImage(0, 0, colorImage);
return QPixmap::fromImage(image);
}
void copyNewFilesFromDirectory(QString src, QString dst)
{
QDir dir(src);
if (!dir.exists())
{
return;
}
foreach (QString d, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot))
{
QString dst_path = dst + QDir::separator() + d;
dir.mkpath(dst_path);
copyNewFilesFromDirectory(src + QDir::separator() + d, dst_path);
}
foreach (QString f, dir.entryList(QDir::Files))
{
if (!QFile::exists(dst + QDir::separator() + f))
{
QFile::copy(src + QDir::separator() + f, dst + QDir::separator() + f);
}
}
}
}
+2
View File
@@ -12,6 +12,8 @@ namespace utility
std::string getStyleSheet(const std::string& path);
QPixmap colorizePixmap(const QPixmap& pixmap, QColor color);
void copyNewFilesFromDirectory(QString src, QString dst);
}
# endif // UTILITY_QT_H
+3 -9
View File
@@ -34,11 +34,10 @@
#include "utility/messaging/type/MessageWindowFocus.h"
#include "utility/messaging/type/MessageZoom.h"
#include "utility/ResourcePaths.h"
#include "utility/UserPaths.h"
#include "version.h"
#include "isTrial.h"
std::string QtMainWindow::m_windowSettingsPath = "data/window_settings.ini";
QtViewToggle::QtViewToggle(View* view, QWidget *parent)
: QWidget(parent)
, m_view(view)
@@ -214,7 +213,7 @@ void QtMainWindow::hideView(View* view)
void QtMainWindow::loadLayout()
{
QSettings settings(m_windowSettingsPath.c_str(), QSettings::IniFormat);
QSettings settings(UserPaths::getWindowSettingsPath().c_str(), QSettings::IniFormat);
settings.beginGroup("MainWindow");
resize(settings.value("size", QSize(600, 400)).toSize());
@@ -236,7 +235,7 @@ void QtMainWindow::loadLayout()
void QtMainWindow::saveLayout()
{
QSettings settings(m_windowSettingsPath.c_str(), QSettings::IniFormat);
QSettings settings(UserPaths::getWindowSettingsPath().c_str(), QSettings::IniFormat);
settings.beginGroup("MainWindow");
settings.setValue("maximized", isMaximized());
@@ -557,11 +556,6 @@ void QtMainWindow::updateRecentProjectMenu()
}
}
void QtMainWindow::setWindowSettingsPath(const std::string& windowSettingsPath)
{
m_windowSettingsPath = windowSettingsPath;
}
void QtMainWindow::toggleShowDockWidgetTitleBars()
{
setShowDockWidgetTitleBars(!m_showDockWidgetTitleBars);
-4
View File
@@ -130,8 +130,6 @@ public slots:
void updateRecentProjectMenu();
static void setWindowSettingsPath(const std::string& windowSettingsPath);
private slots:
void toggleShowDockWidgetTitleBars();
@@ -172,8 +170,6 @@ private:
QShortcut* m_escapeShortcut;
static std::string m_windowSettingsPath;
QtThreadedFunctor<std::string, std::string, std::vector<std::string>, std::vector<std::string>> m_createNewProjectFunctor;
};
+6 -3
View File
@@ -3,6 +3,7 @@
#include "utility/logging/FileLogger.h"
#include "utility/logging/LogManager.h"
#include "utility/ResourcePaths.h"
#include "utility/UserPaths.h"
#include "utility/Version.h"
#include "Application.h"
@@ -24,7 +25,7 @@ void init()
std::shared_ptr<FileLogger> fileLogger = std::make_shared<FileLogger>();
fileLogger->setLogLevel(Logger::LOG_ALL);
FileLogger::setFilePath(logPath);
FileLogger::setFilePath(UserPaths::getLogPath());
LogManager::getInstance()->addLogger(fileLogger);
utility::loadFontsFromDirectory(ResourcePaths::getFontsPath(), ".otf");
@@ -32,9 +33,13 @@ void init()
int main(int argc, char *argv[])
{
QApplication::setApplicationName("Coati");
Version version = Version::fromString(GIT_VERSION_NUMBER);
QApplication::setApplicationVersion(version.toDisplayString().c_str());
setup(argc, argv);
QtApplication qtApp(argc, argv);
qtApp.setAttribute(Qt::AA_UseHighDpiPixmaps);
@@ -52,8 +57,6 @@ int main(int argc, char *argv[])
QtViewFactory viewFactory;
QtNetworkFactory networkFactory;
QtMainWindow::setWindowSettingsPath(windowSettingsPath);
Application::setAppSettingsPath(appSettingsPath);
std::shared_ptr<Application> app = Application::create(version, &viewFactory, &networkFactory);
if (splash)