2022-04-14 20:12:59 +00:00
# include "openfile.hpp"
# include <cstring>
# include <fstream>
2022-06-15 23:28:41 +00:00
# if defined(_WIN32) || defined(__WINDOWS__)
# include <boost/locale.hpp>
# endif
2022-04-14 20:12:59 +00:00
namespace Files
{
2022-06-19 11:28:33 +00:00
std : : unique_ptr < std : : ifstream > openBinaryInputFileStream ( const std : : filesystem : : path & path )
2022-04-14 20:12:59 +00:00
{
2022-06-15 23:28:41 +00: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 20:12:59 +00:00
auto stream = std : : make_unique < std : : ifstream > ( path , std : : ios : : binary ) ;
2022-06-15 23:28:41 +00:00
# endif
2022-04-14 20:12:59 +00:00
if ( ! stream - > is_open ( ) )
2022-06-19 11:28:33 +00: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 20:12:59 +00:00
stream - > exceptions ( std : : ios : : badbit ) ;
return stream ;
}
}