diff --git a/libs/settings/SettingsManager.h b/libs/settings/SettingsManager.h index 493d95722b..59e3133142 100644 --- a/libs/settings/SettingsManager.h +++ b/libs/settings/SettingsManager.h @@ -5,6 +5,8 @@ #include "imodule.h" #include "MajorMinorVersion.h" +#include "os/dir.h" +#include "os/path.h" namespace settings { @@ -34,10 +36,17 @@ class SettingsManager SettingsManager(const IApplicationContext& context, const std::string& currentVersion) : _context(context), _currentVersion(currentVersion) - {} + { + // Set up the path to the current version + _currentVersionSettingsFolder = os::standardPathWithSlash(context.getSettingsPath() + _currentVersion.toString()); + + // Make sure the output folder exists + os::makeDirectory(_currentVersionSettingsFolder); + } - // Returns the output path where all settings files for the current version can be saved to. - // This is usually the same as IApplicationContext::getSettingsPath()/"major.minor"/ + // Returns the output path (including trailing slash) where all settings files + // for the current version can be saved to. + // Matches the pattern IApplicationContext::getSettingsPath()/"major.minor"/ const std::string& getCurrentVersionSettingsFolder() const { return _currentVersionSettingsFolder; diff --git a/test/Settings.cpp b/test/Settings.cpp index 673d37a342..959f8be461 100644 --- a/test/Settings.cpp +++ b/test/Settings.cpp @@ -151,11 +151,6 @@ namespace void testSettingsPathCreation(const IApplicationContext& context, const std::string& versionString) { - // Set up a manager and check if it created the settings output folder - auto manager = versionString.empty() ? - std::make_unique(context) : - std::make_unique(context, versionString); - settings::MajorMinorVersion version(versionString.empty() ? RADIANT_VERSION : versionString); auto expectedFolder = os::standardPathWithSlash(context.getSettingsPath() + version.toString()); @@ -163,10 +158,15 @@ void testSettingsPathCreation(const IApplicationContext& context, const std::str // Let's assume the folder doesn't exist yet EXPECT_FALSE(fs::is_directory(expectedFolder)) << "The output path " << expectedFolder << " already exists"; + // Set up a manager and check if it created the settings output folder + auto manager = versionString.empty() ? + std::make_unique(context) : + std::make_unique(context, versionString); + EXPECT_EQ(manager->getCurrentVersionSettingsFolder(), expectedFolder) << "Output folder is not what we expected"; EXPECT_TRUE(fs::is_directory(expectedFolder)) << "Manager should have created the path " << expectedFolder; - fs::remove_all(expectedFolder); + os::removeDirectory(expectedFolder); } }