Allow to use an empty lms.conf file, default values are now all hardcoded, fixes #584

This commit is contained in:
emeric
2025-01-05 16:12:25 +01:00
parent a6ab9c5ff4
commit 3740c6f899
9 changed files with 42 additions and 40 deletions
+5 -5
View File
@@ -38,12 +38,12 @@ namespace lms::core
private:
// Default values are returned in case of setting not found
std::string_view getString(std::string_view setting, std::string_view def = "") override;
std::string_view getString(std::string_view setting, std::string_view def) override;
void visitStrings(std::string_view setting, std::function<void(std::string_view)> _func, std::initializer_list<std::string_view> defs) override;
std::filesystem::path getPath(std::string_view setting, const std::filesystem::path& def = std::filesystem::path()) override;
unsigned long getULong(std::string_view setting, unsigned long def = 0) override;
long getLong(std::string_view setting, long def = 0) override;
bool getBool(std::string_view setting, bool def = false) override;
std::filesystem::path getPath(std::string_view setting, const std::filesystem::path& def) override;
unsigned long getULong(std::string_view setting, unsigned long def) override;
long getLong(std::string_view setting, long def) override;
bool getBool(std::string_view setting, bool def) override;
libconfig::Config _config;
};
+6 -6
View File
@@ -31,12 +31,12 @@ namespace lms::core
virtual ~IConfig() = default;
// Default values are returned in case of setting not found
virtual std::string_view getString(std::string_view setting, std::string_view def = "") = 0;
virtual void visitStrings(std::string_view setting, std::function<void(std::string_view)> _func, std::initializer_list<std::string_view> def = {}) = 0;
virtual std::filesystem::path getPath(std::string_view setting, const std::filesystem::path& def = std::filesystem::path()) = 0;
virtual unsigned long getULong(std::string_view setting, unsigned long def = 0) = 0;
virtual long getLong(std::string_view setting, long def = 0) = 0;
virtual bool getBool(std::string_view setting, bool def = false) = 0;
virtual std::string_view getString(std::string_view setting, std::string_view def) = 0;
virtual void visitStrings(std::string_view setting, std::function<void(std::string_view)> _func, std::initializer_list<std::string_view> def) = 0;
virtual std::filesystem::path getPath(std::string_view setting, const std::filesystem::path& def) = 0;
virtual unsigned long getULong(std::string_view setting, unsigned long def) = 0;
virtual long getLong(std::string_view setting, long def) = 0;
virtual bool getBool(std::string_view setting, bool def) = 0;
};
std::unique_ptr<IConfig> createConfig(const std::filesystem::path& p);
@@ -32,7 +32,7 @@ namespace lms::recommendation
{
std::filesystem::path getCacheDirectory()
{
return core::Service<core::IConfig>::get()->getPath("working-dir") / "cache" / "features";
return core::Service<core::IConfig>::get()->getPath("working-dir", "/var/lms") / "cache" / "features";
}
std::filesystem::path getCacheNetworkFilePath()
@@ -230,7 +230,7 @@ namespace lms::recommendation
void FeaturesEngineCache::write() const
{
std::filesystem::create_directories(core::Service<core::IConfig>::get()->getPath("working-dir") / "cache" / "features");
std::filesystem::create_directories(core::Service<core::IConfig>::get()->getPath("working-dir", "/var/lms") / "cache" / "features");
if (!networkToCacheFile(_network, getCacheNetworkFilePath())
|| !objectPositionToCacheFile(_trackPositions, getCacheTrackPositionsFilePath()))