forked from I2P_Developers/i2p.i2p
Bugfixes, improvements, more error handling and stability to the osx launcher.
This commit is contained in:
@@ -39,7 +39,7 @@
|
||||
#include "JavaHelper.h"
|
||||
|
||||
inline void sendUserNotification(NSString* title, NSString* informativeText, NSImage* contentImage = NULL, bool makeSound = false) {
|
||||
NSUserNotification *userNotification = [[[NSUserNotification alloc] init] autorelease];
|
||||
NSUserNotification *userNotification = [[NSUserNotification alloc] init];
|
||||
|
||||
userNotification.title = title;
|
||||
userNotification.informativeText = informativeText;
|
||||
@@ -83,19 +83,20 @@ void setGlobalRouterIsRunning(bool running);
|
||||
}
|
||||
@property BOOL enableLogging;
|
||||
@property BOOL enableVerboseLogging;
|
||||
@property (assign) SwiftMainDelegate *swiftRuntime;
|
||||
@property (assign) NSUserDefaults *userPreferences;
|
||||
@property (assign) ExtractMetaInfo *metaInfo;
|
||||
@property (copy) NSImage *contentImage NS_AVAILABLE(10_9, NA);
|
||||
|
||||
- (void) extractI2PBaseDir:(void(^)(BOOL success, NSError *error))completion;
|
||||
- (void) awakeFromNib;
|
||||
- (void) startupI2PRouter;
|
||||
- (void) applicationDidFinishLaunching:(NSNotification *)aNotification;
|
||||
- (void) applicationWillTerminate:(NSNotification *)aNotification;
|
||||
- (void) setApplicationDefaultPreferences;
|
||||
- (void) userChooseJavaHome;
|
||||
- (AppDelegate *) initWithArgc:(int)argc argv:(const char **)argv;
|
||||
#ifdef __cplusplus
|
||||
- (void) startupI2PRouter;
|
||||
- (NSString *) userSelectJavaHome:(JvmListPtr)rawJvmList;
|
||||
#endif
|
||||
- (BOOL) userNotificationCenter:(NSUserNotificationCenter *)center
|
||||
|
||||
@@ -3,3 +3,6 @@
|
||||
//
|
||||
#import "SBridge.h"
|
||||
#import "AppleStuffExceptionHandler.h"
|
||||
#import "AppDelegate.h"
|
||||
#import "RouterTask.h"
|
||||
|
||||
|
||||
@@ -34,7 +34,9 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1</string>
|
||||
<string>3</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.utilities</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
||||
<key>LSUIElement</key>
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14113"/>
|
||||
<capability name="box content view" minToolsVersion="7.0"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.18"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
@@ -120,20 +119,20 @@
|
||||
<scrollView identifier="LoggerTextScrollView" fixedFrame="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="jca-Kn-cO2" userLabel="LoggerTextScrollView">
|
||||
<rect key="frame" x="11" y="17" width="409" height="228"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<clipView key="contentView" ambiguous="YES" id="E5l-WA-qOn">
|
||||
<clipView key="contentView" ambiguous="YES" drawsBackground="NO" id="E5l-WA-qOn">
|
||||
<rect key="frame" x="1" y="1" width="407" height="226"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<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">
|
||||
<rect key="frame" x="0.0" y="0.0" width="407" height="226"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
<size key="minSize" width="407" height="226"/>
|
||||
<size key="maxSize" width="463" height="10000000"/>
|
||||
<color key="insertionPointColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<color key="insertionPointColor" name="textColor" catalog="System" colorSpace="catalog"/>
|
||||
</textView>
|
||||
</subviews>
|
||||
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
|
||||
</clipView>
|
||||
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="YES" id="MRF-Wt-zdZ">
|
||||
<rect key="frame" x="-100" y="-100" width="87" height="18"/>
|
||||
|
||||
@@ -25,9 +25,10 @@ import Cocoa
|
||||
terminate("No java..")
|
||||
}
|
||||
let javaBinPath = self.javaDetector.javaHome
|
||||
RouterProcessStatus.knownJavaBinPath = javaBinPath
|
||||
print("Found java home = ", javaBinPath)
|
||||
|
||||
let (portIsNotTaken, descPort) = RouterProcessStatus.checkTcpPortForListen(port: 7657)
|
||||
let (portIsNotTaken, _) = RouterProcessStatus.checkTcpPortForListen(port: 7657)
|
||||
if (!portIsNotTaken) {
|
||||
RouterProcessStatus.isRouterRunning = true
|
||||
RouterProcessStatus.isRouterChildProcess = false
|
||||
@@ -39,12 +40,12 @@ import Cocoa
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // End of init()
|
||||
|
||||
func findInstalledI2PVersion(jarPath: String, javaBin: String) {
|
||||
@objc func findInstalledI2PVersion() {
|
||||
var i2pPath = NSHomeDirectory()
|
||||
i2pPath += "/Library/I2P"
|
||||
var jExecPath:String = javaBin
|
||||
var jExecPath:String = RouterProcessStatus.knownJavaBinPath!
|
||||
|
||||
// Sometimes, home will return the binary, sometimes the actual home dir. This fixes the diverge.
|
||||
// If JRE is detected, binary follows - if it's JDK, home follows.
|
||||
@@ -52,16 +53,18 @@ import Cocoa
|
||||
jExecPath += "/jre/bin/java"
|
||||
}
|
||||
|
||||
let jarPath = i2pPath + "/lib/i2p.jar"
|
||||
|
||||
let subCmd = jExecPath + " -cp " + jarPath + " net.i2p.CoreVersion"
|
||||
|
||||
var cmdArgs:[String] = ["-c", subCmd]
|
||||
let cmdArgs:[String] = ["-c", subCmd]
|
||||
print(cmdArgs)
|
||||
let sub:Subprocess = Subprocess.init(executablePath: "/bin/sh", arguments: cmdArgs)
|
||||
let results:ExecutionResult = sub.execute(captureOutput: true)!
|
||||
if (results.didCaptureOutput) {
|
||||
print("captured output")
|
||||
let i2pVersion = results.outputLines.first?.replace(target: "I2P Core version: ", withString: "")
|
||||
print("I2P version detected: ",i2pVersion!)
|
||||
NSLog("I2P version detected: %@",i2pVersion ?? "Unknown")
|
||||
RouterProcessStatus.routerVersion = i2pVersion
|
||||
} else {
|
||||
print("did NOT captured output")
|
||||
@@ -74,7 +77,7 @@ import Cocoa
|
||||
var i2pPath = NSHomeDirectory()
|
||||
i2pPath += "/Library/I2P"
|
||||
|
||||
let javaBinPath = self.javaDetector.javaHome.replace(target: " ", withString: "\\ ")
|
||||
//let javaBinPath = self.javaDetector.javaHome.replace(target: " ", withString: "\\ ")
|
||||
|
||||
let fileManager = FileManager()
|
||||
var ok = ObjCBool(true)
|
||||
@@ -84,9 +87,9 @@ import Cocoa
|
||||
// Deploy
|
||||
}
|
||||
|
||||
let i2pJarPath = i2pPath + "/lib/i2p.jar"
|
||||
//let i2pJarPath = i2pPath + "/lib/i2p.jar"
|
||||
|
||||
findInstalledI2PVersion(jarPath: i2pJarPath, javaBin: javaBinPath)
|
||||
findInstalledI2PVersion()
|
||||
}
|
||||
|
||||
@objc static func openLink(url: String) {
|
||||
|
||||
@@ -8,14 +8,19 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
class DetectJava : NSObject {
|
||||
@objc class DetectJava : NSObject {
|
||||
|
||||
var hasJRE : Bool = false
|
||||
var userWantJRE : Bool = false
|
||||
var userAcceptOracleEULA : Bool = false
|
||||
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
}
|
||||
|
||||
// Java checks
|
||||
var javaHome: String = ""{
|
||||
@objc var javaHome: String = ""{
|
||||
|
||||
//Called before the change
|
||||
willSet(newValue){
|
||||
@@ -25,21 +30,26 @@ class DetectJava : NSObject {
|
||||
//Called after the change
|
||||
didSet{
|
||||
hasJRE = true
|
||||
print("MDetectJava.javaHome did change from "+oldValue+" to "+self.javaHome)
|
||||
print("DetectJava.javaHome did change from "+oldValue+" to "+self.javaHome)
|
||||
}
|
||||
};
|
||||
private var testedEnv : Bool = false
|
||||
private var testedJH : Bool = false
|
||||
private var testedDfl : Bool = false
|
||||
|
||||
func isJavaFound() -> Bool {
|
||||
@objc func isJavaFound() -> Bool {
|
||||
if !(self.javaHome.isEmpty) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func findIt() {
|
||||
/**
|
||||
*
|
||||
* The order of the code blocks will decide the order, which will define the preffered.
|
||||
*
|
||||
**/
|
||||
@objc func findIt() {
|
||||
print("Start with checking environment variable")
|
||||
self.checkJavaEnvironmentVariable()
|
||||
if !(self.javaHome.isEmpty) {
|
||||
@@ -47,13 +57,6 @@ class DetectJava : NSObject {
|
||||
hasJRE = true
|
||||
return
|
||||
}
|
||||
print("Checking default JRE install path")
|
||||
self.checkDefaultJREPath()
|
||||
if !(self.javaHome.isEmpty) {
|
||||
RouterProcessStatus.knownJavaBinPath = Optional.some(self.javaHome)
|
||||
hasJRE = true
|
||||
return
|
||||
}
|
||||
print("Checking with the java_home util")
|
||||
self.runJavaHomeCmd()
|
||||
if !(self.javaHome.isEmpty) {
|
||||
@@ -61,9 +64,16 @@ class DetectJava : NSObject {
|
||||
hasJRE = true
|
||||
return
|
||||
}
|
||||
print("Checking default JRE install path")
|
||||
self.checkDefaultJREPath()
|
||||
if !(self.javaHome.isEmpty) {
|
||||
RouterProcessStatus.knownJavaBinPath = Optional.some(self.javaHome)
|
||||
hasJRE = true
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func runJavaHomeCmd() {
|
||||
@objc func runJavaHomeCmd() {
|
||||
let task = Process()
|
||||
task.launchPath = "/usr/libexec/java_home"
|
||||
task.arguments = []
|
||||
@@ -81,7 +91,8 @@ class DetectJava : NSObject {
|
||||
if (str != nil) {
|
||||
let stringVal = str! as String
|
||||
print("got output: "+stringVal)
|
||||
self.javaHome = stringVal
|
||||
// Adding java binary here to be alike the rest
|
||||
self.javaHome = stringVal + "/jre/bin/java"
|
||||
}
|
||||
// TODO: Found something, check it out
|
||||
outHandle.waitForDataInBackgroundAndNotify()
|
||||
@@ -104,7 +115,7 @@ class DetectJava : NSObject {
|
||||
self.testedJH = true
|
||||
}
|
||||
|
||||
func checkDefaultJREPath() {
|
||||
@objc func checkDefaultJREPath() {
|
||||
let defaultJREPath = "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java"
|
||||
if FileManager.default.fileExists(atPath: defaultJREPath) {
|
||||
// Found it!!
|
||||
@@ -114,12 +125,12 @@ class DetectJava : NSObject {
|
||||
// No JRE here
|
||||
}
|
||||
|
||||
func getEnvironmentVar(_ name: String) -> String? {
|
||||
@objc func getEnvironmentVar(_ name: String) -> String? {
|
||||
guard let rawValue = getenv(name) else { return nil }
|
||||
return String(utf8String: rawValue)
|
||||
}
|
||||
|
||||
func checkJavaEnvironmentVariable() {
|
||||
@objc func checkJavaEnvironmentVariable() {
|
||||
let dic = ProcessInfo.processInfo.environment
|
||||
//ProcessInfo.processInfo.environment["JAVA_HOME"]
|
||||
if let javaHomeEnv = dic["JAVA_HOME"] {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import Foundation
|
||||
import AppKit
|
||||
|
||||
class RouterProcessStatus : NSObject {
|
||||
@objc class RouterProcessStatus : NSObject {
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -17,16 +17,30 @@ class RouterProcessStatus : NSObject {
|
||||
*
|
||||
**/
|
||||
|
||||
func setRouterStatus(_ isRunning: Bool = false) {
|
||||
@objc func setRouterStatus(_ isRunning: Bool = false) {
|
||||
RouterProcessStatus.isRouterRunning = isRunning
|
||||
}
|
||||
|
||||
func setRouterRanByUs(_ ranByUs: Bool = false) {
|
||||
@objc func setRouterRanByUs(_ ranByUs: Bool = false) {
|
||||
RouterProcessStatus.isRouterChildProcess = ranByUs
|
||||
}
|
||||
|
||||
func getRouterIsRunning() -> Bool? {
|
||||
return RouterProcessStatus.isRouterRunning
|
||||
@objc func getRouterIsRunning() -> Bool {
|
||||
if (RouterProcessStatus.isRouterRunning == Optional.none) {
|
||||
return false;
|
||||
} else {
|
||||
let running: Bool = RouterProcessStatus.isRouterRunning
|
||||
return running
|
||||
}
|
||||
}
|
||||
|
||||
@objc func getJavaHome() -> String {
|
||||
return RouterProcessStatus.knownJavaBinPath!
|
||||
}
|
||||
|
||||
@objc func setJavaHome(_ home: String) {
|
||||
NSLog("Setting known java to %s", home)
|
||||
RouterProcessStatus.knownJavaBinPath = home
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +97,7 @@ extension RouterProcessStatus {
|
||||
close(socket)
|
||||
}
|
||||
static func descriptionOfLastError() -> String {
|
||||
return String(cString: UnsafePointer(strerror(errno))) ?? "Error: \(errno)"
|
||||
return String(cString: UnsafePointer(strerror(errno)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class RouterRunner: NSObject, I2PSubprocess {
|
||||
if (self.arguments?.isEmpty)! {
|
||||
self.arguments = Optional.some(defaultStartupFlags.joined(separator: " "))
|
||||
};
|
||||
var newArgs:[String] = ["-c ",
|
||||
let newArgs:[String] = ["-c ",
|
||||
self.subprocessPath!,
|
||||
" ",
|
||||
self.arguments!,
|
||||
|
||||
@@ -78,8 +78,11 @@ class PopoverViewController: NSViewController {
|
||||
routerStartStopButton?.target = self
|
||||
quickControlView?.needsDisplay = true
|
||||
|
||||
if (RouterProcessStatus.routerVersion?.isEmpty)! {
|
||||
if (RouterProcessStatus.routerVersion == Optional.none) {
|
||||
routerVersionLabel?.cell?.stringValue = "Router version: Still unknown"
|
||||
// trigger a read to ensure values
|
||||
let tmp = SwiftMainDelegate()
|
||||
tmp.findInstalledI2PVersion()
|
||||
} else {
|
||||
routerVersionLabel?.cell?.stringValue = "Router version: " + RouterProcessStatus.routerVersion!
|
||||
}
|
||||
@@ -106,7 +109,7 @@ extension PopoverViewController {
|
||||
static func freshController() -> PopoverViewController {
|
||||
let storyboard = NSStoryboard(name: "Storyboard", bundle: Bundle.main)
|
||||
//2.
|
||||
let identifier = NSStoryboard.SceneIdentifier(string: "PopoverView")
|
||||
let identifier = NSStoryboard.SceneIdentifier(stringLiteral: "PopoverView")
|
||||
//3.
|
||||
guard let viewcontroller = storyboard.instantiateController(withIdentifier: identifier as String) as? PopoverViewController else {
|
||||
fatalError("Why cant i find PopoverViewController? - Check PopoverViewController.storyboard")
|
||||
|
||||
@@ -22,7 +22,7 @@ import Cocoa
|
||||
|
||||
@objc func constructMenu() -> NSMenu {
|
||||
let menu = NSMenu()
|
||||
let sb = SwiftMainDelegate.objCBridge
|
||||
//let sb = SwiftMainDelegate.objCBridge
|
||||
|
||||
menu.addItem(NSMenuItem(title: "Open I2P Console", action: #selector(self.handleOpenConsole(_:)), keyEquivalent: "O"))
|
||||
menu.addItem(NSMenuItem.separator())
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@@ -17,8 +19,6 @@
|
||||
|
||||
#define DEF_MIN_JVM_VER "1.7+"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "include/strutil.hpp"
|
||||
|
||||
#include <functional>
|
||||
@@ -154,23 +154,9 @@ static void listAllJavaInstallsAvailable()
|
||||
auto javaHomeRes = check_output({"/usr/libexec/java_home","-v",DEF_MIN_JVM_VER,"-X"});
|
||||
CFDataRef javaHomes = CFDataCreate(NULL, (const UInt8 *)javaHomeRes.buf.data(), strlen(javaHomeRes.buf.data()));
|
||||
|
||||
CFErrorRef err;
|
||||
CFPropertyListRef propertyList = CFPropertyListCreateWithData(kCFAllocatorDefault, javaHomes, kCFPropertyListImmutable, NULL, NULL);
|
||||
if (err)
|
||||
{
|
||||
NSError *error = (__bridge NSError *)err;
|
||||
NSLog(@"Failed to read property list: %@", error);
|
||||
[NSApp presentError: error];
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//auto typeId = CFCopyTypeIDDescription(CFGetTypeID(propertyList));
|
||||
//auto test = CFCopyDescription(propertyList);
|
||||
//std::cout << "test: " << [test UTF8String] << " Type: " << [typeId UTF8String] << " num: " << jCount << std::endl;
|
||||
|
||||
// Count number of entries in the property array list.
|
||||
// This is used to set max CRange for CFArrayApplyFunction.
|
||||
|
||||
auto jCount = CFArrayGetCount((CFArrayRef)propertyList);
|
||||
|
||||
|
||||
@@ -127,10 +127,10 @@ namespace Experimental {
|
||||
const size_t n = t.size();
|
||||
// The distance between a string and the empty string is the string's length
|
||||
if (m == 0) {
|
||||
return n;
|
||||
return (unsigned int)n;
|
||||
}
|
||||
if (n == 0) {
|
||||
return m;
|
||||
return (unsigned int)m;
|
||||
}
|
||||
// Size the matrix as necessary
|
||||
if (matrix_.size() < m + 1) {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <vector>
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Foundation/NSFileManager.h>
|
||||
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
@@ -83,6 +84,18 @@ void setGlobalRouterIsRunning(bool running)
|
||||
@implementation ExtractMetaInfo : NSObject
|
||||
@end
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
bool replace(std::string& str, const std::string& from, const std::string& to) {
|
||||
size_t start_pos = str.find(from);
|
||||
if(start_pos == std::string::npos)
|
||||
return false;
|
||||
str.replace(start_pos, from.length(), to);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@implementation AppDelegate
|
||||
|
||||
- (void) awakeFromNib {
|
||||
@@ -90,70 +103,124 @@ void setGlobalRouterIsRunning(bool running)
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "include/subprocess.hpp"
|
||||
|
||||
using namespace subprocess;
|
||||
|
||||
const char* RealHomeDirectory() {
|
||||
struct passwd *pw = getpwuid(getuid());
|
||||
assert(pw);
|
||||
return pw->pw_dir;
|
||||
}
|
||||
|
||||
- (void)extractI2PBaseDir:(void(^)(BOOL success, NSError *error))completion
|
||||
{
|
||||
std::string basePath([self.metaInfo.i2pBase UTF8String]);
|
||||
NSParameterAssert(self.metaInfo.i2pBase);
|
||||
|
||||
NSBundle *launcherBundle = [NSBundle mainBundle];
|
||||
auto homeDir = RealHomeDirectory();
|
||||
NSLog(@"Home directory is %s", homeDir);
|
||||
|
||||
std::string basePath(homeDir);
|
||||
basePath.append("/Library/I2P");
|
||||
auto jarResPath = [launcherBundle pathForResource:@"launcher" ofType:@"jar"];
|
||||
NSLog(@"Trying to load launcher.jar from url = %@", jarResPath);
|
||||
self.metaInfo.jarFile = jarResPath;
|
||||
self.metaInfo.zipFile = [launcherBundle pathForResource:@"base" ofType:@"zip"];
|
||||
|
||||
NSParameterAssert(basePath.c_str());
|
||||
NSError *error = NULL;
|
||||
BOOL success = NO;
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
|
||||
// Get paths
|
||||
NSBundle *launcherBundle = [NSBundle mainBundle];
|
||||
|
||||
std::string basearg("-Di2p.dir.base=");
|
||||
basearg += basePath;
|
||||
|
||||
std::string zippath("-Di2p.base.zip=");
|
||||
zippath += [self.metaInfo.zipFile UTF8String];
|
||||
|
||||
std::string jarfile("-cp ");
|
||||
jarfile += [self.metaInfo.jarFile UTF8String];
|
||||
|
||||
// Create directory
|
||||
mkdir(basePath.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
|
||||
|
||||
auto cli = JavaRunner::defaultFlagsForExtractorJob;
|
||||
setenv("I2PBASE", basePath.c_str(), true);
|
||||
setenv("ZIPPATH", zippath.c_str(), true);
|
||||
//setenv("DYLD_LIBRARY_PATH",".:/usr/lib:/lib:/usr/local/lib", true);
|
||||
|
||||
cli.push_back(basearg);
|
||||
cli.push_back(zippath);
|
||||
cli.push_back(jarfile);
|
||||
cli.push_back("net.i2p.launchers.BaseExtractor");
|
||||
|
||||
auto charCli = map(cli, [](std::string str){ return str.c_str(); });
|
||||
std::string execStr = [self.metaInfo.javaBinary UTF8String];
|
||||
for_each(cli, [&execStr](std::string str){ execStr += std::string(" ") + str; });
|
||||
|
||||
NSLog(@"Trying cmd: %@", [NSString stringWithUTF8String:execStr.c_str()]);
|
||||
try {
|
||||
sendUserNotification(APP_IDSTR, @"Please hold on while we extract I2P. You'll get a new message once done!", self.contentImage);
|
||||
std::string basearg("-Di2p.dir.base=");
|
||||
basearg += basePath;
|
||||
|
||||
std::string zippath("-Di2p.base.zip=");
|
||||
zippath += [self.metaInfo.zipFile UTF8String];
|
||||
|
||||
std::string jarfile("-cp ");
|
||||
jarfile += [self.metaInfo.jarFile UTF8String];
|
||||
|
||||
// Create directory
|
||||
mkdir(basePath.c_str(), S_IRUSR | S_IWUSR | S_IXUSR);
|
||||
|
||||
auto cli = JavaRunner::defaultFlagsForExtractorJob;
|
||||
setenv("I2PBASE", basePath.c_str(), true);
|
||||
setenv("ZIPPATH", zippath.c_str(), true);
|
||||
//setenv("DYLD_LIBRARY_PATH",".:/usr/lib:/lib:/usr/local/lib", true);
|
||||
|
||||
cli.push_back(basearg);
|
||||
cli.push_back(zippath);
|
||||
cli.push_back(jarfile);
|
||||
cli.push_back("net.i2p.launchers.BaseExtractor");
|
||||
auto rs = [[RouterProcessStatus alloc] init];
|
||||
NSString* jh = [rs getJavaHome];
|
||||
if (jh != nil) {
|
||||
NSLog(@"jh er %@", jh);
|
||||
}
|
||||
|
||||
NSString* newString = [NSString stringWithFormat:@"file://%@", rs.getJavaHome];
|
||||
NSURL *baseURL = [NSURL fileURLWithPath:newString];
|
||||
|
||||
NSLog(@"MEEH URL PATH: %s", [baseURL fileSystemRepresentation]);
|
||||
|
||||
auto charCli = map(cli, [](std::string str){ return str.c_str(); });
|
||||
std::string execStr = std::string([rs.getJavaHome UTF8String]);
|
||||
// TODO: Cheap hack, make it better.
|
||||
replace(execStr, "Internet Plug-Ins", "Internet\\ Plug-Ins");
|
||||
replace(execStr, "\n", "");
|
||||
NSLog(@"Java path1 = %s", execStr.c_str());
|
||||
[rs setJavaHome: [NSString stringWithFormat:@"%s", execStr.c_str()]];
|
||||
for_each(cli, [&execStr](std::string str){ execStr += std::string(" ") + str; });
|
||||
|
||||
//execStr = replace(execStr, "\\\\ ", "\\ ");
|
||||
//NSLog(@"Java path2 = %s", execStr.c_str());
|
||||
|
||||
NSLog(@"Trying cmd: %@", [NSString stringWithUTF8String:execStr.c_str()]);
|
||||
try {
|
||||
sendUserNotification(APP_IDSTR, @"Please hold on while we extract I2P. You'll get a new message once done!");
|
||||
int extractStatus = Popen(execStr.c_str(), environment{{
|
||||
{"ZIPPATH", zippath.c_str()},
|
||||
{"I2PBASE", basePath.c_str()}
|
||||
{"ZIPPATH", zippath.c_str()},
|
||||
{"I2PBASE", basePath.c_str()}
|
||||
}}).wait();
|
||||
NSLog(@"Extraction exit code %@",[NSString stringWithUTF8String:(std::to_string(extractStatus)).c_str()]);
|
||||
if (extractStatus == 0)
|
||||
{
|
||||
//success = YES;
|
||||
//success = YES;
|
||||
NSLog(@"Time to detect I2P version in install directory");
|
||||
[self.swiftRuntime findInstalledI2PVersion];
|
||||
}
|
||||
} catch (subprocess::OSError &err) {
|
||||
auto errMsg = [NSString stringWithUTF8String:err.what()];
|
||||
//success = NO;
|
||||
NSLog(@"Exception: %@", errMsg);
|
||||
sendUserNotification(APP_IDSTR, [NSString stringWithFormat:@"Error: %@", errMsg], self.contentImage);
|
||||
}
|
||||
|
||||
// All done. Assume success and error are already set.
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
//sendUserNotification(APP_IDSTR, @"Extraction complete!", self.contentImage);
|
||||
if (completion) {
|
||||
completion(success, error);
|
||||
|
||||
} catch (subprocess::OSError &err) {
|
||||
auto errMsg = [NSString stringWithUTF8String:err.what()];
|
||||
//success = NO;
|
||||
NSLog(@"Exception: %@", errMsg);
|
||||
sendUserNotification(APP_IDSTR, [NSString stringWithFormat:@"Error: %@", errMsg]);
|
||||
}
|
||||
});
|
||||
|
||||
// All done. Assume success and error are already set.
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
//sendUserNotification(APP_IDSTR, @"Extraction complete!", self.contentImage);
|
||||
if (completion) {
|
||||
completion(success, error);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
} catch (OSError &err) {
|
||||
auto errMsg = [NSString stringWithUTF8String:err.what()];
|
||||
NSLog(@"Exception: %@", errMsg);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -224,14 +291,13 @@ inline std::string getDefaultBaseDir()
|
||||
@"autoStartRouter": @YES,
|
||||
@"i2pBaseDirectory": (NSString *)CFStringCreateWithCString(NULL, const_cast<const char *>(getDefaultBaseDir().c_str()), kCFStringEncodingUTF8)
|
||||
}];*/
|
||||
if (self.enableVerboseLogging) NSLog(@"Default JVM home preference set to: %@", (NSString *)cfDefaultHome);
|
||||
if (self.enableVerboseLogging) NSLog(@"Default JVM home preference set to: %@", cfDefaultHome);
|
||||
|
||||
auto dict = [self.userPreferences dictionaryRepresentation];
|
||||
[self.userPreferences setPersistentDomain:dict forName:NSAPPDOMAIN];
|
||||
|
||||
CFPreferencesSetMultiple((CFDictionaryRef)dict, NULL, CFAPPDOMAIN, kCFPreferencesCurrentUser, kCFPreferencesCurrentHost);
|
||||
CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
|
||||
//CFPreferencesSetAppValue(@"javaHome", (CFPropertyListRef)cfDefaultHome, kCFPreferencesCurrentUser, kCFPreferencesCurrentHost);
|
||||
|
||||
if (self.enableVerboseLogging) NSLog(@"Default preferences stored!");
|
||||
}
|
||||
@@ -240,8 +306,7 @@ inline std::string getDefaultBaseDir()
|
||||
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
|
||||
// Init application here
|
||||
|
||||
SwiftMainDelegate *swiftRuntime = [[SwiftMainDelegate alloc] init];
|
||||
swiftRuntime.applicationDidFinishLaunching;
|
||||
self.swiftRuntime = [[SwiftMainDelegate alloc] init];
|
||||
|
||||
[[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:self];
|
||||
// Start with user preferences
|
||||
@@ -251,13 +316,6 @@ inline std::string getDefaultBaseDir()
|
||||
self.enableVerboseLogging = [self.userPreferences boolForKey:@"enableVerboseLogging"];
|
||||
|
||||
|
||||
// Get paths
|
||||
NSBundle *launcherBundle = [NSBundle mainBundle];
|
||||
//auto iconImage = [launcherBundle pathForResource:@"ItoopieTransparent" ofType:@"png"];
|
||||
|
||||
// This is the only GUI the user experience on a regular basis.
|
||||
//self.menuBarCtrl = [[MenuBarCtrl alloc] init];
|
||||
|
||||
#ifdef __cplusplus
|
||||
gRawJvmList = std::make_shared<std::list<JvmVersionPtr> >(std::list<JvmVersionPtr>());
|
||||
#endif
|
||||
@@ -305,7 +363,7 @@ inline std::string getDefaultBaseDir()
|
||||
|
||||
auto getJavaBin = [&pref,&self]() -> std::string {
|
||||
// Get Java home
|
||||
NSString* val = @"";
|
||||
/*NSString* val = @"";
|
||||
val = [pref stringForKey:@"javaHome"];
|
||||
if (val == NULL) val = @"";
|
||||
if (self.enableVerboseLogging) NSLog(@"Javahome: %@", val);
|
||||
@@ -313,11 +371,21 @@ inline std::string getDefaultBaseDir()
|
||||
//trim(javaHome); // Trim to remove endline
|
||||
auto javaBin = std::string(javaHome);
|
||||
javaBin += "/bin/java"; // Append java binary to path.
|
||||
return javaBin;
|
||||
return javaBin;*/
|
||||
DetectJava *dt = [[DetectJava alloc] init];
|
||||
[dt findIt];
|
||||
if ([dt isJavaFound]) {
|
||||
return [dt.javaHome UTF8String];
|
||||
} else {
|
||||
throw new std::runtime_error("Java home fatal error");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//NSBundle *launcherBundle = [NSBundle mainBundle];
|
||||
NSBundle *launcherBundle = [NSBundle mainBundle];
|
||||
|
||||
auto jarResPath = [launcherBundle pathForResource:@"launcher" ofType:@"jar"];
|
||||
NSLog(@"Trying to load launcher.jar from url = %@", jarResPath);
|
||||
|
||||
self.metaInfo = [[ExtractMetaInfo alloc] init];
|
||||
//self.metaInfo.i2pBase = [NSString stringWithUTF8String:i2pBaseDir.c_str()];
|
||||
@@ -330,6 +398,7 @@ inline std::string getDefaultBaseDir()
|
||||
|
||||
std::string jarfile("-cp ");
|
||||
jarfile += [self.metaInfo.zipFile UTF8String];
|
||||
|
||||
|
||||
struct stat sb;
|
||||
if ( !(stat(i2pBaseDir.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) )
|
||||
@@ -339,6 +408,7 @@ inline std::string getDefaultBaseDir()
|
||||
|
||||
[self extractI2PBaseDir:^(BOOL success, NSError *error) {
|
||||
sendUserNotification(@"I2P is done extracting", @"I2P is now installed and ready to run!");
|
||||
[self.swiftRuntime applicationDidFinishLaunching];
|
||||
NSLog(@"Done extracting I2P");
|
||||
if (shouldAutoStartRouter) [self startupI2PRouter];
|
||||
}];
|
||||
@@ -346,7 +416,9 @@ inline std::string getDefaultBaseDir()
|
||||
} else {
|
||||
if (self.enableVerboseLogging) NSLog(@"I2P directory found!");
|
||||
if (shouldAutoStartRouter) [self startupI2PRouter];
|
||||
[self.swiftRuntime applicationDidFinishLaunching];
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -376,14 +448,15 @@ inline std::string getDefaultBaseDir()
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
NSApplication *app = [NSApplication sharedApplication];
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
//NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
app.delegate = [[AppDelegate alloc] initWithArgc:argc argv:argv];
|
||||
AppDelegate *appDelegate = [[AppDelegate alloc] initWithArgc:argc argv:argv];
|
||||
app.delegate = appDelegate;
|
||||
[NSBundle loadNibNamed:@"I2Launcher" owner:NSApp];
|
||||
|
||||
[NSApp run];
|
||||
// Handle any errors
|
||||
[pool drain];
|
||||
//[pool drain];
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user