mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
Add a PathManager that takes care of all paths and creating folders
Move all path/folder-related code from SettingManager to PathManager
This commit is contained in:
parent
c3770707aa
commit
346950d7b7
|
@ -114,7 +114,8 @@ SOURCES += \
|
||||||
src/twitch/twitchaccountmanager.cpp \
|
src/twitch/twitchaccountmanager.cpp \
|
||||||
src/singletons/helper/completionmodel.cpp \
|
src/singletons/helper/completionmodel.cpp \
|
||||||
src/singletons/resourcemanager.cpp \
|
src/singletons/resourcemanager.cpp \
|
||||||
src/singletons/helper/ircmessagehandler.cpp
|
src/singletons/helper/ircmessagehandler.cpp \
|
||||||
|
src/singletons/pathmanager.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/precompiled_headers.hpp \
|
src/precompiled_headers.hpp \
|
||||||
|
@ -198,7 +199,8 @@ HEADERS += \
|
||||||
src/singletons/helper/ircmessagehandler.hpp \
|
src/singletons/helper/ircmessagehandler.hpp \
|
||||||
src/util/serialize-custom.hpp \
|
src/util/serialize-custom.hpp \
|
||||||
src/messages/highlightphrase.hpp \
|
src/messages/highlightphrase.hpp \
|
||||||
src/messages/selection.hpp
|
src/messages/selection.hpp \
|
||||||
|
src/singletons/pathmanager.hpp
|
||||||
|
|
||||||
|
|
||||||
PRECOMPILED_HEADER =
|
PRECOMPILED_HEADER =
|
||||||
|
|
|
@ -20,6 +20,8 @@ Application::Application()
|
||||||
|
|
||||||
logging::init();
|
logging::init();
|
||||||
|
|
||||||
|
singletons::SettingManager::getInstance().init();
|
||||||
|
|
||||||
singletons::WindowManager::getInstance().initMainWindow();
|
singletons::WindowManager::getInstance().initMainWindow();
|
||||||
|
|
||||||
// Initialize everything we need
|
// Initialize everything we need
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "application.hpp"
|
#include "application.hpp"
|
||||||
#include "singletons/settingsmanager.hpp"
|
#include "singletons/pathmanager.hpp"
|
||||||
|
|
||||||
#include <QAbstractNativeEventFilter>
|
#include <QAbstractNativeEventFilter>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
@ -24,9 +24,9 @@ int main(int argc, char *argv[])
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Initialize settings
|
// Initialize settings
|
||||||
bool success = chatterino::singletons::SettingManager::getInstance().init(argc, argv);
|
bool success = chatterino::singletons::PathManager::getInstance().init(argc, argv);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
printf("Error initializing settings\n");
|
printf("Error initializing paths\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
57
src/singletons/pathmanager.cpp
Normal file
57
src/singletons/pathmanager.cpp
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
#include "pathmanager.hpp"
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
namespace singletons {
|
||||||
|
|
||||||
|
PathManager &PathManager::getInstance()
|
||||||
|
{
|
||||||
|
static PathManager instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PathManager::init(int argc, char **argv)
|
||||||
|
{
|
||||||
|
// Options
|
||||||
|
bool portable = false;
|
||||||
|
|
||||||
|
for (int i = 1; i < argc; ++i) {
|
||||||
|
if (strcmp(argv[i], "portable") == 0) {
|
||||||
|
portable = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Root path = %APPDATA%/Chatterino or the folder that the executable resides in
|
||||||
|
QString rootPath;
|
||||||
|
if (portable) {
|
||||||
|
rootPath.append(QDir::currentPath());
|
||||||
|
} else {
|
||||||
|
// Get settings path
|
||||||
|
rootPath.append(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
|
||||||
|
if (rootPath.isEmpty()) {
|
||||||
|
printf("Error finding writable location for settings\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this->settingsFolderPath = rootPath;
|
||||||
|
|
||||||
|
if (!QDir().mkpath(this->settingsFolderPath)) {
|
||||||
|
printf("Error creating directory: %s\n", qPrintable(this->settingsFolderPath));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->customFolderPath = rootPath + "/Custom";
|
||||||
|
|
||||||
|
if (!QDir().mkpath(this->customFolderPath)) {
|
||||||
|
printf("Error creating directory: %s\n", qPrintable(this->customFolderPath));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace singletons
|
||||||
|
} // namespace chatterino
|
22
src/singletons/pathmanager.hpp
Normal file
22
src/singletons/pathmanager.hpp
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
namespace chatterino {
|
||||||
|
namespace singletons {
|
||||||
|
|
||||||
|
class PathManager
|
||||||
|
{
|
||||||
|
PathManager() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static PathManager &getInstance();
|
||||||
|
|
||||||
|
bool init(int argc, char **argv);
|
||||||
|
|
||||||
|
QString settingsFolderPath;
|
||||||
|
QString customFolderPath;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace singletons
|
||||||
|
} // namespace chatterino
|
|
@ -1,6 +1,7 @@
|
||||||
#include "singletons/settingsmanager.hpp"
|
#include "singletons/settingsmanager.hpp"
|
||||||
#include "appdatapath.hpp"
|
#include "appdatapath.hpp"
|
||||||
#include "debug/log.hpp"
|
#include "debug/log.hpp"
|
||||||
|
#include "singletons/pathmanager.hpp"
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
@ -42,38 +43,11 @@ bool SettingManager::isIgnoredEmote(const QString &)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SettingManager::init(int argc, char **argv)
|
void SettingManager::init()
|
||||||
{
|
{
|
||||||
// Options
|
QString settingsPath = PathManager::getInstance().settingsFolderPath + "/settings.json";
|
||||||
bool portable = false;
|
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i) {
|
|
||||||
if (strcmp(argv[i], "portable") == 0) {
|
|
||||||
portable = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QString settingsPath;
|
|
||||||
if (portable) {
|
|
||||||
settingsPath.append(QDir::currentPath());
|
|
||||||
} else {
|
|
||||||
// Get settings path
|
|
||||||
settingsPath.append(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
|
|
||||||
if (settingsPath.isEmpty()) {
|
|
||||||
printf("Error finding writable location for settings\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!QDir().mkpath(settingsPath)) {
|
|
||||||
printf("Error creating directories for settings: %s\n", qPrintable(settingsPath));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
settingsPath.append("/settings.json");
|
|
||||||
|
|
||||||
pajlada::Settings::SettingManager::load(qPrintable(settingsPath));
|
pajlada::Settings::SettingManager::load(qPrintable(settingsPath));
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingManager::updateWordTypeMask()
|
void SettingManager::updateWordTypeMask()
|
||||||
|
|
|
@ -25,7 +25,7 @@ public:
|
||||||
messages::Word::Flags getWordTypeMask();
|
messages::Word::Flags getWordTypeMask();
|
||||||
bool isIgnoredEmote(const QString &emote);
|
bool isIgnoredEmote(const QString &emote);
|
||||||
|
|
||||||
bool init(int argc, char **argv);
|
void init();
|
||||||
|
|
||||||
/// Appearance
|
/// Appearance
|
||||||
BoolSetting showTimestamps = {"/appearance/messages/showTimestamps", true};
|
BoolSetting showTimestamps = {"/appearance/messages/showTimestamps", true};
|
||||||
|
|
Loading…
Reference in a new issue