Changeset 281c5f57


Ignore:
Timestamp:
Sep 19, 2018 12:37:16 AM (2 years ago)
Author:
meeh <meeh@…>
Branches:
master
Children:
46ac0087, 9b958e4
Parents:
01a05f7
Message:

Bugfixes, improvements, more error handling and stability to the osx launcher.

Location:
launchers/macosx
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • launchers/macosx/AppDelegate.h

    r01a05f7 r281c5f57  
    4040
    4141inline void sendUserNotification(NSString* title, NSString* informativeText, NSImage* contentImage = NULL, bool makeSound = false) {
    42   NSUserNotification *userNotification = [[[NSUserNotification alloc] init] autorelease];
     42  NSUserNotification *userNotification = [[NSUserNotification alloc] init];
    4343 
    4444  userNotification.title = title;
     
    8484@property BOOL enableLogging;
    8585@property BOOL enableVerboseLogging;
     86@property (assign) SwiftMainDelegate *swiftRuntime;
    8687@property (assign) NSUserDefaults *userPreferences;
    8788@property (assign) ExtractMetaInfo *metaInfo;
     
    9091- (void) extractI2PBaseDir:(void(^)(BOOL success, NSError *error))completion;
    9192- (void) awakeFromNib;
    92 - (void) startupI2PRouter;
    9393- (void) applicationDidFinishLaunching:(NSNotification *)aNotification;
    9494- (void) applicationWillTerminate:(NSNotification *)aNotification;
     
    9797- (AppDelegate *) initWithArgc:(int)argc argv:(const char **)argv;
    9898#ifdef __cplusplus
     99- (void) startupI2PRouter;
    99100- (NSString *) userSelectJavaHome:(JvmListPtr)rawJvmList;
    100101#endif
  • launchers/macosx/I2PLauncher/I2PLauncher-Bridging-Header.h

    r01a05f7 r281c5f57  
    44#import "SBridge.h"
    55#import "AppleStuffExceptionHandler.h"
     6#import "AppDelegate.h"
     7#import "RouterTask.h"
     8
  • launchers/macosx/I2PLauncher/Info.plist

    r01a05f7 r281c5f57  
    3535        </array>
    3636        <key>CFBundleVersion</key>
    37         <string>1</string>
     37        <string>3</string>
     38        <key>LSApplicationCategoryType</key>
     39        <string>public.app-category.utilities</string>
    3840        <key>LSMinimumSystemVersion</key>
    3941        <string>$(MACOSX_DEPLOYMENT_TARGET)</string>
  • launchers/macosx/I2PLauncher/Storyboard.storyboard

    r01a05f7 r281c5f57  
    11<?xml version="1.0" encoding="UTF-8"?>
    2 <document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
     2<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
    33    <dependencies>
    44        <deployment identifier="macosx"/>
    5         <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14113"/>
    6         <capability name="box content view" minToolsVersion="7.0"/>
     5        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.18"/>
    76        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
    87    </dependencies>
     
    121120                                            <rect key="frame" x="11" y="17" width="409" height="228"/>
    122121                                            <autoresizingMask key="autoresizingMask"/>
    123                                             <clipView key="contentView" ambiguous="YES" id="E5l-WA-qOn">
     122                                            <clipView key="contentView" ambiguous="YES" drawsBackground="NO" id="E5l-WA-qOn">
    124123                                                <rect key="frame" x="1" y="1" width="407" height="226"/>
    125                                                 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
     124                                                <autoresizingMask key="autoresizingMask"/>
    126125                                                <subviews>
    127126                                                    <textView identifier="LoggerTextView" ambiguous="YES" importsGraphics="NO" verticallyResizable="YES" usesFontPanel="YES" findStyle="panel" continuousSpellChecking="YES" allowsUndo="YES" usesRuler="YES" allowsNonContiguousLayout="YES" quoteSubstitution="YES" dashSubstitution="YES" spellingCorrection="YES" smartInsertDelete="YES" id="bgQ-8i-Xgb" userLabel="LoggerTextView">
    128127                                                        <rect key="frame" x="0.0" y="0.0" width="407" height="226"/>
    129128                                                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
    130                                                         <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
     129                                                        <color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
     130                                                        <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
    131131                                                        <size key="minSize" width="407" height="226"/>
    132132                                                        <size key="maxSize" width="463" height="10000000"/>
    133                                                         <color key="insertionPointColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
     133                                                        <color key="insertionPointColor" name="textColor" catalog="System" colorSpace="catalog"/>
    134134                                                    </textView>
    135135                                                </subviews>
    136                                                 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
    137136                                            </clipView>
    138137                                            <scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="YES" id="MRF-Wt-zdZ">
  • launchers/macosx/I2PLauncher/SwiftMainDelegate.swift

    r01a05f7 r281c5f57  
    2626    }
    2727    let javaBinPath = self.javaDetector.javaHome
     28    RouterProcessStatus.knownJavaBinPath = javaBinPath
    2829    print("Found java home = ", javaBinPath)
    2930   
    30     let (portIsNotTaken, descPort) = RouterProcessStatus.checkTcpPortForListen(port: 7657)
     31    let (portIsNotTaken, _) = RouterProcessStatus.checkTcpPortForListen(port: 7657)
    3132    if (!portIsNotTaken) {
    3233      RouterProcessStatus.isRouterRunning = true
     
    4041   
    4142   
    42   }
     43  } // End of init()
    4344 
    44   func findInstalledI2PVersion(jarPath: String, javaBin: String) {
     45  @objc func findInstalledI2PVersion() {
    4546    var i2pPath = NSHomeDirectory()
    4647    i2pPath += "/Library/I2P"
    47     var jExecPath:String = javaBin
     48    var jExecPath:String = RouterProcessStatus.knownJavaBinPath!
    4849   
    4950    // Sometimes, home will return the binary, sometimes the actual home dir. This fixes the diverge.
     
    5354    }
    5455   
     56    let jarPath = i2pPath + "/lib/i2p.jar"
     57   
    5558    let subCmd = jExecPath + " -cp " + jarPath + " net.i2p.CoreVersion"
    5659   
    57     var cmdArgs:[String] = ["-c", subCmd]
     60    let cmdArgs:[String] = ["-c", subCmd]
    5861    print(cmdArgs)
    5962    let sub:Subprocess = Subprocess.init(executablePath: "/bin/sh", arguments: cmdArgs)
     
    6265      print("captured output")
    6366      let i2pVersion = results.outputLines.first?.replace(target: "I2P Core version: ", withString: "")
    64       print("I2P version detected: ",i2pVersion!)
     67      NSLog("I2P version detected: %@",i2pVersion ?? "Unknown")
    6568      RouterProcessStatus.routerVersion = i2pVersion
    6669    } else {
     
    7578    i2pPath += "/Library/I2P"
    7679   
    77     let javaBinPath = self.javaDetector.javaHome.replace(target: " ", withString: "\\ ")
     80    //let javaBinPath = self.javaDetector.javaHome.replace(target: " ", withString: "\\ ")
    7881   
    7982    let fileManager = FileManager()
     
    8588    }
    8689   
    87     let i2pJarPath = i2pPath + "/lib/i2p.jar"
     90    //let i2pJarPath = i2pPath + "/lib/i2p.jar"
    8891   
    89     findInstalledI2PVersion(jarPath: i2pJarPath, javaBin: javaBinPath)
     92    findInstalledI2PVersion()
    9093  }
    9194 
  • launchers/macosx/I2PLauncher/routermgmt/DetectJava.swift

    r01a05f7 r281c5f57  
    99import Foundation
    1010
    11 class DetectJava : NSObject {
     11@objc class DetectJava : NSObject {
    1212 
    1313  var hasJRE : Bool = false
     
    1515  var userAcceptOracleEULA : Bool = false
    1616 
     17 
     18  override init() {
     19    super.init()
     20  }
     21 
    1722  // Java checks
    18   var javaHome: String = ""{
     23  @objc var javaHome: String = ""{
    1924   
    2025    //Called before the change
     
    2631    didSet{
    2732      hasJRE = true
    28       print("MDetectJava.javaHome did change from "+oldValue+" to "+self.javaHome)
     33      print("DetectJava.javaHome did change from "+oldValue+" to "+self.javaHome)
    2934    }
    3035  };
     
    3338  private var testedDfl : Bool = false
    3439 
    35   func isJavaFound() -> Bool {
     40  @objc func isJavaFound() -> Bool {
    3641    if !(self.javaHome.isEmpty) {
    3742      return true
     
    4045  }
    4146 
    42   func findIt() {
     47  /**
     48   *
     49   * The order of the code blocks will decide the order, which will define the preffered.
     50   *
     51   **/
     52  @objc func findIt() {
    4353    print("Start with checking environment variable")
    4454    self.checkJavaEnvironmentVariable()
     55    if !(self.javaHome.isEmpty) {
     56      RouterProcessStatus.knownJavaBinPath = Optional.some(self.javaHome)
     57      hasJRE = true
     58      return
     59    }
     60    print("Checking with the java_home util")
     61    self.runJavaHomeCmd()
    4562    if !(self.javaHome.isEmpty) {
    4663      RouterProcessStatus.knownJavaBinPath = Optional.some(self.javaHome)
     
    5572      return
    5673    }
    57     print("Checking with the java_home util")
    58     self.runJavaHomeCmd()
    59     if !(self.javaHome.isEmpty) {
    60       RouterProcessStatus.knownJavaBinPath = Optional.some(self.javaHome)
    61       hasJRE = true
    62       return
    63     }
    6474  }
    6575 
    66   func runJavaHomeCmd() {
     76  @objc func runJavaHomeCmd() {
    6777    let task = Process()
    6878    task.launchPath = "/usr/libexec/java_home"
     
    8292                                                        let stringVal = str! as String
    8393                                                        print("got output: "+stringVal)
    84                                                         self.javaHome = stringVal
     94                                                        // Adding java binary here to be alike the rest
     95                                                        self.javaHome = stringVal + "/jre/bin/java"
    8596                                                      }
    8697                                                      // TODO: Found something, check it out
     
    105116  }
    106117 
    107   func checkDefaultJREPath() {
     118  @objc func checkDefaultJREPath() {
    108119    let defaultJREPath = "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java"
    109120    if FileManager.default.fileExists(atPath: defaultJREPath) {
     
    115126  }
    116127 
    117   func getEnvironmentVar(_ name: String) -> String? {
     128  @objc func getEnvironmentVar(_ name: String) -> String? {
    118129    guard let rawValue = getenv(name) else { return nil }
    119130    return String(utf8String: rawValue)
    120131  }
    121132 
    122   func checkJavaEnvironmentVariable() {
     133  @objc func checkJavaEnvironmentVariable() {
    123134    let dic = ProcessInfo.processInfo.environment
    124135    //ProcessInfo.processInfo.environment["JAVA_HOME"]
  • launchers/macosx/I2PLauncher/routermgmt/RouterProcessStatus.swift

    r01a05f7 r281c5f57  
    1010import AppKit
    1111
    12 class RouterProcessStatus : NSObject {
     12@objc class RouterProcessStatus : NSObject {
    1313 
    1414  /**
     
    1818   **/
    1919 
    20   func setRouterStatus(_ isRunning: Bool = false) {
     20  @objc func setRouterStatus(_ isRunning: Bool = false) {
    2121    RouterProcessStatus.isRouterRunning = isRunning
    2222  }
    2323 
    24   func setRouterRanByUs(_ ranByUs: Bool = false) {
     24  @objc func setRouterRanByUs(_ ranByUs: Bool = false) {
    2525    RouterProcessStatus.isRouterChildProcess = ranByUs
    2626  }
    2727 
    28   func getRouterIsRunning() -> Bool? {
    29     return RouterProcessStatus.isRouterRunning
     28  @objc func getRouterIsRunning() -> Bool {
     29    if (RouterProcessStatus.isRouterRunning == Optional.none) {
     30      return false;
     31    } else {
     32      let running: Bool = RouterProcessStatus.isRouterRunning
     33      return running
     34    }
     35  }
     36 
     37  @objc func getJavaHome() -> String {
     38    return RouterProcessStatus.knownJavaBinPath!
     39  }
     40 
     41  @objc func setJavaHome(_ home: String) {
     42    NSLog("Setting known java to %s", home)
     43    RouterProcessStatus.knownJavaBinPath = home
    3044  }
    3145}
     
    8498  }
    8599  static func descriptionOfLastError() -> String {
    86     return String(cString: UnsafePointer(strerror(errno))) ?? "Error: \(errno)"
     100    return String(cString: UnsafePointer(strerror(errno)))
    87101  }
    88102}
  • launchers/macosx/I2PLauncher/routermgmt/RouterRunner.swift

    r01a05f7 r281c5f57  
    3939      self.arguments = Optional.some(defaultStartupFlags.joined(separator: " "))
    4040    };
    41     var newArgs:[String] = ["-c ",
     41    let newArgs:[String] = ["-c ",
    4242                            self.subprocessPath!,
    4343      " ",
  • launchers/macosx/I2PLauncher/userinterface/PopoverViewController.swift

    r01a05f7 r281c5f57  
    7979    quickControlView?.needsDisplay = true
    8080   
    81     if (RouterProcessStatus.routerVersion?.isEmpty)! {
     81    if (RouterProcessStatus.routerVersion == Optional.none) {
    8282      routerVersionLabel?.cell?.stringValue = "Router version: Still unknown"
     83      // trigger a read to ensure values
     84      let tmp = SwiftMainDelegate()
     85      tmp.findInstalledI2PVersion()
    8386    } else {
    8487      routerVersionLabel?.cell?.stringValue = "Router version: " + RouterProcessStatus.routerVersion!
     
    107110    let storyboard = NSStoryboard(name: "Storyboard", bundle: Bundle.main)
    108111    //2.
    109     let identifier = NSStoryboard.SceneIdentifier(string: "PopoverView")
     112    let identifier = NSStoryboard.SceneIdentifier(stringLiteral: "PopoverView")
    110113    //3.
    111114    guard let viewcontroller = storyboard.instantiateController(withIdentifier: identifier as String) as? PopoverViewController else {
  • launchers/macosx/I2PLauncher/userinterface/StatusBarController.swift

    r01a05f7 r281c5f57  
    2323  @objc func constructMenu() -> NSMenu {
    2424    let menu = NSMenu()
    25     let sb = SwiftMainDelegate.objCBridge
     25    //let sb = SwiftMainDelegate.objCBridge
    2626   
    2727    menu.addItem(NSMenuItem(title: "Open I2P Console", action: #selector(self.handleOpenConsole(_:)), keyEquivalent: "O"))
  • launchers/macosx/JavaHelper.h

    r01a05f7 r281c5f57  
    11#pragma once
     2
     3#ifdef __cplusplus
    24
    35#include <memory.h>
     
    1719
    1820#define DEF_MIN_JVM_VER "1.7+"
    19 
    20 #ifdef __cplusplus
    2121
    2222#include "include/strutil.hpp"
     
    155155  CFDataRef javaHomes = CFDataCreate(NULL, (const UInt8 *)javaHomeRes.buf.data(), strlen(javaHomeRes.buf.data()));
    156156
    157   CFErrorRef err;
    158157  CFPropertyListRef propertyList = CFPropertyListCreateWithData(kCFAllocatorDefault, javaHomes, kCFPropertyListImmutable, NULL, NULL);
    159   if (err)
    160   {
    161     NSError *error = (__bridge NSError *)err;
    162     NSLog(@"Failed to read property list: %@", error);
    163     [NSApp presentError: error];
    164     return;
    165   }
    166158
    167159
    168   //auto typeId = CFCopyTypeIDDescription(CFGetTypeID(propertyList));
    169   //auto test = CFCopyDescription(propertyList);
    170   //std::cout << "test: " << [test UTF8String] << " Type: " << [typeId UTF8String] << " num: " << jCount << std::endl;
    171 
    172   // Count number of entries in the property array list.
    173   // This is used to set max CRange for CFArrayApplyFunction.
    174160
    175161  auto jCount = CFArrayGetCount((CFArrayRef)propertyList);
  • launchers/macosx/include/fn.h

    r01a05f7 r281c5f57  
    128128            // The distance between a string and the empty string is the string's length
    129129            if (m == 0) {
    130                 return n;
     130                return (unsigned int)n;
    131131            }
    132132            if (n == 0) {
    133                 return m;
     133                return (unsigned int)m;
    134134            }
    135135            // Size the matrix as necessary
  • launchers/macosx/main.mm

    r01a05f7 r281c5f57  
    1111
    1212#import <Foundation/Foundation.h>
     13#import <Foundation/NSFileManager.h>
    1314
    1415
     
    8485@end
    8586
     87#ifdef __cplusplus
     88
     89bool replace(std::string& str, const std::string& from, const std::string& to) {
     90  size_t start_pos = str.find(from);
     91  if(start_pos == std::string::npos)
     92    return false;
     93  str.replace(start_pos, from.length(), to);
     94  return true;
     95}
     96
     97#endif
     98
    8699@implementation AppDelegate
    87100
     
    91104#ifdef __cplusplus
    92105
     106#include <unistd.h>
     107#include <sys/types.h>
     108#include <pwd.h>
     109#include <assert.h>
     110
     111#include "include/subprocess.hpp"
     112
     113using namespace subprocess;
     114
     115const char* RealHomeDirectory() {
     116  struct passwd *pw = getpwuid(getuid());
     117  assert(pw);
     118  return pw->pw_dir;
     119}
     120
    93121- (void)extractI2PBaseDir:(void(^)(BOOL success, NSError *error))completion
    94122{
    95   std::string basePath([self.metaInfo.i2pBase UTF8String]);
    96   NSParameterAssert(self.metaInfo.i2pBase);
     123 
     124  NSBundle *launcherBundle = [NSBundle mainBundle];
     125  auto homeDir = RealHomeDirectory();
     126  NSLog(@"Home directory is %s", homeDir);
     127 
     128  std::string basePath(homeDir);
     129  basePath.append("/Library/I2P");
     130  auto jarResPath = [launcherBundle pathForResource:@"launcher" ofType:@"jar"];
     131  NSLog(@"Trying to load launcher.jar from url = %@", jarResPath);
     132  self.metaInfo.jarFile = jarResPath;
     133  self.metaInfo.zipFile = [launcherBundle pathForResource:@"base" ofType:@"zip"];
     134 
     135  NSParameterAssert(basePath.c_str());
    97136  NSError *error = NULL;
    98137  BOOL success = NO;
    99138  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    100139
    101     // Get paths
    102     NSBundle *launcherBundle = [NSBundle mainBundle];
    103 
    104     std::string basearg("-Di2p.dir.base=");
    105     basearg += basePath;
    106 
    107     std::string zippath("-Di2p.base.zip=");
    108     zippath += [self.metaInfo.zipFile UTF8String];
    109 
    110     std::string jarfile("-cp ");
    111     jarfile += [self.metaInfo.jarFile UTF8String];
    112 
    113     // Create directory
    114     mkdir(basePath.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
    115 
    116     auto cli = JavaRunner::defaultFlagsForExtractorJob;
    117     setenv("I2PBASE", basePath.c_str(), true);
    118     setenv("ZIPPATH", zippath.c_str(), true);
    119     //setenv("DYLD_LIBRARY_PATH",".:/usr/lib:/lib:/usr/local/lib", true);
    120 
    121     cli.push_back(basearg);
    122     cli.push_back(zippath);
    123     cli.push_back(jarfile);
    124     cli.push_back("net.i2p.launchers.BaseExtractor");
    125 
    126     auto charCli = map(cli, [](std::string str){ return str.c_str(); });
    127     std::string execStr = [self.metaInfo.javaBinary UTF8String];
    128     for_each(cli, [&execStr](std::string str){ execStr += std::string(" ") + str; });
    129 
    130     NSLog(@"Trying cmd: %@", [NSString stringWithUTF8String:execStr.c_str()]);
     140
    131141    try {
    132         sendUserNotification(APP_IDSTR, @"Please hold on while we extract I2P. You'll get a new message once done!", self.contentImage);
     142      std::string basearg("-Di2p.dir.base=");
     143      basearg += basePath;
     144
     145      std::string zippath("-Di2p.base.zip=");
     146      zippath += [self.metaInfo.zipFile UTF8String];
     147
     148      std::string jarfile("-cp ");
     149      jarfile += [self.metaInfo.jarFile UTF8String];
     150
     151      // Create directory
     152      mkdir(basePath.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
     153
     154      auto cli = JavaRunner::defaultFlagsForExtractorJob;
     155      setenv("I2PBASE", basePath.c_str(), true);
     156      setenv("ZIPPATH", zippath.c_str(), true);
     157      //setenv("DYLD_LIBRARY_PATH",".:/usr/lib:/lib:/usr/local/lib", true);
     158
     159      cli.push_back(basearg);
     160      cli.push_back(zippath);
     161      cli.push_back(jarfile);
     162      cli.push_back("net.i2p.launchers.BaseExtractor");
     163      auto rs = [[RouterProcessStatus alloc] init];
     164      NSString* jh = [rs getJavaHome];
     165      if (jh != nil) {
     166        NSLog(@"jh er %@", jh);
     167      }
     168     
     169      NSString* newString = [NSString stringWithFormat:@"file://%@", rs.getJavaHome];
     170      NSURL *baseURL = [NSURL fileURLWithPath:newString];
     171     
     172      NSLog(@"MEEH URL PATH: %s", [baseURL fileSystemRepresentation]);
     173
     174      auto charCli = map(cli, [](std::string str){ return str.c_str(); });
     175      std::string execStr = std::string([rs.getJavaHome UTF8String]);
     176      // TODO: Cheap hack, make it better.
     177      replace(execStr, "Internet Plug-Ins", "Internet\\ Plug-Ins");
     178      replace(execStr, "\n", "");
     179      NSLog(@"Java path1 = %s", execStr.c_str());
     180      [rs setJavaHome: [NSString stringWithFormat:@"%s", execStr.c_str()]];
     181      for_each(cli, [&execStr](std::string str){ execStr += std::string(" ") + str; });
     182     
     183      //execStr = replace(execStr, "\\\\ ", "\\ ");
     184      //NSLog(@"Java path2 = %s", execStr.c_str());
     185
     186      NSLog(@"Trying cmd: %@", [NSString stringWithUTF8String:execStr.c_str()]);
     187      try {
     188        sendUserNotification(APP_IDSTR, @"Please hold on while we extract I2P. You'll get a new message once done!");
    133189        int extractStatus = Popen(execStr.c_str(), environment{{
    134             {"ZIPPATH", zippath.c_str()},
    135             {"I2PBASE", basePath.c_str()}
     190          {"ZIPPATH", zippath.c_str()},
     191          {"I2PBASE", basePath.c_str()}
    136192        }}).wait();
    137193        NSLog(@"Extraction exit code %@",[NSString stringWithUTF8String:(std::to_string(extractStatus)).c_str()]);
    138194        if (extractStatus == 0)
    139195        {
    140             //success = YES;
     196          //success = YES;
     197          NSLog(@"Time to detect I2P version in install directory");
     198          [self.swiftRuntime findInstalledI2PVersion];
    141199        }
    142     } catch (subprocess::OSError &err) {
    143         auto errMsg = [NSString stringWithUTF8String:err.what()];
    144         //success = NO;
    145         NSLog(@"Exception: %@", errMsg);
    146         sendUserNotification(APP_IDSTR, [NSString stringWithFormat:@"Error: %@", errMsg], self.contentImage);
     200     
     201      } catch (subprocess::OSError &err) {
     202          auto errMsg = [NSString stringWithUTF8String:err.what()];
     203          //success = NO;
     204          NSLog(@"Exception: %@", errMsg);
     205          sendUserNotification(APP_IDSTR, [NSString stringWithFormat:@"Error: %@", errMsg]);
     206      }
     207
     208      // All done. Assume success and error are already set.
     209      dispatch_async(dispatch_get_main_queue(), ^{
     210        //sendUserNotification(APP_IDSTR, @"Extraction complete!", self.contentImage);
     211        if (completion) {
     212          completion(success, error);
     213        }
     214      });
     215     
     216     
     217    } catch (OSError &err) {
     218      auto errMsg = [NSString stringWithUTF8String:err.what()];
     219      NSLog(@"Exception: %@", errMsg);
    147220    }
    148 
    149     // All done. Assume success and error are already set.
    150     dispatch_async(dispatch_get_main_queue(), ^{
    151       //sendUserNotification(APP_IDSTR, @"Extraction complete!", self.contentImage);
    152       if (completion) {
    153         completion(success, error);
    154       }
    155     });
    156221  });
     222   
     223 
    157224}
    158225
     
    225292    @"i2pBaseDirectory": (NSString *)CFStringCreateWithCString(NULL, const_cast<const char *>(getDefaultBaseDir().c_str()), kCFStringEncodingUTF8)
    226293  }];*/
    227   if (self.enableVerboseLogging) NSLog(@"Default JVM home preference set to: %@", (NSString *)cfDefaultHome);
     294  if (self.enableVerboseLogging) NSLog(@"Default JVM home preference set to: %@", cfDefaultHome);
    228295
    229296  auto dict = [self.userPreferences dictionaryRepresentation];
     
    232299  CFPreferencesSetMultiple((CFDictionaryRef)dict, NULL, CFAPPDOMAIN, kCFPreferencesCurrentUser, kCFPreferencesCurrentHost);
    233300  CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
    234   //CFPreferencesSetAppValue(@"javaHome", (CFPropertyListRef)cfDefaultHome, kCFPreferencesCurrentUser, kCFPreferencesCurrentHost);
    235301
    236302  if (self.enableVerboseLogging) NSLog(@"Default preferences stored!");
     
    241307  // Init application here
    242308 
    243   SwiftMainDelegate *swiftRuntime = [[SwiftMainDelegate alloc] init];
    244   swiftRuntime.applicationDidFinishLaunching;
     309  self.swiftRuntime = [[SwiftMainDelegate alloc] init];
    245310 
    246311  [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
     
    251316  self.enableVerboseLogging = [self.userPreferences boolForKey:@"enableVerboseLogging"];
    252317
    253 
    254     // Get paths
    255     NSBundle *launcherBundle = [NSBundle mainBundle];
    256     //auto iconImage = [launcherBundle pathForResource:@"ItoopieTransparent" ofType:@"png"];
    257  
    258     // This is the only GUI the user experience on a regular basis.
    259     //self.menuBarCtrl = [[MenuBarCtrl alloc] init];
    260318
    261319#ifdef __cplusplus
     
    306364  auto getJavaBin = [&pref,&self]() -> std::string {
    307365    // Get Java home
    308     NSString* val = @"";
     366    /*NSString* val = @"";
    309367    val = [pref stringForKey:@"javaHome"];
    310368    if (val == NULL) val = @"";
     
    314372    auto javaBin = std::string(javaHome);
    315373    javaBin += "/bin/java"; // Append java binary to path.
    316     return javaBin;
     374    return javaBin;*/
     375    DetectJava *dt = [[DetectJava alloc] init];
     376    [dt findIt];
     377    if ([dt isJavaFound]) {
     378      return [dt.javaHome UTF8String];
     379    } else {
     380      throw new std::runtime_error("Java home fatal error");
     381    }
    317382  };
    318383
    319384
    320   //NSBundle *launcherBundle = [NSBundle mainBundle];
     385  NSBundle *launcherBundle = [NSBundle mainBundle];
     386 
     387  auto jarResPath = [launcherBundle pathForResource:@"launcher" ofType:@"jar"];
     388  NSLog(@"Trying to load launcher.jar from url = %@", jarResPath);
    321389   
    322390  self.metaInfo = [[ExtractMetaInfo alloc] init];
     
    331399  std::string jarfile("-cp ");
    332400  jarfile += [self.metaInfo.zipFile UTF8String];
     401 
    333402
    334403  struct stat sb;
     
    340409    [self extractI2PBaseDir:^(BOOL success, NSError *error) {
    341410      sendUserNotification(@"I2P is done extracting", @"I2P is now installed and ready to run!");
     411      [self.swiftRuntime applicationDidFinishLaunching];
    342412      NSLog(@"Done extracting I2P");
    343413      if (shouldAutoStartRouter) [self startupI2PRouter];
     
    347417    if (self.enableVerboseLogging) NSLog(@"I2P directory found!");
    348418    if (shouldAutoStartRouter) [self startupI2PRouter];
    349   }
     419    [self.swiftRuntime applicationDidFinishLaunching];
     420  }
     421 
    350422#endif
    351423}
     
    377449{
    378450  NSApplication *app = [NSApplication sharedApplication];
    379   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    380 
    381   app.delegate = [[AppDelegate alloc] initWithArgc:argc argv:argv];
     451  //NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
     452
     453  AppDelegate *appDelegate = [[AppDelegate alloc] initWithArgc:argc argv:argv];
     454  app.delegate = appDelegate;
    382455  [NSBundle loadNibNamed:@"I2Launcher" owner:NSApp];
    383456
    384457  [NSApp run];
    385458  // Handle any errors
    386   [pool drain];
     459  //[pool drain];
    387460  return 0;
    388461}
Note: See TracChangeset for help on using the changeset viewer.