mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2025-09-05 22:57:47 -04:00
Ensure that CALL3.TXT is not deleted while updating the file
This is necessary so that symlinks that may be used to share CALL3.TXT between WSJT-X instances and with and MAP65 do not get broken when adding new entries in either application.
This commit is contained in:
parent
f884f77321
commit
917acbb97f
@ -1970,16 +1970,16 @@ void MainWindow::on_addButton_clicked() //Add button
|
|||||||
<< endl
|
<< endl
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
f1.close();
|
f1.seek (0);
|
||||||
f1.open(QIODevice::ReadOnly | QIODevice::Text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString tmpFile = m_appDir + "/CALL3.TMP";
|
QString tmpFile = m_appDir + "/CALL3.TMP";
|
||||||
QFile f2(tmpFile);
|
QFile f2(tmpFile);
|
||||||
if(!f2.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
if(!f2.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) {
|
||||||
msgBox("Cannot open " + tmpFile);
|
msgBox("Cannot open " + tmpFile);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
{
|
||||||
QTextStream in(&f1);
|
QTextStream in(&f1);
|
||||||
QTextStream out(&f2);
|
QTextStream out(&f2);
|
||||||
QString hc=hiscall;
|
QString hc=hiscall;
|
||||||
@ -2012,16 +2012,19 @@ void MainWindow::on_addButton_clicked() //Add button
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while(!s.isNull());
|
} while(!s.isNull());
|
||||||
|
|
||||||
f1.close();
|
|
||||||
if(hc>hc1 && !m_call3Modified) out << newEntry + "\n";
|
if(hc>hc1 && !m_call3Modified) out << newEntry + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
if(m_call3Modified) {
|
if(m_call3Modified) {
|
||||||
QFile f0(m_appDir + "/CALL3.OLD");
|
auto const& old_path = m_appDir + "/CALL3.OLD";
|
||||||
|
QFile f0 {old_path};
|
||||||
if (f0.exists ()) f0.remove ();
|
if (f0.exists ()) f0.remove ();
|
||||||
QFile f1(m_appDir + "/CALL3.TXT");
|
f1.copy (old_path); // copying as we want to preserve
|
||||||
f1.rename(m_appDir + "/CALL3.OLD");
|
// symlinks
|
||||||
f2.rename(m_appDir + "/CALL3.TXT");
|
f1.open (QFile::WriteOnly | QFile::Text); // truncates
|
||||||
f2.close();
|
f2.seek (0);
|
||||||
|
f1.write (f2.readAll ()); // copy contents
|
||||||
|
f2.remove ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5670,16 +5670,16 @@ void MainWindow::on_addButton_clicked() //Add button
|
|||||||
<< endl
|
<< endl
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
f1.close();
|
f1.seek (0);
|
||||||
f1.open(QIODevice::ReadOnly | QIODevice::Text);
|
|
||||||
}
|
}
|
||||||
QFile f2 {m_config.writeable_data_dir ().absoluteFilePath ("CALL3.TMP")};
|
QFile f2 {m_config.writeable_data_dir ().absoluteFilePath ("CALL3.TMP")};
|
||||||
if(!f2.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
if(!f2.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) {
|
||||||
MessageBox::warning_message (this, tr ("Add to CALL3.TXT")
|
MessageBox::warning_message (this, tr ("Add to CALL3.TXT")
|
||||||
, tr ("Cannot open \"%1\" for writing: %2")
|
, tr ("Cannot open \"%1\" for writing: %2")
|
||||||
.arg (f2.fileName ()).arg (f2.errorString ()));
|
.arg (f2.fileName ()).arg (f2.errorString ()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
{
|
||||||
QTextStream in(&f1); //Read from CALL3.TXT
|
QTextStream in(&f1); //Read from CALL3.TXT
|
||||||
QTextStream out(&f2); //Copy into CALL3.TMP
|
QTextStream out(&f2); //Copy into CALL3.TMP
|
||||||
QString hc=hisCall;
|
QString hc=hisCall;
|
||||||
@ -5711,16 +5711,19 @@ void MainWindow::on_addButton_clicked() //Add button
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while(!s.isNull());
|
} while(!s.isNull());
|
||||||
|
|
||||||
f1.close();
|
|
||||||
if(hc>hc1 && !m_call3Modified) out << newEntry + QChar::LineFeed;
|
if(hc>hc1 && !m_call3Modified) out << newEntry + QChar::LineFeed;
|
||||||
|
}
|
||||||
|
|
||||||
if(m_call3Modified) {
|
if(m_call3Modified) {
|
||||||
QFile f0 {m_config.writeable_data_dir ().absoluteFilePath ("CALL3.OLD")};
|
auto const& old_path = m_config.writeable_data_dir ().absoluteFilePath ("CALL3.OLD");
|
||||||
|
QFile f0 {old_path};
|
||||||
if (f0.exists ()) f0.remove ();
|
if (f0.exists ()) f0.remove ();
|
||||||
QFile f1 {m_config.writeable_data_dir ().absoluteFilePath ("CALL3.TXT")};
|
f1.copy (old_path); // copying as we want to
|
||||||
f1.rename(m_config.writeable_data_dir ().absoluteFilePath ("CALL3.OLD"));
|
// preserve symlinks
|
||||||
f2.rename(m_config.writeable_data_dir ().absoluteFilePath ("CALL3.TXT"));
|
f1.open (QFile::WriteOnly | QFile::Text); // truncates
|
||||||
f2.close();
|
f2.seek (0);
|
||||||
|
f1.write (f2.readAll ()); // copy contents
|
||||||
|
f2.remove ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user