Keep opened files

This commit is contained in:
Simon Robertshaw 2011-06-25 16:59:25 +01:00
parent d515575612
commit 1dcefb2895
3 changed files with 40 additions and 5 deletions

View File

@ -138,6 +138,9 @@ extern char svf_pass[64];
extern char svf_user_id[64]; extern char svf_user_id[64];
extern char svf_session_id[64]; extern char svf_session_id[64];
extern char svf_filename[255];
extern int svf_fileopen;
extern int svf_open; extern int svf_open;
extern int svf_own; extern int svf_own;
extern int svf_myvote; extern int svf_myvote;

View File

@ -41,6 +41,8 @@ int svf_open = 0;
int svf_own = 0; int svf_own = 0;
int svf_myvote = 0; int svf_myvote = 0;
int svf_publish = 0; int svf_publish = 0;
char svf_filename[255] = "";
int svf_fileopen = 0;
char svf_id[16] = ""; char svf_id[16] = "";
char svf_name[64] = ""; char svf_name[64] = "";
char svf_description[255] = ""; char svf_description[255] = "";
@ -636,16 +638,19 @@ void draw_svf_ui(pixel *vid_buf, int alternate)// all the buttons at the bottom
} }
// the reload button // the reload button
c = svf_open ? 255 : 128; c = (svf_open || svf_fileopen) ? 255 : 128;
drawtext(vid_buf, 23, YRES+(MENUSIZE-14), "\x91", c, c, c, 255); drawtext(vid_buf, 23, YRES+(MENUSIZE-14), "\x91", c, c, c, 255);
drawrect(vid_buf, 19, YRES+(MENUSIZE-16), 16, 14, c, c, c, 255); drawrect(vid_buf, 19, YRES+(MENUSIZE-16), 16, 14, c, c, c, 255);
// the save sim button // the save sim button
if(alternate) if(alternate || svf_fileopen)
{ {
fillrect(vid_buf, 36, YRES+(MENUSIZE-16)-1, 152, 16, 255, 255, 255, 255); fillrect(vid_buf, 36, YRES+(MENUSIZE-16)-1, 152, 16, 255, 255, 255, 255);
drawtext(vid_buf, 40, YRES+(MENUSIZE-14), "\x82", 0, 0, 0, 255); drawtext(vid_buf, 40, YRES+(MENUSIZE-14), "\x82", 0, 0, 0, 255);
drawtext(vid_buf, 58, YRES+(MENUSIZE-12), "[save to disk]", 0, 0, 0, 255); if(svf_fileopen)
drawtext(vid_buf, 58, YRES+(MENUSIZE-12), svf_filename, 0, 0, 0, 255);
else
drawtext(vid_buf, 58, YRES+(MENUSIZE-12), "[save to disk]", 0, 0, 0, 255);
} else { } else {
c = svf_login ? 255 : 128; c = svf_login ? 255 : 128;
drawtext(vid_buf, 40, YRES+(MENUSIZE-14), "\x82", c, c, c, 255); drawtext(vid_buf, 40, YRES+(MENUSIZE-14), "\x82", c, c, c, 255);
@ -1666,6 +1671,8 @@ int save_name_ui(pixel *vid_buf)
svf_open = 1; svf_open = 1;
svf_own = 1; svf_own = 1;
svf_publish = cb.checked; svf_publish = cb.checked;
svf_filename[0] = 0;
svf_fileopen = 0;
free(old_vid); free(old_vid);
return nd+1; return nd+1;
} }
@ -3628,12 +3635,16 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date)
svf_tags[0] = 0; svf_tags[0] = 0;
} }
svf_myvote = info->myvote; svf_myvote = info->myvote;
svf_filename[0] = 0;
svf_fileopen = 0;
retval = 1; retval = 1;
break; break;
} else { } else {
queue_open = 0; queue_open = 0;
svf_open = 0; svf_open = 0;
svf_filename[0] = 0;
svf_fileopen = 0;
svf_publish = 0; svf_publish = 0;
svf_own = 0; svf_own = 0;
svf_myvote = 0; svf_myvote = 0;
@ -5219,6 +5230,11 @@ int save_filename_ui(pixel *vid_buf)
ed.cursor = 0; ed.cursor = 0;
ed.multiline = 0; ed.multiline = 0;
ed.str[0] = 0; ed.str[0] = 0;
if(svf_fileopen){
strncpy(ed.str, svf_filename, 255);
ed.cursor = strlen(ed.str);
}
while (!sdl_poll()) while (!sdl_poll())
{ {
@ -5264,8 +5280,10 @@ int save_filename_ui(pixel *vid_buf)
if(b && !bq) if(b && !bq)
{ {
FILE *f = NULL; FILE *f = NULL;
char *savefname = malloc(strlen(ed.str)+5);
char *filename = malloc(strlen(LOCAL_SAVE_DIR)+strlen(PATH_SEP)+strlen(ed.str)+5); char *filename = malloc(strlen(LOCAL_SAVE_DIR)+strlen(PATH_SEP)+strlen(ed.str)+5);
sprintf(filename, "%s%s%s.cps", LOCAL_SAVE_DIR, PATH_SEP, ed.str); sprintf(filename, "%s%s%s.cps", LOCAL_SAVE_DIR, PATH_SEP, ed.str);
sprintf(savefname, "%s.cps", ed.str);
#ifdef WIN32 #ifdef WIN32
_mkdir(LOCAL_SAVE_DIR); _mkdir(LOCAL_SAVE_DIR);
@ -5285,6 +5303,11 @@ int save_filename_ui(pixel *vid_buf)
{ {
fwrite(save_data, save_size, 1, f); fwrite(save_data, save_size, 1, f);
fclose(f); fclose(f);
if(svf_fileopen)
{
strncpy(svf_filename, savefname, 255);
svf_fileopen = 1;
}
break; break;
} else { } else {
error_ui(vid_buf, 0, "Unable to write to save file."); error_ui(vid_buf, 0, "Unable to write to save file.");
@ -5448,6 +5471,9 @@ void catalogue_ui(pixel * vid_buf)
status = parse_save(data, size, 1, 0, 0, bmap, fvx, fvy, signs, parts, pmap); status = parse_save(data, size, 1, 0, 0, bmap, fvx, fvy, signs, parts, pmap);
if(!status) if(!status)
{ {
//svf_filename[0] = 0;
strncpy(svf_filename, csave->name, 255);
svf_fileopen = 1;
svf_open = 0; svf_open = 0;
svf_publish = 0; svf_publish = 0;
svf_own = 0; svf_own = 0;
@ -5456,9 +5482,13 @@ void catalogue_ui(pixel * vid_buf)
svf_name[0] = 0; svf_name[0] = 0;
svf_description[0] = 0; svf_description[0] = 0;
svf_tags[0] = 0; svf_tags[0] = 0;
svf_last = data;
data = NULL;
svf_lsize = size;
goto openfin; goto openfin;
} else { } else {
error_ui(vid_buf, 0, "Save data corrupt"); error_ui(vid_buf, 0, "Save data corrupt");
free(data);
} }
} else { } else {
error_ui(vid_buf, 0, "Unable to read save file"); error_ui(vid_buf, 0, "Unable to read save file");

View File

@ -567,7 +567,7 @@ int parse_save(void *save, int size, int replace, int x0, int y0, unsigned char
airMode = ((c[3]>>4)&0x07);// | ((c[3]>>4)&0x02) | ((c[3]>>4)&0x01); airMode = ((c[3]>>4)&0x07);// | ((c[3]>>4)&0x02) | ((c[3]>>4)&0x01);
} }
if (ver>=49 && replace) { if (ver>=49 && replace) {
tempGrav = ((c[3]>>7)&0x01); tempGrav = ((c[3]>>7)&0x01);
} }
} else { } else {
if (c[3]==1||c[3]==0) { if (c[3]==1||c[3]==0) {
@ -2875,6 +2875,8 @@ int main(int argc, char *argv[])
pfree = 0; pfree = 0;
legacy_enable = 0; legacy_enable = 0;
svf_filename[0] = 0;
svf_fileopen = 0;
svf_myvote = 0; svf_myvote = 0;
svf_open = 0; svf_open = 0;
svf_publish = 0; svf_publish = 0;
@ -2940,7 +2942,7 @@ int main(int argc, char *argv[])
memset(fire_b, 0, sizeof(fire_b)); memset(fire_b, 0, sizeof(fire_b));
} }
} }
if (x>=19 && x<=35 && svf_last && svf_open && !bq) { if (x>=19 && x<=35 && svf_last && (svf_open || svf_fileopen) && !bq) {
//int tpval = sys_pause; //int tpval = sys_pause;
parse_save(svf_last, svf_lsize, 1, 0, 0, bmap, fvx, fvy, signs, parts, pmap); parse_save(svf_last, svf_lsize, 1, 0, 0, bmap, fvx, fvy, signs, parts, pmap);
//sys_pause = tpval; //sys_pause = tpval;