// // File loader // #include #include #include #include #include #include "ithelib.h" #include "loadfile.h" #include "oscli.h" #include "tdgui.h" // Defines // Macro to make a directory using the right API version #ifdef _WIN32 #define MAKE_DIR(a) mkdir(a) #else #define MAKE_DIR(a) mkdir(a,S_IRUSR|S_IWUSR|S_IXUSR); #endif // Variables char savegamedest[1024]; // Functions extern int check_rar_file(char *filename); extern void scan_rar_file(char *filename); #ifdef _WIN32 static void winslash(char *name); #endif static int blank_savegame(const char *name, int attrib, void *irrelevant); static int copy_savegame(const char *name, int attrib, void *irrelevant); // Code // user can choose a datafile int data_choose(char *path,char *path_file,int size) { char *home; int i,len; int k=0; memset(path,0,size); // Blank it // home=getenv("HOME"); // if(!home) home="."; strcpy(path_file,home); strcat(path_file,"/"); // if(!file_select_ex("load game (gamedata.ini)",path_file,"ini",size,0,0)) if(!billfile_select("load game (gamedata.ini)",path_file,"ini")) return 0; else { len = strlen(path_file); strslash(path_file); // Ensure slashes are correct // Find last slash for (i=0;isize, fp); putw(spr->color_depth, fp); putw(spr->w, fp); putw(spr->h, fp); fwrite(spr->dat, 1, spr->size, fp); putw(avgcol, fp); fclose(fp); } /* * Load an RLE-compressed sprite, optionally get the average colour weight */ RLE_SPRITE* load_rle_sprite(char *fname, long *avgcol) { RLE_SPRITE* spr = 0; int sz = 0; FILE *fp; fp = fopen(fname,"rb"); if(!fp) return NULL; sz = getw(fp); if(sz < 1) return 0; spr = calloc(1,sizeof(RLE_SPRITE) + sz); if(!spr) { // out of memory, but skip rest of data in file fseek(fp, sz + 12, SEEK_SET); return 0; } spr->color_depth = getw(fp); spr->w = getw(fp); spr->h = getw(fp); spr->size = sz; fread(spr->dat, 1, sz, fp); // Get average pixel colour, if a pointer is given if(avgcol) *avgcol=getw(fp); fclose(fp); return spr; } #ifdef _WIN32 void makepath(char *fname) { char buffer[1024]; char *p,*pp; strcpy(buffer,fname); winslash(buffer); // Normalise slashes p=strrchr(buffer,'\\'); if(p) *p=0; // Chop off the filename MAKE_DIR(buffer); pp=&buffer[0]; do { p=strchr(pp,'\\'); if(p) { *p=0; // Pop the slash out MAKE_DIR(buffer); *p='\\'; // Put it back pp=++p; // Look for the next one? } } while(p); } #else void makepath(char *fname) { char buffer[1024]; char *p,*pp; strcpy(buffer,fname); strslash(buffer); // Normalise slashes p=strrchr(buffer,'/'); if(p) *p=0; // Chop off the filename MAKE_DIR(buffer); pp=&buffer[0]; do { p=strchr(pp,'/'); if(p) { *p=0; // Pop the slash out MAKE_DIR(buffer); *p='/'; // Put it back pp=++p; // Look for the next one? } } while(p); } #endif /* // copy a file from an absolute path to a relative path void cpfile(char *local_path, char *abs_path, char *file_name) { char cmd[1024]; char tmp1[1024]; char tmp2[1024]; FILE *fd; strcpy(tmp1,abs_path); strcat(tmp1,file_name); strcpy(tmp2,local_path); strcat(tmp2,file_name); // Can we copy it? if(access(tmp1,R_OK)) return; // BUG: This checks if it exists, not if it can be created // if(access(tmp2,W_OK)) // return; sprintf(cmd,"cp -f %s %s > /dev/null",tmp1,tmp2); fd = fopen(tmp2,"r"); if (!fd) system(cmd); else fclose(fd); // printf("%s\n",cmd); } */