Add private evidence autosaving into inventories/autosave.ini (#778)
* Add private evidence autosaving into inventories/autosave.ini * Make evidence autosave more robust by accounting for evidence transfers and deleteions Fix the ini not using UTF-8 codec Correct save/load functions working on local evidence list (displayed) rather than the proper private one * set ini codec Co-authored-by: oldmud0 <oldmud0@users.noreply.github.com> Co-authored-by: Salanto <62221668+Salanto@users.noreply.github.com> Co-authored-by: stonedDiscord <Tukz@gmx.de> Co-authored-by: oldmud0 <oldmud0@users.noreply.github.com>
This commit is contained in:
parent
f896475de4
commit
d8c89f056b
@ -986,6 +986,8 @@ private slots:
|
||||
void evidence_switch(bool global);
|
||||
void on_evidence_save_clicked();
|
||||
void on_evidence_load_clicked();
|
||||
void evidence_save(QString filename);
|
||||
void evidence_load(QString filename);
|
||||
bool compare_evidence_changed(evi_type evi_a, evi_type evi_b);
|
||||
|
||||
void on_back_to_lobby_clicked();
|
||||
|
@ -103,6 +103,7 @@ void Courtroom::initialize_evidence()
|
||||
&Courtroom::on_evidence_edited);
|
||||
|
||||
ui_evidence->hide();
|
||||
evidence_load("inventories/autosave.ini");
|
||||
}
|
||||
|
||||
void Courtroom::refresh_evidence()
|
||||
@ -571,6 +572,9 @@ void Courtroom::on_evidence_delete_clicked()
|
||||
local_evidence_list.remove(current_evidence);
|
||||
private_evidence_list = local_evidence_list;
|
||||
set_evidence_page();
|
||||
|
||||
// Autosave private evidence
|
||||
evidence_save("inventories/autosave.ini");
|
||||
}
|
||||
|
||||
current_evidence = 0;
|
||||
@ -634,6 +638,11 @@ void Courtroom::on_evidence_ok_clicked()
|
||||
set_evidence_page();
|
||||
}
|
||||
}
|
||||
|
||||
// Autosave private evidence
|
||||
if (!current_evidence_global) {
|
||||
evidence_save("inventories/autosave.ini");
|
||||
}
|
||||
}
|
||||
|
||||
void Courtroom::on_evidence_switch_clicked()
|
||||
@ -664,6 +673,9 @@ void Courtroom::on_evidence_transfer_clicked()
|
||||
evi_type f_evi = local_evidence_list.at(current_evidence);
|
||||
name = f_evi.name;
|
||||
private_evidence_list.append(f_evi);
|
||||
|
||||
// Autosave private evidence
|
||||
evidence_save("inventories/autosave.ini");
|
||||
}
|
||||
|
||||
QMessageBox *msgBox = new QMessageBox;
|
||||
@ -743,25 +755,19 @@ void Courtroom::on_evidence_save_clicked()
|
||||
return; // Don't allow saving/loading operations when in global inventory
|
||||
// mode for now
|
||||
|
||||
// "Inventories" dir keeps our private evidence data
|
||||
if (!dir_exists("inventories")) {
|
||||
// Create one if it doesn't yet exist
|
||||
QDir("inventories").mkdir("inventories");
|
||||
}
|
||||
|
||||
QString p_path = QFileDialog::getSaveFileName(
|
||||
this, tr("Save Inventory"), "base/inventories/", tr("Ini Files (*.ini)"));
|
||||
if (p_path.isEmpty())
|
||||
return;
|
||||
this, tr("Save Inventory"), "inventories/", tr("Ini Files (*.ini)"));
|
||||
|
||||
evidence_close();
|
||||
ui_evidence_name->setText("");
|
||||
|
||||
QSettings inventory(p_path, QSettings::IniFormat);
|
||||
inventory.setIniCodec("UTF-8");
|
||||
inventory.clear();
|
||||
for (int i = 0; i < local_evidence_list.size(); i++) {
|
||||
inventory.beginGroup(QString::number(i));
|
||||
inventory.setValue("name", local_evidence_list[i].name);
|
||||
inventory.setValue("description", local_evidence_list[i].description);
|
||||
inventory.setValue("image", local_evidence_list[i].image);
|
||||
inventory.endGroup();
|
||||
}
|
||||
inventory.sync();
|
||||
evidence_save(p_path);
|
||||
}
|
||||
|
||||
void Courtroom::on_evidence_load_clicked()
|
||||
@ -771,35 +777,59 @@ void Courtroom::on_evidence_load_clicked()
|
||||
// mode for now
|
||||
|
||||
QString p_path = QFileDialog::getOpenFileName(
|
||||
this, tr("Open Inventory"), "base/inventories/", tr("Ini Files (*.ini)"));
|
||||
this, tr("Open Inventory"), "inventories/", tr("Ini Files (*.ini)"));
|
||||
if (p_path.isEmpty())
|
||||
return;
|
||||
|
||||
evidence_close();
|
||||
ui_evidence_name->setText("");
|
||||
|
||||
QSettings inventory(p_path, QSettings::IniFormat);
|
||||
inventory.setIniCodec("UTF-8");
|
||||
local_evidence_list.clear();
|
||||
QMap<int, QString> sorted_evi;
|
||||
for (const auto &s : inventory.childGroups()) {
|
||||
sorted_evi[s.toInt()] = s;
|
||||
evidence_load(p_path);
|
||||
local_evidence_list = private_evidence_list;
|
||||
set_evidence_page();
|
||||
}
|
||||
QStringList evilist(sorted_evi.values());
|
||||
for (const QString &evi : evilist) {
|
||||
|
||||
void Courtroom::evidence_load(QString filename)
|
||||
{
|
||||
if (!file_exists(filename)) {
|
||||
qWarning() << "Trying to load a non-existant evidence save file:" << filename;
|
||||
return;
|
||||
}
|
||||
QSettings inventory(filename, QSettings::IniFormat);
|
||||
inventory.setIniCodec("UTF-8");
|
||||
private_evidence_list.clear();
|
||||
foreach (QString evi, inventory.childGroups()) {
|
||||
if (evi == "General")
|
||||
continue;
|
||||
|
||||
evi_type f_evi;
|
||||
f_evi.name = inventory.value(evi + "/name", tr("UNKNOWN")).value<QString>();
|
||||
f_evi.name = inventory.value(evi + "/name", "<name>").value<QString>();
|
||||
f_evi.description =
|
||||
inventory.value(evi + "/description", tr("UNKNOWN")).value<QString>();
|
||||
inventory.value(evi + "/description", "<description>").value<QString>();
|
||||
f_evi.image =
|
||||
inventory.value(evi + "/image", "UNKNOWN.png").value<QString>();
|
||||
local_evidence_list.append(f_evi);
|
||||
inventory.value(evi + "/image", "empty.png").value<QString>();
|
||||
private_evidence_list.append(f_evi);
|
||||
}
|
||||
private_evidence_list = local_evidence_list;
|
||||
set_evidence_page();
|
||||
}
|
||||
|
||||
void Courtroom::evidence_save(QString filename)
|
||||
{
|
||||
// "Inventories" dir keeps our private evidence data
|
||||
if (!dir_exists("inventories")) {
|
||||
// Create one if it doesn't yet exist
|
||||
QDir("inventories").mkdir("inventories");
|
||||
}
|
||||
|
||||
QSettings inventory(filename, QSettings::IniFormat);
|
||||
inventory.setIniCodec("UTF-8");
|
||||
inventory.clear();
|
||||
for (int i = 0; i < private_evidence_list.size(); i++) {
|
||||
inventory.beginGroup(QString::number(i));
|
||||
inventory.setValue("name", private_evidence_list[i].name);
|
||||
inventory.setValue("description", private_evidence_list[i].description);
|
||||
inventory.setValue("image", private_evidence_list[i].image);
|
||||
inventory.endGroup();
|
||||
}
|
||||
inventory.sync();
|
||||
}
|
||||
|
||||
bool Courtroom::compare_evidence_changed(evi_type evi_a, evi_type evi_b)
|
||||
|
Loading…
Reference in New Issue
Block a user