summaryrefslogtreecommitdiff
path: root/macosx/plugins/DFNet/macsrc/SockDialog.m
blob: 77a09f04322bdffdb67dcae3a2a5d4f2d0ebc697 (plain) (blame)
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
//
//  SockDialog.m
//  DFNet
//
//  Created by C.W. Betts on 2/18/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "SockDialog.h"
#include "dfnet.h"

#import "EmuThread.h"
#import "ARCBridge.h"

void SysMessage(const char *fmt, ...)
{
	va_list list;
	char msg[512];
	//char cmd[512];
	
	va_start(list, fmt);
	vsprintf(msg, fmt, list);
	va_end(list);
	
	//sprintf(cmd, "message %s\n", msg);
	NSString *errString = @(msg);
	fprintf(stderr, "%s", msg);
	NSAlert *alert = [NSAlert alertWithMessageText:@"Error" defaultButton:@"Exit" alternateButton:nil otherButton:nil informativeTextWithFormat:@"%@", errString];
	[alert setAlertStyle:NSCriticalAlertStyle];
	//NSInteger result = NSRunAlertPanel(errString, nil, @"Okay", nil, nil);
	NSInteger result = [alert runModal];
	if (result == NSAlertDefaultReturn)
	{
		Class theEmuClass = NSClassFromString(@"EmuThread");
		if (theEmuClass) {
			[theEmuClass stop];
		} else {
			NSLog(@"Unable to stop emulation because the Objective-C class \"EmuThreaed\" was not found. Are you using a different emulator than PCSXR?");
		}
	}
}

static inline void RunOnMainThreadSync(dispatch_block_t block)
{
	if ([NSThread isMainThread]) {
		block();
	} else {
		dispatch_sync(dispatch_get_main_queue(), block);
	}
}

static SockDialog *globalSock = nil;

void sockCreateWaitDlg()
{
	RunOnMainThreadSync(^{
		if (globalSock == nil) {
			globalSock = [[SockDialog alloc] init];
		}
		NSWindow *tempWindow = [globalSock window];
		[tempWindow center];
		[globalSock showWindow:nil];
		[tempWindow makeKeyAndOrderFront:nil];
	});
}

void sockDlgUpdate()
{
	
}

long sockOpen()
{
	LoadConf();
	
	return 0;
}

void sockDestroyWaitDlg()
{
	RunOnMainThreadSync(^{
		if (globalSock != nil) {
			[globalSock close];
			
			RELEASEOBJ(globalSock);
			globalSock = nil;
		}
	});
}

@implementation SockDialog

- (IBAction)cancel:(id)sender {
	WaitCancel = 1;
}

- (id)init
{
	if ((self = [super initWithWindowNibName:@"SockDialog"])) {
		
	}
	return self;
}

#if !__has_feature(objc_arc)
-(void)dealloc
{
	
	[super dealloc];
}
#endif

@end