elviss 2 năm trước cách đây
mục cha
commit
fd5238ae64
3 tập tin đã thay đổi với 53 bổ sung7 xóa
  1. 12 1
      src/PackageClass.php
  2. 15 5
      src/Utility.php
  3. 26 1
      src/WscriptShell.php

+ 12 - 1
src/PackageClass.php

@@ -191,6 +191,16 @@ class PackageClass
 	//初始化
 	private static function initialize($vendorDir)
 	{
+		//创建下载包缓存目录
+		$cacheDir = getCacheDir();
+		if( !file_exists($cacheDir) ){
+			createDirectory($cacheDir);
+		}
+		setHiddenAttrib($cacheDir);
+		if(! defined('CACHE_DIR')){
+			define('CACHE_DIR',$cacheDir);
+		}
+		
 		//创建.distribute目录
 		$distributeDir = pathJoin(dirname($vendorDir),'.distribute');
 		if( !file_exists($distributeDir) ){
@@ -244,6 +254,7 @@ class PackageClass
 			}
 			logInfo("succeeded to decode config file -- .distribute/config.json");
 		}
+
 		return true;
 	}
 	
@@ -293,7 +304,7 @@ class PackageClass
 		
 		
 		//获取缓存目录
-		$cacheDir = pathJoin($config['cache-dir'],str_replace('/','-',$pkg->getName()));
+		$cacheDir = pathJoin(CACHE_DIR,str_replace('/','-',$pkg->getName()));
 		
 		//返回包的相关信息
 		return array(

+ 15 - 5
src/Utility.php

@@ -3,7 +3,6 @@
 function defaultConfig(){
 	return array(
 		'distribute-mode' => 'install',
-		'cache-dir' => 'd:/dist-cache/',
 		'tool-dir' => '',
 		//'oss-host' => 'http://sis31-disthelp.oss-cn-hangzhou.aliyuncs.com',
 		'oss-host' => 'http://192.168.3.10:8996',
@@ -43,6 +42,20 @@ function getOsName(){
 		return "linux";
 }
 
+
+//获取当前缓存目录
+function getCacheDir(){
+	$os = getOsName();
+	if( $os == 'win'){
+		$path = __FILE__;
+		$disk = substr($path,0,2);
+		return $disk . '/$DIST.CACHE';
+	}
+	else{
+		return '/tmp/distcache';
+	}
+}
+
 //判断是否键值对类型的数组
 function isAssocArray($array){
 	if(! is_array($array) )
@@ -232,13 +245,10 @@ function loadConfig($cfgPath){
 		logError("distribute-mode node not exists");
 		return false;
 	}
-	if(! $config['cache-dir'] ){
-		logError("cache-dir node not exists");
-		return false;
-	}
 	return $config;
 }
 
+
 //多线程下载文件
 function downloadToDir($toolDir,$ossHost,$repoName,$fileName,$targetDir){
 	if (!file_exists($targetDir)){

+ 26 - 1
src/WscriptShell.php

@@ -320,4 +320,29 @@ class WinDesktopShortcut extends WscriptShell
 		$shortcutPath = pathJoin($desktopFolder,$shortcutName);
 		return self::createShortcut($shortcutPath,$targetPath,$description);
 	}
-};
+};
+
+//windows文件操作
+class WinFile extends WscriptShell
+{
+	public function __construct()
+	{
+		WscriptShell::__construct();
+	}
+	public static function setHidden($path)
+	{
+		$cmd = "cmd.exe /C attrib \"{$path}\" +s +h";
+		return self::Run($cmd,0,1);
+	}	
+};
+
+function setHiddenAttrib($path){
+	$os = getOsName();
+	if( $os == 'win'){
+		$wf = WinFile();
+		return $wf->setHidden($path);
+	}
+	else{
+		return true;
+	}
+}