shenshihai 2 years ago
parent
commit
1237c1f2bd
2 changed files with 25 additions and 12 deletions
  1. 16 5
      src/PackageClass.php
  2. 9 7
      src/WscriptShell.php

+ 16 - 5
src/PackageClass.php

@@ -438,10 +438,10 @@ class PackageClass
 		$removePath = $app["distribute-root"]["remove-path"] ? : array();
 		$removePath = $app["distribute-root"]["remove-path"] ? : array();
 		$registerPath = $app["distribute-root"]["register-path"] ? : array();
 		$registerPath = $app["distribute-root"]["register-path"] ? : array();
 		
 		
-		$arrRemovePath = array();
+		$arrRemovePattern = array();
 		foreach($removePath as $item){
 		foreach($removePath as $item){
-			$path = pathJoin($rootDir,$item['path']);
-			array_push($arrRemovePath,$path);
+			$pattern = pathJoin($rootDir,$item['pattern']);
+			array_push($arrRemovePattern,$pattern);
 		}
 		}
 		$arrAddPath = array();
 		$arrAddPath = array();
 		foreach($registerPath as $item){
 		foreach($registerPath as $item){
@@ -449,11 +449,18 @@ class PackageClass
 			array_push($arrAddPath,$path);
 			array_push($arrAddPath,$path);
 		}
 		}
 		
 		
+		$removePathes = array();
 		$env = new WinEnvPath();
 		$env = new WinEnvPath();
-		if(! $env->updatePath($arrRemovePath,$arrAddPath) ){
-			logError('failed to registerPath');
+		if(! $env->updatePath($arrRemovePattern,$arrAddPath,$removePathes) ){
+			logError('failed to register path');
 			return false;
 			return false;
 		}
 		}
+		foreach($removePathes as $path){
+			logInfo('succeeded to remove path',$path);
+		}
+		foreach($arrAddPath as $path){
+			logInfo('succeeded to add path',$path);
+		}
 		return true;
 		return true;
 	}
 	}
 	
 	
@@ -471,6 +478,7 @@ class PackageClass
 				logError('failed to remove autorun',$item['name']);
 				logError('failed to remove autorun',$item['name']);
 				return false;
 				return false;
 			}
 			}
+			logInfo('succeeded to remove autorun',$item['name']);
 		}
 		}
 		foreach($regAutorun as $item){
 		foreach($regAutorun as $item){
 			$cmd = pathJoin($rootDir,$item['path']);
 			$cmd = pathJoin($rootDir,$item['path']);
@@ -478,6 +486,7 @@ class PackageClass
 				logError('failed to register autorun',$item['name']);
 				logError('failed to register autorun',$item['name']);
 				return false;
 				return false;
 			}
 			}
+			logInfo('succeeded to register autorun',$item['name']);
 		}
 		}
 		return true;
 		return true;
 	}
 	}
@@ -496,6 +505,7 @@ class PackageClass
 				logError('failed to remove shortcut',$item['name']);
 				logError('failed to remove shortcut',$item['name']);
 				return false;
 				return false;
 			}
 			}
+			logInfo('succeeded to remove shortcut',$item['name']);
 		}
 		}
 		foreach($regShortcut as $item){
 		foreach($regShortcut as $item){
 			$path = pathJoin($rootDir,$item['path']);
 			$path = pathJoin($rootDir,$item['path']);
@@ -503,6 +513,7 @@ class PackageClass
 				logError('failed to register shortcut',$item['name']);
 				logError('failed to register shortcut',$item['name']);
 				return false;
 				return false;
 			}
 			}
+			logInfo('succeeded to register shortcut',$item['name']);
 		}
 		}
 		return true;
 		return true;
 	}
 	}

+ 9 - 7
src/WscriptShell.php

@@ -1,7 +1,6 @@
 <?php
 <?php
 namespace DistributeHelper;
 namespace DistributeHelper;
 error_reporting(E_ALL & ~E_NOTICE);
 error_reporting(E_ALL & ~E_NOTICE);
-//include "Utility.php";
 
 
 class WscriptShell
 class WscriptShell
 {
 {
@@ -10,7 +9,7 @@ class WscriptShell
 	{
 	{
 		try{
 		try{
 			if(self::$shell == null)
 			if(self::$shell == null)
-				self::$shell = new com("WScript.Shell");
+				self::$shell = new \com("WScript.Shell");
 		}catch (Exception $e) {
 		}catch (Exception $e) {
 			 logError('failed to creeate WScript.Shell',$e->getCode(),$e->getMessage());
 			 logError('failed to creeate WScript.Shell',$e->getCode(),$e->getMessage());
 		}
 		}
@@ -106,15 +105,15 @@ class WinEnvPath extends WscriptShell
 	{
 	{
 		return self::RegRead(self::$KEY_PATH);
 		return self::RegRead(self::$KEY_PATH);
 	}
 	}
-	public static function updatePath(array $removePatterns ,array $addPathes)
+	public static function updatePath(array $removePatterns ,array $addPathes,array &$removePathes)
 	{
 	{
 		$envPath = self::RegRead(self::$KEY_PATH);
 		$envPath = self::RegRead(self::$KEY_PATH);
 		if($envPath === false){
 		if($envPath === false){
 			return false;
 			return false;
 		}
 		}
-		$newPath = self::removePath($envPath,$removePatterns);
+		$newPath = self::removePath($envPath,$removePatterns,$removePathes);
 		$newPath = self::addPath($newPath,$addPathes);
 		$newPath = self::addPath($newPath,$addPathes);
-		return $shell->RegWrite(self::$KEY_PATH,$newPath,'REG_EXPAND_SZ');
+		return self::RegWrite(self::$KEY_PATH,$newPath,'REG_EXPAND_SZ');
 	}
 	}
 	private static function isPattern(string $path,array $patterns)
 	private static function isPattern(string $path,array $patterns)
 	{
 	{
@@ -125,12 +124,15 @@ class WinEnvPath extends WscriptShell
 		}
 		}
 		return false;
 		return false;
 	}
 	}
-	private static function removePath(string $envPath,array $patterns)
+	private static function removePath(string $envPath,array $patterns,array &$removePathes)
 	{
 	{
 		$array = explode(';',$envPath);
 		$array = explode(';',$envPath);
 		$result = array();
 		$result = array();
 		foreach($array as $path){
 		foreach($array as $path){
-			if(! self::isPattern($path,$patterns)){
+			if( self::isPattern($path,$patterns)){
+				array_push($removePathes,$path);
+			}
+			else{
 				array_push($result,$path);
 				array_push($result,$path);
 			}
 			}
 		}
 		}