diff --git a/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp b/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp index 33dd2fdb9d..24d3122c97 100644 --- a/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp +++ b/apps/OpenSpace/ext/launcher/src/launcherwindow.cpp @@ -395,7 +395,9 @@ void LauncherWindow::populateProfilesList(std::string preset) { } _profileBox->addItem(QString::fromStdString("--- User Profiles ---")); - const QStandardItemModel* model = qobject_cast(_profileBox->model()); + const QStandardItemModel* model = qobject_cast( + _profileBox->model() + ); model->item(_userAssetCount)->setEnabled(false); ++_userAssetCount; @@ -410,7 +412,10 @@ void LauncherWindow::populateProfilesList(std::string preset) { } std::sort(profiles.begin(), profiles.end()); for (const fs::directory_entry& p : profiles) { - _profileBox->addItem(QString::fromStdString(p.path().stem().string())); + _profileBox->addItem( + QString::fromStdString(p.path().stem().string()), + QString::fromStdString(p.path().string()) + ); } _profileBox->addItem(QString::fromStdString("--- OpenSpace Profiles ---")); @@ -430,14 +435,30 @@ void LauncherWindow::populateProfilesList(std::string preset) { // Add sorted items to list for (const fs::directory_entry& profile : profiles) { - _profileBox->addItem(QString::fromStdString(profile.path().stem().string())); + std::string abc = profile.path().string(); + _profileBox->addItem( + QString::fromStdString(profile.path().stem().string()), + QString::fromStdString(profile.path().string()) + ); } // Try to find the requested profile and set it as the current one - const int idx = _profileBox->findText(QString::fromStdString(std::move(preset))); - if (idx != -1) { - _profileBox->setCurrentIndex(idx); + int idx = _profileBox->findText(QString::fromStdString(preset)); + if (idx == -1) { + // We didn't find the preset, so the user probably specified a path in the + // configuration file that doesn't match any value in the list + _profileBox->addItem(QString::fromStdString("--- Configuration File ---")); + model = qobject_cast(_profileBox->model()); + model->item(_profileBox->count() - 1)->setEnabled(false); + + _profileBox->addItem( + QString::fromStdString(preset), + QString::fromStdString(preset) + ); + idx = _profileBox->count() - 1; } + + _profileBox->setCurrentIndex(idx); } // Returns 'true' if the file was a configuration file, 'false' otherwise @@ -602,7 +623,8 @@ bool LauncherWindow::wasLaunchSelected() const { } std::string LauncherWindow::selectedProfile() const { - return _profileBox->currentText().toStdString(); + // The user data stores the full path to the profile + return _profileBox->currentData().toString().toStdString(); } std::string LauncherWindow::selectedWindowConfig() const { diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 3edd3b459c..43323feeab 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -303,41 +303,50 @@ void OpenSpaceEngine::initialize() { // Process profile file (must be provided in configuration file) if (!global::configuration->profile.empty()) { - std::string inputProfilePath = absPath("${PROFILES}").string(); - std::string outputScenePath = absPath("${TEMPORARY}").string(); - std::string inputProfile = inputProfilePath + "/" + global::configuration->profile - + ".profile"; - std::string inputUserProfile = absPath("${USER_PROFILES}").string() + "/" + - global::configuration->profile + ".profile"; + std::filesystem::path profile; + if (!std::filesystem::is_regular_file(global::configuration->profile)) { + std::filesystem::path userCandidate = absPath(fmt::format( + "${{USER_PROFILES}}/{}.profile", global::configuration->profile + )); + std::filesystem::path profileCandidate = absPath(fmt::format( + "${{PROFILES}}/{}.profile", global::configuration->profile + )); - if (std::filesystem::is_regular_file(inputUserProfile)) { - inputProfile = inputUserProfile; - } - - if (!std::filesystem::is_regular_file(inputProfile)) { - LERROR(fmt::format( - "Could not load profile '{}': File does not exist", inputProfile) - ); + // Give the user profile priority if there are both + if (std::filesystem::is_regular_file(userCandidate)) { + profile = userCandidate; + } + else if (std::filesystem::is_regular_file(profileCandidate)) { + profile = profileCandidate; + } + else { + throw ghoul::RuntimeError(fmt::format( + "Could not load profile '{}': File does not exist", + global::configuration->profile + )); + } } else { - // Load the profile - std::ifstream inFile; - try { - inFile.open(inputProfile, std::ifstream::in); - } - catch (const std::ifstream::failure& e) { - throw ghoul::RuntimeError(fmt::format( - "Exception opening profile file for read: {} ({})", - inputProfile, e.what()) - ); - } - - std::string content( - (std::istreambuf_iterator(inFile)), - std::istreambuf_iterator() - ); - *global::profile = Profile(content); + profile = global::configuration->profile; } + + // Load the profile + std::ifstream inFile; + try { + inFile.open(profile, std::ifstream::in); + } + catch (const std::ifstream::failure& e) { + throw ghoul::RuntimeError(fmt::format( + "Exception opening profile file for read: {} ({})", + profile, e.what()) + ); + } + + std::string content( + (std::istreambuf_iterator(inFile)), + std::istreambuf_iterator() + ); + *global::profile = Profile(content); } // Set up asset loader