int eof_undo_load_state(const char * fn) { EOF_SONG * sp = NULL; PACKFILE * fp = NULL, * rfp = NULL; char rheader[16] = {0}; int old_eof_silence_loaded = eof_silence_loaded; //Retain this value, since it is destroyed by eof_destroy_song() char eof_recover_path[50]; eof_log("eof_undo_load_state() entered", 1); if(fn == NULL) { return 0; } fp = pack_fopen(fn, "r"); if(!fp) { return 0; } if(pack_fread(rheader, 16, fp) != 16) { return 0; //Return error if 16 bytes cannot be read } sp = eof_create_song(); //Initialize an empty chart if(sp == NULL) { return 0; } sp->tags->accurate_ts = 0; //For existing projects, this setting must be manually enabled in order to prevent unwanted alteration to beat timings (void) snprintf(eof_recover_path, sizeof(eof_recover_path) - 1, "%seof.recover", eof_temp_path); rfp = pack_fopen(eof_recover_path, "r"); //Open the recovery file to prevent eof_destroy_song() from deleting it if(!eof_load_song_pf(sp, fp)) { //If loading the undo state fails allegro_message("Failed to perform undo"); (void) pack_fclose(rfp); //Close this recovery file handle so that it will be deleted by the following call to eof_destroy_song() eof_destroy_song(sp); return 0; //Return failure } if(eof_song) { eof_destroy_song(eof_song); //Destroy the chart that is open } (void) pack_fclose(rfp); eof_song = sp; //Replacing it with the loaded undo state eof_silence_loaded = old_eof_silence_loaded; //Restore the status of whether chart audio is loaded (void) pack_fclose(fp); return 1; }
int eof_undo_load_state(const char * fn) { EOF_SONG * sp = NULL; PACKFILE * fp = NULL; char rheader[16] = {0}; int old_eof_silence_loaded = eof_silence_loaded; //Retain this value, since it is destroyed by eof_destroy_song() eof_log("eof_undo_load_state() entered", 1); if(fn == NULL) { return 0; } fp = pack_fopen(fn, "r"); if(!fp) { return 0; } if(pack_fread(rheader, 16, fp) != 16) { return 0; //Return error if 16 bytes cannot be read } sp = eof_create_song(); //Initialize an empty chart if(sp == NULL) { return 0; } if(!eof_load_song_pf(sp, fp)) { //If loading the undo state fails allegro_message("Failed to perform undo"); eof_destroy_song(sp); return 0; //Return failure } if(eof_song) { eof_destroy_song(eof_song); //Destroy the chart that is open } eof_song = sp; //Replacing it with the loaded undo state eof_silence_loaded = old_eof_silence_loaded; //Restore the status of whether chart audio is loaded (void) pack_fclose(fp); return 1; }
int eof_undo_load_state(const char * fn) { EOF_SONG * sp = NULL; PACKFILE * fp = NULL, * rfp = NULL; char rheader[16] = {0}; int old_eof_silence_loaded = eof_silence_loaded; //Retain this value, since it is destroyed by eof_destroy_song() char eof_recover_path[50]; eof_log("eof_undo_load_state() entered", 1); if(fn == NULL) { return 0; } fp = pack_fopen(fn, "r"); if(!fp) { return 0; } if(pack_fread(rheader, 16, fp) != 16) { (void) pack_fclose(fp); return 0; //Return error if 16 bytes cannot be read } sp = eof_create_song(); //Initialize an empty chart if(sp == NULL) { (void) pack_fclose(fp); return 0; } sp->tags->accurate_ts = 0; //For existing projects, this setting must be manually enabled in order to prevent unwanted alteration to beat timings (void) snprintf(eof_recover_path, sizeof(eof_recover_path) - 1, "%seof.recover", eof_temp_path_s); rfp = pack_fopen(eof_recover_path, "r"); //Open the recovery file to prevent eof_destroy_song() from deleting it if(!eof_load_song_pf(sp, fp)) { //If loading the undo state fails allegro_message("Failed to perform undo"); (void) pack_fclose(rfp); //Close this recovery file handle so that it will be deleted by the following call to eof_destroy_song() eof_destroy_song(sp); (void) pack_fclose(fp); return 0; //Return failure } (void) pack_fclose(fp); if(EOF_TRACK_PRO_GUITAR_B >= sp->tracks) { //If the chart loaded does not contain a bonus pro guitar track (a pre 1.8RC12 chart or a post 1.8RC12 chart with an empty bonus track during save) if(eof_song_add_track(sp, &eof_default_tracks[EOF_TRACK_PRO_GUITAR_B]) == 0) //Add a blank bonus pro guitar track { //If the track failed to be added allegro_message("Failed to perform undo"); (void) pack_fclose(rfp); //Close this recovery file handle so that it will be deleted by the following call to eof_destroy_song() eof_destroy_song(sp); return 0; //Return failure } } if(eof_song) { eof_undo_in_progress = 1; //Signal to eof_destroy_song() that the waveform and spectrogram are not to be destroyed along with the active project structure eof_destroy_song(eof_song); //Destroy the chart that is open eof_undo_in_progress = 0; } (void) pack_fclose(rfp); //Calls to eof_destroy_song() are finished, the recovery file handle can be released now eof_song = sp; //Replacing it with the loaded undo state eof_silence_loaded = old_eof_silence_loaded; //Restore the status of whether chart audio is loaded return 1; }