<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Allegro 5, android, writing files.</title>
		<link>http://www.allegro.cc/forums/view/617084</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 11 Oct 2017 00:41:05 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello All,</p><p>I&#39;m (still) porting an A5 game I wrote for RaspberryPi and Windows to Android. My current difficulty is creating/writing files. Hi score tables, saved config, that sort of thing. </p><p>As per this thread ( <a href="https://www.allegro.cc/forums/thread/617058">https://www.allegro.cc/forums/thread/617058</a> ) I learned that I need to call al_android_set_apk_file_interface() in order to load any assets, but according to the manual this gives read-only access.</p><p>I tried the following, hoping to write a file somewhere:</p><p> </p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="k3">&lt;</span>snip&gt;
<span class="number">  2</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_FILE"><span class="a">ALLEGRO_FILE</span></a> <span class="k3">*</span>testfile<span class="k2">;</span>
<span class="number">  3</span>    <span class="k1">char</span> str<span class="k2">[</span><span class="k2">]</span> <span class="k3">=</span> <span class="s">"File Open\n"</span><span class="k2">;</span>
<span class="number">  4</span>    <span class="k1">char</span> pathstr<span class="k2">[</span><span class="n">100</span><span class="k2">]</span><span class="k2">;</span>
<span class="number">  5</span>    <span class="k1">char</span> <span class="k3">*</span>pathptr<span class="k2">;</span> 
<span class="number">  6</span>    <span class="k1">int</span> error<span class="k2">;</span>   
<span class="number">  7</span>    
<span class="number">  8</span>    <a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span>
<span class="number"> 10</span>    <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 class="k2">;</span>
<span class="number"> 11</span>    ALLEGRO_PATH <span class="k3">*</span>path <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_standard_path"><span class="a">al_get_standard_path</span></a><span class="k2">(</span>ALLEGRO_USER_DATA_PATH<span class="k2">)</span><span class="k2">;</span>    
<span class="number"> 12</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_737.html" target="_blank">sprintf</a><span class="k2">(</span>pathstr,<span class="s">"%s"</span>,<a href="http://www.allegro.cc/manual/al_path_cstr"><span class="a">al_path_cstr</span></a><span class="k2">(</span>path, <span class="s">'/'</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>    <a href="http://www.allegro.cc/manual/al_change_directory"><span class="a">al_change_directory</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_path_cstr"><span class="a">al_path_cstr</span></a><span class="k2">(</span>path, <span class="s">'/'</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>  
<span class="number"> 14</span>    pathptr <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_current_directory"><span class="a">al_get_current_directory</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span>    
<span class="number"> 16</span>    testfile <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_fopen"><span class="a">al_fopen</span></a><span class="k2">(</span><span class="s">"ipl.txt"</span>,<span class="s">"w"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</span>    error <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_fputs"><span class="a">al_fputs</span></a><span class="k2">(</span>testfile, str<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 18</span>    error <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_fclose"><span class="a">al_fclose</span></a><span class="k2">(</span>testfile<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span><span class="k3">&lt;</span>snip&gt;
</div></div><p>

(Incidentally, I haven&#39;t used al_android_set_apk_file_interface() here, so that&#39;s not causing problems)</p><p>If I step through the code, I see:</p><p>pathstr = <i>data/user/0/com.tootiredgames.gravstorm/files</i> (output from get_standard_path)<br />pathptr = /data/data/com.tootiredgames.gravstorm/files (output from get_current_directory)</p><p>If I look at the filesystem, either with an android file manager, or under windows when connected by USB, I see a path that looks more like:</p><p>This PC\MotoE2(4G-LTE)\Internal storage\Android\data\com.tootiredgames.gravstorm\files</p><p>al_fopen returns a pointer (i.e. not NULL) and both al_fputs() and al_fclose() return success.</p><p>So, can anyone help with any of these questions:</p><p>What should I be doing differently to write a file, and where can I find it?</p><p>Failing answers to that, does anyone know:<br />- Why do I end up with different values for pathstr and pathptr?</p><p>- Why do neither of them match what I see with a file browser?</p><p>- Where, if anywhere, has my file been written?</p><p>Cheers,</p><p>Ian.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ian Lewis)</author>
		<pubDate>Tue, 10 Oct 2017 00:13:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Why don&#39;t you try to open the file after writing closing it, and then read it again? What you see in Windows is deceiving, Windows mounts the file system in a different way than Android does. What you will get in your app will be different, especially the first few directories.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Tue, 10 Oct 2017 01:47:50 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Good idea <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> I tried that, and it seems that my app can happily read back what it&#39;s written, even though all the file browsers are conspiring to hide it from me <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p><p>In a practical sense, my problem is solved (thank you beoran) though I&#39;m still interested if anyone can enlighten me as to how all these paths relate to each other, where my files are being written, and why I can&#39;t see them???</p><p>Cheers,</p><p>Ian.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ian Lewis)</author>
		<pubDate>Tue, 10 Oct 2017 13:09:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Android is Linux and you can have several symbolic or hard links to a single file or directory. So, both pathstr and pathptr point to the same path, even though the names differ. You can use that directory without problems, and if you need the contents of that file, just send it over the network. You might need to use command line tools to find back the files &quot;real&quot; location.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (beoran)</author>
		<pubDate>Wed, 11 Oct 2017 00:41:05 +0000</pubDate>
	</item>
</rss>
