mirror of
https://gitlab.com/pholy/OSCAR-code.git
synced 2025-04-06 19:20:45 +00:00
Check for ability to write to data directory at startup
Show critical error message and exit OSCAR if unable to write to data directory Improve qWarning message in logger.cpp Present warning dialog if logger cannot write to disk
This commit is contained in:
parent
86bc4ac606
commit
b338d7aa3d
@ -87,11 +87,11 @@ void LogThread::connectionReady()
|
|||||||
qDebug() << "Logging UI initialized";
|
qDebug() << "Logging UI initialized";
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogThread::logToFile()
|
bool LogThread::logToFile()
|
||||||
{
|
{
|
||||||
if (m_logStream) {
|
if (m_logStream) {
|
||||||
qWarning().noquote() << "Already logging to" << m_logFile->fileName();
|
qWarning().noquote() << "Already logging to" << m_logFile->fileName();
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString debugLog = GetLogDir() + "/debug.txt";
|
QString debugLog = GetLogDir() + "/debug.txt";
|
||||||
@ -109,8 +109,10 @@ void LogThread::logToFile()
|
|||||||
if (m_logStream) {
|
if (m_logStream) {
|
||||||
qDebug().noquote() << "Logging to" << debugLog;
|
qDebug().noquote() << "Logging to" << debugLog;
|
||||||
} else {
|
} else {
|
||||||
qWarning().noquote() << "Unable to open" << debugLog;
|
qWarning().noquote() << "Could not open" << debugLog << "error code" << m_logFile->error() << m_logFile->errorString();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogThread::~LogThread()
|
LogThread::~LogThread()
|
||||||
|
@ -29,7 +29,7 @@ public:
|
|||||||
void appendClean(QString msg);
|
void appendClean(QString msg);
|
||||||
bool isRunning() { return running; }
|
bool isRunning() { return running; }
|
||||||
void connectionReady();
|
void connectionReady();
|
||||||
void logToFile();
|
bool logToFile();
|
||||||
QString logFileName();
|
QString logFileName();
|
||||||
|
|
||||||
void quit();
|
void quit();
|
||||||
|
@ -379,7 +379,7 @@ int main(int argc, char *argv[]) {
|
|||||||
initializeLogger();
|
initializeLogger();
|
||||||
// After initializing the logger, any qDebug() messages will be queued but not written to console
|
// After initializing the logger, any qDebug() messages will be queued but not written to console
|
||||||
// until MainWindow is constructed below. In spite of that, we initialize the logger here so that
|
// until MainWindow is constructed below. In spite of that, we initialize the logger here so that
|
||||||
// the intervening messages to show up in the debug pane.
|
// the intervening messages show up in the debug pane.
|
||||||
//
|
//
|
||||||
// The only time this is really noticeable is when initTranslations() presents its language
|
// The only time this is really noticeable is when initTranslations() presents its language
|
||||||
// selection QDialog, which waits indefinitely for user input before MainWindow is constructed.
|
// selection QDialog, which waits indefinitely for user input before MainWindow is constructed.
|
||||||
@ -555,8 +555,27 @@ int main(int argc, char *argv[]) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure we can write to the data directory
|
||||||
|
QFile testFile(GetAppData()+"/testfile.txt");
|
||||||
|
if (testFile.exists())
|
||||||
|
testFile.remove();
|
||||||
|
if (!testFile.open(QFile::ReadWrite)) {
|
||||||
|
QString errMsg = QObject::tr("Unable to write to OSCAR data directory") + "\n" +
|
||||||
|
GetAppData() + "\n" +
|
||||||
|
QObject::tr("Error code") + ": " + QString::number(testFile.error()) + " - " + testFile.errorString() + "\n\n" +
|
||||||
|
QObject::tr("OSCAR cannot continue and is exiting.") + "\n";
|
||||||
|
qCritical() << errMsg;
|
||||||
|
QMessageBox::critical(nullptr, QObject::tr("Exiting"), errMsg);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
testFile.remove();
|
||||||
|
|
||||||
// Begin logging to file now that there's a data folder.
|
// Begin logging to file now that there's a data folder.
|
||||||
logger->logToFile();
|
if (!logger->logToFile()) {
|
||||||
|
QMessageBox::warning(nullptr, STR_MessageBox_Warning,
|
||||||
|
QObject::tr("Unable to write to debug log. You can still use the debug pane (Help/Troubleshooting/Show Debug Pane) but the debug log will not be written to disk."));
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Initialize preferences system (Don't use p_pref before this point!)
|
// Initialize preferences system (Don't use p_pref before this point!)
|
||||||
|
Loading…
Reference in New Issue
Block a user