| 30 | static int nb_frame_advance = 0; |
| 31 | |
| 32 | void AutoSave::update(Context* context, MovieFile& movie) |
| 33 | { |
| 34 | /* Check if autosave is enabled */ |
| 35 | if (!context->config.autosave) |
| 36 | return; |
| 37 | |
| 38 | /* Check if the movie was modified */ |
| 39 | if (!movie.inputs->modifiedSinceLastAutoSave) |
| 40 | return; |
| 41 | |
| 42 | /* Update the frame counter and check if we must auto-save */ |
| 43 | if ((++nb_frame_advance > context->config.autosave_frames) && |
| 44 | (difftime(time(nullptr), last_time_saved) > context->config.autosave_delay_sec)) |
| 45 | { |
| 46 | nb_frame_advance = 0; |
| 47 | time(&last_time_saved); |
| 48 | |
| 49 | /* Build the autosave filename */ |
| 50 | std::filesystem::path moviename = context->config.moviefile.stem(); |
| 51 | |
| 52 | /* We remove old saves here while we have the correct movie name */ |
| 53 | removeOldSaves(context, moviename.string()); |
| 54 | |
| 55 | moviename = context->config.tempmoviedir / moviename; |
| 56 | |
| 57 | char buf[32]; |
| 58 | strftime(buf, 32, "_%Y%m%d-%H%M%S.ltm", localtime(&last_time_saved)); |
| 59 | |
| 60 | moviename += buf; |
| 61 | |
| 62 | std::cout << "Autosave movie to " << moviename << std::endl; |
| 63 | |
| 64 | /* Save the movie */ |
| 65 | movie.saveMovie(moviename); |
| 66 | |
| 67 | movie.inputs->modifiedSinceLastAutoSave = false; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | void AutoSave::removeOldSaves(Context* context, const std::string& moviename) |
| 72 | { |
no test coverage detected