llappviewermacosx-objc.mm 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * @file llappviewermacosx-objc.mm
  3. * @brief Functions related to LLAppViewerMacOSX that must be expressed in obj-c
  4. *
  5. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #import <Cocoa/Cocoa.h>
  27. #include <iostream>
  28. #include "llappviewermacosx-objc.h"
  29. void launchApplication(const std::string* app_name, const std::vector<std::string>* args)
  30. {
  31. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  32. if (app_name->empty()) return;
  33. NSMutableString* app_name_ns = [NSMutableString stringWithString:[[NSBundle mainBundle] resourcePath]]; //Path to resource dir
  34. [app_name_ns appendFormat:@"/%@", [NSString stringWithCString:app_name->c_str()
  35. encoding:[NSString defaultCStringEncoding]]];
  36. NSMutableArray *args_ns = nil;
  37. args_ns = [[NSMutableArray alloc] init];
  38. for (int i=0; i < args->size(); ++i)
  39. {
  40. NSLog(@"Adding string %s", (*args)[i].c_str());
  41. [args_ns addObject:
  42. [NSString stringWithCString:(*args)[i].c_str()
  43. encoding:[NSString defaultCStringEncoding]]];
  44. }
  45. NSTask *task = [[NSTask alloc] init];
  46. NSBundle *bundle = [NSBundle bundleWithPath:[[NSWorkspace sharedWorkspace] fullPathForApplication:app_name_ns]];
  47. [task setLaunchPath:[bundle executablePath]];
  48. [task setArguments:args_ns];
  49. [task launch];
  50. // NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
  51. // NSURL *url = [NSURL fileURLWithPath:[workspace fullPathForApplication:app_name_ns]];
  52. //
  53. // NSError *error = nil;
  54. // [workspace launchApplicationAtURL:url options:0 configuration:[NSDictionary dictionaryWithObject:args_ns forKey:NSWorkspaceLaunchConfigurationArguments] error:&error];
  55. //TODO Handle error
  56. [pool release];
  57. return;
  58. }