mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
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:
commit
51483c2ff1
|
@ -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();
|
||||
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;
|
||||
|
|
|
@ -343,6 +343,7 @@ public:
|
|||
|
||||
void RequestDDNetInfo();
|
||||
void ResetDDNetInfo();
|
||||
bool IsDDNetInfoChanged();
|
||||
void FinishDDNetInfo();
|
||||
void LoadDDNetInfo();
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue