<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>ALLEGRO_PATH/ALLEGRO_FS_ENTRY and PHYSFS addon</title>
		<link>http://www.allegro.cc/forums/view/618616</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 04 Mar 2022 18:36:15 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m adding PHYSFS integration to my project and I&#39;ve been struggling to get it to work as expected so I went and tried writing a small program for testing.</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="p">#include &lt;stdio.h&gt;</span>
<span class="number">  2</span><span class="p">#include &lt;stdlib.h&gt;</span>
<span class="number">  3</span><span class="p">#include &lt;allegro5/allegro.h&gt;</span>
<span class="number">  4</span><span class="p">#include &lt;allegro5/allegro_physfs.h&gt;</span>
<span class="number">  5</span><span class="p">#include &lt;physfs.h&gt;</span>
<span class="number">  6</span>
<span class="number">  7</span><span class="k1">void</span> allegro_initialization<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</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>    <a href="http://www.allegro.cc/manual/al_install_keyboard"><span class="a">al_install_keyboard</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span>    <a href="http://www.allegro.cc/manual/al_install_mouse"><span class="a">al_install_mouse</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span>    <a href="http://www.allegro.cc/manual/al_set_new_display_flags"><span class="a">al_set_new_display_flags</span></a><span class="k2">(</span>ALLEGRO_WINDOWED<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span>    al_set_new_window_title<span class="k2">(</span><span class="s">"Allegro test"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a> <span class="k3">*</span>display <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_display"><span class="a">al_create_display</span></a><span class="k2">(</span><span class="n">800</span>, <span class="n">600</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span><span class="k2">}</span>
<span class="number"> 15</span>
<span class="number"> 16</span><span class="k1">int</span> print<span class="k2">(</span><a href="http://www.allegro.cc/manual/ALLEGRO_FS_ENTRY"><span class="a">ALLEGRO_FS_ENTRY</span></a> <span class="k3">*</span>entry, <span class="k1">void</span> <span class="k3">*</span>extra<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 17</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"%s\n"</span>, <a href="http://www.allegro.cc/manual/al_get_fs_entry_name"><span class="a">al_get_fs_entry_name</span></a><span class="k2">(</span>entry<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 18</span>    <span class="k1">return</span> ALLEGRO_FOR_EACH_FS_ENTRY_SKIP<span class="k2">;</span>
<span class="number"> 19</span><span class="k2">}</span>
<span class="number"> 20</span>
<span class="number"> 21</span><span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc, <span class="k1">char</span> <span class="k3">*</span><span class="k3">*</span>argv<span class="k2">)</span> <span class="k2">{</span>
<span class="number"> 22</span>    allegro_initialization<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 23</span>
<span class="number"> 24</span>
<span class="number"> 25</span><span class="c">//    PHYSFS_init(argv[0]);</span>
<span class="number"> 26</span><span class="c">//    PHYSFS_mount("/home/user/tests/test.zip", NULL, 1);</span>
<span class="number"> 27</span><span class="c">//    al_set_physfs_file_interface();</span>
<span class="number"> 28</span>
<span class="number"> 29</span>
<span class="number"> 30</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_FS_ENTRY"><span class="a">ALLEGRO_FS_ENTRY</span></a> <span class="k3">*</span>entry <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_fs_entry"><span class="a">al_create_fs_entry</span></a><span class="k2">(</span><span class="s">"subdirectory"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 31</span>    al_for_each_fs_entry<span class="k2">(</span>entry, print, NULL<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 32</span>
<span class="number"> 33</span>    ALLEGRO_PATH <span class="k3">*</span>p1 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_path_for_directory"><span class="a">al_create_path_for_directory</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_fs_entry_name"><span class="a">al_get_fs_entry_name</span></a><span class="k2">(</span>entry<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 34</span>    ALLEGRO_PATH <span class="k3">*</span>p2 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_path_for_directory"><span class="a">al_create_path_for_directory</span></a><span class="k2">(</span><span class="s">".."</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 35</span>    <a href="http://www.allegro.cc/manual/al_join_paths"><span class="a">al_join_paths</span></a><span class="k2">(</span>p1, p2<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 36</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"==========\nNew path:%s\n==========\n"</span>, <a href="http://www.allegro.cc/manual/al_path_cstr"><span class="a">al_path_cstr</span></a><span class="k2">(</span>p1, <span class="s">'/'</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 37</span>
<span class="number"> 38</span>    <a href="http://www.allegro.cc/manual/al_destroy_fs_entry"><span class="a">al_destroy_fs_entry</span></a><span class="k2">(</span>entry<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 39</span>    entry <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_fs_entry"><span class="a">al_create_fs_entry</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>p1, <span class="s">'/'</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 40</span>    al_for_each_fs_entry<span class="k2">(</span>entry, print, NULL<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 41</span>    <a href="http://www.allegro.cc/manual/al_rest"><span class="a">al_rest</span></a><span class="k2">(</span><span class="n">3</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 42</span><span class="k2">}</span>
</div></div><p>

This code works correctly, assuming there&#39;s a <i>subdirectory</i> in the current working directory. Sample output is something like this:</p><pre class="terminal scroll">/home/user/tests/subdirectory/cmake_install.cmake
/home/user/tests/subdirectory/CMakeCache.txt
/home/user/tests/subdirectory/Makefile
/home/user/tests/subdirectory/dummy
==========
New path:/home/user/tests/subdirectory/../
==========
/home/user/tests/subdirectory/../dummy.exe
/home/user/tests/subdirectory/../CMakeLists.txt
/home/user/tests/subdirectory/../dummy.c
/home/user/tests/subdirectory/../dummy.cpp
/home/user/tests/subdirectory/../subdirectory
...</pre><p>

However, if I uncomment the PHYSFS lines, the code will print nothing for the second path. The .zip does contain a <i>subdirectory</i>. Sample output when using the PHYSFS addon is:</p><pre class="terminal">/subdirectory/cmake_install.cmake
/subdirectory/CMakeCache.txt
/subdirectory/Makefile
/subdirectory/dummy
==========
New path:/subdirectory/../
==========</pre><p>

This is on Linux with Allegro 5.2.4, haven&#39;t tried with the latest version of Allegro.</p><p>I know in this case I could probably get the same result by using <span class="source-code"><a href="http://www.allegro.cc/manual/al_drop_path_tail"><span class="a">al_drop_path_tail</span></a><span class="k2">(</span><span class="k2">)</span></span> but, still, I&#39;m not sure if this is a bug or I&#39;m doing something wrong.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kenmasters1976)</author>
		<pubDate>Wed, 02 Mar 2022 04:26:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m not sure, but I&#39;ve never heard of physfs working with &#39;up&#39; directories. That is, the root of the zip file is the base directory, and everything else is based on that. Why do you need to use &#39;..&#39; anyway? You know the root of the zip file?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 02 Mar 2022 18:22:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m trying to add file browsing to my project and using &#39;..&#39; seemed like the obvious choice for moving up to the parent directory. Note that I&#39;m not trying to get outside the PHYSFS filesystem, I&#39;m trying to go up to a directory still within the zip file. However, after adding a simple check for <span class="source-code"><a href="http://www.allegro.cc/manual/al_get_fs_entry_mode"><span class="a">al_get_fs_entry_mode</span></a><span class="k2">(</span>entry<span class="k2">)</span> <span class="k3">&amp;</span> ALLEGRO_FILEMODE_ISDIR</span> it&#39;s obvious that something like <i>/subdirectory/../</i> is not considered a directory when using PHYSFS (it should point to the zip&#39;s root in this case).</p><p>As I said, I know I can use <span class="source-code"><a href="http://www.allegro.cc/manual/al_drop_path_tail"><span class="a">al_drop_path_tail</span></a><span class="k2">(</span><span class="k2">)</span></span>, for example, but I initially thought &#39;..&#39; would do the job.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kenmasters1976)</author>
		<pubDate>Wed, 02 Mar 2022 22:49:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you want, you could take a look at my filesystem. It works with PHYSFS and mounts zip files as directories.</p><p>Code is here :</p><p><a href="https://github.com/EdgarReynaldo/EagleGUI/blob/master/include/Eagle/File.hpp">https://github.com/EdgarReynaldo/EagleGUI/blob/master/include/Eagle/File.hpp</a><br /><a href="https://github.com/EdgarReynaldo/EagleGUI/blob/master/src/Eagle/File.cpp">https://github.com/EdgarReynaldo/EagleGUI/blob/master/src/Eagle/File.cpp</a><br /><a href="https://github.com/EdgarReynaldo/EagleGUI/blob/master/include/Eagle/FileSystem.hpp">https://github.com/EdgarReynaldo/EagleGUI/blob/master/include/Eagle/FileSystem.hpp</a><br /><a href="https://github.com/EdgarReynaldo/EagleGUI/blob/master/src/Eagle/FileSystem.cpp">https://github.com/EdgarReynaldo/EagleGUI/blob/master/src/Eagle/FileSystem.cpp</a></p><p>Zip files are mounted transparently and navigated as if they were just another folder on the filesystem.</p><p>If you really need &#39;up&#39; directories, you might want to rethink things a little. It would be trivial to implement a special folder called .. .
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 03 Mar 2022 22:00:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/618616/1051806#target">Edgar Reynaldo</a> said:</div><div class="quote"><p> Zip files are mounted transparently and navigated as if they were just another folder on the filesystem.
</p></div></div><p>Interesting, will take a look into it.</p><p>Thanks.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (kenmasters1976)</author>
		<pubDate>Fri, 04 Mar 2022 12:07:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You might want to take a look at the driver too. Everything is implemented on the backend through Allegro 5 atm.</p><p><a href="https://github.com/EdgarReynaldo/EagleGUI/blob/master/include/Eagle/backends/Allegro5/Allegro5FileSystem.hpp">https://github.com/EdgarReynaldo/EagleGUI/blob/master/include/Eagle/backends/Allegro5/Allegro5FileSystem.hpp</a><br /><a href="https://github.com/EdgarReynaldo/EagleGUI/blob/master/src/backends/Allegro5/Allegro5FileSystem.cpp">https://github.com/EdgarReynaldo/EagleGUI/blob/master/src/backends/Allegro5/Allegro5FileSystem.cpp</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Fri, 04 Mar 2022 18:36:15 +0000</pubDate>
	</item>
</rss>
