ALLEGRO_PATH/ALLEGRO_FS_ENTRY and PHYSFS addon
kenmasters1976

I'm adding PHYSFS integration to my project and I've been struggling to get it to work as expected so I went and tried writing a small program for testing.

#SelectExpand
1#include <stdio.h> 2#include <stdlib.h> 3#include <allegro5/allegro.h> 4#include <allegro5/allegro_physfs.h> 5#include <physfs.h> 6 7void allegro_initialization() { 8 al_init(); 9 al_install_keyboard(); 10 al_install_mouse(); 11 al_set_new_display_flags(ALLEGRO_WINDOWED); 12 al_set_new_window_title("Allegro test"); 13 ALLEGRO_DISPLAY *display = al_create_display(800, 600); 14} 15 16int print(ALLEGRO_FS_ENTRY *entry, void *extra) { 17 printf("%s\n", al_get_fs_entry_name(entry)); 18 return ALLEGRO_FOR_EACH_FS_ENTRY_SKIP; 19} 20 21int main(int argc, char **argv) { 22 allegro_initialization(); 23 24 25// PHYSFS_init(argv[0]); 26// PHYSFS_mount("/home/user/tests/test.zip", NULL, 1); 27// al_set_physfs_file_interface(); 28 29 30 ALLEGRO_FS_ENTRY *entry = al_create_fs_entry("subdirectory"); 31 al_for_each_fs_entry(entry, print, NULL); 32 33 ALLEGRO_PATH *p1 = al_create_path_for_directory(al_get_fs_entry_name(entry)); 34 ALLEGRO_PATH *p2 = al_create_path_for_directory(".."); 35 al_join_paths(p1, p2); 36 printf("==========\nNew path:%s\n==========\n", al_path_cstr(p1, '/')); 37 38 al_destroy_fs_entry(entry); 39 entry = al_create_fs_entry(al_path_cstr(p1, '/')); 40 al_for_each_fs_entry(entry, print, NULL); 41 al_rest(3); 42}

This code works correctly, assuming there's a subdirectory in the current working directory. Sample output is something like this:

/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
...

However, if I uncomment the PHYSFS lines, the code will print nothing for the second path. The .zip does contain a subdirectory. Sample output when using the PHYSFS addon is:

/subdirectory/cmake_install.cmake
/subdirectory/CMakeCache.txt
/subdirectory/Makefile
/subdirectory/dummy
==========
New path:/subdirectory/../
==========

This is on Linux with Allegro 5.2.4, haven't tried with the latest version of Allegro.

I know in this case I could probably get the same result by using al_drop_path_tail() but, still, I'm not sure if this is a bug or I'm doing something wrong.

Edgar Reynaldo

I'm not sure, but I've never heard of physfs working with 'up' 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 '..' anyway? You know the root of the zip file?

kenmasters1976

I'm trying to add file browsing to my project and using '..' seemed like the obvious choice for moving up to the parent directory. Note that I'm not trying to get outside the PHYSFS filesystem, I'm trying to go up to a directory still within the zip file. However, after adding a simple check for al_get_fs_entry_mode(entry) & ALLEGRO_FILEMODE_ISDIR it's obvious that something like /subdirectory/../ is not considered a directory when using PHYSFS (it should point to the zip's root in this case).

As I said, I know I can use al_drop_path_tail(), for example, but I initially thought '..' would do the job.

Edgar Reynaldo

If you want, you could take a look at my filesystem. It works with PHYSFS and mounts zip files as directories.

Code is here :

https://github.com/EdgarReynaldo/EagleGUI/blob/master/include/Eagle/File.hpp
https://github.com/EdgarReynaldo/EagleGUI/blob/master/src/Eagle/File.cpp
https://github.com/EdgarReynaldo/EagleGUI/blob/master/include/Eagle/FileSystem.hpp
https://github.com/EdgarReynaldo/EagleGUI/blob/master/src/Eagle/FileSystem.cpp

Zip files are mounted transparently and navigated as if they were just another folder on the filesystem.

If you really need 'up' directories, you might want to rethink things a little. It would be trivial to implement a special folder called .. .

kenmasters1976

Zip files are mounted transparently and navigated as if they were just another folder on the filesystem.

Interesting, will take a look into it.

Thanks.

Edgar Reynaldo
Thread #618616. Printed from Allegro.cc