2022-04-14 22:12:59 +02:00
# include "openfile.hpp"
# include <cstring>
# include <fstream>
2022-06-16 00:28:41 +01:00
# if defined(_WIN32) || defined(__WINDOWS__)
# include <boost/locale.hpp>
# endif
2022-04-14 22:12:59 +02:00
namespace Files
{
2022-06-19 13:28:33 +02:00
std : : unique_ptr < std : : ifstream > openBinaryInputFileStream ( const std : : filesystem : : path & path )
2022-04-14 22:12:59 +02:00
{
2022-06-16 00:28:41 +01:00
# if defined(_WIN32) || defined(__WINDOWS__)
std : : wstring wpath = boost : : locale : : conv : : utf_to_utf < wchar_t > ( path ) ;
auto stream = std : : make_unique < std : : ifstream > ( wpath , std : : ios : : binary ) ;
# else
2022-04-14 22:12:59 +02:00
auto stream = std : : make_unique < std : : ifstream > ( path , std : : ios : : binary ) ;
2022-06-16 00:28:41 +01:00
# endif
2022-04-14 22:12:59 +02:00
if ( ! stream - > is_open ( ) )
2022-06-19 13:28:33 +02:00
throw std : : runtime_error ( " Failed to open ' " + path . string ( ) + " ' for reading: " + std : : strerror ( errno ) ) ; //TODO(Project579): This will probably break in windows with unicode paths
2022-04-14 22:12:59 +02:00
stream - > exceptions ( std : : ios : : badbit ) ;
return stream ;
}
}