From a46bb29254f848b81304c1d17760c6d1dbf052dc Mon Sep 17 00:00:00 2001 From: kervala Date: Thu, 20 Oct 2016 13:07:18 +0200 Subject: [PATCH] Changed: Logs in Ryzom Installer --- .../client/ryzom_installer/src/downloader.cpp | 9 +++- .../ryzom_installer/src/installdialog.cpp | 9 ++-- .../tools/client/ryzom_installer/src/main.cpp | 27 +++++++++++ .../ryzom_installer/src/migratedialog.cpp | 8 ++-- .../client/ryzom_installer/src/operation.h | 2 + .../tools/client/ryzom_installer/src/stdpch.h | 6 ++- .../client/ryzom_installer/src/utils.cpp | 48 +++++++++++++++++++ .../tools/client/ryzom_installer/src/utils.h | 10 ++++ 8 files changed, 108 insertions(+), 11 deletions(-) diff --git a/code/ryzom/tools/client/ryzom_installer/src/downloader.cpp b/code/ryzom/tools/client/ryzom_installer/src/downloader.cpp index bbc660f8a..19e5793ee 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/downloader.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/downloader.cpp @@ -272,6 +272,8 @@ void CDownloader::onHeadFinished() { if (redirection.isEmpty()) { + nlwarning("No redirection defined"); + if (m_listener) m_listener->operationFail(tr("Redirection URL is not defined")); return; } @@ -298,6 +300,8 @@ void CDownloader::onHeadFinished() if (!m_supportsAcceptRanges && acceptRanges == "bytes") { + nlinfo("Server supports resume for %s", Q2C(url)); + // server supports resume, part 1 m_supportsAcceptRanges = true; @@ -309,6 +313,7 @@ void CDownloader::onHeadFinished() // server doesn't support resume or // we requested range, but server always returns 200 // download from the beginning + nlwarning("Server doesn't support resume, download %s from the beginning", Q2C(url)); } // we requested with a range @@ -327,10 +332,12 @@ void CDownloader::onHeadFinished() // update offset and size if (m_listener) m_listener->operationInit(m_offset, m_size); + + nlinfo("Server supports resume for %s: offset %" NL_I64 "d, size %" NL_I64 "d", Q2C(url), m_offset, m_size); } else { - qDebug() << "Unable to parse"; + nlwarning("Unable to parse %s", Q2C(contentRange)); } } diff --git a/code/ryzom/tools/client/ryzom_installer/src/installdialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/installdialog.cpp index 65378c369..b1ef5de67 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/installdialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/installdialog.cpp @@ -132,17 +132,18 @@ void CInstallDialog::accept() // check free disk space qint64 freeSpace = NLMISC::CSystemInfo::availableHDSpace(m_dstDirectory.toUtf8().constData()); + // shouldn't happen if (freeSpace == 0) { - QString error = qFromUtf8(NLMISC::formatErrorMessage(NLMISC::getLastError())); + int error = NLMISC::getLastError(); - QMessageBox::StandardButton res = QMessageBox::warning(this, tr("Error"), tr("Error '%1' occured when trying to check free disk space on %2.").arg(error).arg(m_dstDirectory)); - return; + nlwarning("Error '%s' (%d) occured when trying to check free disk space on %s, continue anyway", NLMISC::formatErrorMessage(error).c_str(), error, Q2C(m_dstDirectory)); } const CServer &server = CConfigFile::getInstance()->getServer(); - if (freeSpace < server.dataUncompressedSize) + // compare with exact size of current directory + if (freeSpace && freeSpace < server.dataUncompressedSize) { QMessageBox::StandardButton res = QMessageBox::warning(this, tr("Not enough free disk space"), tr("You don't have enough free space on this disk, please make more space or choose a directory on another disk.")); return; diff --git a/code/ryzom/tools/client/ryzom_installer/src/main.cpp b/code/ryzom/tools/client/ryzom_installer/src/main.cpp index 3420ef42e..47201a807 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/main.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/main.cpp @@ -152,6 +152,11 @@ int main(int argc, char *argv[]) return 1; } + // init log + CLogHelper logHelper(config.getInstallationDirectory()); + + nlinfo("Launched %s", Q2C(config.getInstallerCurrentFilePath())); + #if defined(Q_OS_WIN) && !defined(_DEBUG) // under Windows, Ryzom Installer should always be copied in TEMP directory QString tempPath = QStandardPaths::writableLocation(QStandardPaths::TempLocation); @@ -159,6 +164,8 @@ int main(int argc, char *argv[]) // check if launched from TEMP directory if (step == Done && !config.getInstallerCurrentDirPath().startsWith(tempPath)) { + nlinfo("Not launched from TEMP directory"); + // try to delete all temporary installers QDir tempDir(tempPath); @@ -173,17 +180,25 @@ int main(int argc, char *argv[]) QDir dirToRemove(tempDir); dirToRemove.cd(dir); dirToRemove.removeRecursively(); + + nlinfo("Delete directory %s", Q2C(dir)); } tempPath += QString("/ryzom_installer_%1").arg(QDateTime::currentMSecsSinceEpoch()); + nlinfo("Creating directory %s", Q2C(tempPath)); + // copy installer and required files to TEMP directory if (QDir().mkdir(tempPath) && copyInstallerFiles(config.getInstallerRequiredFiles(), tempPath)) { QString tempFile = tempPath + "/" + QFileInfo(config.getInstallerCurrentFilePath()).fileName(); + nlinfo("Launching %s", Q2C(tempFile)); + // launch copy in TEMP directory with same arguments if (QProcess::startDetached(tempFile, QApplication::arguments())) return 0; + + nlwarning("Unable to launch %s", Q2C(tempFile)); } } #endif @@ -193,6 +208,8 @@ int main(int argc, char *argv[]) if (parser.isSet(uninstallOption)) { + nlinfo("Uninstalling..."); + SComponents components; // add all servers by default @@ -227,6 +244,8 @@ int main(int argc, char *argv[]) if (step == ShowMigrateWizard) { + nlinfo("Display migration dialog"); + CMigrateDialog dialog; if (!dialog.exec()) return 1; @@ -235,6 +254,8 @@ int main(int argc, char *argv[]) } else if (step == ShowInstallWizard) { + nlinfo("Display installation dialog"); + CInstallDialog dialog; if (!dialog.exec()) return 1; @@ -242,6 +263,8 @@ int main(int argc, char *argv[]) step = config.getInstallNextStep(); } + nlinfo("Next step is %s", Q2C(stepToString(step))); + bool restartInstaller = false; if (step != Done) @@ -254,6 +277,8 @@ int main(int argc, char *argv[]) step = config.getInstallNextStep(); + nlinfo("Last step is %s", Q2C(stepToString(step))); + if (step == LaunchInstalledInstaller) { // restart more recent installed Installer version @@ -271,6 +296,8 @@ int main(int argc, char *argv[]) if (restartInstaller) { #ifndef _DEBUG + nlinfo("Restart Installer %s", Q2C(config.getInstallerInstalledFilePath())); + #ifndef Q_OS_WIN32 // fix executable permissions under UNIX QFile::setPermissions(config.getInstallerInstalledFilePath(), QFile::permissions(config.getInstallerInstalledFilePath()) | QFile::ExeGroup | QFile::ExeUser | QFile::ExeOther); diff --git a/code/ryzom/tools/client/ryzom_installer/src/migratedialog.cpp b/code/ryzom/tools/client/ryzom_installer/src/migratedialog.cpp index 5f645042a..0aec91d09 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/migratedialog.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/migratedialog.cpp @@ -147,16 +147,16 @@ void CMigrateDialog::accept() // check free disk space qint64 freeSpace = NLMISC::CSystemInfo::availableHDSpace(m_dstDirectory.toUtf8().constData()); + // shouldn't happen if (freeSpace == 0) { - QString error = qFromUtf8(NLMISC::formatErrorMessage(NLMISC::getLastError())); + int error = NLMISC::getLastError(); - QMessageBox::StandardButton res = QMessageBox::warning(this, tr("Error"), tr("Error '%1' occured when trying to check free disk space on %2.").arg(error).arg(m_dstDirectory)); - return; + nlwarning("Error '%s' (%d) occured when trying to check free disk space on %s, continue anyway", NLMISC::formatErrorMessage(error).c_str(), error, Q2C(m_dstDirectory)); } // compare with exact size of current directory - if (freeSpace < getDirectorySize(m_currentDirectory, true)) + if (freeSpace && freeSpace < getDirectorySize(m_currentDirectory, true)) { QMessageBox::StandardButton res = QMessageBox::warning(this, tr("Not enough free disk space"), tr("You don't have enough free space on this disk, please make more space or choose a directory on another disk.")); return; diff --git a/code/ryzom/tools/client/ryzom_installer/src/operation.h b/code/ryzom/tools/client/ryzom_installer/src/operation.h index 71627363e..341e93a74 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/operation.h +++ b/code/ryzom/tools/client/ryzom_installer/src/operation.h @@ -73,6 +73,8 @@ enum OperationStep Done }; +QString stepToString(OperationStep); + enum OperationType { OperationNone, diff --git a/code/ryzom/tools/client/ryzom_installer/src/stdpch.h b/code/ryzom/tools/client/ryzom_installer/src/stdpch.h index 4ebe147f0..d066915d7 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/stdpch.h +++ b/code/ryzom/tools/client/ryzom_installer/src/stdpch.h @@ -54,8 +54,10 @@ #include -#include -#include +#include "nel/misc/types_nl.h" +#include "nel/misc/debug.h" +#include "nel/misc/path.h" +#include "nel/misc/system_info.h" #endif diff --git a/code/ryzom/tools/client/ryzom_installer/src/utils.cpp b/code/ryzom/tools/client/ryzom_installer/src/utils.cpp index 0a31629f9..25f084726 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/utils.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/utils.cpp @@ -563,3 +563,51 @@ CCOMHelper::~CCOMHelper() if (m_mustUninit) CoUninitialize(); #endif } + +CLogHelper::CLogHelper(const QString &logPath) +{ + // disable nldebug messages in logs in Release +#ifdef NL_RELEASE + NLMISC::DisableNLDebug = true; +#endif + + // don't create a file for the moment, we'll create it manually + NLMISC::createDebug(NULL, false); + + // ryzom_installer.Log displayer + NLMISC::CFileDisplayer *LogDisplayer = new NLMISC::CFileDisplayer(qToUtf8(logPath) + "/ryzom_installer.log", true, "DEFAULT_FD"); + NLMISC::DebugLog->addDisplayer(LogDisplayer); + NLMISC::InfoLog->addDisplayer(LogDisplayer); + NLMISC::WarningLog->addDisplayer(LogDisplayer); + NLMISC::ErrorLog->addDisplayer(LogDisplayer); + NLMISC::AssertLog->addDisplayer(LogDisplayer); + + std::string type; + +#ifdef NL_RELEASE + type = "RELEASE"; +#else + type = "DEBUG"; +#endif + + // Display installer version + nlinfo("RYZOM INSTALLER VERSION: %s (%s)", Q2C(QApplication::applicationVersion()), type.c_str()); + nlinfo("Memory: %s/%s", NLMISC::bytesToHumanReadable(NLMISC::CSystemInfo::availablePhysicalMemory()).c_str(), NLMISC::bytesToHumanReadable(NLMISC::CSystemInfo::totalPhysicalMemory()).c_str()); + nlinfo("OS: %s", NLMISC::CSystemInfo::getOS().c_str()); + nlinfo("Processor: %s", NLMISC::CSystemInfo::getProc().c_str()); +} + +CLogHelper::~CLogHelper() +{ + NLMISC::IDisplayer *LogDisplayer = NLMISC::ErrorLog->getDisplayer("DEFAULT_FD"); + + if (LogDisplayer) + { + NLMISC::DebugLog->removeDisplayer(LogDisplayer); + NLMISC::InfoLog->removeDisplayer(LogDisplayer); + NLMISC::WarningLog->removeDisplayer(LogDisplayer); + NLMISC::ErrorLog->removeDisplayer(LogDisplayer); + NLMISC::AssertLog->removeDisplayer(LogDisplayer); + delete LogDisplayer; + } +} diff --git a/code/ryzom/tools/client/ryzom_installer/src/utils.h b/code/ryzom/tools/client/ryzom_installer/src/utils.h index e3de8155b..980826a16 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/utils.h +++ b/code/ryzom/tools/client/ryzom_installer/src/utils.h @@ -58,6 +58,8 @@ QString qFromWide(const wchar_t *str); // convert an QString to wchar_t* wchar_t* qToWide(const QString &str); +#define Q2C(x) qToUtf8(x).c_str() + // check if a shortcut already exists (the extension will be added) bool shortcutExists(const QString &shortcut); @@ -92,4 +94,12 @@ public: ~CCOMHelper(); }; +// a little helper class to init/uninit log +class CLogHelper +{ +public: + CLogHelper(const QString &logPath); + ~CLogHelper(); +}; + #endif