Ogre读取中文路径名的文件失败的解决办法
2011-04-23 11:40
369 查看
Ogre的文件读取是使用的标准库的io库读取的,众所周知的是,在vs2005是存在着bug的。
因此想要一劳永逸的解决这个办法唯有去修改Ogre的源代码,以下为修改方法:
打开OgreFileSystem.cpp文件,找到FileSystemArchive::open方法,使用以下代码替换之:
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
static std::vector<wchar_t> s_wchar_buf((size_t)128);
size_t lengthUnicode = MultiByteToWideChar(CP_ACP, 0, full_path.c_str(), full_path.size(), NULL, 0);
if (s_wchar_buf.size() < lengthUnicode + 1)
s_wchar_buf.resize(lengthUnicode * 2);
}
wchar_t* szUnicode = &s_wchar_buf[0];
MultiByteToWideChar(CP_ACP, 0, full_path.c_str(), full_path.size(), szUnicode, lengthUnicode);
szUnicode[lengthUnicode] = 0;
std::ifstream* origStream = new std::ifstream();
origStream->open(szUnicode, std::ios::in | std::ios::binary);
// Should check ensure open succeeded, in case fail for some reason.
if (origStream->fail())
delete origStream;
OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND,
"Cannot open file: " + filename,
"FileSystemArchive::open");
}
/**//// Construct return stream, tell it to delete on destroy
FileStreamDataStream* stream = new FileStreamDataStream(filename,
origStream, tagStat.st_size, true);
return DataStreamPtr(stream);
}
posted on 2008-12-09 03:42 杨粼波 阅读(957) 评论(2) 编辑 收藏 引用
//Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tAjaxHolder$UpdatePanel1'], [], [], 90);
//]]>
用setlocale(LC_ALL,"Chinese-simplified");就可以了。 回复 更多评论
# re: Ogre读取中文路径名的文件失败的解决办法[未登录] 2010-09-12 00:56 杨粼波
你知道setlocale这个方法的代价有多大么?会带来什么影响么? 回复 更多评论
因此想要一劳永逸的解决这个办法唯有去修改Ogre的源代码,以下为修改方法:
打开OgreFileSystem.cpp文件,找到FileSystemArchive::open方法,使用以下代码替换之:
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
static std::vector<wchar_t> s_wchar_buf((size_t)128);
size_t lengthUnicode = MultiByteToWideChar(CP_ACP, 0, full_path.c_str(), full_path.size(), NULL, 0);
if (s_wchar_buf.size() < lengthUnicode + 1)
s_wchar_buf.resize(lengthUnicode * 2);
}
wchar_t* szUnicode = &s_wchar_buf[0];
MultiByteToWideChar(CP_ACP, 0, full_path.c_str(), full_path.size(), szUnicode, lengthUnicode);
szUnicode[lengthUnicode] = 0;
std::ifstream* origStream = new std::ifstream();
origStream->open(szUnicode, std::ios::in | std::ios::binary);
// Should check ensure open succeeded, in case fail for some reason.
if (origStream->fail())
delete origStream;
OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND,
"Cannot open file: " + filename,
"FileSystemArchive::open");
}
/**//// Construct return stream, tell it to delete on destroy
FileStreamDataStream* stream = new FileStreamDataStream(filename,
origStream, tagStat.st_size, true);
return DataStreamPtr(stream);
}
posted on 2008-12-09 03:42 杨粼波 阅读(957) 评论(2) 编辑 收藏 引用
//Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tAjaxHolder$UpdatePanel1'], [], [], 90);
//]]>
Feedback
# re: Ogre读取中文路径名的文件失败的解决办法 2010-09-05 19:16 风生竹韵用setlocale(LC_ALL,"Chinese-simplified");就可以了。 回复 更多评论
# re: Ogre读取中文路径名的文件失败的解决办法[未登录] 2010-09-12 00:56 杨粼波
你知道setlocale这个方法的代价有多大么?会带来什么影响么? 回复 更多评论
相关文章推荐
- 转载:ogre无法读取中文路径的解决办法
- ogre无法读取中文路径的解决办法
- ogre无法读取中文路径的解决办法
- 有时候用ifstream或ofstream打开带有中文路径的文件会失败。 解决办法
- Pandas读取路径或文件名称包含中文的文件时报错及解决办法
- Python在使用FTP下载上传文件时遇到中文名称和路径时的解决办法
- Java 读取文件 使用BufferReader出现中文乱码的解决办法
- 解决OpenCV的imread函数无法读取中文路径和中文命名的文件的问题。
- 关于ORA-01187:由于验证测试失败而无法从文件 201 读取的解决办法
- hadoop读取hdfs文件中的中文乱码解决办法
- 解决Java读取properties文件的中文问题的新办法(不使用native2ascii.exe及其他工具)
- JAVA学习提高之---- Java读取文件中含有中文的解决办法
- Java读取文件中含有中文的解决办法
- 【Android】连接网络读取文件内容中文乱码解决办法
- C# 读取含中文字符的数据,失败原因,和解决办法
- [转]GDAL1.9.0版本编译后,打不开含中文路径文件的解决办法
- SpringMVC--上传功能失败,控制台提示找不到文件临时路径(解决办法)
- java读取文件内容(中文文件解决办法)
- 用convert把FAT32转换NTFS失败出现文件或目录损坏且无法读取——解决办法
- Java读取文件中含有中文的解决办法