diff --git a/.gitignore b/.gitignore index e75af825e0..a20830ba55 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ Thumbs.db /logs/ /screenshots/ /recordings/ +/user/ /sync/ /temp/ # Customization is not supposed to be committed diff --git a/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp b/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp index 4d48860657..631c1bb27b 100644 --- a/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp +++ b/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp @@ -172,7 +172,6 @@ LauncherWindow::LauncherWindow(bool profileEnabled, setCentralWidget(createCentralWidget()); - populateProfilesList(globalConfig.profile); _profileBox->setEnabled(profileEnabled); @@ -326,14 +325,6 @@ void LauncherWindow::populateProfilesList(std::string preset) { return; } - if (!std::filesystem::exists(_userProfilePath)) { - LINFOC( - "LauncherWindow", - fmt::format("Could not find user profile folder '{}'", _userProfilePath) - ); - return; - } - _profileBox->addItem(QString::fromStdString("--- User Profiles ---")); const QStandardItemModel* model = qobject_cast(_profileBox->model()); model->item(_userAssetCount)->setEnabled(false); @@ -373,30 +364,22 @@ void LauncherWindow::populateWindowConfigsList(std::string preset) { _windowConfigBox->clear(); - if (std::filesystem::exists(_userConfigPath)) { - _userConfigCount = 0; - _windowConfigBox->addItem(QString::fromStdString("--- User Configurations ---")); - const QStandardItemModel* model = qobject_cast(_windowConfigBox->model()); - model->item(_userConfigCount)->setEnabled(false); - ++_userConfigCount; - // Add all the files with the .xml extension to the dropdown - for (const fs::directory_entry& p : fs::directory_iterator(_userConfigPath)) { - if (p.path().extension() != ".xml") { - continue; - } - _windowConfigBox->addItem(QString::fromStdString(p.path().stem().string())); - ++_userConfigCount; + _userConfigCount = 0; + _windowConfigBox->addItem(QString::fromStdString("--- User Configurations ---")); + const QStandardItemModel* model = qobject_cast(_windowConfigBox->model()); + model->item(_userConfigCount)->setEnabled(false); + ++_userConfigCount; + // Add all the files with the .xml extension to the dropdown + for (const fs::directory_entry& p : fs::directory_iterator(_userConfigPath)) { + if (p.path().extension() != ".xml") { + continue; } - _windowConfigBox->addItem(QString::fromStdString("--- OpenSpace Configurations ---")); - model = qobject_cast(_windowConfigBox->model()); - model->item(_userConfigCount)->setEnabled(false); - } - else { - LINFOC( - "LauncherWindow", - fmt::format("Could not find config folder '{}'", _configPath) - ); + _windowConfigBox->addItem(QString::fromStdString(p.path().stem().string())); + ++_userConfigCount; } + _windowConfigBox->addItem(QString::fromStdString("--- OpenSpace Configurations ---")); + model = qobject_cast(_windowConfigBox->model()); + model->item(_userConfigCount)->setEnabled(false); if (std::filesystem::exists(_configPath)) { // Add all the files with the .xml extension to the dropdown diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index 06ba02a6a2..6330167b4a 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -1162,7 +1162,6 @@ int main(int argc, char* argv[]) { global::openSpaceEngine->registerPathTokens(); - bool hasSGCTConfig = false; bool hasProfile = false; std::string sgctFunctionName; @@ -1178,6 +1177,9 @@ int main(int argc, char* argv[]) { sgctFunctionName ); + //TODO consider LFATAL if ${USER} doens't exist rather then recurisve create. + global::openSpaceEngine->createUserDirectoriesIfNecessary(); + // (abock, 2020-12-07) For some reason on Apple the keyboard handler in CEF will call // the Qt one even if the QApplication was destroyed, leading to invalid memory // access. The only way we could fix this for the release was to keep the diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 2710a709f3..68843243ca 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -99,6 +99,7 @@ public: void writeSceneDocumentation(); void writeStaticDocumentation(); + void createUserDirectoriesIfNecessary(); /** * Returns the Lua library that contains all Lua functions available to affect the diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 388efdbfc3..7c306ddc2d 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -220,6 +220,7 @@ void OpenSpaceEngine::initialize() { } + // Initialize the requested logs from the configuration file // We previously initialized the LogManager with a console log to provide some logging // until we know which logs should be added @@ -953,6 +954,23 @@ void OpenSpaceEngine::writeStaticDocumentation() { } } +void OpenSpaceEngine::createUserDirectoriesIfNecessary() { + LTRACE(absPath("${USER}")); + + if (!std::filesystem::exists(absPath("${USER_ASSETS}"))) { + FileSys.createDirectory(absPath("${USER_ASSETS}"), + ghoul::filesystem::FileSystem::Recursive::Yes); + } + if (!std::filesystem::exists(absPath("${USER_PROFILES}"))) { + FileSys.createDirectory(absPath("${USER_PROFILES}"), + ghoul::filesystem::FileSystem::Recursive::Yes); + } + if (!std::filesystem::exists(absPath("${USER_CONFIG}"))) { + FileSys.createDirectory(absPath("${USER_CONFIG}"), + ghoul::filesystem::FileSystem::Recursive::Yes); + } +} + void OpenSpaceEngine::runGlobalCustomizationScripts() { ZoneScoped diff --git a/user/.gitignore b/user/.gitignore deleted file mode 100644 index 76bedaeabb..0000000000 --- a/user/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -# Ignore everything in this directory -* -# Except this file -!.gitignore -