E:/PPC/XFlib/source/xf_saves.c

Go to the documentation of this file.
00001 
00002 
00003 #include "xf_saves.h"
00004 #include <stdio.h>
00005 
00006         
00007 xf_savetype xf_save;
00008 
00009 extern char *XF_Path;
00010 
00011 
00012 u8 XF_InitSave(char *name, void *data, u32 size){
00013    sprintf(xf_save.Filename, "%s%s.sav", XF_Path, name); 
00014    xf_save.Init = 1; // Ok
00015    xf_save.Data = data;
00016    xf_save.Size = size;
00017    
00018    FILE* save = fopen (xf_save.Filename, "rb"); // Regarder si existe déjà ou pas. Renvoie 0 si existe pas, 1 si existe...
00019    
00020    if(save) {
00021            fclose(save);
00022            XF_LoadData(); // Charger la save
00023                 return 1; // Save exists, you can use it...
00024         }       
00025         
00026         return 0; // No save, you'll have to create it
00027 }   
00028         
00029 u8 XF_SaveData(void){
00030    
00031    if(xf_save.Init == 0) return 0; // Pouf ! Pas bon...
00032     
00033    FILE* save = fopen (xf_save.Filename, "wb+");
00034         
00035         if(save != 0){
00036                 fwrite(xf_save.Data, 1, xf_save.Size, save);
00037                 fclose(save);
00038                 
00039                 return 1; // Ca roule 
00040         }       
00041         
00042         return 0; // Pas bon    
00043 }               
00044 
00045 
00046 u8 XF_LoadData(void){
00047    
00048    if(xf_save.Init == 0) return 0; // Pouf ! Pas bon...
00049    
00050         FILE* save = fopen (xf_save.Filename, "rb"); 
00051         
00052         if(save != 0){ // Le fichier existe...
00053            fread(xf_save.Data, 1, xf_save.Size, save);
00054                 fclose(save);    
00055                 return 1; // Ok  
00056         }   
00057         return 0; // Pas bon
00058 }   

Generated on Wed Dec 12 23:46:38 2007 for XFlib by  doxygen 1.5.4