From 279deffa86af55dd1a86df8b45c7ce7ddef454b1 Mon Sep 17 00:00:00 2001 From: def Date: Wed, 9 Sep 2020 17:49:29 +0200 Subject: [PATCH 1/2] Refresh server browser immediately when updated ddnet info arrived 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. --- src/engine/client/client.cpp | 53 ++++++++++++++++++++++++++++++++++-- src/engine/client/client.h | 1 + 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index a4d01da0a..9996f76ad 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -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 Version; diff --git a/src/engine/client/client.h b/src/engine/client/client.h index 6c47ca02b..e51305e5e 100644 --- a/src/engine/client/client.h +++ b/src/engine/client/client.h @@ -343,6 +343,7 @@ public: void RequestDDNetInfo(); void ResetDDNetInfo(); + bool IsDDNetInfoChanged(); void FinishDDNetInfo(); void LoadDDNetInfo(); From 80b7ceb3d773e2f4012cc6598fd38264cba37ec9 Mon Sep 17 00:00:00 2001 From: def Date: Thu, 10 Sep 2020 23:25:33 +0200 Subject: [PATCH 2/2] dilate: Don't crash if file doesn't exist --- src/tools/dilate.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/tools/dilate.cpp b/src/tools/dilate.cpp index 8a87c9859..38de84eef 100644 --- a/src/tools/dilate.cpp +++ b/src/tools/dilate.cpp @@ -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) {