Display current save slot information
This commit is contained in:
parent
185085a019
commit
b7dfe28ae1
3 changed files with 77 additions and 7 deletions
|
@ -22,6 +22,7 @@ extern bool system_corrupt;
|
|||
std::vector<char>& get_host_memory();
|
||||
movie& get_movie();
|
||||
|
||||
std::string resolve_relative_path(const std::string& path);
|
||||
std::pair<std::string, std::string> split_author(const std::string& author) throw(std::bad_alloc,
|
||||
std::runtime_error);
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "core/window.hpp"
|
||||
#include "library/framebuffer.hpp"
|
||||
#include "library/pixfmt-lrgb.hpp"
|
||||
#include "library/zip.hpp"
|
||||
|
||||
#include <iomanip>
|
||||
#include <cassert>
|
||||
|
@ -89,6 +90,49 @@ namespace
|
|||
{
|
||||
return (stringfmt() << "${project}" << (i + 1) << ".lsmv").str();
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> slotinfo_cache;
|
||||
|
||||
std::string vector_to_string(const std::vector<char>& x)
|
||||
{
|
||||
std::string y(x.begin(), x.end());
|
||||
while(y.length() > 0 && y[y.length() - 1] < 32)
|
||||
y = y.substr(0, y.length() - 1);
|
||||
return y;
|
||||
}
|
||||
|
||||
std::string get_slotinfo(const std::string& _filename)
|
||||
{
|
||||
std::string filename = resolve_relative_path(_filename);
|
||||
if(!slotinfo_cache.count(filename)) {
|
||||
std::ostringstream out;
|
||||
try {
|
||||
std::string projid = vector_to_string(read_file_relative(filename + "/projectid",
|
||||
""));
|
||||
std::string rerecords = vector_to_string(read_file_relative(filename + "/rerecords",
|
||||
""));
|
||||
std::string frame = vector_to_string(read_file_relative(filename + "/saveframe", ""));
|
||||
if(our_movie.projectid == projid)
|
||||
out << rerecords << "R/" << frame << "F";
|
||||
else
|
||||
out << "Wrong movie";
|
||||
} catch(...) {
|
||||
out << "Nonexistent";
|
||||
}
|
||||
slotinfo_cache[filename] = out.str();
|
||||
}
|
||||
return slotinfo_cache[filename];
|
||||
}
|
||||
|
||||
void flush_slotinfo(const std::string& filename)
|
||||
{
|
||||
slotinfo_cache.erase(resolve_relative_path(filename));
|
||||
}
|
||||
|
||||
void flush_slotinfo()
|
||||
{
|
||||
slotinfo_cache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
path_setting firmwarepath_setting("firmwarepath");
|
||||
|
@ -208,11 +252,13 @@ namespace
|
|||
if(smode == SAVE_MOVIE) {
|
||||
//Just do this immediately.
|
||||
do_save_movie(filename);
|
||||
flush_slotinfo(filename);
|
||||
return;
|
||||
}
|
||||
if(location_special == SPECIAL_SAVEPOINT) {
|
||||
//We can save immediately here.
|
||||
do_save_state(filename);
|
||||
flush_slotinfo(filename);
|
||||
return;
|
||||
}
|
||||
queued_saves.insert(filename);
|
||||
|
@ -292,10 +338,14 @@ void update_movie_state()
|
|||
x << "F";
|
||||
_status.set("Flags", x.str());
|
||||
}
|
||||
if(jukebox_size > 0)
|
||||
_status.set("Saveslot", translate_name_mprefix(save_jukebox_name(save_jukebox_pointer)));
|
||||
else
|
||||
_status.erase("Saveslot");
|
||||
if(jukebox_size > 0) {
|
||||
std::string sfilen = translate_name_mprefix(save_jukebox_name(save_jukebox_pointer));
|
||||
_status.set("Slot", sfilen);
|
||||
_status.set("Slotinf", get_slotinfo(sfilen));
|
||||
} else {
|
||||
_status.erase("Slot");
|
||||
_status.erase("Slotinf");
|
||||
}
|
||||
{
|
||||
std::ostringstream x;
|
||||
x << get_framerate();
|
||||
|
@ -685,6 +735,11 @@ namespace
|
|||
messages << "Pending saves canceled." << std::endl;
|
||||
});
|
||||
|
||||
function_ptr_command<> flushslots("flush-slotinfo", "Flush slotinfo cache", "Flush slotinfo cache\n",
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
flush_slotinfo();
|
||||
});
|
||||
|
||||
function_ptr_command<> test1("test-1", "no description available", "No help available\n",
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
redraw_framebuffer(screen_nosignal);
|
||||
|
@ -834,6 +889,7 @@ namespace
|
|||
return 1;
|
||||
}
|
||||
if(pending_load != "") {
|
||||
std::string old_project = our_movie.projectid;
|
||||
system_corrupt = false;
|
||||
if(loadmode != LOAD_STATE_BEGINNING && loadmode != LOAD_STATE_ROMRELOAD &&
|
||||
!do_load_state(pending_load, loadmode)) {
|
||||
|
@ -859,6 +915,8 @@ namespace
|
|||
information_dispatch::do_status_update();
|
||||
platform::flush_command_queue();
|
||||
}
|
||||
if(old_project != our_movie.projectid)
|
||||
flush_slotinfo(); //Wrong movie may be stale.
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -869,8 +927,10 @@ namespace
|
|||
{
|
||||
if(!queued_saves.empty() || (do_unsafe_rewind && !unsafe_rewind_obj)) {
|
||||
core_runtosave();
|
||||
for(auto i : queued_saves)
|
||||
for(auto i : queued_saves) {
|
||||
do_save_state(i);
|
||||
flush_slotinfo(i);
|
||||
}
|
||||
if(do_unsafe_rewind && !unsafe_rewind_obj) {
|
||||
uint64_t t = get_utime();
|
||||
std::vector<char> s = save_core_state(true);
|
||||
|
|
|
@ -214,6 +214,15 @@ std::pair<std::string, std::string> split_author(const std::string& author) thro
|
|||
return std::make_pair(fullname, nickname);
|
||||
}
|
||||
|
||||
//Resolve relative path.
|
||||
std::string resolve_relative_path(const std::string& path)
|
||||
{
|
||||
try {
|
||||
return boost_fs::absolute(boost_fs::path(path)).string();
|
||||
} catch(...) {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
//Save state.
|
||||
void do_save_state(const std::string& filename) throw(std::bad_alloc,
|
||||
|
@ -251,7 +260,7 @@ void do_save_state(const std::string& filename) throw(std::bad_alloc,
|
|||
messages << "Save failed: " << e.what() << std::endl;
|
||||
lua_callback_err_save(filename2);
|
||||
}
|
||||
last_save = boost_fs::absolute(boost_fs::path(filename2)).string();
|
||||
last_save = resolve_relative_path(filename2);
|
||||
}
|
||||
|
||||
//Save movie.
|
||||
|
@ -279,7 +288,7 @@ void do_save_movie(const std::string& filename) throw(std::bad_alloc, std::runti
|
|||
messages << "Save failed: " << e.what() << std::endl;
|
||||
lua_callback_err_save(filename2);
|
||||
}
|
||||
last_save = boost_fs::absolute(boost_fs::path(filename2)).string();
|
||||
last_save = resolve_relative_path(filename2);
|
||||
}
|
||||
|
||||
extern time_t random_seed_value;
|
||||
|
|
Loading…
Add table
Reference in a new issue