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..02fc9d4318 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 () @@ -110,7 +111,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 *serverName = [NSString stringWithSTString:GetServerDisplayName()]; NSMutableDictionary *settingsDictionary = [[[NSUserDefaults standardUserDefaults] dictionaryForKey:serverName] mutableCopy]; if(!settingsDictionary) settingsDictionary = [NSMutableDictionary dictionary]; @@ -122,7 +123,7 @@ -(void)mutableUserDefaults:(bool (^)(NSMutableDictionary *dictionary))callback { -(void)save { //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 *serverName = [NSString stringWithSTString:GetServerDisplayName()]; NSMutableDictionary *settingsDictionary = [[[NSUserDefaults standardUserDefaults] dictionaryForKey:serverName] mutableCopy]; if(!settingsDictionary) settingsDictionary = [NSMutableDictionary dictionary]; @@ -144,16 +145,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]; } } @@ -210,7 +211,7 @@ - (void)windowDidLoad { [super windowDidLoad]; [self.window center]; - [self.productTextField setStringValue:[NSString stringWithCString:plProduct::ProductString().c_str() encoding:NSUTF8StringEncoding]]; + [self.productTextField setStringValue:[NSString stringWithSTString:plProduct::ProductString().c_str()]]; } - (NSNibName)windowNibName { @@ -253,7 +254,7 @@ -(void)loginAttemptEndedWithResult:(ENetError)result { } - (IBAction)needAccountButtonHit:(id)sender { - NSString *urlString = [NSString stringWithCString:GetServerSignupUrl().c_str() encoding:NSUTF8StringEncoding]; + NSString *urlString = [NSString stringWithSTString:GetServerSignupUrl()]; NSURL *url = [NSURL URLWithString:urlString]; if(url) { [[NSWorkspace sharedWorkspace] openURL:url]; diff --git a/Sources/Plasma/Apps/plClient/OSX/PLSPatcher.mm b/Sources/Plasma/Apps/plClient/OSX/PLSPatcher.mm index 76ffbe95c1..a4223a936c 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]; @@ -129,7 +129,7 @@ bool IApproveDownload(const plFileName& file) [patcher.delegate patcherCompleted:patcher]; }); } else { - NSString *msgString = [NSString stringWithCString:msg.c_str() encoding:NSUTF8StringEncoding]; + NSString *msgString = [NSString stringWithSTString:msg]; dispatch_async(dispatch_get_main_queue(), ^{ [parent.delegate patcherCompletedWithError:parent error:[NSError diff --git a/Sources/Plasma/Apps/plClient/OSX/PLSServerStatus.mm b/Sources/Plasma/Apps/plClient/OSX/PLSServerStatus.mm index d90406baf3..8a0380b8ba 100644 --- a/Sources/Plasma/Apps/plClient/OSX/PLSServerStatus.mm +++ b/Sources/Plasma/Apps/plClient/OSX/PLSServerStatus.mm @@ -43,6 +43,7 @@ #import "PLSServerStatus.h" #include #include "plNetGameLib/plNetGameLib.h" +#include "StringTheory_NSString.h" @interface PLSServerStatus () @property NSString * serverStatusString; @@ -61,7 +62,7 @@ +(id)sharedStatus { -(void)loadServerStatus { - NSString *urlString = [NSString stringWithCString:GetServerStatusUrl().c_str() encoding:NSUTF8StringEncoding]; + NSString *urlString = [NSString stringWithSTString:GetServerStatusUrl()]; NSURL *url = [NSURL URLWithString:urlString]; NSURLSessionConfiguration *URLSessionConfiguration = [NSURLSessionConfiguration ephemeralSessionConfiguration]; NSURLSession *session = [NSURLSession sessionWithConfiguration:URLSessionConfiguration delegate:self delegateQueue:NSOperationQueue.mainQueue]; 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 diff --git a/Sources/Plasma/Apps/plClient/OSX/main.mm b/Sources/Plasma/Apps/plClient/OSX/main.mm index 7d04f10f1d..fd47aa25e9 100644 --- a/Sources/Plasma/Apps/plClient/OSX/main.mm +++ b/Sources/Plasma/Apps/plClient/OSX/main.mm @@ -79,6 +79,8 @@ #include "plNetClient/plNetClientMgr.h" #define PARABLE_NORMAL_EXIT 0 // i.e. exited WinMain normally +#include "StringTheory_NSString.h" + void PumpMessageQueueProc(); @@ -464,7 +466,7 @@ - (void)startClient { - (void)updateWindowTitle { - NSString *productTitle = [NSString stringWithCString:plProduct::LongName().c_str() encoding:NSUTF8StringEncoding]; + NSString *productTitle = [NSString stringWithSTString:plProduct::LongName()]; id device = ((CAMetalLayer *) self.window.contentView.layer).device; #ifdef HS_DEBUGGING [self.window setTitle:[NSString stringWithFormat:@"%@ - %@, %@",