mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
58 lines
1.4 KiB
C++
58 lines
1.4 KiB
C++
|
#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
|