2789: Refresh server browser immediately when updated ddnet info arrived r=heinrich5991 a=def-

At the moment it only happens the next time you press refresh.

Before we had it so that it always reloaded once the ddnet info arrived,
causing a quick flickering and lots of packets having to be resent every
time someone pressed refresh, even if nothing changed.

The new approach combines the advantages of both without the
disadvantages. An even nicer way would be to compare the json objects,
so that news and version updates don't matter, but our json library
doesn't seem to support that.

2797: dilate: Don't crash if file doesn't exist r=heinrich5991 a=def-



Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2020-09-10 22:24:06 +00:00 committed by GitHub
commit 51483c2ff1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 3 deletions

View file

@ -2381,11 +2381,60 @@ void CClient::ResetDDNetInfo()
}
}
bool CClient::IsDDNetInfoChanged()
{
IOHANDLE OldFile = m_pStorage->OpenFile(DDNET_INFO, IOFLAG_READ, IStorage::TYPE_SAVE);
if(!OldFile)
return true;
IOHANDLE NewFile = m_pStorage->OpenFile(m_aDDNetInfoTmp, IOFLAG_READ, IStorage::TYPE_SAVE);
if(NewFile)
{
char aOldData[4096];
char aNewData[4096];
unsigned OldBytes;
unsigned NewBytes;
do
{
OldBytes = io_read(OldFile, aOldData, sizeof(aOldData));
NewBytes = io_read(NewFile, aNewData, sizeof(aNewData));
if(OldBytes != NewBytes || mem_comp(aOldData, aNewData, OldBytes) != 0)
{
io_close(NewFile);
io_close(OldFile);
return true;
}
}
while(OldBytes > 0);
io_close(NewFile);
}
io_close(OldFile);
return false;
}
void CClient::FinishDDNetInfo()
{
ResetDDNetInfo();
m_pStorage->RenameFile(m_aDDNetInfoTmp, DDNET_INFO, IStorage::TYPE_SAVE);
LoadDDNetInfo();
if(IsDDNetInfoChanged())
{
m_pStorage->RenameFile(m_aDDNetInfoTmp, DDNET_INFO, IStorage::TYPE_SAVE);
LoadDDNetInfo();
if(g_Config.m_UiPage == CMenus::PAGE_DDNET)
m_ServerBrowser.Refresh(IServerBrowser::TYPE_DDNET);
else if(g_Config.m_UiPage == CMenus::PAGE_KOG)
m_ServerBrowser.Refresh(IServerBrowser::TYPE_KOG);
}
else
{
m_pStorage->RemoveFile(m_aDDNetInfoTmp, IStorage::TYPE_SAVE);
}
}
typedef std::tuple<int, int, int> Version;

View file

@ -343,6 +343,7 @@ public:
void RequestDDNetInfo();
void ResetDDNetInfo();
bool IsDDNetInfoChanged();
void FinishDDNetInfo();
void LoadDDNetInfo();

View file

@ -54,7 +54,14 @@ int DilateFile(const char *pFileName)
CPixel *pBuffer[3] = {0,0,0};
png_init(0, 0);
png_open_file(&Png, pFileName);
int Error = png_open_file(&Png, pFileName);
if(Error != PNG_NO_ERROR)
{
dbg_msg("dilate", "failed to open image file. filename='%s'", pFileName);
if(Error != PNG_FILE_ERROR)
png_close_file(&Png);
return 0;
}
if(Png.color_type != PNG_TRUECOLOR_ALPHA)
{