Browse Source

osx authorize

Nicolas Cannasse 18 years ago
parent
commit
a15e6aa742
1 changed files with 34 additions and 14 deletions
  1. 34 14
      doc/Installer.hx

+ 34 - 14
doc/Installer.hx

@@ -40,7 +40,7 @@ class Installer {
 
 
 	function display( txt ) {
 	function display( txt ) {
 		wnd.log(txt);
 		wnd.log(txt);
-		neko.Sys.sleep(0.1);
+		neko.Sys.sleep(0.03);
 	}
 	}
 
 
 	function version(v : { major : Int, minor : Int, build : Int } ) {
 	function version(v : { major : Int, minor : Int, build : Int } ) {
@@ -56,6 +56,7 @@ class Installer {
 	function run() {
 	function run() {
 		try {
 		try {
 			install();
 			install();
+			display("Installation Completed");
 			xcross.Api.message("Done","Installation Completed");
 			xcross.Api.message("Done","Installation Completed");
 		} catch( e : Dynamic ) {
 		} catch( e : Dynamic ) {
 			display("");
 			display("");
@@ -67,6 +68,21 @@ class Installer {
 		wnd.enabled = true;
 		wnd.enabled = true;
 	}
 	}
 
 
+	function checkRights() {
+		try {
+			var tmp = baseDir + "/.tmp.haxe.inst";
+			var f = neko.io.File.write(tmp,true);
+			f.close();
+			neko.FileSystem.deleteFile(tmp);
+			return true;
+		} catch( e : Dynamic ) {
+			if( xcross.Api.authorize() )
+				return false;
+			error("You don't have the rights to write in "+baseDir+", please run the installer using 'sudo'");
+			return false;
+		}
+	}
+
 	function install() {
 	function install() {
 		// CLEANUP
 		// CLEANUP
 		var dirs = [
 		var dirs = [
@@ -81,16 +97,6 @@ class Installer {
 		if( debug )
 		if( debug )
 			display("DEBUG MODE ON");
 			display("DEBUG MODE ON");
 
 
-		// SUDO
-		try {
-			var tmp = baseDir + "/.tmp.haxe.inst";
-			var f = neko.io.File.write(tmp,true);
-			f.close();
-			neko.FileSystem.deleteFile(tmp);
-		} catch( e : Dynamic ) {
-			error("You don't have the rights to write in "+baseDir+", please run the installer using 'sudo'");
-		}
-
 		// PROXY
 		// PROXY
 		var p = neko.net.ProxyDetect.detect();
 		var p = neko.net.ProxyDetect.detect();
 		if( p == null )
 		if( p == null )
@@ -279,9 +285,14 @@ class Installer {
 					neko.FileSystem.createDirectory(ddir);
 					neko.FileSystem.createDirectory(ddir);
 				continue;
 				continue;
 			}
 			}
-			var ch = neko.io.File.write(dir+"/"+path.join("/"),true);
+			var filename = dir + "/" + path.join("/");
+			var ch = neko.io.File.write(filename,true);
 			ch.write(neko.zip.File.unzip(f));
 			ch.write(neko.zip.File.unzip(f));
 			ch.close();
 			ch.close();
+			if( SYS != "Windows" ) {
+				var exe = neko.io.Path.extension(filename) == "";
+				neko.Sys.command("chmod "+(if( exe ) 755 else 644)+" "+filename);
+			}
 		}
 		}
 	}
 	}
 
 
@@ -308,6 +319,12 @@ class Installer {
 		link("haxe","haxe",binDir);
 		link("haxe","haxe",binDir);
 		link("haxe","haxelib",binDir);
 		link("haxe","haxelib",binDir);
 		link("haxe","haxedoc",binDir);
 		link("haxe","haxedoc",binDir);
+		// HAXELIB setup
+		var haxelib = baseDir + "/haxe/lib";
+		if( !neko.FileSystem.exists(haxelib) ) {
+			neko.FileSystem.createDirectory(haxelib);
+			neko.Sys.command("chmod 666 "+haxelib);
+		}
 	}
 	}
 
 
 	function removeRec( file ) {
 	function removeRec( file ) {
@@ -321,14 +338,17 @@ class Installer {
 	}
 	}
 
 
 	static function main() {
 	static function main() {
+		var debug = neko.Sys.getEnv("INST_DEBUG") != null;
+		var i = new Installer(debug);
+		if( !i.checkRights() )
+			return;
 		wnd = new xcross.Winlog("haXe Installer");
 		wnd = new xcross.Winlog("haXe Installer");
 		wnd.button = "Exit";
 		wnd.button = "Exit";
 		wnd.enabled = false;
 		wnd.enabled = false;
 		wnd.onClick = function() {
 		wnd.onClick = function() {
 			xcross.Api.stop();
 			xcross.Api.stop();
 		};
 		};
-		var debug = neko.Sys.getEnv("INST_DEBUG") != null;
-		neko.vm.Thread.create(new Installer(debug).run);
+		neko.vm.Thread.create(i.run);
 		xcross.Api.loop();
 		xcross.Api.loop();
 	}
 	}