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

ogre cannot open file with multibyte

Post by oiram » 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.

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
0 x

oiram
Halfling
Posts: 87
Joined: Sun Dec 13, 2009 5:06 am

Re: ogre cannot open file with multibyte

Post by oiram » Fri Dec 18, 2009 3:43 am

I'm quite sad I got no answer to my post :cry:
0 x

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Re: ogre cannot open file with multibyte

Post by jacmoe » Fri Dec 18, 2009 4:23 pm

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

I removed your double in Developers.
0 x
/* 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
Contact:

Re: ogre cannot open file with multibyte

Post by jacmoe » Fri Dec 18, 2009 4:26 pm

0 x
/* 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

Re: ogre cannot open file with multibyte

Post by oiram » Fri Dec 18, 2009 4:47 pm

your reply so fast...
i remember that... sorry :cry:
0 x

User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19261
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
Contact:

Re: ogre cannot open file with multibyte

Post by sinbad » Tue Dec 22, 2009 5:32 pm

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.
0 x

User avatar
luis
Greenskin
Posts: 109
Joined: Tue Mar 02, 2004 3:33 pm
Location: Spain / Argentina
x 2
Contact:

Re: ogre cannot open file with multibyte

Post by luis » Sun Dec 27, 2009 7:44 pm

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.
0 x

Post Reply