Merge with develop

--HG--
branch : compatibility-develop
This commit is contained in:
kervala 2016-10-20 13:08:48 +02:00
commit 2e7af6ab0d
44 changed files with 302 additions and 184 deletions

View file

@ -422,7 +422,7 @@ namespace NLGUI
{
nlassert(key);
nlassert(isValid());
if (!isTable()) throw ELuaNotATable(NLMISC::toString("Trying to set a value '%d" NL_I64 "' at key %s on object '%s' of type %s (not a table).", value, key, getId().c_str(), getTypename()));
if (!isTable()) throw ELuaNotATable(NLMISC::toString("Trying to set a value '%" NL_I64 "d' at key %s on object '%s' of type %s (not a table).", value, key, getId().c_str(), getTypename()));
CLuaStackChecker lsc(_LuaState);
push();
_LuaState->push(key);

View file

@ -1082,7 +1082,7 @@ NLMISC_CATEGORISED_COMMAND(nel,displayMeasures, "display hierarchical timer", "[
}
sint depth = 0;
bool hasDepth = (sscanf(args[0].c_str(), "%d", &depth) == 1 || (args.size() > 1 && sscanf(args[1].c_str(), "%d", &depth) == 1));
bool hasDepth = (fromString(args[0], depth) || (args.size() > 1 && fromString(args[1], depth)));
CASE_DISPLAYMEASURES(NoSort, -3)
CASE_DISPLAYMEASURES(TotalTime, -2)

View file

@ -419,13 +419,13 @@ int main(int argc, char* argv[])
float weldThreshold, middleEdgeWeldThreshold;
if (::sscanf(argv[2], "%f", &weldThreshold) != 1)
if (!fromString(argv[2], weldThreshold))
{
nlinfo("invalid weldThreshold");
return -1;
}
if (::sscanf(argv[3], "%f", &middleEdgeWeldThreshold) != 1)
if (!fromString(argv[3], middleEdgeWeldThreshold))
{
nlinfo("invalid middleEdgeWeldThreshold");
return -1;

View file

@ -894,7 +894,7 @@ void CObjectInteger::inPlaceCopy(const CObjectInteger &src)
}
std::string CObjectInteger::doToString() const { return NLMISC::toString("%" NL_I64 "d", _Value); }
std::string CObjectInteger::doToString() const { return NLMISC::toString(_Value); }
void CObjectInteger::doSerialize(std::string& out, CSerializeContext& /* context */) const
{

View file

@ -3122,8 +3122,8 @@ static void setRyzomDebugDate(CRyzomDate &rd)
NLMISC_COMMAND(setDebugHour, "set the current debug hour", "<hour>")
{
if (args.size() != 1) return false;
int hour;
if (sscanf(args[0].c_str(), "%d", &hour) != 1) return false;
sint hour;
if (!fromString(args[0], hour)) return false;
CRyzomDate rd;
getRyzomDebugDate(rd);
rd.Time = fmodf(rd.Time, 1.f) + (float) hour;
@ -3134,8 +3134,8 @@ NLMISC_COMMAND(setDebugHour, "set the current debug hour", "<hour>")
NLMISC_COMMAND(setDebugDayOfYear, "set the current debug day of year (first day has index 1)", "<day>")
{
if (args.size() != 1) return false;
int day;
if (sscanf(args[0].c_str(), "%d", &day) != 1) return false;
sint day;
if (!fromString(args[0], day)) return false;
CRyzomDate rd;
getRyzomDebugDate(rd);
rd.Day = day - 1; // for the user, days start at '1'

View file

@ -1002,7 +1002,7 @@ ENTITY_VARIABLE(Money, "Money")
if (get)
{
value = toString("%"NL_I64"u", c->getMoney());
value = toString(c->getMoney());
}
else
{
@ -1054,7 +1054,7 @@ ENTITY_VARIABLE(MoneyGuild, "MoneyGuild")
if (get)
{
value = toString("%"NL_I64"u", guild->getMoney());
value = toString(guild->getMoney());
}
else
{

View file

@ -3916,7 +3916,8 @@ NLMISC_COMMAND( db, "Display or set the value of a property in the database", "<
{
// Set
sint64 value;
sscanf( args[2].c_str(), "%"NL_I64"d", &value );
fromString(args[2], value);
if ( (args.size() > 3) && (args[3]!="0") )
{
res = e->_PropertyDatabase.x_setPropButDontSend( entry, value );

View file

@ -1011,7 +1011,7 @@ NLMISC_COMMAND(getMoney, "get money of player", "<uid>")
{
GET_ACTIVE_CHARACTER
string value = toString("%"NL_I64"u", c->getMoney());
string value = toString(c->getMoney());
log.displayNL(value.c_str());

View file

@ -1217,7 +1217,7 @@ NLMISC_COMMAND(dumpToXml, "dump the content of an object into an xml file", "<da
if (id == NLMISC::CEntityId::Unknown)
{
if (sscanf(args[1].c_str(), "%"NL_I64"u", &key) != 1)
if (!fromString(args[1], key))
{
log.displayNL("id '%s' is not recognized as an EntityId, an ObjectIndex nor a 64 bits raw key", args[1].c_str());
return false;

View file

@ -26,7 +26,7 @@
#define new DEBUG_NEW
#endif
CDownloader::CDownloader(QObject *parent, IOperationProgressListener *listener):QObject(parent), m_listener(listener), m_manager(NULL), m_reply(NULL), m_timer(NULL),
CDownloader::CDownloader(QObject *parent, IOperationProgressListener *listener):QObject(parent), m_listener(listener), m_manager(NULL), m_timer(NULL),
m_offset(0), m_size(0), m_supportsAcceptRanges(false), m_supportsContentRange(false),
m_downloadAfterHead(false), m_file(NULL)
{
@ -169,10 +169,10 @@ void CDownloader::getFileHead()
request.setRawHeader("Range", QString("bytes=%1-").arg(m_offset).toLatin1());
}
m_reply = m_manager->head(request);
QNetworkReply *reply = m_manager->head(request);
connect(m_reply, SIGNAL(finished()), SLOT(onHeadFinished()));
connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(onError(QNetworkReply::NetworkError)));
connect(reply, SIGNAL(finished()), SLOT(onHeadFinished()));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(onError(QNetworkReply::NetworkError)));
startTimer();
}
@ -212,12 +212,12 @@ void CDownloader::downloadFile()
request.setRawHeader("Range", QString("bytes=%1-%2").arg(m_offset).arg(m_size-1).toLatin1());
}
m_reply = m_manager->get(request);
QNetworkReply *reply = m_manager->get(request);
connect(m_reply, SIGNAL(finished()), SLOT(onDownloadFinished()));
connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(onError(QNetworkReply::NetworkError)));
connect(m_reply, SIGNAL(downloadProgress(qint64, qint64)), SLOT(onDownloadProgress(qint64, qint64)));
connect(m_reply, SIGNAL(readyRead()), SLOT(onDownloadRead()));
connect(reply, SIGNAL(finished()), SLOT(onDownloadFinished()));
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(onError(QNetworkReply::NetworkError)));
connect(reply, SIGNAL(downloadProgress(qint64, qint64)), SLOT(onDownloadProgress(qint64, qint64)));
connect(reply, SIGNAL(readyRead()), SLOT(onDownloadRead()));
if (m_listener) m_listener->operationStart();
@ -254,24 +254,35 @@ void CDownloader::onHeadFinished()
{
stopTimer();
int status = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
QString redirection = m_reply->header(QNetworkRequest::LocationHeader).toString();
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QString url = reply->url().toString();
m_size = m_reply->header(QNetworkRequest::ContentLengthHeader).toInt();
m_lastModified = m_reply->header(QNetworkRequest::LastModifiedHeader).toDateTime().toUTC();
QString redirection = reply->header(QNetworkRequest::LocationHeader).toString();
QString acceptRanges = QString::fromLatin1(m_reply->rawHeader("Accept-Ranges"));
QString contentRange = QString::fromLatin1(m_reply->rawHeader("Content-Range"));
m_size = reply->header(QNetworkRequest::ContentLengthHeader).toInt();
m_lastModified = reply->header(QNetworkRequest::LastModifiedHeader).toDateTime().toUTC();
m_reply->deleteLater();
m_reply = NULL;
QString acceptRanges = QString::fromLatin1(reply->rawHeader("Accept-Ranges"));
QString contentRange = QString::fromLatin1(reply->rawHeader("Content-Range"));
reply->deleteLater();
nlinfo("HTTP status code %d on HEAD for %s", status, Q2C(url));
if (!redirection.isEmpty())
{
nlinfo("Redirected to %s", Q2C(redirection));
}
// redirection
if (status == 302)
{
if (redirection.isEmpty())
{
nlwarning("No redirection defined");
if (m_listener) m_listener->operationFail(tr("Redirection URL is not defined"));
return;
}
@ -298,6 +309,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 +322,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 +341,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));
}
}
@ -367,10 +383,14 @@ void CDownloader::onHeadFinished()
void CDownloader::onDownloadFinished()
{
int status = m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
m_reply->deleteLater();
m_reply = NULL;
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QString url = reply->url().toString();
reply->deleteLater();
nlwarning("Download finished with HTTP status code %d when downloading %s", status, Q2C(url));
closeFile();
@ -401,6 +421,10 @@ void CDownloader::onDownloadFinished()
void CDownloader::onError(QNetworkReply::NetworkError error)
{
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
nlwarning("Network error %s (%d) when downloading %s", Q2C(reply->errorString()), error, Q2C(m_url));
if (!m_listener) return;
if (error == QNetworkReply::OperationCanceledError)
@ -415,13 +439,17 @@ void CDownloader::onDownloadProgress(qint64 current, qint64 total)
if (!m_listener) return;
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
m_listener->operationProgress(m_offset + current, m_url);
// abort download
if (m_listener->operationShouldStop() && m_reply) m_reply->abort();
if (m_listener->operationShouldStop() && reply) reply->abort();
}
void CDownloader::onDownloadRead()
{
if (m_file) m_file->write(m_reply->readAll());
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
if (m_file && reply) m_file->write(reply->readAll());
}

View file

@ -76,7 +76,6 @@ protected:
bool checkDownloadedFile();
QNetworkAccessManager *m_manager;
QNetworkReply *m_reply;
QTimer *m_timer;
QString m_url;

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -73,6 +73,8 @@ enum OperationStep
Done
};
QString stepToString(OperationStep);
enum OperationType
{
OperationNone,

View file

@ -54,8 +54,10 @@
#include <string>
#include <nel/misc/types_nl.h>
#include <nel/misc/config_file.h>
#include "nel/misc/types_nl.h"
#include "nel/misc/debug.h"
#include "nel/misc/path.h"
#include "nel/misc/system_info.h"
#endif

View file

@ -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;
}
}

View file

@ -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