Fixed: Browser css file could not be loaded from bnp

--HG--
branch : html-improvements
hg/feature/html-improvements
Nimetu 5 years ago
parent 5940e276fb
commit d3c6098207

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

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

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

Loading…
Cancel
Save