| 53 | namespace { |
| 54 | |
| 55 | void UpdateFileResource( |
| 56 | const fs::path& path, |
| 57 | const std::wstring& type, |
| 58 | const std::wstring& name, |
| 59 | const std::optional< std::wstring >& lang, |
| 60 | const std::vector< uint8_t >& value, |
| 61 | std::error_code& ec ) |
| 62 | { |
| 63 | BOOL ret = FALSE; |
| 64 | |
| 65 | guard::BeginUpdateResourceHandleW hUpdate = |
| 66 | BeginUpdateResourceW( path.c_str(), FALSE ); |
| 67 | |
| 68 | if( !hUpdate ) { |
| 69 | ec.assign( GetLastError(), std::system_category() ); |
| 70 | spdlog::debug( "Failed BeginUpdateResource: {}", ec.message() ); |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | const auto langId = |
| 75 | lang ? std::stoi( *lang ) : MAKELANGID( LANG_NEUTRAL, SUBLANG_NEUTRAL ); |
| 76 | |
| 77 | ret = UpdateResourceW( |
| 78 | hUpdate.get(), |
| 79 | type.c_str(), |
| 80 | name.c_str(), |
| 81 | langId, |
| 82 | reinterpret_cast< LPVOID >( const_cast< uint8_t* >( value.data() ) ), |
| 83 | static_cast< DWORD >( value.size() ) ); |
| 84 | |
| 85 | if( ret == FALSE ) { |
| 86 | ec.assign( GetLastError(), std::system_category() ); |
| 87 | spdlog::debug( "Failed UpdateResource: {}", ec.message() ); |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | ret = EndUpdateResourceW( hUpdate.get(), FALSE ); |
| 92 | |
| 93 | if( ret == FALSE ) { |
| 94 | ec.assign( GetLastError(), std::system_category() ); |
| 95 | spdlog::debug( "Failed EndUpdateResource: {}", ec.message() ); |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | hUpdate.detach(); |
| 100 | } |
| 101 | |
| 102 | std::pair< std::string_view, guard::MapView > MapFile( |
| 103 | const fs::path filePath, |