<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Can&#39;t modify config file</title>
		<link>http://www.allegro.cc/forums/view/616549</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 27 Oct 2016 19:57:29 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello!</p><p>I have some code to check if there&#39;s a config file and if there isn&#39;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.</p><p>Here&#39;s some of my code.<br />I first load the config file in the beginning of my code
</p><div class="source-code snippet"><div class="inner"><pre><span class="c">// Outside of main()</span>
<a href="http://www.allegro.cc/manual/ALLEGRO_CONFIG"><span class="a">ALLEGRO_CONFIG</span></a><span class="k3">*</span> config<span class="k2">;</span>
<span class="c">// Inside of main()</span>
config <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_config_file"><span class="a">al_load_config_file</span></a><span class="k2">(</span><span class="s">"config.ini"</span><span class="k2">)</span><span class="k2">;</span>
<span class="c">// This works just fine</span>
value <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_config_value"><span class="a">al_get_config_value</span></a><span class="k2">(</span>config, <span class="s">"blah"</span> <span class="s">"blah"</span><span class="k2">)</span><span class="k2">;</span>
<span class="c">// But this doesn't :c</span>
<a href="http://www.allegro.cc/manual/al_set_config_value"><span class="a">al_set_config_value</span></a><span class="k2">(</span>config, <span class="s">"blah"</span>, <span class="s">"blah"</span>, <span class="s">"blah"</span><span class="k2">)</span><span class="k2">;</span>
<span class="c">// This returns false and the file isn't changed</span>
<a href="http://www.allegro.cc/manual/al_save_config_file"><span class="a">al_save_config_file</span></a><span class="k2">(</span><span class="s">"config.ini"</span>, config<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Not sure what I&#39;m doing wrong.<br />Thanks! <img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Emily Brace)</author>
		<pubDate>Wed, 26 Oct 2016 00:59:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hey Emily,</p><p>Here are a few things to try.</p><p>1. Is the file read-only? Save would fail in that case.</p><p>2. Have you compiled in debug mode or release mode with debugging info and checked allegro.log for clues?</p><p>3. Have you tried saving as a different file?</p><p>4. How do you know al_set_config_value has failed? Have you checked it with al_get_config_value?</p><p>5. What version of Allegro 5 are you using? If it&#39;s a bug, it may have been fixed by now.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 26 Oct 2016 01:24:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>1.<br />No, it can create the file just fine.</p><p>2.<br />Tried compiling in debug mode. Where can I find allegro.log?</p><p>3.<br />Yes, and that also fails.</p><p>4.<br />Sorry that I was unclear. Meant that al_save_config_file failed. If I try to check the value before and after, the value changes.</p><p>5.<br />Running Allegro 5.2.1.1
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Emily Brace)</author>
		<pubDate>Wed, 26 Oct 2016 01:33:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><span class="source-code"><a href="http://www.allegro.cc/manual/al_save_config_file"><span class="a">al_save_config_file</span></a></span> 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.</p><p>allegro.log will be created in the same folder as your program if the version of allegro you linked to has debugging logs enabled.</p><p>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&#39;t triggered, then the file couldn&#39;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.</p><p>I can give you a short tutorial on debugging with gdb if you need help.</p><p>Can you provide a small test case that fails for you? And provide the config file and source file you&#39;re using? That way I can test it out on my machine and see if it works for me or not.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 26 Oct 2016 01:56:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I tried recompiling Allegro with WANT_RELEASE_LOGGING, but no log is being created.<br />I&#39;ll see what I can figure out...</p><p>Just to be clear, I&#39;m trying to update an already created config file. A workaround could be to remove the file and create it again if it&#39;s needed...</p><p>EDIT: Tried removing the file and write it again like this and it removes the file, but doesn&#39;t write it again
</p><div class="source-code snippet"><div class="inner"><pre>ifstream fileCheck<span class="k2">(</span><span class="s">"config.ini"</span><span class="k2">)</span><span class="k2">;</span>
<span class="k1">if</span> <span class="k2">(</span>fileCheck.good<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
<span class="k2">{</span>
  fileCheck.close<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
  <a href="http://www.delorie.com/djgpp/doc/libc/libc_659.html" target="_blank">remove</a><span class="k2">(</span><span class="s">"engine.ini"</span><span class="k2">)</span><span class="k2">;</span>

  <a href="http://www.allegro.cc/manual/ALLEGRO_CONFIG"><span class="a">ALLEGRO_CONFIG</span></a><span class="k3">*</span> config <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_config"><span class="a">al_create_config</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
  <a href="http://www.allegro.cc/manual/al_set_config_value"><span class="a">al_set_config_value</span></a><span class="k2">(</span>config, <span class="s">"Blah"</span>, <span class="s">"Bloh"</span>, <span class="s">"Bleh"</span><span class="k2">)</span><span class="k2">;</span>
  <a href="http://www.allegro.cc/manual/al_set_config_value"><span class="a">al_set_config_value</span></a><span class="k2">(</span>config, <span class="s">"Blah"</span>, <span class="s">"Bleh"</span>, <span class="s">"Bloh"</span><span class="k2">)</span><span class="k2">;</span>

  <a href="http://www.allegro.cc/manual/al_save_config_file"><span class="a">al_save_config_file</span></a><span class="k2">(</span><span class="s">"engine.ini"</span>, config<span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Emily Brace)</author>
		<pubDate>Wed, 26 Oct 2016 04:32:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You&#39;re calling this after <span class="source-code"><a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a></span>, right?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Wed, 26 Oct 2016 05:16:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes, I can create it just fine, just not modify it afterwards.<br />I&#39;m using various other Allegro stuff for graphics etc. so I know it&#39;s working.<br />Dunno if PhysFS is messing stuff up though.</p><p>EDIT: Yup, after initializing PhysFS, you can&#39;t save config files, since PhysFS doesn&#39;t support writing to zip files. Not sure if bug or not though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Emily Brace)</author>
		<pubDate>Wed, 26 Oct 2016 05:31:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can probably configure PhysFS to be able to save outside the zip file if you mount a real directory. Alternatively, you could call <span class="source-code"><a href="http://www.allegro.cc/manual/al_set_standard_file_interface"><span class="a">al_set_standard_file_interface</span></a><span class="k2">(</span><span class="k2">)</span></span> before saving your config file and then restoring it with <span class="source-code"><a href="http://www.allegro.cc/manual/al_set_physfs_file_interface"><span class="a">al_set_physfs_file_interface</span></a><span class="k2">(</span><span class="k2">)</span></span>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Wed, 26 Oct 2016 06:11:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>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&#39;re trying to do could be done. And 7-zip supports MANY different formats.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 26 Oct 2016 23:51:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>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.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Emily Brace)</author>
		<pubDate>Thu, 27 Oct 2016 02:34:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>That&#39;s why it&#39;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&#39;s going on. I would never have guessed you were using PhysFS from what you showed us. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 27 Oct 2016 03:49:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Good point, although, I wouldn&#39;t have thought of including that code either way xd
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Emily Brace)</author>
		<pubDate>Thu, 27 Oct 2016 06:06:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I wonder if we should provide a function <span class="source-code">al_set_physfs_file_interface_read_only</span>. 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&#39;s responsibility to set the file interface they want to use.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Thu, 27 Oct 2016 06:28:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Or some version of the function that excludes config files :p
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Emily Brace)</author>
		<pubDate>Thu, 27 Oct 2016 19:57:29 +0000</pubDate>
	</item>
</rss>
