Ogre读取中文路径名的文件失败的解决办法

简介:
Ogre的文件读取是使用的标准库的io库读取的,众所周知的是,在vs2005是存在着bug的。
因此想要一劳永逸的解决这个办法唯有去修改Ogre的源代码,以下为修改方法:

打开OgreFileSystem.cpp文件,找到FileSystemArchive::open方法,使用以下代码替换之:
None.gifDataStreamPtr FileSystemArchive::open( const String& filename)  const
ExpandedBlockStart.gif     {
InBlock.gif        String full_path = concatenate_path(mName, filename);
InBlock.gif
InBlock.gif        // Use filesystem to determine size 
InBlock.gif        
// (quicker than streaming to the end and back)
InBlock.gif
        struct stat tagStat;
InBlock.gif        int ret = stat(full_path.c_str(), &tagStat);
InBlock.gif        assert(ret == 0 && "Problem getting file size" );
InBlock.gif
InBlock.gif        // Always open in binary mode
InBlock.gif
        static std::vector<wchar_t>    s_wchar_buf((size_t)128);
InBlock.gif        size_t lengthUnicode = MultiByteToWideChar(CP_ACP, 0, full_path.c_str(), full_path.size(), NULL, 0);
InBlock.gif        if (s_wchar_buf.size() < lengthUnicode + 1)
ExpandedSubBlockStart.gif        {
InBlock.gif            s_wchar_buf.resize(lengthUnicode * 2);
ExpandedSubBlockEnd.gif        }

InBlock.gif        wchar_t* szUnicode = &s_wchar_buf[0];
InBlock.gif        MultiByteToWideChar(CP_ACP, 0, full_path.c_str(), full_path.size(), szUnicode, lengthUnicode);
InBlock.gif        szUnicode[lengthUnicode] = 0;
InBlock.gif        std::ifstream* origStream = new std::ifstream();
InBlock.gif        origStream->open(szUnicode, std::ios::in | std::ios::binary);
InBlock.gif
InBlock.gif        // Should check ensure open succeeded, in case fail for some reason.
InBlock.gif
        if (origStream->fail())
ExpandedSubBlockStart.gif        {
InBlock.gif            delete origStream;
InBlock.gif            OGRE_EXCEPT(Exception::ERR_FILE_NOT_FOUND,
InBlock.gif                "Cannot open file: " + filename,
InBlock.gif                "FileSystemArchive::open");
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gif        /// Construct return stream, tell it to delete on destroy
InBlock.gif        FileStreamDataStream* stream = new FileStreamDataStream(filename,
InBlock.gif            origStream, tagStat.st_size, true);
InBlock.gif        return DataStreamPtr(stream);
ExpandedBlockEnd.gif    }
目录
相关文章
|
13天前
|
C++ 计算机视觉 Windows
【C++】由于找不到xxx.dll,无法继续执行代码,重新安装程序可能会解决此问题。(解决办法)
【C++】由于找不到xxx.dll,无法继续执行代码,重新安装程序可能会解决此问题。(解决办法)
|
C# C++
GDAL打开中文路径和读写中文字段的问题
版权声明:欢迎评论和转载,转载请注明来源。 https://blog.csdn.net/zy332719794/article/details/40394839 GDAL不同的版本对中文的默认支持不一,有时候默认支持,有时候需要自己去设置。
1627 0
|
4月前
|
定位技术 Python
Python依据某一文件夹中大量文件的名称复制另一文件夹中的同名文件
Python依据某一文件夹中大量文件的名称复制另一文件夹中的同名文件
|
4月前
|
存储 C#
【Untiy 3D】C#中文件夹与读写文件操作详解(附测试代码 超详细)
【Untiy 3D】C#中文件夹与读写文件操作详解(附测试代码 超详细)
35 0
|
11月前
|
Python
Python 使用pyinstaller打包程序失败提示找不到c盘的某个dll文件解决方法,FileNotFoundError: [WinError 2] 系统找不到指定的文件
Python 使用pyinstaller打包程序失败提示找不到c盘的某个dll文件解决方法,FileNotFoundError: [WinError 2] 系统找不到指定的文件
188 0
|
程序员
win10怎么改文件后缀名格式(win10怎么显示修改文件扩展名)
win10怎么改文件后缀名格式(win10怎么显示修改文件扩展名)
676 0
编译好的编译ffmpeg又出错:更改输出目录产生各种古怪错误
编译好的编译ffmpeg又出错:更改输出目录产生各种古怪错误
71 0
|
编解码 Python
Geany导入带有中文字符的.py文件然后执行报错解决办法
Geany导入带有中文字符的.py文件然后执行报错解决办法
154 0
Geany导入带有中文字符的.py文件然后执行报错解决办法
|
C#
C# .Resx文件无效解决方案 Resx文件报错解决方法
C# .Resx文件无效解决方案 Resx文件报错解决方法
582 7
C# .Resx文件无效解决方案 Resx文件报错解决方法
IDEA提示CreateProcess error=206, 文件名或扩展名太长。
在使用IDEA运行一个测试类是,提示错误 > CreateProcess error=206, 文件名或扩展名太长。
1527 0
IDEA提示CreateProcess error=206, 文件名或扩展名太长。