From c379347d59c3dc6581bc3f3154ac7d0b69a3e80c Mon Sep 17 00:00:00 2001 From: Ted John Date: Wed, 8 Feb 2017 22:00:04 +0000 Subject: [PATCH] Use stream for chat log --- src/openrct2/core/FileStream.hpp | 8 +++++++- src/openrct2/network/network.cpp | 15 ++++++++++----- src/openrct2/network/network.h | 3 +-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/openrct2/core/FileStream.hpp b/src/openrct2/core/FileStream.hpp index a0c3821896..8eb5aa9e44 100644 --- a/src/openrct2/core/FileStream.hpp +++ b/src/openrct2/core/FileStream.hpp @@ -25,7 +25,8 @@ enum { FILE_MODE_OPEN, - FILE_MODE_WRITE + FILE_MODE_WRITE, + FILE_MODE_APPEND, }; /** @@ -61,6 +62,11 @@ public: _canRead = true; _canWrite = true; break; + case FILE_MODE_APPEND: + mode = "a"; + _canRead = false; + _canWrite = true; + break; default: throw; } diff --git a/src/openrct2/network/network.cpp b/src/openrct2/network/network.cpp index a102008205..3ec5a3a7a6 100644 --- a/src/openrct2/network/network.cpp +++ b/src/openrct2/network/network.cpp @@ -807,10 +807,11 @@ void Network::AppendChatLog(const utf8 *text) utf8 directory[MAX_PATH]; Path::GetDirectory(directory, sizeof(directory), chatLogPath); if (platform_ensure_directory_exists(directory)) { - _chatLogStream = SDL_RWFromFile(chatLogPath, "a"); - if (_chatLogStream != nullptr) { - utf8 buffer[256]; + try + { + _chatLogStream = new FileStream(chatLogPath, FILE_MODE_APPEND); + utf8 buffer[256]; time_t timer; struct tm * tmInfo; time(&timer); @@ -821,8 +822,12 @@ void Network::AppendChatLog(const utf8 *text) utf8_remove_formatting(buffer, false); String::Append(buffer, sizeof(buffer), PLATFORM_NEWLINE); - SDL_RWwrite(_chatLogStream, buffer, strlen(buffer), 1); - SDL_RWclose(_chatLogStream); + _chatLogStream->Write(buffer, strlen(buffer)); + delete _chatLogStream; + _chatLogStream = nullptr; + } + catch (const Exception &) + { } } } diff --git a/src/openrct2/network/network.h b/src/openrct2/network/network.h index f965285832..7ee03f6af5 100644 --- a/src/openrct2/network/network.h +++ b/src/openrct2/network/network.h @@ -67,7 +67,6 @@ extern "C" { #include #include #include -#include #include "../core/Json.hpp" #include "../core/Nullable.hpp" #include "NetworkConnection.h" @@ -214,7 +213,7 @@ private: INetworkServerAdvertiser * _advertiser = nullptr; uint32 server_connect_time = 0; uint8 default_group = 0; - SDL_RWops *_chatLogStream = nullptr; + IStream * _chatLogStream = nullptr; std::string _chatLogPath; uint32 game_commands_processed_this_tick = 0;