ogre cannot open file with multibyte

What it says on the tin: a place to discuss proposed new features.
Post Reply
oiram
Halfling
Posts: 87
Joined: Sun Dec 13, 2009 5:06 am
x 6

ogre cannot open file with multibyte

Post 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
oiram
Halfling
Posts: 87
Joined: Sun Dec 13, 2009 5:06 am
x 6

Re: ogre cannot open file with multibyte

Post by oiram »

I'm quite sad I got no answer to my post :cry:
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: ogre cannot open file with multibyte

Post by jacmoe »

You don't deserve answers when you double-post.
Don't do it. :evil:

I removed your double in Developers.
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Re: ogre cannot open file with multibyte

Post by jacmoe »

/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.
oiram
Halfling
Posts: 87
Joined: Sun Dec 13, 2009 5:06 am
x 6

Re: ogre cannot open file with multibyte

Post by oiram »

your reply so fast...
i remember that... sorry :cry:
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Re: ogre cannot open file with multibyte

Post 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.
User avatar
luis
Greenskin
Posts: 122
Joined: Tue Mar 02, 2004 3:33 pm
Location: Spain / Argentina
x 7
Contact:

Re: ogre cannot open file with multibyte

Post 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.
Post Reply