Skip to content

Commit

Permalink
Initial work on String Theory wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
colincornaby committed Feb 19, 2023
1 parent fd6f501 commit ca7b78b
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Sources/Plasma/Apps/plClient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -107,6 +108,7 @@ elseif(APPLE)
OSX/PLSPatcherWindowController.h
OSX/PLSPatcher.h
OSX/PLSServerStatus.h
OSX/StringTheory_NSString.h
)
set(RESOURCES
OSX/MainMenu.xib
Expand Down
15 changes: 8 additions & 7 deletions Sources/Plasma/Apps/plClient/OSX/PLSLoginWindowController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "pfPasswordStore/pfPasswordStore.h"
#include <regex>
#include "pnEncryption/plChallengeHash.h"
#include "StringTheory_NSString.h"

@interface PLSLoginWindowController ()

Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand All @@ -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];
}
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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];
Expand Down
8 changes: 4 additions & 4 deletions Sources/Plasma/Apps/plClient/OSX/PLSPatcher.mm
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "pfPatcher/plManifests.h"
#include "plNetGameLib/plNetGameLib.h"
#include <string_theory/format>
#include "StringTheory_NSString.h"

class Patcher {
public:
Expand Down Expand Up @@ -96,16 +97,15 @@ -(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];
});
}

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];
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Sources/Plasma/Apps/plClient/OSX/PLSServerStatus.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#import "PLSServerStatus.h"
#include <string_theory/string>
#include "plNetGameLib/plNetGameLib.h"
#include "StringTheory_NSString.h"

@interface PLSServerStatus () <NSURLSessionDelegate>
@property NSString * serverStatusString;
Expand All @@ -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];
Expand Down
57 changes: 57 additions & 0 deletions Sources/Plasma/Apps/plClient/OSX/StringTheory_NSString.h
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
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 [email protected]
or by snail mail at:
Cyan Worlds, Inc.
14617 N Newport Hwy
Mead, WA 99021
*==LICENSE==*/

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

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
60 changes: 60 additions & 0 deletions Sources/Plasma/Apps/plClient/OSX/StringTheory_NSString.mm
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
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 [email protected]
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
4 changes: 3 additions & 1 deletion Sources/Plasma/Apps/plClient/OSX/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
#include "plNetClient/plNetClientMgr.h"
#define PARABLE_NORMAL_EXIT 0 // i.e. exited WinMain normally

#include "StringTheory_NSString.h"

void PumpMessageQueueProc();


Expand Down Expand Up @@ -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<MTLDevice> device = ((CAMetalLayer *) self.window.contentView.layer).device;
#ifdef HS_DEBUGGING
[self.window setTitle:[NSString stringWithFormat:@"%@ - %@, %@",
Expand Down

0 comments on commit ca7b78b

Please sign in to comment.