| 30 | } |
| 31 | |
| 32 | void Config::writeToFile() |
| 33 | { |
| 34 | #ifndef __EMSCRIPTEN__ |
| 35 | // although json is a textual format, we open the file in binary mode to get exactly the same result on Windows and Linux |
| 36 | std::ofstream os( filePath_, std::ofstream::binary ); |
| 37 | if ( loggerHandle_ ) |
| 38 | loggerHandle_->info( "Saving config file: " + utf8string( filePath_ ) ); |
| 39 | if ( os.is_open() ) |
| 40 | { |
| 41 | os << config_; |
| 42 | os.close(); |
| 43 | } |
| 44 | else |
| 45 | { |
| 46 | if ( loggerHandle_ ) |
| 47 | loggerHandle_->warn( "Failed to save json config file " + utf8string( filePath_ ) ); |
| 48 | } |
| 49 | #else |
| 50 | std::stringstream strStream; |
| 51 | strStream << config_; |
| 52 | std::string str = strStream.str(); |
| 53 | #pragma GCC diagnostic push |
| 54 | #pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension" |
| 55 | EM_ASM({ localStorage.setItem( 'config', UTF8ToString( $0 ) ) }, str.c_str() ); |
| 56 | #pragma GCC diagnostic pop |
| 57 | #endif |
| 58 | } |
| 59 | |
| 60 | void Config::reset( const std::filesystem::path& filePath ) |
| 61 | { |
no test coverage detected