Page 1 of 1

Another UNICODE issue

Posted: Wed Jul 28, 2010 12:37
by MarkR
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

Re: Another UNICODE issue

Posted: Wed Jul 28, 2010 19:38
by Jamarr
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 ;)

Re: Another UNICODE issue

Posted: Thu Jul 29, 2010 02:11
by Timo
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...

Re: Another UNICODE issue

Posted: Thu Jul 29, 2010 08:43
by CrazyEddie
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.

Re: Another UNICODE issue

Posted: Thu Jul 29, 2010 09:02
by MarkR
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)
         {

Re: Another UNICODE issue

Posted: Thu Jul 29, 2010 11:42
by CrazyEddie
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.

Re: Another UNICODE issue

Posted: Thu May 12, 2011 04:20
by 1337
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?

Re: Another UNICODE issue

Posted: Sun May 15, 2011 19:39
by CrazyEddie
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

Re: Another UNICODE issue

Posted: Sun May 15, 2011 20:49
by 1337
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.

Re: Another UNICODE issue

Posted: Mon May 16, 2011 07:34
by CrazyEddie
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