Skip to content

Commit

Permalink
Start writing new history file
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro-Beirao committed Jun 1, 2024
1 parent a9b834b commit 12ce4da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,8 @@ void MainWindow::SaveHistory(QStringList args)
QString h = "# Do not edit this file manually\n\nchecksum=" + QString::number(checksum) + "\n";
QString streamstr = stream.readAll();

QFile file_out(historyListWindow->historyPath);
file_out.open(QIODevice::WriteOnly | QIODevice::Text);
QFile file_out(historyListWindow->historyPath + "_tmp");
file_out.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate);
if (!file_out.isOpen())
{
return;
Expand Down Expand Up @@ -809,9 +809,9 @@ void MainWindow::SaveHistory(QStringList args)
out << h;
}
file_out.close();
states::saveStateToFile(historyListWindow->historyPath + "s");
states::saveStateToFile(historyListWindow->historyPath + "_tmp");
QFile::remove(historyListWindow->historyPath);
QFile::rename(historyListWindow->historyPath + "s", historyListWindow->historyPath);
QFile::rename(historyListWindow->historyPath + "_tmp", historyListWindow->historyPath);
}

QString demoFile;
Expand Down
15 changes: 10 additions & 5 deletions src/states.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ void states::loadStateNew(QTextStream &stream)
{
QString buffer;
stream.readLineInto(&buffer);
buffer = buffer.trimmed();

QString buffer_name;
QString buffer_value;
Expand Down Expand Up @@ -317,13 +318,17 @@ void states::saveStateToFile(QString filePath)
MainWindow *ui = MainWindow::pMainWindow;

QFile file(filePath);
if (!file.open(QFile::ReadWrite | QFile::Text | QFile::Truncate))
QTextStream out(&file);
if (getExtension(filePath) == "states_tmp")
{
return;
if (!file.open(QFile::ReadWrite | QFile::Text | QIODevice::Append)) return;
out << "-\n";
}
else
{
if (!file.open(QFile::ReadWrite | QFile::Text | QFile::Truncate)) return;
out << STATE_HEADER + "\n\n";
}
QTextStream out(&file);

out << STATE_HEADER + "\n\n";

out << "iwad " + ui->iwad_comboBox()->currentText() + "\n";
out << "complevel " + ui->complevel_comboBox()->currentText() + "\n";
Expand Down

0 comments on commit 12ce4da

Please sign in to comment.