* looks for a previously written file (base_path+unique filename). * If this file exists, create settings from it - otherwise, create default * and persist. */
| 106 | * and persist. |
| 107 | */ |
| 108 | void init() { |
| 109 | if (!OHDFilesystemUtil::exists(_base_path)) { |
| 110 | OHDFilesystemUtil::create_directory(_base_path); |
| 111 | } |
| 112 | const auto last_settings_opt = read_last_settings(); |
| 113 | if (last_settings_opt.has_value()) { |
| 114 | _settings = std::make_unique<T>(last_settings_opt.value()); |
| 115 | openhd::log::info_log("Using settings in [" + get_file_path() + "]"); |
| 116 | } else { |
| 117 | openhd::log::info_log("Creating default settings in [" + get_file_path() + |
| 118 | "]"); |
| 119 | // create default settings and persist them for the next reboot |
| 120 | _settings = std::make_unique<T>(create_default()); |
| 121 | persist_settings(); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | protected: |
| 126 | // NEEDS TO BE OVERRIDDEN |
nothing calls this directly
no outgoing calls
no test coverage detected