![]() |
|
[a5] al_fopen trouble (using PhysFS) |
SpectreNectar
Member #10,969
May 2009
![]() |
ALLEGRO_FILE *file = al_fopen("level.txt", "wb"); if(file==0) { std::cout << "fail" << std::endl; }
Hello, I don't get why this outputs fail |
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
If it is a text file, you shouldn't use "wb", but "w" for text mode. As for why it fails - you might not have write permission to the directory it is trying to create a file in. You said you were using PhysFS, so what are you actually trying to write to? A zip file? Show more code. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
SpectreNectar
Member #10,969
May 2009
![]() |
This should be all the code relevant for physfs (if I remember correctly): 1bool setup( Assets& v ) {
2
3 al_set_physfs_file_interface();
4
5 /* Set up PhysicsFS. */
6 if(!PHYSFS_init(0)) std::cout << "failed initializing" << std::endl;
7 else if(!PHYSFS_addToSearchPath("data", 1)) std::cout << "failed adding search path" << std::endl;
8
9 ...
10}
11
12bool deinit( Assets& v ) {
13
14 PHYSFS_deinit();
15
16 ...
17
18}
I can't find other places that messes with file interfaces by searching. There shouldn't be any either. 1void eEditor::save() {
2
3 ALLEGRO_FILE *file = al_fopen("level.txt", "wb");
4 if(file==0) {
5
6
7 std::cout << "fail" << std::endl;
8
9 }
10
11 std::stringstream ss;
12
13 ss << draw_list_len;
14
15 al_fputs(file, ss.str().c_str());
16 //al_fputs(file, " ");
17 //al_fwrite(file, " ", strlen(" "));
18
19 al_fclose(file);
20
21}
|
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Try calling PHYSFS_init before calling al_set_physfs_file_interface. Make sure your current working directory is correct, and make sure that the 'data' folder exists. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
SpectreNectar
Member #10,969
May 2009
![]() |
I tried doing as you suggested but it was still the same result. I think my current working directory is wrong like you suggest actually. But I'm not sure how to set it or figure out what it is. The data dir exists - I'm already loading resources in and they are in that dir. I actually copy pasted the path originally. |
Trent Gamblin
Member #261
April 2000
![]() |
Try al_set_standard_file_interface() before doing that.
|
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
If you're using gcc, you can use getcwd(const char* buffer , int buf_size); to check the current working directory. A5 has functions to change the current working directory and find the full path to your executable. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
SpectreNectar
Member #10,969
May 2009
![]() |
If I call al_set_standard_file_interface() just before al_fopen then it DOES work, but the program crashes because I need PhysFS to display the font and graphics of the closing dialog I use (and basically everything with resources everywhere). My problem indeed seems to be figuring out how to open a file for writing using the physfs file interface. So I'm stuck again with this and don't know where to go from here: 1void eEditor::save() {
2
3 if(!al_change_directory("/lvl")) std::cout << "no change of dir" << std::endl; //Outputs
4
5 ALLEGRO_FILE *file = al_fopen("level.bin", "wb");
6 if(file==0) {
7
8 ALLEGRO_PATH *path = al_get_standard_path(ALLEGRO_RESOURCES_PATH);
9
10 char * dir = al_get_current_directory();
11
12 std::cout << "fail: " << al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP) << std::endl; //Outputs the directory of the executable
13 std::cout << "info: " << dir << std::endl; //Outputs /
14
15 al_free(dir);
16
17 al_destroy_path(path);
18
19
20 }
21
22 al_fclose(file);
23
24}
Also a small change here... /* Set up PhysicsFS. */ if(!PHYSFS_init(0)) std::cout << "failed initializing" << std::endl; else { al_set_standard_file_interface(); al_set_physfs_file_interface(); if(!PHYSFS_addToSearchPath("data", 1)) std::cout << "failed adding search path" << std::endl; if(!PHYSFS_addToSearchPath("lvl", 1)) std::cout << "failed adding search path2" << std::endl; }
EDIT: |
Thomas Fjellstrom
Member #476
June 2000
![]() |
I think you need to setup the main filesystem as a mount in PhysFS or you can't access the main filesystem. "Standard Path's" mean nothing in PhysFS if you don't have the filesystem "mounted". -- |
Trent Gamblin
Member #261
April 2000
![]() |
You can switch back to the physfs interface at any time with al_set_physfs_file_interface(); ... that's probably not ideal, something like Thomas said might work better, but I just switch back and forth as needed.
|
SpectreNectar
Member #10,969
May 2009
![]() |
Alright I'll switch back and forth from interfaces until I learn how setting up mounts work. It wont be much of a problem in this case really. Thanks very much for your comments/advice. |
|