From d3c609820797d0767a6108ad22d646a80b688cca Mon Sep 17 00:00:00 2001 From: Nimetu Date: Thu, 12 Sep 2019 18:15:09 +0300 Subject: [PATCH] Fixed: Browser css file could not be loaded from bnp --HG-- branch : html-improvements --- code/nel/include/nel/misc/file.h | 5 +++++ code/nel/src/gui/group_html.cpp | 18 +++++++++++++++--- code/nel/src/misc/file.cpp | 31 +++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/code/nel/include/nel/misc/file.h b/code/nel/include/nel/misc/file.h index 78dba95c6..3e40d122a 100644 --- a/code/nel/include/nel/misc/file.h +++ b/code/nel/include/nel/misc/file.h @@ -119,6 +119,11 @@ public: // Advanced Usage. // return a string separated by \n or eof, used to parsing text file void getline (char *buffer, uint32 bufferSize); + // read whole file into a string. resulting buffer may contain NULL chars. + // internal read position is modified. + // return true on success, false on failure. + bool readAll(std::string &buffer); + // return the size of the file uint32 getFileSize () const { return _FileSize; } diff --git a/code/nel/src/gui/group_html.cpp b/code/nel/src/gui/group_html.cpp index 2e34ad8fa..b6b83fa3c 100644 --- a/code/nel/src/gui/group_html.cpp +++ b/code/nel/src/gui/group_html.cpp @@ -2175,12 +2175,24 @@ namespace NLGUI std::string filename = CPath::lookup(_BrowserCssFile, false, true, true); if (!filename.empty()) { - NLMISC::CSString css; - if (css.readFromFile(filename)) + CIFile in; + if (in.open(filename)) { - _BrowserStyle.parseStylesheet(css); + std::string css; + if (in.readAll(css)) + _BrowserStyle.parseStylesheet(css); + else + nlwarning("Failed to read browser css from '%s'", filename.c_str()); + } + else + { + nlwarning("Failed to open browser css file '%s'", filename.c_str()); } } + else + { + nlwarning("Browser css file '%s' not found", _BrowserCssFile.c_str()); + } } } else diff --git a/code/nel/src/misc/file.cpp b/code/nel/src/misc/file.cpp index 63b27e768..834b11a8d 100644 --- a/code/nel/src/misc/file.cpp +++ b/code/nel/src/misc/file.cpp @@ -361,6 +361,37 @@ void CIFile::flush() } } +// ====================================================================================================== +bool CIFile::readAll(std::string &buffer) +{ + try + { + uint32 remaining = _FileSize; + + buffer.clear(); + buffer.reserve(_FileSize); + while(!eof() && remaining > 0) + { + const static uint bufsize = 1024; + char buf[bufsize]; + uint32 readnow = bufsize; + if (readnow > remaining) + readnow = remaining; + + serialBuffer((uint8 *)&buf[0], readnow); + buffer.append(buf, readnow); + remaining -= readnow; + } + } + catch (const EFile &) + { + // buffer state is unknown + return false; + } + + return true; +} + // ====================================================================================================== void CIFile::getline (char *buffer, uint32 bufferSize) {