2013-05-31 20:48:40 +04:00
|
|
|
//
|
|
|
|
// AppDelegate.m
|
|
|
|
// MacClient2
|
|
|
|
//
|
|
|
|
// Created by Benoît et Kathy on 2013-05-08.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "AppDelegate.h"
|
2013-06-26 00:05:37 +04:00
|
|
|
#import "MacFreeRDP/mfreerdp.h"
|
|
|
|
#import "MacFreeRDP/mf_client.h"
|
2013-05-31 20:48:40 +04:00
|
|
|
|
|
|
|
@implementation AppDelegate
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
2013-06-23 04:27:23 +04:00
|
|
|
[super dealloc];
|
2013-05-31 20:48:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
@synthesize window = window;
|
|
|
|
|
|
|
|
@synthesize mrdpView = mrdpView;
|
|
|
|
|
2013-06-18 22:30:21 +04:00
|
|
|
@synthesize context = context;
|
|
|
|
|
2013-06-18 20:03:22 +04:00
|
|
|
- (void) applicationDidFinishLaunching:(NSNotification*)aNotification
|
2013-05-31 20:48:40 +04:00
|
|
|
{
|
2013-06-23 04:27:23 +04:00
|
|
|
int status;
|
2013-06-23 06:55:51 +04:00
|
|
|
mfContext* mfc;
|
2013-06-23 04:27:23 +04:00
|
|
|
|
|
|
|
[self CreateContext];
|
|
|
|
|
|
|
|
status = [self ParseCommandLineArguments];
|
|
|
|
|
2013-06-23 06:55:51 +04:00
|
|
|
mfc = (mfContext*) context;
|
|
|
|
mfc->view = (void*) mrdpView;
|
|
|
|
|
2013-06-23 04:27:23 +04:00
|
|
|
if (status < 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-23 06:55:51 +04:00
|
|
|
freerdp_client_start(context);
|
2013-06-23 04:27:23 +04:00
|
|
|
}
|
2013-05-31 20:48:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) applicationWillTerminate:(NSNotification*)notification
|
|
|
|
{
|
2013-06-23 04:27:23 +04:00
|
|
|
[mrdpView releaseResources];
|
2013-05-31 20:48:40 +04:00
|
|
|
}
|
|
|
|
|
2013-06-18 20:03:22 +04:00
|
|
|
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
|
|
|
|
{
|
2013-06-23 04:27:23 +04:00
|
|
|
return YES;
|
2013-06-18 20:03:22 +04:00
|
|
|
}
|
|
|
|
|
2013-06-18 22:30:21 +04:00
|
|
|
- (int) ParseCommandLineArguments
|
|
|
|
{
|
2013-06-23 04:27:23 +04:00
|
|
|
int i;
|
|
|
|
int len;
|
2013-06-23 06:55:51 +04:00
|
|
|
int status;
|
2013-06-23 04:27:23 +04:00
|
|
|
char* cptr;
|
|
|
|
int argc;
|
|
|
|
char** argv = nil;
|
|
|
|
|
2013-06-23 08:18:55 +04:00
|
|
|
NSArray* args = [[NSProcessInfo processInfo] arguments];
|
2013-06-18 22:30:21 +04:00
|
|
|
|
2013-06-23 04:27:23 +04:00
|
|
|
argc = (int) [args count];
|
2013-06-23 08:18:55 +04:00
|
|
|
argv = malloc(sizeof(char*) * argc);
|
2013-06-18 22:30:21 +04:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
2013-06-23 08:18:55 +04:00
|
|
|
for (NSString* str in args)
|
2013-06-23 04:27:23 +04:00
|
|
|
{
|
|
|
|
len = (int) ([str length] + 1);
|
2013-06-23 08:18:55 +04:00
|
|
|
cptr = (char*) malloc(len);
|
2013-06-23 04:27:23 +04:00
|
|
|
strcpy(cptr, [str UTF8String]);
|
|
|
|
argv[i++] = cptr;
|
|
|
|
}
|
2013-06-18 22:30:21 +04:00
|
|
|
|
2013-06-23 08:18:55 +04:00
|
|
|
status = freerdp_client_parse_command_line(context, argc, argv);
|
2013-06-23 04:27:23 +04:00
|
|
|
|
|
|
|
return status;
|
2013-06-18 22:30:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) CreateContext
|
|
|
|
{
|
|
|
|
RDP_CLIENT_ENTRY_POINTS clientEntryPoints;
|
2013-06-23 04:27:23 +04:00
|
|
|
|
2013-06-18 22:30:21 +04:00
|
|
|
ZeroMemory(&clientEntryPoints, sizeof(RDP_CLIENT_ENTRY_POINTS));
|
|
|
|
clientEntryPoints.Size = sizeof(RDP_CLIENT_ENTRY_POINTS);
|
|
|
|
clientEntryPoints.Version = RDP_CLIENT_INTERFACE_VERSION;
|
2013-06-23 04:27:23 +04:00
|
|
|
|
2013-06-18 22:30:21 +04:00
|
|
|
RdpClientEntry(&clientEntryPoints);
|
2013-06-23 04:27:23 +04:00
|
|
|
|
2013-06-18 22:30:21 +04:00
|
|
|
context = freerdp_client_context_new(&clientEntryPoints);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) ReleaseContext
|
|
|
|
{
|
2013-06-23 08:18:55 +04:00
|
|
|
freerdp_client_context_free(context);
|
2013-06-23 04:27:23 +04:00
|
|
|
context = nil;
|
2013-06-18 22:30:21 +04:00
|
|
|
}
|
|
|
|
|
2013-05-31 20:48:40 +04:00
|
|
|
@end
|