Location of Saved Files
inspiredevistate

A quick question...

I am trying to control where the user saves a file. For example, the user creates a bitmap and wants to save this bitmap.

I want the bitmap to be saved under the folder the program is run from under a folder called "Bitmaps"

Currently, I am only using save_bitmap();

I am thinking file_select_ex() may be what I need? But is there another way?

TeamTerradactyl

Usually, if you do not provide a path option for them, such as file_select_ex, then the user is forced to accept your path selections.

1) Prompt them for the "save to:" filename (not path)
2) Allow all characters as input except those that could be perceived as a "change path" character (/ or \\, etc.)
3) When they're done typing, you can do some extra stripping of the characters and ensure that the page that you specify, like SAVE_DIR, is the same that you will be saving the resulting BITMAP (or filename, or whatever) into. If it is, save as normal. Otherwise, strip off all "extra" characters.

Matthew Dalrymple
char* Savefilename;
Savefilename = "Bitmaps/hethisismyfirstbitmap.bmp";
save_bitmap(Savefilename, ...)

Just include the relative path in the filename section in save_bitmap(), that will store it in any directory you want.

inspiredevistate
Quote:

char* Savefilename;
Savefilename = "Bitmaps/hethisismyfirstbitmap.bmp";
save_bitmap(Savefilename, ...)

for some reason, it didn't create the BITMAP folder, I searched for it and could not find it... this is what i used

char *path;
/*allegro has been init and all that good stuff
and user picks Yes to save file*/
path = "Bitmaps\\testbmp.bmp";
save_bitmap(path, myBMP, pal);
/*exiting allegro, etc*/

LennyLen
Quote:

for some reason, it didn't create the BITMAP folder

You will have to do this yourself. If you're using gcc, there is the mkdir() function for creating directories.

inspiredevistate

Thanks! I've finally figured it out!

Thanks to all your help!!;D

TeamTerradactyl

You may also want to use '/' instead of '\\' for path separators: Windows will automatically convert these to the double-backslashes for you, and this makes it more cross-compatible with Linux/Mac.

Thread #588717. Printed from Allegro.cc