Skip to content

Commit ca7b78b

Browse files
committed
Initial work on String Theory wrapper
1 parent fd6f501 commit ca7b78b

File tree

7 files changed

+136
-13
lines changed

7 files changed

+136
-13
lines changed

Sources/Plasma/Apps/plClient/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ elseif(APPLE)
9999
OSX/PLSPatcherWindowController.mm
100100
OSX/PLSPatcher.mm
101101
OSX/PLSServerStatus.mm
102+
OSX/StringTheory_NSString.mm
102103
)
103104
set(plClient_HEADERS ${plClient_HEADERS}
104105
OSX/PLSKeyboardEventMonitor.h
@@ -107,6 +108,7 @@ elseif(APPLE)
107108
OSX/PLSPatcherWindowController.h
108109
OSX/PLSPatcher.h
109110
OSX/PLSServerStatus.h
111+
OSX/StringTheory_NSString.h
110112
)
111113
set(RESOURCES
112114
OSX/MainMenu.xib

Sources/Plasma/Apps/plClient/OSX/PLSLoginWindowController.mm

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "pfPasswordStore/pfPasswordStore.h"
4848
#include <regex>
4949
#include "pnEncryption/plChallengeHash.h"
50+
#include "StringTheory_NSString.h"
5051

5152
@interface PLSLoginWindowController ()
5253

@@ -110,7 +111,7 @@ - (id)init {
110111

111112
-(void)mutableUserDefaults:(bool (^)(NSMutableDictionary *dictionary))callback {
112113
//windows segments by product name here. in since user defaults belong to this product, we don't need to do that.
113-
NSString *serverName = [NSString stringWithCString:GetServerDisplayName().c_str() encoding:NSUTF8StringEncoding];
114+
NSString *serverName = [NSString stringWithSTString:GetServerDisplayName()];
114115
NSMutableDictionary *settingsDictionary = [[[NSUserDefaults standardUserDefaults] dictionaryForKey:serverName] mutableCopy];
115116
if(!settingsDictionary)
116117
settingsDictionary = [NSMutableDictionary dictionary];
@@ -122,7 +123,7 @@ -(void)mutableUserDefaults:(bool (^)(NSMutableDictionary *dictionary))callback {
122123

123124
-(void)save {
124125
//windows segments by product name here. in since user defaults belong to this product, we don't need to do that.
125-
NSString *serverName = [NSString stringWithCString:GetServerDisplayName().c_str() encoding:NSUTF8StringEncoding];
126+
NSString *serverName = [NSString stringWithSTString:GetServerDisplayName()];
126127
NSMutableDictionary *settingsDictionary = [[[NSUserDefaults standardUserDefaults] dictionaryForKey:serverName] mutableCopy];
127128
if(!settingsDictionary)
128129
settingsDictionary = [NSMutableDictionary dictionary];
@@ -144,16 +145,16 @@ -(void)save {
144145
}
145146

146147
-(void)load {
147-
NSString *serverName = [NSString stringWithCString:GetServerDisplayName().c_str() encoding:NSUTF8StringEncoding];
148+
NSString *serverName = [NSString stringWithSTString:GetServerDisplayName()];
148149
NSDictionary *settingsDictionary = [[NSUserDefaults standardUserDefaults] dictionaryForKey:serverName];
149150
self.username = [settingsDictionary objectForKey:@"LastAccountName"];
150151
self.rememberPassword = [[settingsDictionary objectForKey:@"RememberPassword"] boolValue];
151152

152153
if(self.rememberPassword) {
153154
pfPasswordStore* store = pfPasswordStore::Instance();
154-
ST::string username = ST::string([self.username cStringUsingEncoding:NSUTF8StringEncoding]);
155+
ST::string username = [self.username stString];
155156
ST::string password = store->GetPassword(username);
156-
self.password = [NSString stringWithCString:password.c_str() encoding:NSUTF8StringEncoding];
157+
self.password = [NSString stringWithSTString:password];
157158
}
158159
}
159160

@@ -210,7 +211,7 @@ - (void)windowDidLoad {
210211
[super windowDidLoad];
211212

212213
[self.window center];
213-
[self.productTextField setStringValue:[NSString stringWithCString:plProduct::ProductString().c_str() encoding:NSUTF8StringEncoding]];
214+
[self.productTextField setStringValue:[NSString stringWithSTString:plProduct::ProductString().c_str()]];
214215
}
215216

216217
- (NSNibName)windowNibName {
@@ -253,7 +254,7 @@ -(void)loginAttemptEndedWithResult:(ENetError)result {
253254
}
254255

255256
- (IBAction)needAccountButtonHit:(id)sender {
256-
NSString *urlString = [NSString stringWithCString:GetServerSignupUrl().c_str() encoding:NSUTF8StringEncoding];
257+
NSString *urlString = [NSString stringWithSTString:GetServerSignupUrl()];
257258
NSURL *url = [NSURL URLWithString:urlString];
258259
if(url) {
259260
[[NSWorkspace sharedWorkspace] openURL:url];

Sources/Plasma/Apps/plClient/OSX/PLSPatcher.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "pfPatcher/plManifests.h"
4949
#include "plNetGameLib/plNetGameLib.h"
5050
#include <string_theory/format>
51+
#include "StringTheory_NSString.h"
5152

5253
class Patcher {
5354
public:
@@ -96,16 +97,15 @@ -(void)start {
9697

9798
void Patcher::IOnDownloadBegin(const plFileName& file)
9899
{
99-
const char* wideChars = file.AsString().c_str();
100-
NSString *fileName = [NSString stringWithCString:(char *)wideChars encoding:NSUTF8StringEncoding];
100+
NSString *fileName = [NSString stringWithSTString:file.AsString()];
101101
dispatch_async(dispatch_get_main_queue(), ^{
102102
[parent.delegate patcher:parent beganDownloadOfFile:fileName];
103103
});
104104
}
105105

106106
void Patcher::IOnProgressTick(uint64_t curBytes, uint64_t totalBytes, const ST::string& status)
107107
{
108-
NSString *statusString = [NSString stringWithCString:status.c_str() encoding:NSUTF8StringEncoding];
108+
NSString *statusString = [NSString stringWithSTString:status];
109109

110110
dispatch_async(dispatch_get_main_queue(), ^{
111111
[parent.delegate patcher:parent updatedProgress:statusString withBytes:curBytes outOf:totalBytes];
@@ -129,7 +129,7 @@ bool IApproveDownload(const plFileName& file)
129129
[patcher.delegate patcherCompleted:patcher];
130130
});
131131
} else {
132-
NSString *msgString = [NSString stringWithCString:msg.c_str() encoding:NSUTF8StringEncoding];
132+
NSString *msgString = [NSString stringWithSTString:msg];
133133

134134
dispatch_async(dispatch_get_main_queue(), ^{
135135
[parent.delegate patcherCompletedWithError:parent error:[NSError

Sources/Plasma/Apps/plClient/OSX/PLSServerStatus.mm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#import "PLSServerStatus.h"
4444
#include <string_theory/string>
4545
#include "plNetGameLib/plNetGameLib.h"
46+
#include "StringTheory_NSString.h"
4647

4748
@interface PLSServerStatus () <NSURLSessionDelegate>
4849
@property NSString * serverStatusString;
@@ -61,7 +62,7 @@ +(id)sharedStatus {
6162

6263
-(void)loadServerStatus
6364
{
64-
NSString *urlString = [NSString stringWithCString:GetServerStatusUrl().c_str() encoding:NSUTF8StringEncoding];
65+
NSString *urlString = [NSString stringWithSTString:GetServerStatusUrl()];
6566
NSURL *url = [NSURL URLWithString:urlString];
6667
NSURLSessionConfiguration *URLSessionConfiguration = [NSURLSessionConfiguration ephemeralSessionConfiguration];
6768
NSURLSession *session = [NSURLSession sessionWithConfiguration:URLSessionConfiguration delegate:self delegateQueue:NSOperationQueue.mainQueue];
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*==LICENSE==*
2+
3+
CyanWorlds.com Engine - MMOG client, server and tools
4+
Copyright (C) 2011 Cyan Worlds, Inc.
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
Additional permissions under GNU GPL version 3 section 7
20+
21+
If you modify this Program, or any covered work, by linking or
22+
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
23+
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
24+
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
25+
(or a modified version of those libraries),
26+
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
27+
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
28+
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
29+
licensors of this Program grant you additional
30+
permission to convey the resulting work. Corresponding Source for a
31+
non-source form of such a combination shall include the source code for
32+
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
33+
work.
34+
35+
You can contact Cyan Worlds, Inc. by email [email protected]
36+
or by snail mail at:
37+
Cyan Worlds, Inc.
38+
14617 N Newport Hwy
39+
Mead, WA 99021
40+
41+
*==LICENSE==*/
42+
43+
#import <Foundation/Foundation.h>
44+
#include <string_theory/string>
45+
46+
NS_ASSUME_NONNULL_BEGIN
47+
48+
@interface NSString (StringTheory)
49+
50+
-(id)initWithSTString:(const ST::string&)string;
51+
+(id)stringWithSTString:(const ST::string&)string;
52+
53+
-(const ST::string)stString;
54+
55+
@end
56+
57+
NS_ASSUME_NONNULL_END
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*==LICENSE==*
2+
3+
CyanWorlds.com Engine - MMOG client, server and tools
4+
Copyright (C) 2011 Cyan Worlds, Inc.
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
Additional permissions under GNU GPL version 3 section 7
20+
21+
If you modify this Program, or any covered work, by linking or
22+
combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK,
23+
NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent
24+
JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK
25+
(or a modified version of those libraries),
26+
containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA,
27+
PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG
28+
JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the
29+
licensors of this Program grant you additional
30+
permission to convey the resulting work. Corresponding Source for a
31+
non-source form of such a combination shall include the source code for
32+
the parts of OpenSSL and IJG JPEG Library used as well as that of the covered
33+
work.
34+
35+
You can contact Cyan Worlds, Inc. by email [email protected]
36+
or by snail mail at:
37+
Cyan Worlds, Inc.
38+
14617 N Newport Hwy
39+
Mead, WA 99021
40+
41+
*==LICENSE==*/
42+
43+
#include "StringTheory_NSString.h"
44+
45+
@implementation NSString (StringTheory)
46+
47+
-(id)initWithSTString:(const ST::string&)string {
48+
self = [self initWithCString:string.data() encoding:NSUTF8StringEncoding];
49+
return self;
50+
}
51+
52+
+(id)stringWithSTString:(const ST::string&)string {
53+
return [[NSString alloc] initWithSTString:string];
54+
}
55+
56+
-(const ST::string)stString {
57+
return ST::string([self cStringUsingEncoding:NSUTF8StringEncoding]);
58+
}
59+
60+
@end

Sources/Plasma/Apps/plClient/OSX/main.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
#include "plNetClient/plNetClientMgr.h"
8080
#define PARABLE_NORMAL_EXIT 0 // i.e. exited WinMain normally
8181

82+
#include "StringTheory_NSString.h"
83+
8284
void PumpMessageQueueProc();
8385

8486

@@ -464,7 +466,7 @@ - (void)startClient {
464466

465467
- (void)updateWindowTitle
466468
{
467-
NSString *productTitle = [NSString stringWithCString:plProduct::LongName().c_str() encoding:NSUTF8StringEncoding];
469+
NSString *productTitle = [NSString stringWithSTString:plProduct::LongName()];
468470
id<MTLDevice> device = ((CAMetalLayer *) self.window.contentView.layer).device;
469471
#ifdef HS_DEBUGGING
470472
[self.window setTitle:[NSString stringWithFormat:@"%@ - %@, %@",

0 commit comments

Comments
 (0)