replay: add replay_save_syspath()

This commit is contained in:
Andrei Alexeyev 2023-06-13 06:22:28 +02:00
parent 6a7a65e6b8
commit 100036c676
No known key found for this signature in database
GPG key ID: 72D26128040B9690
2 changed files with 32 additions and 4 deletions

View file

@ -100,14 +100,18 @@ bool replay_load_syspath(Replay *rpy, const char *path, ReplayReadMode mode) {
if(!strcmp(path, "-")) {
file = SDL_RWFromFP(stdin, false);
if(!file) {
log_sdl_error(LOG_ERROR, "SDL_RWFromFP");
return false;
}
} else {
file = SDL_RWFromFile(path, "rb");
if(!file) {
log_sdl_error(LOG_ERROR, "SDL_RWFromFile");
return false;
}
}
if(!file) {
log_error("SDL_RWFromFile() failed: %s", SDL_GetError());
return false;
}
bool result = replay_read(rpy, file, mode, path);
@ -115,6 +119,29 @@ bool replay_load_syspath(Replay *rpy, const char *path, ReplayReadMode mode) {
return result;
}
bool replay_save_syspath(Replay *rpy, const char *path, uint16_t version) {
log_info("Saving %s", path);
SDL_RWops *file;
if(!strcmp(path, "-")) {
file = SDL_RWFromFP(stdout, false);
if(!file) {
log_sdl_error(LOG_ERROR, "SDL_RWFromFP");
return false;
}
} else {
file = SDL_RWFromFile(path, "wb");
if(!file) {
log_sdl_error(LOG_ERROR, "SDL_RWFromFile");
return false;
}
}
bool result = replay_write(rpy, file, version);
SDL_RWclose(file);
return result;
}
int replay_find_stage_idx(Replay *rpy, uint8_t stageid) {
dynarray_foreach(&rpy->stages, int i, ReplayStage *stg, {
if(stg->stage == stageid) {

View file

@ -38,6 +38,7 @@ bool replay_write(Replay *rpy, SDL_RWops *file, uint16_t version) attr_nonnull_a
bool replay_read(Replay *rpy, SDL_RWops *file, ReplayReadMode mode, const char *source) attr_nonnull(1, 2);
bool replay_save(Replay *rpy, const char *name) attr_nonnull_all;
bool replay_save_syspath(Replay *rpy, const char *path, uint16_t version) attr_nonnull_all;
bool replay_load(Replay *rpy, const char *name, ReplayReadMode mode) attr_nonnull_all;
bool replay_load_syspath(Replay *rpy, const char *path, ReplayReadMode mode) attr_nonnull_all;
bool replay_load_vfspath(Replay *rpy, const char *path, ReplayReadMode mode) attr_nonnull_all;