SaveTool,ProfileManager: make backups 0.8-ready.

This commit is contained in:
Guillaume Jacquemin 2022-03-20 09:14:11 +01:00
parent 75d77413f6
commit e91c015c00
3 changed files with 35 additions and 19 deletions

View file

@ -127,9 +127,10 @@ auto ProfileManager::deleteProfile(std::size_t index, bool delete_builds) -> boo
auto ProfileManager::backupProfile(std::size_t index, bool backup_builds) -> bool {
std::time_t timestamp = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::tm* time = std::localtime(&timestamp);
auto& profile = _profiles[index];
auto filename = Utility::format("{}_{}{:.2d}{:.2d}_{:.2d}{:.2d}{:.2d}.mbprofbackup",
Utility::String::replaceAll(_profiles[index].companyName().data(), " ", "_").c_str(),
Utility::String::replaceAll(profile.companyName().data(), " ", "_").c_str(),
time->tm_year + 1900, time->tm_mon + 1, time->tm_mday,
time->tm_hour, time->tm_min, time->tm_sec);
@ -142,31 +143,32 @@ auto ProfileManager::backupProfile(std::size_t index, bool backup_builds) -> boo
return false;
}
zip_source_t* profile_source = zip_source_file(zip, Utility::Path::toNativeSeparators(Utility::Path::join(_saveDirectory, _profiles[index].filename())).data(), 0, 0);
zip_source_t* profile_source = zip_source_file(zip, Utility::Path::toNativeSeparators(Utility::Path::join(_saveDirectory, profile.filename())).data(), 0, 0);
if(profile_source == nullptr) {
_lastError = zip_strerror(zip);
zip_source_free(profile_source);
return false;
}
if(zip_file_add(zip, _profiles[index].filename().data(), profile_source, ZIP_FL_ENC_UTF_8) == -1) {
if(zip_file_add(zip, profile.filename().data(), profile_source, ZIP_FL_ENC_UTF_8) == -1) {
_lastError = zip_strerror(zip);
zip_source_free(profile_source);
return false;
}
auto comment = "|"_s.join({_profiles[index].companyName(),
_profiles[index].type() == ProfileType::Demo ? "demo"_s : "full"_s,
Utility::format("{}-{:.2d}-{:.2d}-{:.2d}-{:.2d}-{:.2d}",
time->tm_year + 1900, time->tm_mon + 1, time->tm_mday,
time->tm_hour, time->tm_min, time->tm_sec)});
auto comment = Utility::format("{}|{}{}|{}-{:.2d}-{:.2d}-{:.2d}-{:.2d}-{:.2d}",
profile.companyName(),
profile.isDemo() ? "demo"_s : "full"_s,
profile.isLegacy() ? ""_s : "_new"_s,
time->tm_year + 1900, time->tm_mon + 1, time->tm_mday,
time->tm_hour, time->tm_min, time->tm_sec);
zip_set_archive_comment(zip, comment.data(), comment.size());
if(backup_builds) {
for(UnsignedByte i = 0; i < 32; ++i) {
auto build_filename = Utility::format("{}Unit{:.2d}{}.sav",
_profiles[index].type() == ProfileType::Demo ? "Demo"_s : ""_s, i,
_profiles[index].account());
profile.isDemo() ? "Demo"_s : ""_s, i,
profile.account());
if(!Utility::Path::exists(Utility::Path::join(_saveDirectory, build_filename))) {
continue;
@ -252,9 +254,19 @@ void ProfileManager::refreshBackups() {
if(info[1] == "full") {
backup.type = ProfileType::FullGame;
backup.version = ProfileVersion::Legacy;
}
else if(info[1] == "demo") {
backup.type = ProfileType::Demo;
backup.version = ProfileVersion::Legacy;
}
else if(info[1] == "full_new") {
backup.type = ProfileType::FullGame;
backup.version = ProfileVersion::Normal;
}
else if(info[1] == "demo_new") {
backup.type = ProfileType::Demo;
backup.version = ProfileVersion::Normal;
}
else {
continue;

View file

@ -29,6 +29,7 @@ struct Backup {
Containers::String filename;
Containers::String company;
ProfileType type;
ProfileVersion version;
struct {
int year;
int month;

View file

@ -250,13 +250,14 @@ auto SaveTool::drawBackupListPopup() -> ImGuiID {
ImGui::TextUnformatted("Actions");
for(std::size_t i = 0; i < _profileManager->backups().size(); ++i) {
auto& backup = _profileManager->backups()[i];
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
ImGui::TextUnformatted(_profileManager->backups()[i].company.data());
ImGui::TextUnformatted(backup.company.data());
if(ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
for(const auto& file : _profileManager->backups()[i].includedFiles) {
for(const auto& file : backup.includedFiles) {
ImGui::TextUnformatted(file.data());
}
ImGui::EndTooltip();
@ -264,15 +265,17 @@ auto SaveTool::drawBackupListPopup() -> ImGuiID {
ImGui::TableSetColumnIndex(1);
ImGui::Text("%.4i-%.2i-%.2i %.2i:%.2i:%.2i",
_profileManager->backups()[i].timestamp.year,
_profileManager->backups()[i].timestamp.month,
_profileManager->backups()[i].timestamp.day,
_profileManager->backups()[i].timestamp.hour,
_profileManager->backups()[i].timestamp.minute,
_profileManager->backups()[i].timestamp.second);
backup.timestamp.year,
backup.timestamp.month,
backup.timestamp.day,
backup.timestamp.hour,
backup.timestamp.minute,
backup.timestamp.second);
ImGui::TableSetColumnIndex(2);
ImGui::TextUnformatted(_profileManager->backups()[i].type == ProfileType::Demo ? "Demo" : "Full");
ImGui::Text("%s%s",
backup.type == ProfileType::Demo ? "Demo" : "Full",
backup.version == ProfileVersion::Legacy ? " (legacy)" : "");
ImGui::TableSetColumnIndex(3);
ImGui::PushID(i);