|
A5 Make Path Absolute |
James Bunting
Member #30
April 2000
|
In Allegro 5, al_make_path_canonical does not seem to convert relative paths to absolute, whereas Allegro 4's canonicalize_filename did (as I recall). I concede that the newer approach makes perfect sense as a relative path is arguably more simple but don't worry about all that. Anyway, I could missing something simple so... Does Allegro 5 have a simple "1 liner" method to make a path absolute, or do I have to code my way around it by getting the CWD manually and appending the path? al_make_path_absolute_where_possible()? |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Here ya go : string RelativeToAbsolute(string relative) { return string(al_get_current_directory()) + ALLEGRO_NATIVE_PATH_SEP + relative; }
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 |
Matthew Leverton
Supreme Loser
January 1999
|
First create a path for the current working directory: char *tmp = al_get_current_directory(); ALLEGRO_PATH *cwd = al_create_path_for_directory(tmp); al_free(tmp); Then whenever you want an absolute path: al_rebase_path(cwd, path); So it's a one liner if you first create a global path object for the current working directory. (Be sure to free it later.) Edgar Reynaldo said: Here ya go : Leaks memory due to the call to al_get_current_directory(). |
Thomas Fjellstrom
Member #476
June 2000
|
Hm, I thought it existed, but it looks like it slipped my mind. All it would likely do is just append cwd and the path, which can be done easily enough. -- |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Matthew Leverton said: Leaks memory due to the call to al_get_current_directory(). Whoops. Fixed : string RelativeToAbsolute(string relative) { char* cwd = al_get_current_directory(); string path = string(cwd) + ALLEGRO_NATIVE_PATH_SEP + relative; al_free(cwd); return path; }
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 |
Matthew Leverton
Supreme Loser
January 1999
|
Thomas Fjellstrom said: Hm, I thought it existed, but it looks like it slipped my mind It's kind of a specialty function that I'm not sure should exist in Allegro. That is, creating an absolute path from the current working directory is two discrete steps. It might be nice to have something like: al_get_standard_path(ALLEGRO_CURRENT_PATH), but even that is just a convenience wrapper around the code I wrote above. |
James Bunting
Member #30
April 2000
|
Thanks for the help people. For the record I am working on porting a file picker dialog I originally wrote for AllegroGL under Allegro 4. I could not find a file dialog in 5 (apart from the native one which crashes in full screen and would require a mode switch anyway). |
Edgar Reynaldo
Major Reynaldo
May 2007
|
If it crashes in full screen, then cheat : al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);. 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 |
James Bunting
Member #30
April 2000
|
Sounds promising, I will look into that thanks. Shot of work in progress picker here BTW |
Edgar Reynaldo
Major Reynaldo
May 2007
|
RE: pic If you're feeling ambitious, you might want to implement a folder tree. 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 |
|