ogre cannot open file with multibyte
Posted: Thu Dec 17, 2009 6:23 am
when open file with multibyte char (like chinese) in its location, ogre filesystem will throw exception.
attached code is how ogre open file for r/w.
if i change page code to locale then it's fine but worse when output integer or float like "1000" will change to "1,000". so page code must be restored when file opened.
env is vs2005 sp1 + ogre 1.6.4 + xp english.
any advice?
attached code is how ogre open file for r/w.
Code: Select all
DataStreamPtr FileSystemArchive::open(const String& filename) const
{
String full_path = concatenate_path(mName, filename);
// Use filesystem to determine size
// (quicker than streaming to the end and back)
struct stat tagStat;
int ret = stat(full_path.c_str(), &tagStat);
assert(ret == 0 && "Problem getting file size" );
// Always open in binary mode
std::ifstream *origStream = OGRE_NEW_T(std::ifstream, MEMCATEGORY_GENERAL)();
origStream->open(full_path.c_str(), std::ios::in | std::ios::binary);
// Should check ensure open succeeded, in case fail for some reason.
if (origStream->fail())
{
OGRE_DELETE_T(origStream, basic_ifstream, MEMCATEGORY_GENERAL);
OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND,
"Cannot open file: " + filename,
"FileSystemArchive::open");
}
/// Construct return stream, tell it to delete on destroy
FileStreamDataStream* stream = OGRE_NEW FileStreamDataStream(filename,
origStream, tagStat.st_size, true);
return DataStreamPtr(stream);
}
Code: Select all
std::locale saveLocal = std::locale::global(std::locale(""));
origStream->open(full_path.c_str(), std::ios::in | std::ios::binary);
std::locale::global(saveLocal);
any advice?