From 698daf0496e9da897423a50982c4e8693b1c9147 Mon Sep 17 00:00:00 2001 From: Colin Cornaby Date: Sat, 18 Feb 2023 22:01:43 -0800 Subject: [PATCH] Initial work on String Theory wrapper --- Sources/Plasma/Apps/plClient/CMakeLists.txt | 2 + .../plClient/OSX/PLSLoginWindowController.mm | 8 ++- .../Plasma/Apps/plClient/OSX/PLSPatcher.mm | 6 +- .../Apps/plClient/OSX/StringTheory_NSString.h | 57 ++++++++++++++++++ .../plClient/OSX/StringTheory_NSString.mm | 60 +++++++++++++++++++ 5 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 Sources/Plasma/Apps/plClient/OSX/StringTheory_NSString.h create mode 100644 Sources/Plasma/Apps/plClient/OSX/StringTheory_NSString.mm diff --git a/Sources/Plasma/Apps/plClient/CMakeLists.txt b/Sources/Plasma/Apps/plClient/CMakeLists.txt index 75c38dd718..d463ba5d0d 100644 --- a/Sources/Plasma/Apps/plClient/CMakeLists.txt +++ b/Sources/Plasma/Apps/plClient/CMakeLists.txt @@ -99,6 +99,7 @@ elseif(APPLE) OSX/PLSPatcherWindowController.mm OSX/PLSPatcher.mm OSX/PLSServerStatus.mm + OSX/StringTheory_NSString.mm ) set(plClient_HEADERS ${plClient_HEADERS} OSX/PLSKeyboardEventMonitor.h @@ -107,6 +108,7 @@ elseif(APPLE) OSX/PLSPatcherWindowController.h OSX/PLSPatcher.h OSX/PLSServerStatus.h + OSX/StringTheory_NSString.h ) set(RESOURCES OSX/MainMenu.xib diff --git a/Sources/Plasma/Apps/plClient/OSX/PLSLoginWindowController.mm b/Sources/Plasma/Apps/plClient/OSX/PLSLoginWindowController.mm index 58ae2ff5a0..a04509df30 100644 --- a/Sources/Plasma/Apps/plClient/OSX/PLSLoginWindowController.mm +++ b/Sources/Plasma/Apps/plClient/OSX/PLSLoginWindowController.mm @@ -47,6 +47,7 @@ #include "pfPasswordStore/pfPasswordStore.h" #include #include "pnEncryption/plChallengeHash.h" +#include "StringTheory_NSString.h" @interface PLSLoginWindowController () @@ -111,6 +112,7 @@ - (id)init { -(void)mutableUserDefaults:(bool (^)(NSMutableDictionary *dictionary))callback { //windows segments by product name here. in since user defaults belong to this product, we don't need to do that. NSString *serverName = [NSString stringWithCString:GetServerDisplayName().c_str() encoding:NSUTF8StringEncoding]; + NSString *serverName2 = [NSString stringWithSTString:GetServerDisplayName()]; NSMutableDictionary *settingsDictionary = [[[NSUserDefaults standardUserDefaults] dictionaryForKey:serverName] mutableCopy]; if(!settingsDictionary) settingsDictionary = [NSMutableDictionary dictionary]; @@ -144,16 +146,16 @@ -(void)save { } -(void)load { - NSString *serverName = [NSString stringWithCString:GetServerDisplayName().c_str() encoding:NSUTF8StringEncoding]; + NSString *serverName = [NSString stringWithSTString:GetServerDisplayName()]; NSDictionary *settingsDictionary = [[NSUserDefaults standardUserDefaults] dictionaryForKey:serverName]; self.username = [settingsDictionary objectForKey:@"LastAccountName"]; self.rememberPassword = [[settingsDictionary objectForKey:@"RememberPassword"] boolValue]; if(self.rememberPassword) { pfPasswordStore* store = pfPasswordStore::Instance(); - ST::string username = ST::string([self.username cStringUsingEncoding:NSUTF8StringEncoding]); + ST::string username = [self.username stString]; ST::string password = store->GetPassword(username); - self.password = [NSString stringWithCString:password.c_str() encoding:NSUTF8StringEncoding]; + self.password = [NSString stringWithSTString:password]; } } diff --git a/Sources/Plasma/Apps/plClient/OSX/PLSPatcher.mm b/Sources/Plasma/Apps/plClient/OSX/PLSPatcher.mm index 76ffbe95c1..54d2923146 100644 --- a/Sources/Plasma/Apps/plClient/OSX/PLSPatcher.mm +++ b/Sources/Plasma/Apps/plClient/OSX/PLSPatcher.mm @@ -48,6 +48,7 @@ #include "pfPatcher/plManifests.h" #include "plNetGameLib/plNetGameLib.h" #include +#include "StringTheory_NSString.h" class Patcher { public: @@ -96,8 +97,7 @@ -(void)start { void Patcher::IOnDownloadBegin(const plFileName& file) { - const char* wideChars = file.AsString().c_str(); - NSString *fileName = [NSString stringWithCString:(char *)wideChars encoding:NSUTF8StringEncoding]; + NSString *fileName = [NSString stringWithSTString:file.AsString()]; dispatch_async(dispatch_get_main_queue(), ^{ [parent.delegate patcher:parent beganDownloadOfFile:fileName]; }); @@ -105,7 +105,7 @@ -(void)start { void Patcher::IOnProgressTick(uint64_t curBytes, uint64_t totalBytes, const ST::string& status) { - NSString *statusString = [NSString stringWithCString:status.c_str() encoding:NSUTF8StringEncoding]; + NSString *statusString = [NSString stringWithSTString:status]; dispatch_async(dispatch_get_main_queue(), ^{ [parent.delegate patcher:parent updatedProgress:statusString withBytes:curBytes outOf:totalBytes]; diff --git a/Sources/Plasma/Apps/plClient/OSX/StringTheory_NSString.h b/Sources/Plasma/Apps/plClient/OSX/StringTheory_NSString.h new file mode 100644 index 0000000000..e806680cd3 --- /dev/null +++ b/Sources/Plasma/Apps/plClient/OSX/StringTheory_NSString.h @@ -0,0 +1,57 @@ +/*==LICENSE==* + +CyanWorlds.com Engine - MMOG client, server and tools +Copyright (C) 2011 Cyan Worlds, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Additional permissions under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK +(or a modified version of those libraries), +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the +licensors of this Program grant you additional +permission to convey the resulting work. Corresponding Source for a +non-source form of such a combination shall include the source code for +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered +work. + +You can contact Cyan Worlds, Inc. by email legal@cyan.com + or by snail mail at: + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + +*==LICENSE==*/ + +#import +#include + +NS_ASSUME_NONNULL_BEGIN + +@interface NSString (StringTheory) + +-(id)initWithSTString:(const ST::string&)string; ++(id)stringWithSTString:(const ST::string&)string; + +-(const ST::string)stString; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sources/Plasma/Apps/plClient/OSX/StringTheory_NSString.mm b/Sources/Plasma/Apps/plClient/OSX/StringTheory_NSString.mm new file mode 100644 index 0000000000..623f325825 --- /dev/null +++ b/Sources/Plasma/Apps/plClient/OSX/StringTheory_NSString.mm @@ -0,0 +1,60 @@ +/*==LICENSE==* + +CyanWorlds.com Engine - MMOG client, server and tools +Copyright (C) 2011 Cyan Worlds, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Additional permissions under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK +(or a modified version of those libraries), +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the +licensors of this Program grant you additional +permission to convey the resulting work. Corresponding Source for a +non-source form of such a combination shall include the source code for +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered +work. + +You can contact Cyan Worlds, Inc. by email legal@cyan.com + or by snail mail at: + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + +*==LICENSE==*/ + +#include "StringTheory_NSString.h" + +@implementation NSString (StringTheory) + +-(id)initWithSTString:(const ST::string&)string { + self = [self initWithCString:string.data() encoding:NSUTF8StringEncoding]; + return self; +} + ++(id)stringWithSTString:(const ST::string&)string { + return [[NSString alloc] initWithSTString:string]; +} + +-(const ST::string)stString { + return ST::string([self cStringUsingEncoding:NSUTF8StringEncoding]); +} + +@end