Another UNICODE issue

If you found a bug in our library or on our website, please report it in this section. In this forum you can also make concrete suggestions or feature requests.

Moderators: CEGUI MVP, CEGUI Team

MarkR
Quite a regular
Quite a regular
Posts: 64
Joined: Thu Jul 15, 2010 06:55

Another UNICODE issue

Postby MarkR » Wed Jul 28, 2010 12:37

I already searched the forum, just to find hundreds of entries with "UNICODE", but not a single one about logfiles.

I'm working in a windows environment, where I want to store the logfiles within the directory %APPDATA%\MyApplication.
This works pretty well, as long as the username doesn't contain unicode characters.

I already tried receiving the target directory with 'SHGetFolderPathW(0, CSIDL_APPDATA, 0, SHGFP_TYPE_CURRENT, temppath);' and then converting it to an UTF-8 string, but this obviousy doesn't work, too.
The problem is, that std::ofstream takes its filename either as std::string (which obviously won't work with unicode characters in the path) or as std::wstring, which isn't supported by CEGUI::String.
I followed a few discussions concerning compatibility between CEGUI::String and std::wstring, but wouldn't it make sense at least to offer an alternative DefaultLogger::setLogFilename, taking an std::wstring?

Regards
- Mark

Jamarr
CEGUI MVP
CEGUI MVP
Posts: 812
Joined: Tue Jun 03, 2008 23:59
Location: USA

Re: Another UNICODE issue

Postby Jamarr » Wed Jul 28, 2010 19:38

As far as I know, CE has no intentions of supporting wchar_t or wstring. Anyway, windows already provides facilities for converting from multibyte to wide character, so you should not have any trouble converting to wstring. As far as the logger is concerned, you can easily derive a class from the DefaultLogger and add your own version of setLogFilename that takes a wstring parameter.

If you want CEGUI to support wchar_t/wstring natively then you will need provide an argument strong enough to convince CE to spend the time to implement it; or, you could implement it yourself and then contribute your work back to CEGUI ;)
If somebody helps you by replying to your thread, upvote him/her as a thanks! Make sure to include your CEGUI.log and everything you tried when posting! And remember that we are not magicians!

Timo
Not too shy to talk
Not too shy to talk
Posts: 24
Joined: Sun Feb 14, 2010 09:38

Re: Another UNICODE issue

Postby Timo » Thu Jul 29, 2010 02:11

I think that CEGUI should at least have support for unicode filenames on Windows. Yes, users can derive their own classes, but since unicode support is such a key requirement nowadays, this functionality should really be part of the CEGUI library.

Function arguments could still use CEGUI::String, but whenever there's stuff stuff like opening files, in Windows environment it would do the conversion to UTF-16. For example in the case of setLogFilename it could be something like this:

Code: Select all

#ifdef _MSC_VER
std::wstring utf16filename = ConvertFromUTF32ToUTF16(filename); //Implement a conversion function in the String class or use MultiByteToWideChar() or whatever.
d_ostream.open(utf16filename.c_str(), std::ios_base::out | (append ? std::ios_base::app : std::ios_base::trunc));
#else
d_ostream.open(filename.c_str(), std::ios_base::out | (append ? std::ios_base::app : std::ios_base::trunc));
#endif

Of course this is just for MSVC, and I have absolutely no idea about other windows compilers...

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Another UNICODE issue

Postby CrazyEddie » Thu Jul 29, 2010 08:43

I wish you guys would post version information. This support (for international chars in filenames) was added for the DefaultResourceProvider on 20th February (so it's in branches/v0-7, trunk and the snapshots). If this support is not working, is this a bug report, then?

I hope you guys now see the importance of posting the version of the code you're using ;)

CE.

MarkR
Quite a regular
Quite a regular
Posts: 64
Joined: Thu Jul 15, 2010 06:55

Re: Another UNICODE issue

Postby MarkR » Thu Jul 29, 2010 09:02

I'm using the trunk version from 10/06/21, Rev #2567

Manually checking the DefaultResourceProvider, I found out, that Unicode support is implemented there (did not look into it before, as I didn't have a problem with that so far) :-P

However, it's missing in the DefaultLogger Module.
Patch follows:

Code: Select all

diff --git a/cegui/src/CEGUIDefaultLogger.cpp b/cegui/src/CEGUIDefaultLogger.cpp
index f4b0ec1..f443806 100644
--- a/cegui/src/CEGUIDefaultLogger.cpp
+++ b/cegui/src/CEGUIDefaultLogger.cpp
@@ -31,6 +31,8 @@
 #include <ctime>
 #include <iomanip>
 
+std::wstring Utf8ToUtf16(const std::string& utf8text);
+
 // Start of CEGUI namespace section
 namespace CEGUI
 {
@@ -143,7 +145,11 @@ namespace CEGUI
             d_ostream.close();
         }
 
+#if defined(__WIN32__) || defined(_WIN32)
+        d_ostream.open(Utf8ToUtf16(filename.c_str()).c_str(), std::ios_base::out | (append ? std::ios_base::app : std::ios_base::trunc));
+#else
         d_ostream.open(filename.c_str(), std::ios_base::out | (append ? std::ios_base::app : std::ios_base::trunc));
+#endif
 
         if (!d_ostream)
         {

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Another UNICODE issue

Postby CrazyEddie » Thu Jul 29, 2010 11:42

Ah, I actually failed to notice your post did actually mention the logger - speed reading FTW! ... or not!

Thanks for the other info and patch. I'll take a look sometime over the coming weekend.

CE.

1337
Just popping in
Just popping in
Posts: 9
Joined: Tue Nov 04, 2008 22:54

Re: Another UNICODE issue

Postby 1337 » Thu May 12, 2011 04:20

I'm afraid to wake up this old thread.
But has the problem ever been dealt with? I'm using CEGUI 0.7.5 on Windows 7 and I still get the issue and the patch doesn't seem to be applied if I look at my CEGUI sources.

Do I have to implement my almost exact copy of the default logger then?

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Another UNICODE issue

Postby CrazyEddie » Sun May 15, 2011 19:39

I'm not sure what happened over that weekend, but if you say the change is not in, then I appear to have forgotten this.

I have added a ticket so that it's less likely to get lost in the future: http://www.cegui.org.uk/mantis/view.php?id=444

Thanks for the reminder :oops:

CE

1337
Just popping in
Just popping in
Posts: 9
Joined: Tue Nov 04, 2008 22:54

Re: Another UNICODE issue

Postby 1337 » Sun May 15, 2011 20:49

Thanks for taking care of it. And I see you've also had a look at my ticket about throwing a C-String in the very same class.

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Another UNICODE issue

Postby CrazyEddie » Mon May 16, 2011 07:34

I see you've also had a look at my ticket about throwing a C-String in the very same class.

Yeah, I saw that. It's a left-over from a time when i) We did not use std::exception either directly or as a base class, and ii) CEGUI::Exception always attempted to write to the log - preventing the use of CEGUI::Exception anywhere before / during Logger construction. Neither of these points are still true, so the exception throw will get updated for 0.8.0.

CE


Return to “Bug Reports, Suggestions, Feature Requests”

Who is online

Users browsing this forum: No registered users and 3 guests