mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
changed settings paths
This commit is contained in:
parent
e0ecd97184
commit
2f91e3097a
17 changed files with 158 additions and 94 deletions
|
@ -378,7 +378,8 @@ HEADERS += \
|
|||
src/widgets/userinfopopup.hpp \
|
||||
src/widgets/welcomedialog.hpp \
|
||||
src/util/clamp.hpp \
|
||||
src/widgets/label.hpp
|
||||
src/widgets/label.hpp \
|
||||
src/util/combine_path.hpp
|
||||
|
||||
RESOURCES += \
|
||||
resources/resources.qrc
|
||||
|
|
|
@ -71,7 +71,10 @@ void Channel::addMessage(MessagePtr message)
|
|||
this->addRecentChatter(message);
|
||||
}
|
||||
|
||||
app->logging->addMessage(this->name, message);
|
||||
// FOURTF: change this when adding more providers
|
||||
if (this->isTwitchChannel()) {
|
||||
app->logging->addMessage(this->name, message);
|
||||
}
|
||||
|
||||
if (this->messages.pushBack(message, deleted)) {
|
||||
this->messageRemovedFromStart.invoke(deleted);
|
||||
|
|
|
@ -40,7 +40,7 @@ CommandController::CommandController()
|
|||
void CommandController::load()
|
||||
{
|
||||
auto app = getApp();
|
||||
this->filePath = app->paths->customFolderPath + "/Commands.txt";
|
||||
this->filePath = app->paths->settingsDirectory + "/commands.txt";
|
||||
|
||||
QFile textFile(this->filePath);
|
||||
if (!textFile.open(QIODevice::ReadOnly)) {
|
||||
|
|
|
@ -39,7 +39,7 @@ int main(int argc, char *argv[])
|
|||
// QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL, true);
|
||||
QApplication a(argc, argv);
|
||||
|
||||
chatterino::singletons::PathManager::initInstance(argc, argv);
|
||||
chatterino::singletons::PathManager::initInstance();
|
||||
|
||||
// read args
|
||||
QStringList args;
|
||||
|
@ -83,7 +83,7 @@ int runGui(QApplication &a, int argc, char *argv[])
|
|||
|
||||
auto &pathMan = *app->paths;
|
||||
// Running file
|
||||
auto runningPath = pathMan.settingsFolderPath + "/running_" + pathMan.appPathHash;
|
||||
auto runningPath = pathMan.miscDirectory + "/running_" + pathMan.applicationFilePathHash;
|
||||
|
||||
if (QFile::exists(runningPath)) {
|
||||
#ifndef DISABLE_CRASH_DIALOG
|
||||
|
|
|
@ -25,13 +25,16 @@ LoggingChannel::LoggingChannel(const QString &_channelName)
|
|||
this->subDirectory = QStringLiteral("Channels") + QDir::separator() + channelName;
|
||||
}
|
||||
|
||||
// FOURTF: change this when adding more providers
|
||||
this->subDirectory = "Twitch/" + this->subDirectory;
|
||||
|
||||
auto app = getApp();
|
||||
|
||||
app->settings->logPath.connect([this](const QString &logPath, auto) {
|
||||
auto app = getApp();
|
||||
|
||||
if (logPath.isEmpty()) {
|
||||
this->baseDirectory = app->paths->logsFolderPath;
|
||||
this->baseDirectory = app->paths->messageLogDirectory;
|
||||
} else {
|
||||
this->baseDirectory = logPath;
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ void NativeMessagingManager::registerHost()
|
|||
auto registerManifest = [&](const QString &manifestFilename, const QString ®istryKeyName,
|
||||
const QJsonDocument &document) {
|
||||
// save the manifest
|
||||
QString manifestPath = app->paths->settingsFolderPath + manifestFilename;
|
||||
QString manifestPath = app->paths->miscDirectory + manifestFilename;
|
||||
QFile file(manifestPath);
|
||||
file.open(QIODevice::WriteOnly | QIODevice::Truncate);
|
||||
file.write(document.toJson());
|
||||
|
@ -235,7 +235,8 @@ void NativeMessagingManager::ReceiverThread::handleMessage(const QJsonObject &ro
|
|||
std::string &NativeMessagingManager::getGuiMessageQueueName()
|
||||
{
|
||||
static std::string name =
|
||||
"chatterino_gui" + singletons::PathManager::getInstance()->appPathHash.toStdString();
|
||||
"chatterino_gui" +
|
||||
singletons::PathManager::getInstance()->applicationFilePathHash.toStdString();
|
||||
return name;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,76 +6,27 @@
|
|||
#include <QStandardPaths>
|
||||
#include <cassert>
|
||||
|
||||
#include "util/combine_path.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
namespace singletons {
|
||||
|
||||
PathManager *PathManager::instance = nullptr;
|
||||
|
||||
PathManager::PathManager(int argc, char **argv)
|
||||
PathManager::PathManager()
|
||||
{
|
||||
// hash of app path
|
||||
this->appPathHash = QCryptographicHash::hash(QCoreApplication::applicationFilePath().toUtf8(),
|
||||
QCryptographicHash::Sha224)
|
||||
.toBase64()
|
||||
.mid(0, 32)
|
||||
.replace("+", "-")
|
||||
.replace("/", "x");
|
||||
this->initAppFilePathHash();
|
||||
|
||||
// Options
|
||||
this->portable = false;
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (strcmp(argv[i], "portable") == 0) {
|
||||
this->portable = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (QFileInfo::exists(QCoreApplication::applicationDirPath() + "/this->portable")) {
|
||||
this->portable = true;
|
||||
}
|
||||
|
||||
// Root path = %APPDATA%/Chatterino or the folder that the executable resides in
|
||||
QString rootPath;
|
||||
if (this->portable) {
|
||||
rootPath.append(QCoreApplication::applicationDirPath());
|
||||
} else {
|
||||
// Get settings path
|
||||
rootPath.append(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
|
||||
if (rootPath.isEmpty()) {
|
||||
throw std::runtime_error("Error finding writable location for settings");
|
||||
}
|
||||
}
|
||||
|
||||
this->settingsFolderPath = rootPath;
|
||||
|
||||
if (!QDir().mkpath(this->settingsFolderPath)) {
|
||||
throw std::runtime_error("Error creating settings folder");
|
||||
}
|
||||
|
||||
this->customFolderPath = rootPath + "/Custom";
|
||||
|
||||
if (!QDir().mkpath(this->customFolderPath)) {
|
||||
throw std::runtime_error("Error creating custom folder");
|
||||
}
|
||||
|
||||
this->cacheFolderPath = rootPath + "/Cache";
|
||||
|
||||
if (!QDir().mkpath(this->cacheFolderPath)) {
|
||||
throw std::runtime_error("Error creating cache folder");
|
||||
}
|
||||
|
||||
this->logsFolderPath = rootPath + "/Logs";
|
||||
|
||||
if (!QDir().mkpath(this->logsFolderPath)) {
|
||||
throw std::runtime_error("Error creating logs folder");
|
||||
}
|
||||
this->initCheckPortable();
|
||||
this->initAppDataDirectory();
|
||||
this->initSubDirectories();
|
||||
}
|
||||
|
||||
void PathManager::initInstance(int argc, char **argv)
|
||||
void PathManager::initInstance()
|
||||
{
|
||||
assert(!instance);
|
||||
|
||||
instance = new PathManager(argc, argv);
|
||||
instance = new PathManager();
|
||||
}
|
||||
|
||||
PathManager *PathManager::getInstance()
|
||||
|
@ -92,7 +43,77 @@ bool PathManager::createFolder(const QString &folderPath)
|
|||
|
||||
bool PathManager::isPortable()
|
||||
{
|
||||
return this->portable;
|
||||
return this->portable.get();
|
||||
}
|
||||
|
||||
void PathManager::initAppFilePathHash()
|
||||
{
|
||||
this->applicationFilePathHash =
|
||||
QCryptographicHash::hash(QCoreApplication::applicationFilePath().toUtf8(),
|
||||
QCryptographicHash::Sha224)
|
||||
.toBase64()
|
||||
.mid(0, 32)
|
||||
.replace("+", "-")
|
||||
.replace("/", "x");
|
||||
}
|
||||
|
||||
void PathManager::initCheckPortable()
|
||||
{
|
||||
this->portable =
|
||||
QFileInfo::exists(util::combinePath(QCoreApplication::applicationDirPath(), "portable"));
|
||||
}
|
||||
|
||||
void PathManager::initAppDataDirectory()
|
||||
{
|
||||
assert(this->portable.is_initialized());
|
||||
|
||||
// Root path = %APPDATA%/Chatterino or the folder that the executable resides in
|
||||
|
||||
this->rootAppDataDirectory = [&]() -> QString {
|
||||
// portable
|
||||
if (this->portable) {
|
||||
return QCoreApplication::applicationDirPath();
|
||||
}
|
||||
|
||||
// permanent installation
|
||||
QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||
if (path.isEmpty()) {
|
||||
throw std::runtime_error("Error finding writable location for settings");
|
||||
}
|
||||
|
||||
// create directory Chatterino2 instead of chatterino on windows because the ladder one is takes by
|
||||
// chatterino 1 already
|
||||
#ifdef Q_OS_WIN
|
||||
path.replace("chatterino", "Chatterino");
|
||||
|
||||
path += "2";
|
||||
#endif
|
||||
return path;
|
||||
}();
|
||||
}
|
||||
|
||||
void PathManager::initSubDirectories()
|
||||
{
|
||||
// required the app data directory to be set first
|
||||
assert(!this->rootAppDataDirectory.isEmpty());
|
||||
|
||||
// create settings subdirectories and validate that they are created properly
|
||||
auto makePath = [&](const std::string &name) -> QString {
|
||||
|
||||
auto path = util::combinePath(this->rootAppDataDirectory, QString::fromStdString(name));
|
||||
|
||||
if (!QDir().mkpath(path)) {
|
||||
throw std::runtime_error("Error creating appdata path %appdata%/chatterino/" + name);
|
||||
}
|
||||
|
||||
return path;
|
||||
};
|
||||
|
||||
makePath("");
|
||||
this->settingsDirectory = makePath("Settings");
|
||||
this->cacheDirectory = makePath("Cache");
|
||||
this->messageLogDirectory = makePath("Logs");
|
||||
this->miscDirectory = makePath("Misc");
|
||||
}
|
||||
|
||||
} // namespace singletons
|
||||
|
|
|
@ -1,38 +1,49 @@
|
|||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
namespace chatterino {
|
||||
namespace singletons {
|
||||
|
||||
class PathManager
|
||||
{
|
||||
PathManager(int argc, char **argv);
|
||||
PathManager();
|
||||
|
||||
public:
|
||||
static void initInstance(int argc, char **argv);
|
||||
static void initInstance();
|
||||
static PathManager *getInstance();
|
||||
|
||||
// %APPDATA%/chatterino or ExecutablePath for portable mode
|
||||
QString settingsFolderPath;
|
||||
// Root directory for the configuration files. %APPDATA%/chatterino or ExecutablePath for
|
||||
// portable mode
|
||||
QString rootAppDataDirectory;
|
||||
|
||||
// %APPDATA%/chatterino/Custom or ExecutablePath/Custom for portable mode
|
||||
QString customFolderPath;
|
||||
// Directory for settings files. Same as <appDataDirectory>/Settings
|
||||
QString settingsDirectory;
|
||||
|
||||
// %APPDATA%/chatterino/Cache or ExecutablePath/Cache for portable mode
|
||||
QString cacheFolderPath;
|
||||
// Directory for cache files. Same as <appDataDirectory>/Misc
|
||||
QString cacheDirectory;
|
||||
|
||||
// Default folder for logs. %APPDATA%/chatterino/Logs or ExecutablePath/Logs for portable mode
|
||||
QString logsFolderPath;
|
||||
// Directory for message log files. Same as <appDataDirectory>/Misc
|
||||
QString messageLogDirectory;
|
||||
|
||||
QString appPathHash;
|
||||
// Directory for miscellaneous files. Same as <appDataDirectory>/Misc
|
||||
QString miscDirectory;
|
||||
|
||||
// Hash of QCoreApplication::applicationFilePath()
|
||||
QString applicationFilePathHash;
|
||||
|
||||
bool createFolder(const QString &folderPath);
|
||||
bool isPortable();
|
||||
|
||||
private:
|
||||
static PathManager *instance;
|
||||
bool portable;
|
||||
boost::optional<bool> portable;
|
||||
|
||||
void initAppFilePathHash();
|
||||
void initCheckPortable();
|
||||
void initAppDataDirectory();
|
||||
void initSubDirectories();
|
||||
};
|
||||
|
||||
} // namespace singletons
|
||||
|
|
|
@ -66,7 +66,7 @@ bool SettingManager::isIgnoredEmote(const QString &)
|
|||
void SettingManager::load()
|
||||
{
|
||||
auto app = getApp();
|
||||
QString settingsPath = app->paths->settingsFolderPath + "/settings.json";
|
||||
QString settingsPath = app->paths->settingsDirectory + "/settings.json";
|
||||
|
||||
pajlada::Settings::SettingManager::load(qPrintable(settingsPath));
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include <QDebug>
|
||||
|
||||
#define SETTINGS_FILENAME "/layout.json"
|
||||
#define SETTINGS_FILENAME "/window-layout.json"
|
||||
|
||||
namespace chatterino {
|
||||
namespace singletons {
|
||||
|
@ -157,7 +157,7 @@ void WindowManager::initialize()
|
|||
assert(!this->initialized);
|
||||
|
||||
// load file
|
||||
QString settingsPath = app->paths->settingsFolderPath + SETTINGS_FILENAME;
|
||||
QString settingsPath = app->paths->settingsDirectory + SETTINGS_FILENAME;
|
||||
QFile file(settingsPath);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
QByteArray data = file.readAll();
|
||||
|
@ -311,7 +311,7 @@ void WindowManager::save()
|
|||
document.setObject(obj);
|
||||
|
||||
// save file
|
||||
QString settingsPath = app->paths->settingsFolderPath + SETTINGS_FILENAME;
|
||||
QString settingsPath = app->paths->settingsDirectory + SETTINGS_FILENAME;
|
||||
QFile file(settingsPath);
|
||||
file.open(QIODevice::WriteOnly | QIODevice::Truncate);
|
||||
|
||||
|
@ -459,6 +459,8 @@ float WindowManager::getUiScaleValue(int scale)
|
|||
return 3.5f;
|
||||
case 10:
|
||||
return 4;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
16
src/util/combine_path.hpp
Normal file
16
src/util/combine_path.hpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include <QDir>
|
||||
#include <QString>
|
||||
|
||||
namespace chatterino {
|
||||
namespace util {
|
||||
|
||||
// https://stackoverflow.com/a/13014491
|
||||
static QString combinePath(const QString &a, const QString &b)
|
||||
{
|
||||
return QDir::cleanPath(a + QDir::separator() + b);
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace chatterino
|
|
@ -30,7 +30,7 @@ void NetworkRequest::Data::writeToCache(const QByteArray &bytes)
|
|||
if (this->useQuickLoadCache) {
|
||||
auto app = getApp();
|
||||
|
||||
QFile cachedFile(app->paths->cacheFolderPath + "/" + this->getHash());
|
||||
QFile cachedFile(app->paths->cacheDirectory + "/" + this->getHash());
|
||||
|
||||
if (cachedFile.open(QIODevice::WriteOnly)) {
|
||||
cachedFile.write(bytes);
|
||||
|
|
|
@ -183,7 +183,7 @@ public:
|
|||
if (this->data.useQuickLoadCache) {
|
||||
auto app = getApp();
|
||||
|
||||
QFile cachedFile(app->paths->cacheFolderPath + "/" + this->data.getHash());
|
||||
QFile cachedFile(app->paths->cacheDirectory + "/" + this->data.getHash());
|
||||
|
||||
if (cachedFile.exists()) {
|
||||
if (cachedFile.open(QIODevice::ReadOnly)) {
|
||||
|
@ -329,7 +329,7 @@ private:
|
|||
if (this->data.useQuickLoadCache) {
|
||||
auto app = getApp();
|
||||
|
||||
QFile cachedFile(app->paths->cacheFolderPath + "/" + this->data.getHash());
|
||||
QFile cachedFile(app->paths->cacheDirectory + "/" + this->data.getHash());
|
||||
|
||||
if (cachedFile.exists()) {
|
||||
if (cachedFile.open(QIODevice::ReadOnly)) {
|
||||
|
|
|
@ -44,9 +44,9 @@ void LogInWithCredentials(const std::string &userID, const std::string &username
|
|||
return;
|
||||
}
|
||||
|
||||
QMessageBox messageBox;
|
||||
messageBox.setIcon(QMessageBox::Information);
|
||||
messageBox.setText("Successfully logged in with user <b>" + qS(username) + "</b>!");
|
||||
// QMessageBox messageBox;
|
||||
// messageBox.setIcon(QMessageBox::Information);
|
||||
// messageBox.setText("Successfully logged in with user <b>" + qS(username) + "</b>!");
|
||||
pajlada::Settings::Setting<std::string>::set("/accounts/uid" + userID + "/username", username);
|
||||
pajlada::Settings::Setting<std::string>::set("/accounts/uid" + userID + "/userID", userID);
|
||||
pajlada::Settings::Setting<std::string>::set("/accounts/uid" + userID + "/clientID", clientID);
|
||||
|
@ -55,7 +55,7 @@ void LogInWithCredentials(const std::string &userID, const std::string &username
|
|||
|
||||
getApp()->accounts->twitch.reloadUsers();
|
||||
|
||||
messageBox.exec();
|
||||
// messageBox.exec();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -190,9 +190,10 @@ void AdvancedLoginWidget::refreshButtons()
|
|||
|
||||
LoginWidget::LoginWidget()
|
||||
{
|
||||
#ifdef USEWINSDK
|
||||
::SetWindowPos((HWND)this->winId(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
|
||||
#endif
|
||||
#ifdef USEWINSDK
|
||||
::SetWindowPos((HWND)this->winId(), HWND_TOPMOST, 0, 0, 0, 0,
|
||||
SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
|
||||
#endif
|
||||
|
||||
this->setLayout(&this->ui.mainLayout);
|
||||
|
||||
|
|
|
@ -36,6 +36,10 @@ CommandPage::CommandPage()
|
|||
util::LayoutCreator<CommandPage> layoutCreator(this);
|
||||
auto layout = layoutCreator.emplace<QVBoxLayout>().withoutMargin();
|
||||
|
||||
auto warning = layout.emplace<QLabel>("The command system will be reworked in the "
|
||||
"future!\nYour saved commands will get discarded then.");
|
||||
warning.getElement()->setStyleSheet("color: #f00");
|
||||
|
||||
helper::EditableModelView *view =
|
||||
*layout.emplace<helper::EditableModelView>(app->commands->createModel(nullptr));
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "widgets/helper/editablemodelview.hpp"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QHeaderView>
|
||||
#include <QListWidget>
|
||||
#include <QPushButton>
|
||||
#include <QStandardItemModel>
|
||||
|
|
|
@ -50,7 +50,7 @@ ModerationPage::ModerationPage()
|
|||
app->settings->logPath.connect([app, created](const QString &logPath, auto) mutable {
|
||||
if (logPath == "") {
|
||||
created->setText("Logs are saved to " +
|
||||
CreateLink(app->paths->logsFolderPath, true));
|
||||
CreateLink(app->paths->messageLogDirectory, true));
|
||||
} else {
|
||||
created->setText("Logs are saved to " + CreateLink(logPath, true));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue