Skip to content

Commit

Permalink
Convert all hsMessageBox inputs to ST::string
Browse files Browse the repository at this point in the history
Co-Authored-By: Adam Johnson <AdamJohnso@gmail.com>
  • Loading branch information
dpogue and Hoikas committed Aug 27, 2023
1 parent 7feef42 commit c8a21f1
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Sources/Plasma/Apps/plClient/plClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 1 addition & 10 deletions Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string_theory/string>
#include <string_theory/format>

// Need a proper implementation for Linux, but for now let's just print out to the console
Expand All @@ -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);
}
5 changes: 2 additions & 3 deletions Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define _hsMessageBox_h_

#include "HeadSpin.h"
#include <string_theory/string>

namespace ST { class string; }

enum hsMessageBoxKind { // Kind of MessageBox...passed to hsMessageBox
hsMessageBoxAbortRetyIgnore,
Expand Down Expand Up @@ -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_
1 change: 1 addition & 0 deletions Sources/Plasma/PubUtilLib/plMessageBox/hsMessageBox_Mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

#include "hsMessageBox.h"

#include <string_theory/string>
#import <Cocoa/Cocoa.h>

hsMessageBoxResult hsMessageBox(const ST::string& message, const ST::string& caption, hsMessageBoxKind kind, hsMessageBoxIcon icon)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com

#include "hsMessageBox.h"
#include "hsWindows.h"
#include <string_theory/string>

class hsMinimizeClientGuard
{
Expand Down
3 changes: 2 additions & 1 deletion Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
41 changes: 19 additions & 22 deletions Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1367,46 +1367,44 @@ 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<plRegistryPageNode*>& pages, char* buf, int bufSize)
static ST::string ICatPageNames(std::vector<plRegistryPageNode*>& 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<plRegistryPageNode*>& invalidPages, bool conflictingSeqNums)
{
#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

Expand All @@ -1433,14 +1431,13 @@ bool plResManager::IWarnNewerPages(std::vector<plRegistryPageNode*> &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

Expand Down

0 comments on commit c8a21f1

Please sign in to comment.