Page 1 of 1

ogre cannot open file with multibyte

Posted: Thu Dec 17, 2009 6:23 am
by oiram
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.

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);
    }
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.

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);
env is vs2005 sp1 + ogre 1.6.4 + xp english.

any advice? :P

Re: ogre cannot open file with multibyte

Posted: Fri Dec 18, 2009 3:43 am
by oiram
I'm quite sad I got no answer to my post :cry:

Re: ogre cannot open file with multibyte

Posted: Fri Dec 18, 2009 4:23 pm
by jacmoe
You don't deserve answers when you double-post.
Don't do it. :evil:

I removed your double in Developers.

Re: ogre cannot open file with multibyte

Posted: Fri Dec 18, 2009 4:26 pm
by jacmoe

Re: ogre cannot open file with multibyte

Posted: Fri Dec 18, 2009 4:47 pm
by oiram
your reply so fast...
i remember that... sorry :cry:

Re: ogre cannot open file with multibyte

Posted: Tue Dec 22, 2009 5:32 pm
by sinbad
We'll probably never support multibyte characters this way, we're just not a text-oriented library. Except for DisplayString (which is UTF), none of the text gets displayed to the user anyway. Ogre's resource system is designed for speed, not language support, I suggest you use another approach for reading your multilingual text.

Re: ogre cannot open file with multibyte

Posted: Sun Dec 27, 2009 7:44 pm
by luis
Oiram, I'm using multibyte in INI files using Ogre::ConfigFile with no problems. Just open a TXT file and set it to "UTF-8 without BOM" save and read as always.
I think you don't need ogre resource system.