From c8a21f14e7587fbfb42ee563e7473b57a130bb40 Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Wed, 16 Aug 2023 23:35:44 -0700 Subject: [PATCH] Convert all hsMessageBox inputs to ST::string Co-Authored-By: Adam Johnson --- Sources/Plasma/Apps/plClient/plClient.cpp | 2 +- .../PubUtilLib/plMessageBox/hsMessageBox.cpp | 11 +---- .../PubUtilLib/plMessageBox/hsMessageBox.h | 5 +-- .../plMessageBox/hsMessageBox_Mac.mm | 1 + .../plMessageBox/hsMessageBox_Win.cpp | 1 + .../PubUtilLib/plNetClient/plNetClientMgr.cpp | 3 +- .../PubUtilLib/plResMgr/plResManager.cpp | 41 +++++++++---------- 7 files changed, 27 insertions(+), 37 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/plClient.cpp b/Sources/Plasma/Apps/plClient/plClient.cpp index 6b1d14a3de..9f6b741dd9 100644 --- a/Sources/Plasma/Apps/plClient/plClient.cpp +++ b/Sources/Plasma/Apps/plClient/plClient.cpp @@ -493,7 +493,7 @@ bool plClient::InitPipeline(hsWindowHndl display, uint32_t devType) #ifdef PLASMA_EXTERNAL_RELEASE hsMessageBox(ST_LITERAL("There was an error initializing the video card.\nSetting defaults."), ST_LITERAL("Error"), hsMessageBoxNormal); #else - hsMessageBox( pipe->GetErrorString(), "Error creating pipeline", hsMessageBoxNormal ); + hsMessageBox(ST::string(pipe->GetErrorString()), ST_LITERAL("Error creating pipeline"), hsMessageBoxNormal); #endif delete pipe; devSel.GetDefault(&dmr); diff --git a/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.cpp b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.cpp index 59df69e66c..3d2a678aab 100644 --- a/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.cpp +++ b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.cpp @@ -45,6 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com bool hsMessageBox_SuppressPrompts = false; #if !defined(HS_BUILD_FOR_APPLE) && !defined(HS_BUILD_FOR_WIN32) +#include #include // Need a proper implementation for Linux, but for now let's just print out to the console @@ -57,13 +58,3 @@ hsMessageBoxResult hsMessageBox(const ST::string& message, const ST::string& cap return hsMBoxCancel; } #endif - -hsMessageBoxResult hsMessageBox(const char* message, const char* caption, hsMessageBoxKind kind, hsMessageBoxIcon icon) -{ - return hsMessageBox(ST::string::from_latin_1(message), ST::string::from_latin_1(caption), kind, icon); -} - -hsMessageBoxResult hsMessageBox(const wchar_t* message, const wchar_t* caption, hsMessageBoxKind kind, hsMessageBoxIcon icon) -{ - return hsMessageBox(ST::string::from_wchar(message), ST::string::from_wchar(caption), kind, icon); -} diff --git a/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.h b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.h index 26390d4a38..8243e2f753 100644 --- a/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.h +++ b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.h @@ -44,7 +44,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #define _hsMessageBox_h_ #include "HeadSpin.h" -#include + +namespace ST { class string; } enum hsMessageBoxKind { // Kind of MessageBox...passed to hsMessageBox hsMessageBoxAbortRetyIgnore, @@ -75,7 +76,5 @@ enum hsMessageBoxResult { // RETURN VALUES FROM hsMessageBox extern bool hsMessageBox_SuppressPrompts; hsMessageBoxResult hsMessageBox(const ST::string& message, const ST::string& caption, hsMessageBoxKind kind, hsMessageBoxIcon icon=hsMessageBoxIconAsterisk); -hsMessageBoxResult hsMessageBox(const char* message, const char* caption, hsMessageBoxKind kind, hsMessageBoxIcon icon=hsMessageBoxIconAsterisk); -hsMessageBoxResult hsMessageBox(const wchar_t* message, const wchar_t* caption, hsMessageBoxKind kind, hsMessageBoxIcon icon=hsMessageBoxIconAsterisk); #endif // _hsMessageBox_h_ diff --git a/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Mac.mm b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Mac.mm index 378a71be29..69de1129ec 100644 --- a/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Mac.mm +++ b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Mac.mm @@ -42,6 +42,7 @@ #include "hsMessageBox.h" +#include #import hsMessageBoxResult hsMessageBox(const ST::string& message, const ST::string& caption, hsMessageBoxKind kind, hsMessageBoxIcon icon) diff --git a/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Win.cpp b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Win.cpp index 36f5b8393b..1879538094 100644 --- a/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Win.cpp +++ b/Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Win.cpp @@ -42,6 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsMessageBox.h" #include "hsWindows.h" +#include class hsMinimizeClientGuard { diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp index b7c11acbe1..cf65f85a55 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp @@ -1149,7 +1149,8 @@ void plNetClientMgr::IDisableNet () { { // KI may not be loaded ST::string title = ST::format("{} Error", plProduct::CoreName()); - hsMessageBox(fDisableMsg->str, title.c_str(), hsMessageBoxNormal, hsMessageBoxIconError ); + ST::string errMsg = ST::string(fDisableMsg->str); + hsMessageBox(errMsg, title, hsMessageBoxNormal, hsMessageBoxIconError); plClientMsg *quitMsg = new plClientMsg(plClientMsg::kQuit); quitMsg->Send(hsgResMgr::ResMgr()->FindKey(kClient_KEY)); } diff --git a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp index 2f89e11cd2..fb4bfc49ca 100644 --- a/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp +++ b/Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp @@ -1367,26 +1367,24 @@ bool plResManager::VerifyPages() // Given an array of pages that are invalid (major version out-of-date or // whatnot), asks the user what we should do about them. -static void ICatPageNames(std::vector& pages, char* buf, int bufSize) +static ST::string ICatPageNames(std::vector& pages, const ST::string& msg) { + ST::string_stream ss; + ss << msg; + for (size_t i = 0; i < pages.size(); i++) { if (i >= 25) { - strcat(buf, "...\n"); + ss << ST_LITERAL("...\n"); break; } ST::string pageFile = pages[i]->GetPagePath().GetFileName(); - if (strlen(buf) + pageFile.size() > bufSize - 5) - { - strcat(buf, "...\n"); - break; - } - - strcat(buf, pageFile.c_str()); - strcat(buf, "\n"); + ss << pageFile << '\n'; } + + return ss.to_string(); } bool plResManager::IDeleteBadPages(std::vector& invalidPages, bool conflictingSeqNums) @@ -1394,19 +1392,19 @@ bool plResManager::IDeleteBadPages(std::vector& invalidPage #ifndef PLASMA_EXTERNAL_RELEASE if (!hsMessageBox_SuppressPrompts) { - char msg[4096]; + ST::string msg; // Prompt what to do if (conflictingSeqNums) - strcpy(msg, "The following pages have conflicting sequence numbers. This usually happens when " - "you copy data files between machines that had random sequence numbers assigned at " - "export. To avoid crashing, these pages will be deleted:\n\n"); + msg = ST_LITERAL("The following pages have conflicting sequence numbers. This usually happens when " + "you copy data files between machines that had random sequence numbers assigned at " + "export. To avoid crashing, these pages will be deleted:\n\n"); else - strcpy(msg, "The following pages are out of date and will be deleted:\n\n"); + msg = ST_LITERAL("The following pages are out of date and will be deleted:\n\n"); - ICatPageNames(invalidPages, msg, sizeof(msg)); + msg = ICatPageNames(invalidPages, msg); - hsMessageBox(msg, "Warning", hsMessageBoxNormal); + hsMessageBox(msg, ST_LITERAL("Warning"), hsMessageBoxNormal); } #endif // PLASMA_EXTERNAL_RELEASE @@ -1433,14 +1431,13 @@ bool plResManager::IWarnNewerPages(std::vector &newerPages) #ifndef PLASMA_EXTERNAL_RELEASE if (!hsMessageBox_SuppressPrompts) { - char msg[4096]; // Prompt what to do - strcpy(msg, "The following pages have newer version numbers than this client and cannot be \nloaded. " - "They will be ignored but their files will NOT be deleted:\n\n"); + ST::string msg = ST_LITERAL("The following pages have newer version numbers than this client and cannot be \nloaded. " + "They will be ignored but their files will NOT be deleted:\n\n"); - ICatPageNames(newerPages, msg, sizeof(msg)); + msg = ICatPageNames(newerPages, msg); - hsMessageBox(msg, "Warning", hsMessageBoxNormal); + hsMessageBox(msg, ST_LITERAL("Warning"), hsMessageBoxNormal); } #endif // PLASMA_EXTERNAL_RELEASE