1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
/*
* Copyright (c) 2010, Wei Mingzhi <whistler@openoffice.org>.
* All Rights Reserved.
*
* Based on: Cdrom for Psemu Pro like Emulators
* By: linuzappz <linuzappz@hotmail.com>
*
* 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 2 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>.
*/
#import "PluginConfigController.h"
#include "dfnet.h"
#define kIPADDRKEY @"IP Address"
#define kIPPORT @"IP Port"
#define kPLAYERNUM @"Player Number"
#define APP_ID @"net.codeplex.pcsxr.DFNet"
#define PrefsKey APP_ID @" Settings"
static PluginConfigController *windowController = nil;
static inline void RunOnMainThreadSync(dispatch_block_t block)
{
if ([NSThread isMainThread]) {
block();
} else {
dispatch_sync(dispatch_get_main_queue(), block);
}
}
void AboutDlgProc()
{
// Get parent application instance
NSBundle *bundle = [NSBundle bundleWithIdentifier:APP_ID];
// Get Credits.rtf
NSString *path = [bundle pathForResource:@"Credits" ofType:@"rtf"];
NSAttributedString *credits;
if (path) {
credits = [[NSAttributedString alloc] initWithPath: path
documentAttributes:NULL];
} else {
credits = [[NSAttributedString alloc] initWithString:@""];
}
// Get Application Icon
NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:[bundle bundlePath]];
[icon setSize:NSMakeSize(64, 64)];
NSDictionary *infoPaneDict =
@{@"ApplicationName": [bundle objectForInfoDictionaryKey:@"CFBundleName"],
@"ApplicationIcon": icon,
@"ApplicationVersion": [bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"],
@"Version": [bundle objectForInfoDictionaryKey:@"CFBundleVersion"],
@"Copyright": [bundle objectForInfoDictionaryKey:@"NSHumanReadableCopyright"],
@"Credits": credits};
dispatch_async(dispatch_get_main_queue(), ^{
[NSApp orderFrontStandardAboutPanelWithOptions:infoPaneDict];
});
}
void ConfDlgProc()
{
RunOnMainThreadSync(^{
NSWindow *window;
if (windowController == nil) {
windowController = [[PluginConfigController alloc] initWithWindowNibName:@"DFNet"];
}
window = [windowController window];
[windowController loadValues];
[window center];
[window makeKeyAndOrderFront:nil];
});
}
void ReadConfig()
{
NSDictionary *keyValues;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults registerDefaults:@{PrefsKey: @{kIPADDRKEY: @"127.0.0.1",
kIPPORT: @33306,
kPLAYERNUM: @1}}];
keyValues = [defaults dictionaryForKey:PrefsKey];
conf.PortNum = [keyValues[kIPPORT] intValue];
conf.PlayerNum = [keyValues[kPLAYERNUM] intValue];
strlcpy(conf.ipAddress, [keyValues[kIPADDRKEY] cStringUsingEncoding:NSASCIIStringEncoding], sizeof(conf.ipAddress));
}
@implementation PluginConfigController
- (IBAction)cancel:(id)sender
{
[self close];
}
- (IBAction)ok:(id)sender
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *theAddress = [ipAddress stringValue];
NSInteger asciiLen = [theAddress lengthOfBytesUsingEncoding:NSASCIIStringEncoding];
if (asciiLen > (sizeof(conf.ipAddress) - 1)) {
NSBeginAlertSheet(@"Address too long", nil, nil, nil, [self window], nil, NULL, NULL, NULL, @"The address is too long.\n\nTry to use only the IP address and not a host name.");
return;
} else if (asciiLen == 0) {
NSBeginAlertSheet(@"Blank address", nil, nil, nil, [self window], nil, NULL, NULL, NULL, @"The address specified is either blank, or can't be converted to ASCII.\n\nTry connecting directly using the IP address using latin numerals.");
return;
}
NSMutableDictionary *writeDic = [NSMutableDictionary dictionaryWithDictionary:[defaults dictionaryForKey:PrefsKey]];
writeDic[kIPPORT] = @((unsigned short)[portNum intValue]);
writeDic[kPLAYERNUM] = @([playerNum intValue]);
writeDic[kIPADDRKEY] = theAddress;
// write to defaults
[defaults setObject:writeDic forKey:PrefsKey];
[defaults synchronize];
// and set global values accordingly
ReadConfig();
[self close];
}
- (void)loadValues
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
ReadConfig();
NSDictionary *keyValues = [defaults dictionaryForKey:PrefsKey];
[ipAddress setStringValue:keyValues[kIPADDRKEY]];
[portNum setIntValue:[keyValues[kIPPORT] unsignedShortValue]];
[playerNum setIntValue:[keyValues[kPLAYERNUM] intValue]];
}
@end
#import "OSXPlugLocalization.h"
PLUGLOCIMP([PluginConfigController class]);
|