From: Christer S. <chr...@md...> - 2005-11-16 19:24:46
|
On Wednesday 16 November 2005 18.10, Murat AYIK wrote: > I tried to learn and use datafiles but failed >to make use of them. I need to create files >during runtime and store them in datafiles. The >names of the files should be generated according >to the situation and the object they belong to. >As far as I understand, Allegro DATAFILEs don't >use filenames of objects but indexes, which >should be told to the program during >compile-time!! That doesn't seem flexible to me. >Or may I have missed the lines which explain how >to do that? > > Basically I need to do something like this: >- Create a file which carries info about some >particular situation, such as "data_" + time, >and save it in a datafile with a name mentioning >today's date. >- If a picture taken at 8 AM is needed, load >"data_0800_AM.bmp" from the datafile with the >name "day_something.dat" >- If that fails, take appropriate action. > > Pregenerated indexes won't work for me, >because I don't know what objects will need extra >info during runtime(or if it will ever be >needed), and I don't want to create extra files >which hold information about who needs what. I >need exactly what a ZIP file does; searching by >filenames. In case you are eager to use the Allegro datafiles there is an addon named CGUI that provides the function that I think fullfilles what you are asking for. int SaveDatafileObject(const char *path, void *data, int type); where path is something like "/tmp/test.dat#data_0800_AM", data is e.g. a pointer to your BITMAP and type is corresponding type (i.e. DAT_BITMAP). There is an example (number 21) that shows a usage. The lib of course contains a lot of other stuff that you don't need for saving objects into datafiles... -- Christer |