PHYSFS_addToSearchPath
APrince

In the documentation there is this sentence:

"Add an archive or directory to the search path."

And my question is... Can I mount a directory that is inside an archive? Say i have an archive called archive.dat in which there is a directory named folder. Now I want to search for certain files first in folder and if they are not found, then in the root of the archive. I tried something like this:

PHYSFS_addToSearchPath("archive.dat/folder", 0) //0 so that it is prepended

... but it fails. Is there a way to do it?

Thanks...

Trent Gamblin

Not a very good answer, but I think you can "cd" in the archive. Check the manual.

APrince

What manual? There's the documentation but I don't know of anything else...

Trent Gamblin

If I'm not mistaken you want al_change_directory after al_set_physfs_file_system. You'll have to try it yourself though unless someone else knows for sure.

Todd Cope

Yes, you can use al_change_directory with the PhysFS add-on.

APrince

I tried by it does not help me much. The problem is with the use case I described. There may be (typically are) more files with the same name. Now I need to make sure that first, they are going to be searched in the subdirectory. Now I don't know how this whole al_change_directory() thing works internally, but what would happen if I called the al_change_directory("folder") and there were more directories called "folder" present in the path?

And did you mean al_set_physfs_file_interface() rather than al_set_physfs_file_system()?

Izual

After a quick read trough the PHYSFS documentation it seems that "mounting a directory" is referring to the real directory on your drive not the one in the archive.

You cannot do:
PHYSFS_addToSearchPath("archive.dat/my_folder", 0);

You can do only:
PHYSFS_addToSearchPath("archive.dat", 0);
PHYSFS_addToSearchPath("$HOME/my_folder", 0);
PHYSFS_addToSearchPath("c:/BrokenOS/my_folder", 0)

And if you don't need backward compatibility with PHYSFS 1.0 you should use:
int PHYSFS_mount( const char *newDir, const char *mountPoint, int appendToPath );

For the searching part, i guess you could do something like this:

#SelectExpand
1ALLEGRO_FILE *f; 2 3f = al_fopen( "$ARCHIVE_ROOT/search_here_fist/file_to_find.dat", "rb"); 4if( !f ) 5 { 6 f = al_fopen( "$ARCHIVE_ROOT/file_to_find.dat", "rb" ); 7 } 8 9if( f ) 10 { 11 // Do something with the file... 12 al_fclose( f ); 13 } 14else 15 { 16 // Could not find the file... 17 }

Correct me if i am wrong on something.

Thomas Fjellstrom

I "think" allegro's al_change_directory emulates a chdir inside archives. Id have to check the code to make sure. but I think it works, even inside archives.

Trent Gamblin

I trust Todd when he says it does.

Todd Cope
APrince said:

There may be (typically are) more files with the same name.

PhysFS will load the "newest" file of any given name based on when search paths were added.

If you have archive.zip/sounds/swipe.wav and mypath/sounds/swipe.wav, PhysFS will open whichever was added to the search path most recently. If you use al_change_directory() to go into the sounds directory, the rule still applies.

Quote:

Now I don't know how this whole al_change_directory() thing works internally, but what would happen if I called the al_change_directory("folder") and there were more directories called "folder" present in the path?

You just have to remember how PhysFS works. If there are two search paths with folders named sounds, you can open files from either of those directories as if they are in the same directory.

In the above example, if there was a file called touch.wav in mypath/sounds but not in archive.zip/sounds, calling al_load_sample("sounds/touch.wav") will load the file mypath/sounds/touch.wav. If touch.wav was in both, it would load whichever is "newer" as previously described.

Thread #613087. Printed from Allegro.cc