![]() |
|
Can't modify config file |
Emily Brace
Member #16,568
October 2016
|
Hello! I have some code to check if there's a config file and if there isn't, it will create one, simple stuff. I can then read from the file just fine, but when I try to set values and then save, the save fails. Here's some of my code. // Outside of main() ALLEGRO_CONFIG* config; // Inside of main() config = al_load_config_file("config.ini"); // This works just fine value = al_get_config_value(config, "blah" "blah"); // But this doesn't :c al_set_config_value(config, "blah", "blah", "blah"); // This returns false and the file isn't changed al_save_config_file("config.ini", config);
Not sure what I'm doing wrong. Meow :3 |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Hey Emily, Here are a few things to try. 1. Is the file read-only? Save would fail in that case. 2. Have you compiled in debug mode or release mode with debugging info and checked allegro.log for clues? 3. Have you tried saving as a different file? 4. How do you know al_set_config_value has failed? Have you checked it with al_get_config_value? 5. What version of Allegro 5 are you using? If it's a bug, it may have been fixed by now. 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 |
Emily Brace
Member #16,568
October 2016
|
1. 2. 3. 4. 5. Meow :3 |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
al_save_config_file only fails in a couple of cases. One, where the files fails to be created, to be saved, or to be closed. Two, where there is an error in the file stream. allegro.log will be created in the same folder as your program if the version of allegro you linked to has debugging logs enabled. Your best bet is to debug this yourself. Set a breakpoint in config.c:433, and then check the return values of retsave and retclose and see if there was an error. If the breakpoint isn't triggered, then the file couldn't be created. If retsave is false, then set a breakpoint in al_save_config_file_f and step through the function checking return values. I can give you a short tutorial on debugging with gdb if you need help. Can you provide a small test case that fails for you? And provide the config file and source file you're using? That way I can test it out on my machine and see if it works for me or not. 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 |
Emily Brace
Member #16,568
October 2016
|
I tried recompiling Allegro with WANT_RELEASE_LOGGING, but no log is being created. Just to be clear, I'm trying to update an already created config file. A workaround could be to remove the file and create it again if it's needed... EDIT: Tried removing the file and write it again like this and it removes the file, but doesn't write it again ifstream fileCheck("config.ini"); if (fileCheck.good()) { fileCheck.close(); remove("engine.ini"); ALLEGRO_CONFIG* config = al_create_config(); al_set_config_value(config, "Blah", "Bloh", "Bleh"); al_set_config_value(config, "Blah", "Bleh", "Bloh"); al_save_config_file("engine.ini", config); }
Meow :3 |
SiegeLord
Member #7,827
October 2006
![]() |
You're calling this after al_init, right? "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Emily Brace
Member #16,568
October 2016
|
Yes, I can create it just fine, just not modify it afterwards. EDIT: Yup, after initializing PhysFS, you can't save config files, since PhysFS doesn't support writing to zip files. Not sure if bug or not though. Meow :3 |
SiegeLord
Member #7,827
October 2006
![]() |
You can probably configure PhysFS to be able to save outside the zip file if you mount a real directory. Alternatively, you could call al_set_standard_file_interface() before saving your config file and then restoring it with al_set_physfs_file_interface(). "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
As an aside, I think 7-zip has an API that lets you write to archive files. If we wrote a file system driver for 7-zip, what you're trying to do could be done. And 7-zip supports MANY different formats. 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 |
Emily Brace
Member #16,568
October 2016
|
Well, that would also be cool, but the point was never to write to the zip file itself. The issue was just that it tried to do that and that was why it failed. Meow :3 |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
That's why it's always best to try and provide a minimum, complete, verifiable example (MCVE like Stack Overflow likes to call it), so others can try to reproduce it and so we can see everything that's going on. I would never have guessed you were using PhysFS from what you showed us. 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 |
Emily Brace
Member #16,568
October 2016
|
Good point, although, I wouldn't have thought of including that code either way xd Meow :3 |
Elias
Member #358
May 2000
|
I wonder if we should provide a function al_set_physfs_file_interface_read_only. But then when you try and read your config file it still would try to read from the .zip - I guess it has to be the user's responsibility to set the file interface they want to use. -- |
Emily Brace
Member #16,568
October 2016
|
Or some version of the function that excludes config files :p Meow :3 |
|