BinObj code uses wide-strings on Windows.

This commit is contained in:
James Turner
2017-02-07 16:05:06 +00:00
parent b93b362e2f
commit 48b7b70e23
+21 -10
View File
@@ -94,6 +94,17 @@ enum sgVertexAttributeTypes {
SG_VA_FLOAT_3 = 0x00000800, SG_VA_FLOAT_3 = 0x00000800,
}; };
static gzFile gzFileFromSGPath(const SGPath& path, const char* mode)
{
#if defined(SG_WINDOWS)
std::wstring ws = path.wstr();
return gzopen_w(ws.c_str(), mode);
#else
std::string ps = path.utf8Str();
return gzopen(ps.c_str(), mode);
#endif
}
enum sgPropertyTypes { enum sgPropertyTypes {
SG_MATERIAL = 0, SG_MATERIAL = 0,
SG_INDEX_TYPES = 1, SG_INDEX_TYPES = 1,
@@ -534,15 +545,16 @@ bool SGBinObject::read_bin( const SGPath& file ) {
fans_vas.clear(); fans_vas.clear();
fan_materials.clear(); fan_materials.clear();
gzFile fp; gzFile fp = gzFileFromSGPath(file, "rb");
string f = file.local8BitStr(); if ( fp == NULL ) {
if ( (fp = gzopen( f.c_str(), "rb" )) == NULL ) { SGPath withGZ = file;
string filegz = f + ".gz"; withGZ.concat(".gz");
if ( (fp = gzopen( filegz.c_str(), "rb" )) == NULL ) { fp = gzFileFromSGPath(withGZ, "rb");
if (fp == nullptr) {
SG_LOG( SG_EVENT, SG_ALERT, SG_LOG( SG_EVENT, SG_ALERT,
"ERROR: opening " << file << " or " << filegz << " for reading!"); "ERROR: opening " << file << " or " << withGZ << " for reading!");
throw sg_io_exception("Error opening for reading (and .gz)", sg_location(f)); throw sg_io_exception("Error opening for reading (and .gz)", sg_location(file));
} }
} }
@@ -957,9 +969,8 @@ bool SGBinObject::write_bin_file(const SGPath& file)
SGPath file2(file); SGPath file2(file);
file2.create_dir( 0755 ); file2.create_dir( 0755 );
gzFile fp; gzFile fp = gzFileFromSGPath(file, "wb9");
std::string localPath = file.local8BitStr(); if ( fp == nullptr ) {
if ( (fp = gzopen( localPath.c_str(), "wb9" )) == NULL ) {
cout << "ERROR: opening " << file << " for writing!" << endl; cout << "ERROR: opening " << file << " for writing!" << endl;
return false; return false;
} }