|
problem loading config file again |
William Labbett
Member #4,486
March 2004
|
With regards to this post : https://www.allegro.cc/forums/thread/615390 I don't know why now but for some reason I thought I'd solved the issue. I've recently used the project mentioned in the post as a template for another project and have come up with the same problem. Here's my directory structure : {"name":"609476","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/1\/11b909a366c48e6565e096f63be09d60.png","w":861,"h":465,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/1\/11b909a366c48e6565e096f63be09d60"} {"name":"609477","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/1\/91b05884ab04f5868c8b2d0827e19fc2.png","w":739,"h":179,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/1\/91b05884ab04f5868c8b2d0827e19fc2"} Here's the code for loading the .cfg file. 1class ConfigManagerClass
2{
3
4 ALLEGRO_CONFIG *cfg;
5
6 int init_okay_flag;
7
8 public:
9
10 ConfigManagerClass() : cfg(NULL)
11 {
12
13
14 }
15
16 void load_config_file(const char *filename, Rabbit_Log& log)
17 {
18 cfg = al_load_config_file(filename);
19
20 log.write_message_number();
21 log.write_string("About to load configuration file (");
22 log.write_string(filename);
23 log.write_string(").");
24 log.end_message();
25
26 log.write_message_number();
27 if( cfg == NULL )
28 {
29 log.write_string("Failed to load it.");
30 init_okay_flag = RED_FLAG;
31
32 }
33 else
34 {
35 log.write_string("Loaded it successfully.");
36 init_okay_flag = GREEN_FLAG;
37
38 }
39 log.end_message();
40
41 }
42
43 int get_integer(const char *key, int *integer_to_get)
44 {
45 const char *string = NULL;
46
47 string = al_get_config_value( cfg, NULL, "p1");
48
49 if(string == NULL)
50 {
51 return ERROR_1;
52 }
53 else
54 {
55 return atoi(string);
56 }
57
58 }
59
60
61 int init_okay()
62 {
63 return init_okay_flag;
64 }
65
66};
Here's where the loading function is called from : /***************** End of Section *************************************/ /**********************************************************************/ /**************** Section : load configuration file. ******************/ /**********************************************************************/ config_manager.load_config_file("configuration/no_ap_3_configuration_file.cfg", log); if(config_manager.init_okay() != GREEN_FLAG) { /* add clear up code */ return 0; } Here's the log file : MESSAGE : 0 : Log file opened. I hope someone can help
|
raynebc
Member #11,908
May 2010
|
One thing to try is to load the full (not relative) path to your config file: If this works, it's probably that the current working directory isn't as you expect it to be (the program's directory) or it's having problems using the forward slashes as the directory separator instead of backslashes. I thought Windows/Allegro handled the difference between forward and backward slashes nicely, but you'd still want to rule it out. |
William Labbett
Member #4,486
March 2004
|
I've tried both of those but the file still doesn't load.
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
raynebc said:
One thing to try is to load the full (not relative) path to your config file: If he used that path directly there would be a problem, since backslash is the escape character. Try using forward slashes and the full path. If that doesn't work, post your configuration file so others can try it. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
raynebc
Member #11,908
May 2010
|
He could use \\ for each backslash, it's not much of an issue. Allegro 4 had a put_backslash() function to append the appropriate folder separator for whatever platform was running, I don't know if A5 has an equivalent function. |
William Labbett
Member #4,486
March 2004
|
Muchas gracias, amigos. Changed the code to this :- /***************** End of Section *************************************/ /**********************************************************************/ /**************** Section : load configuration file. ******************/ /**********************************************************************/ config_manager.load_config_file("configuration\\no_ap_3_configuration_file.cfg", log); if(config_manager.init_okay() != GREEN_FLAG) { /* add clear up code */ return 0; } New output file :- MESSAGE : 0 : Log file opened. \no_ap_3_configuration_file.cfg). /* config file attached */ I could upload the whole project if need be.
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
I can load the config file you uploaded without problems. You must have a problem with the current working directory. You can check the cwd with this : printf("Working directory is '%s'\n" , al_get_current_directory()); And you can set the cwd to the directory your exe is in by using this : ALLEGRO_PATH* exepath = al_get_standard_path(ALLEGRO_EXENAME_PATH); al_set_path_filename(exepath , NULL); al_change_directory(al_path_cstr(exepath , ALLEGRO_NATIVE_PATH_SEP)); al_destroy_path(exepath); // ALLEGRO_CONFIG* config = al_load_config_file("test.cfg"); // printf("%s config file\n" , config?"Loaded ":"Failed to load "); Just replace test.cfg with your cfg file. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
William Labbett
Member #4,486
March 2004
|
Thanks Edgar. I've followed all the advice and still it won't load. Shall I zip the project
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Make a copy of your config file named test.cfg and try this first. Run your executable from any directory and put the test.cfg file next to it. 1
2#include "allegro5/allegro.h"
3#include <cstdio>
4
5int main()
6{
7 al_init();
8
9 ALLEGRO_PATH* exepath = al_get_standard_path(ALLEGRO_EXENAME_PATH);
10 al_set_path_filename(exepath , NULL);
11 al_change_directory(al_path_cstr(exepath , ALLEGRO_NATIVE_PATH_SEP));
12 printf("Changing to directory '%s'\n" , al_path_cstr(exepath , ALLEGRO_NATIVE_PATH_SEP));
13 al_destroy_path(exepath);
14
15 ALLEGRO_CONFIG* config = al_load_config_file("test.cfg");
16 printf("%s config file\n" , config?"Loaded ":"Failed to load ");
17
18 return 0;
19}
If that doesn't work by itself, then there is something wrong with your version of allegro. If it does work, there is something wrong with the way you are calling al_load_config_file or your cwd is wrong. Post the output of the code above. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Thomas Fjellstrom
Member #476
June 2000
|
He is using physfs, maybe he isn't setting up the location the config file is in with physfs? -- |
William Labbett
Member #4,486
March 2004
|
I'm going to try tomasu's suggestion (hoping that someone will respond to this post so that I can keep y'all up to date).
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Thomas Fjellstrom said: He is using physfs, maybe he isn't setting up the location the config file is in with physfs? Oh, okay. Didn't see that. That could definitely affect the way the config file is being loaded. William, please show us where you are setting up PhysFS and its search directories. Or something else you can try is resetting the file interface before loading your config file. It would defeat the purpose of using physfs, but it should tell you if the basic config file loading is working or not. Try calling al_set_standard_file_interface(); before loading the config file. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|