I'm using Allegro 4.2.1 and functiom get_config_string does not work for me. All others do ( int, float ).
string s = get_config_string( "Vars", "LogPath", "Not Read" );
s == "Not Read"
and I'm sure that section and value exist in my cfg.file ( LogPath = log.txt )
Anyone has any advice? Can this be a bug? Thanks.
No, it isn't a bug. Try this code, though.
set_config_string("Vars", "LogPath", "set value"); string s = get_config_string("Vars", "LogPath", "Not Read");
As tell me what the value is.
Yes... It works now. s == "set value"
Well... I guess problem is in file... but I have no idea where
Could you please explain it to me?
Can you provide the file as an attachment?
Here it is
http://www.members.allegro.cc/mscava/setup.cfg
( File also as an atachment... )
EDIT:
I see no difference between text generated by set_config_string and text written manually to notepad. Even non-visible characters are the same. Anyone has any idea what's wrong?
EDIT2: And I've found out, that it's not gonna read even file into which was written by set_config_string. Pls... help me someone...
try that.
string s.c_str() = get_config_string("Vars", "LogPath", "Not Read");
Edit:
for a lot of allegro fountions the string must be converted to a char string
Piccolo, that has nothing to do with the problem. And that would most probably crash the program.
I haven't done much work with the config routines. Try posting the relevant parts of your source.
for a lot of allegro fountions the string must be converted to a char string
Yes, when sending values in. But when assigning, string reads from char* just fine.
Here is my configuration function:
| 1 | void Setup :: |
| 2 | SetupAllFromFile ( const string& path ) |
| 3 | { |
| 4 | CfgFile :: SetCfgFile ( path ); |
| 5 | |
| 6 | string s = get_config_string("Vars", "LogPath", "Not Read"); |
| 7 | Log :: SetOutputFile ( s ); |
| 8 | |
| 9 | Log :: Write ( "WrapAll::Setup started initialization!" ); |
| 10 | |
| 11 | Setup :: InstallDevices(); |
| 12 | |
| 13 | Renderer :: RenderMode renderMode = static_cast <Renderer::RenderMode> |
| 14 | ( CfgFile::ReadInt ( "Gfx", "RenderMode" ) ); |
| 15 | Renderer :: WindowMode windowMode = static_cast <Renderer::WindowMode> |
| 16 | ( CfgFile::ReadBool ( "Gfx", "WindowMode" ) ); |
| 17 | |
| 18 | Renderer :: SetupScreen( CfgFile::ReadInt ( "Gfx", "ResolutionWidth" ), |
| 19 | CfgFile::ReadInt ( "Gfx", "ResolutionHeight" ), |
| 20 | CfgFile::ReadInt ( "Gfx", "ColorDepth" ), |
| 21 | windowMode, renderMode ); |
| 22 | |
| 23 | Updater :: Start ( CfgFile::ReadInt ( "Game", "TimerSpeed" ) ); |
| 24 | |
| 25 | FpsCounter :: Start( CfgFile::ReadBool ( "Misc", "ShowFps" ) ); |
| 26 | |
| 27 | Font :: InstallFont(); |
| 28 | } |
Everything gets initialized, only Log is associated with file 'Not Read'. Well it's the only string that is being loaded in this procedure, so I've tried even:
string s = get_config_string("Gfx", "ResolutionWidth", "Not Read"); Log :: SetOutputFile ( s );
But with the same result. Well... I'm attaching my Setup.cfg ( the file that is being read ), so someone else might try it.
I'm gonna do some more tests meanwhile... Hopefully I'm gonna find a solution.
Reading numbers etc work then? How does your CfgFile class look?
Yes. Reading numbers works.
Really simple wrapper. I want to to add functionality in the future...
class CfgFile { public: static void SetCfgFile ( const string& path ); static string ReadString ( const string& section, const string& name ); static int ReadInt ( const string& section, const string& name ); static float ReadFloat ( const string& section, const string& name ); static bool ReadBool ( const string& section, const string& name ); };
And now source file:
| 1 | void CfgFile :: |
| 2 | SetCfgFile ( const string& path ) |
| 3 | { |
| 4 | set_config_file ( path.c_str() ); |
| 5 | } |
| 6 | |
| 7 | string CfgFile :: |
| 8 | ReadString ( const string& section, const string& name ) |
| 9 | { |
| 10 | return string ( get_config_string( section.c_str(), name.c_str(), "Not Read" ) ); |
| 11 | } |
| 12 | |
| 13 | int CfgFile :: |
| 14 | ReadInt ( const string& section, const string& name ) |
| 15 | { |
| 16 | return get_config_int ( section.c_str(), name.c_str(), -1 ); |
| 17 | } |
| 18 | |
| 19 | float CfgFile :: |
| 20 | ReadFloat ( const string& section, const string& name ) |
| 21 | { |
| 22 | return get_config_float ( section.c_str(), name.c_str(), -1.0 ); |
| 23 | } |
| 24 | |
| 25 | bool CfgFile :: |
| 26 | ReadBool ( const string& section, const string& name ) |
| 27 | { |
| 28 | return ( static_cast <bool> ( get_config_int ( section.c_str(), name.c_str(), 0 ) ) ); |
| 29 | } |
In the example I didn't used ReadString, so I'm sure the problem is not in my class.
Well... Anyone tried to use my setup.cfg wheter it works. Or even tried to use get_config_string wheter it is not a bug?
I've tested your file and it works for me. Also I'm using the get_config_string(); function many times in my custom project and never had problems with it.
It's probably bug in your code, sorry.