123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827 |
- <?php
- namespace DistributeHelper;
- error_reporting(E_ALL & ~E_NOTICE);
- include_once "Utility.php";
- include_once "WscriptShell.php";
- class PackageClass
- {
- private static $config = null; //全局配置信息
- private static $app = null; //当前安装包composer.json
- //当所有包都安装完毕后
- public static function postUpdate($vendorDir,$rootPkg,$vendorPkgs)
- {
- //检查管理员权限
- $priv = new WinAdminPriv();
- if(! $priv->check() ){
- self::setProgressFailed('NO_ADMIN_PRIVILEGE');
- return false;
- }
-
- //初始化
- if(! self::initialize($vendorDir)){
- self::setProgressFailed('INITIALIZE_FAILED');
- return false;
- }
-
- //预先系统准备操作
- if(! self::prepare($vendorDir,$rootPkg) ){
- self::setProgressFailed('PREPARE_FAILED');
- return false;
- }
-
- //分发模式
- $dist_mode = self::$config['distribute-mode'];
- logInfo("distribute mode: ",$dist_mode);
- if( $dist_mode == 'install'){ //在线安装
- return self::install($vendorDir,$rootPkg,$vendorPkgs);
- }
- elseif( $dist_mode == 'upgrade'){ //在线升级
- return self::upgrade($vendorDir,$rootPkg,$vendorPkgs);
- }
- elseif( $dist_mode == 'offpkg'){ //生成离线包
- return self::offpkg($vendorDir,$rootPkg,$vendorPkgs);
- }
- elseif( $dist_mode == 'offinst'){ //离线安装
- return self::offinst($vendorDir,$rootPkg,$vendorPkgs);
- }
- elseif( $dist_mode == 'offupgd'){ //离线升级
- return self::offupgd($vendorDir,$rootPkg,$vendorPkgs);
- }
- else{
- self::setProgressFailed('INVALID_DIST_MODE');
- return false;
- }
- }
-
- private static function prepare($vendorDir,$pkg)
- {
- //获取包信息
- $repoDir = dirname($vendorDir);
- $packageInfo = self::getPackageInfo($vendorDir,$repoDir,$pkg);
-
- //关闭进程
- if(! self::removeProcess($packageInfo) ){
- return false;
- }
-
- return true;
- }
-
- private static function install($vendorDir,$rootPkg,$vendorPkgs){
- //依赖库都已下载,默认先给个进度
- self::setProgressStep1(100);
-
- //逐个依赖仓库操作
- if(! self::postUpdateVendorPkgs($vendorDir,$vendorPkgs) ){
- return false;
- }
-
- //顶层仓库操作
- if(! self::postUpdateRootPkg($vendorDir,$rootPkg) ){
- return false;
- }
-
- //全部操作完毕
- self::setProgressOK(true);
-
- return true;
- }
- private static function upgrade($vendorDir,$rootPkg,$vendorPkgs){
- //依赖库都已下载,默认先给个进度
- self::setProgressStep1(100);
-
- //逐个依赖仓库操作
- if(! self::postUpdateVendorPkgs($vendorDir,$vendorPkgs) ){
- return false;
- }
-
- //顶层仓库操作
- if(! self::postUpdateRootPkg($vendorDir,$rootPkg) ){
- return false;
- }
-
- //全部操作完毕
- self::setProgressOK(true);
-
- return true;
- }
- private static function offpkg($vendorDir,$rootPkg,$vendorPkgs){
- //依赖库都已下载,默认先给个进度
- self::setProgressStep1(100);
-
- //逐个依赖仓库操作
- if(! self::postUpdateVendorPkgs($vendorDir,$vendorPkgs) ){
- return false;
- }
-
- //顶层仓库操作
- if(! self::postUpdateRootPkg($vendorDir,$rootPkg) ){
- return false;
- }
-
- //全部操作完毕
- self::setProgressOK(true);
-
- return true;
- }
-
- private static function offinst($vendorDir,$rootPkg,$vendorPkgs){
- return true;
- }
- private static function offupgd($vendorDir,$rootPkg,$vendorPkgs){
- return true;
- }
- /*
- private static function createModuleIni($vendorDir,$vendorPkgs)
- {
- //[MODULE]节点内容
- $content = '[MODULE]' . PHP_EOL;
- foreach($vendorPkgs as $i=>$pkg){
- if( in_array($pkg->getName(),['a/distribute-helper']) )
- continue;
- $cfgPath = pathJoin($vendorDir,$pkg->getName(),'composer.json');
- $data = json_decode(file_get_contents($cfgPath), true);
- $moduleName = $data["distribute-helper"]["module-name"];
- if(!$moduleName){
- logError('bad format. no module-name node exists.',$cfgPath);
- return false;
- }
- $content .= $moduleName . '=' . $pkg->getName() . ',' . $pkg->getPrettyVersion() . PHP_EOL;
- }
- //[CONFIG]节点内容
- //获取包信息
- $repoDir = dirname($vendorDir);
- $packageInfo = self::getPackageInfo($vendorDir,$repoDir,$pkg);
- $moduleConfig = $packageInfo['helper']['module-config'] ? : array();
- $content = '[CONFIG]' . PHP_EOL;
- foreach($moduleConfig as $i=>$cfg){
- $content .= $cfg['name'] . '=' . $cfg['value'] . PHP_EOL;
- }
- //保存文件
- file_put_contents(MODULEINI_PATH,$content);
- return true;
- }*/
- private static function postUpdateVendorPkgs($vendorDir,$vendorPkgs)
- {
- $count = count($vendorPkgs);
- foreach($vendorPkgs as $i=>$pkg){
- //获取包信息
- $repoDir = pathJoin($vendorDir,$pkg->getName());
- $packageInfo = self::getPackageInfo($vendorDir,$repoDir,$pkg);
-
- //获取当前包的module文件
- if(! self::fetchModuleFiles($packageInfo) ){
- self::setProgressFailed('FETCH_MODULE_FILES_FAILED');
- return false;
- }
- self::setProgressStep2($count,$i,1);
-
- //获取当前包的common文件
- if(! self::fetchCommonFiles($packageInfo) ){
- self::setProgressFailed('FETCH_COMMON_FILES_FAILED');
- return false;
- }
- self::setProgressStep2($count,$i,2);
- //拷贝当前包的vendor文件
- if(! self::fetchVendorFiles($packageInfo) ){
- self::setProgressFailed('FETCH_VENDOR_FILES_FAILED');
- return false;
- }
- self::setProgressStep2($count,$i,3);
- }
- return true;
- }
-
- private static function postUpdateRootPkg($vendorDir,$pkg)
- {
- //获取包信息
- $repoDir = dirname($vendorDir);
- $packageInfo = self::getPackageInfo($vendorDir,$repoDir,$pkg);
-
- //运行script-files文件
- if(! self::scriptFiles($packageInfo) ){
- self::setProgressFailed('RUN_SCRIPT_FILES_FAILED');
- return false;
- }
-
- //拷贝copy-files文件
- if(! self::copyFiles($packageInfo) ){
- self::setProgressFailed('COPY_FILES_FAILED');
- return false;
- }
-
- //替换文件内的宏变量
- if(! self::macoFiles($packageInfo) ){
- self::setProgressFailed('MACRO_FILES_FAILED');
- return false;
- }
-
- //注册全局路径
- if(! self::registerPath($packageInfo) ){
- self::setProgressFailed('REGISTER_PATH_FAILED');
- return false;
- }
-
- //注册自启动程序
- if(! self::registerAutorun($packageInfo) ){
- self::setProgressFailed('REGISTER_AUTORUN_FAILED');
- return false;
- }
- //注册服务程序
- if(! self::registerService($packageInfo) ){
- self::setProgressFailed('REGISTER_SERVICE_FAILED');
- return false;
- }
-
- //注册桌面快捷方式
- if(! self::registerShortcut($packageInfo) ){
- self::setProgressFailed('REGISTER_SHORTCUT_FAILED');
- return false;
- }
- return true;
-
- }
- //初始化
- 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) ){
- createDirectory($distributeDir);
- }
- if(! defined('DIST_DIR')){
- define('DIST_DIR',$distributeDir);
- }
-
- //设置日志文件路径
- if(! defined('LOG_PATH')){
- $logPath = pathJoin($distributeDir,'log.txt');
- define('LOG_PATH',$logPath);
- if(file_exists($logPath))
- unlink($logPath);
- }
-
- //设置进度文件路径
- if(! defined('PROGRESS_PATH')){
- $progressPath = pathJoin($distributeDir,'progress.txt');
- define('PROGRESS_PATH',$progressPath);
- if(file_exists($progressPath))
- unlink($progressPath);
- }
-
- //创建module目录
- $moduleDir = pathJoin(dirname($vendorDir),'module');
- if( !file_exists($moduleDir) ){
- createDirectory($moduleDir);
- }
-
- //解析安装包信息
- $composerJson = pathJoin(dirname($vendorDir),'composer.json');
- self::$app = json_decode(file_get_contents($composerJson), true);
- if(! self::$app ){
- logError("failed to decode " . $composerJson);
- return false;
- }
-
- //获取部署配置信息
- $cfgPath = pathJoin($distributeDir,'config.json');
- if(! file_exists($cfgPath) ){
- logInfo(".distribute/config.json file not exists,use default config. ");
- self::$config = defaultConfig();
- }
- else{
- self::$config = loadConfig($cfgPath);
- if(!self::$config){
- logError("Failed to load distribute config",$cfgPath);
- return false;
- }
- logInfo("succeeded to decode config file -- .distribute/config.json");
- }
-
- //如果检测到在SIS内网,替换成内网IP
- $clientip = getClientIp();
- if($clientip === false){
- return false;
- }
- if( $clientip == '39.171.62.20'){
- logInfo("sis intranet detected. oss host http://192.168.3.10:8996");
- self::$config['oss-host'] = 'http://192.168.3.10:8996';
- }else{
- logInfo("internet detected. oss host http://192.168.3.10:8996");
- self::$config['oss-host'] = 'http://sis31-disthelp.oss-cn-hangzhou.aliyuncs.com';
- }
- //工具换成wget
- self::$config['down-client'] = 'wget';
- return true;
- }
-
- private static function setProgressStep1($percent)
- {
- $progress = 0.1 * $percent;
- file_put_contents(PROGRESS_PATH,strval($progress));
- }
- private static function setProgressStep2($total,$index,$step)
- {
- $index = $index + $step/3.0;
- $progress = 10 + intval(90.0 * $index / $total);
- file_put_contents(PROGRESS_PATH,strval($progress));
- }
- private static function setProgressFailed($msg)
- {
- file_put_contents(PROGRESS_PATH,"FAIL:" . $msg);
- }
- private static function setProgressOK($restart)
- {
- if($restart){
- file_put_contents(PROGRESS_PATH,"OK:NEED_RESTART");
- }
- else{
- file_put_contents(PROGRESS_PATH,"OK:NO_RESTART");
- }
- }
- //获取包相关信息
- private static function getPackageInfo($vendorDir,$repoDir,$pkg)
- {
- $config = self::$config;
- $app = self::$app;
- $repoName = $pkg->getName();
- $module_alias = $app["distribute-root"]["module-alias"];
-
- $cfgPath = pathJoin($repoDir,'composer.json');
- $data = json_decode(file_get_contents($cfgPath), true);
-
- $moduleName = $module_alias[$repoName] ? : $repoName;
-
- //获取安装目录
- $rootDir = dirname($vendorDir);
- $commonDir = pathJoin($rootDir,'common');
- $configDir = pathJoin($rootDir,'config',$moduleName);
- $moduleDir = pathJoin($rootDir,'module',$moduleName);
-
-
- //获取缓存目录
- $cacheDir = pathJoin(CACHE_DIR,str_replace('/','-',$repoName));
-
- //返回包的相关信息
- return array(
- "repoName" => $repoName,
- "version" => $pkg->getPrettyVersion(),
- "rootDir" => $rootDir,
- "vendorDir" => $vendorDir,
- "cacheDir" => $cacheDir,
- "toolDir" => $config['tool-dir'],
- "downClient" => $config['down-client'],
- "ossHost" => $config['oss-host'],
- "moduleName" => $moduleName,
- "commonDir" => $commonDir,
- "configDir" => $configDir,
- "moduleDir" => $moduleDir,
- "helper" => $data["distribute-helper"],
- );
- }
-
- //运行脚本文件
- private static function scriptFiles($packageInfo)
- {
- $toolDir = $packageInfo['toolDir'];
- $cacheDir = $packageInfo['cacheDir'];
- $repoName = $packageInfo['repoName'];
- $rootDir = $packageInfo['rootDir'];
- $version = $packageInfo['version'];
- $vendorDir = $packageInfo['vendorDir'];
- $ossHost = $packageInfo['ossHost'];
-
- $fileMacros = array(
- '{vendor}' => $vendorDir,
- '{root}' => $rootDir,
- );
-
- $app = self::$app;
- $scriptFiles = $app["distribute-root"]["script-files"] ? : array();
- foreach($scriptFiles as $info){
- $name = $info['name'];
- $type = $info['type'];
- if($type == 'txt'){
- $filePath = pathJoin($rootDir,$name);
- if(! self::runScriptFile($filePath,$fileMacros) ){
- logError('failed to run script file',$filePath);
- return false;
- }
- }
- }
- return true;
- }
- private static function runScriptFile($filePath,$fileMacros){
- $fileLines = readFileLines($filePath);
- foreach($fileLines as $fileLine){
- $cmd = replaceTextMacro($fileLine,$fileMacros);
- logInfo("start to run script file cmd --",$cmd);
- system($cmd, $ret);
- if ($ret != 0) {
- logError("failed to run script file cmd --",$cmd);
- return false;
- }
- }
- return true;
- }
- //下载包module文件
- private static function fetchModuleFiles($packageInfo)
- {
- $toolDir = $packageInfo['toolDir'];
- $downClient = $packageInfo['downClient'];
- $cacheDir = $packageInfo['cacheDir'];
- $repoName = $packageInfo['repoName'];
- $version = $packageInfo['version'];
- $moduleDir = $packageInfo['moduleDir'];
- $ossHost = $packageInfo['ossHost'];
-
- $moduleFiles = $packageInfo['helper']['module-files'] ? : array();
- foreach($moduleFiles as $fileInfo){
- $fileName = $fileInfo['name'];
- $fileMd5 = $fileInfo['md5'];
- $fileSize = intval($fileInfo['size']);
- //下载文件到缓存区
- $filePath = downloadToDir($toolDir,$downClient,$ossHost,$repoName,$fileName,$fileMd5,$fileSize,$cacheDir);
- if(! $filePath ){
- logError($repoName,"fetch module file failed",$fileName);
- return false;
- }
- logInfo("succeeded to fetch module file --",$repoName,$fileName);
-
- //当前是生成离线包模式,同时拷贝到离线包目录
- if(self::$config['offpkg-dir']){
- $targetPath = pathJoin(self::$config['offpkg-dir'],str_replace('/','-',$repoName),$fileName);
- if(! fileCopy($filePath,$targetPath) ){
- logError($repoName,"offpkg file copy failed",$filePath,'-->',$targetPath);
- return false;
- }
- }
- // 解压或拷贝文件
- if( isZipFile($fileName) ){
- if(! unzipFile($toolDir,$filePath,$moduleDir)) {
- logError($repoName,"unzip module file failed",$fileName);
- return false;
- }
- }else{
- $targetPath = pathJoin($moduleDir,$fileName);
- if(! fileCopy($filePath,$targetPath) ){
- logError($repoName,"copy module file failed",$filePath,'-->',$targetPath);
- return false;
- }
- }
- }
- return true;
- }
-
- //下载包common文件
- private static function fetchCommonFiles($packageInfo)
- {
- $toolDir = $packageInfo['toolDir'];
- $downClient = $packageInfo['downClient'];
- $cacheDir = $packageInfo['cacheDir'];
- $repoName = $packageInfo['repoName'];
- $version = $packageInfo['version'];
- $commonDir = $packageInfo['commonDir'];
- $ossHost = $packageInfo['ossHost'];
- $commonFiles = $packageInfo['helper']['common-files']? : array();
- foreach($commonFiles as $fileInfo){
- $fileName = $fileInfo['name'];
- $fileMd5 = $fileInfo['md5'];
- $fileSize = intval($fileInfo['size']);
- $target = $fileInfo['target'];
- //下载文件到缓存区
- $filePath = downloadToDir($toolDir,$downClient,$ossHost,$repoName,$fileName,$fileMd5,$fileSize,$cacheDir);
- if(! $filePath ){
- logError($repoName,"fetch common file failed",$fileName);
- return false;
- }
- logInfo("succeeded to fetch common file --",$repoName,$fileName);
- // 解压或拷贝文件
- $targetDir = pathJoin($commonDir,$target);
- if( isZipFile($fileName) ){
- if(! unzipFile($toolDir,$filePath,$targetDir)) {
- logError($repoName,"unzip common file failed",$fileName);
- return false;
- }
- }else{
- $targetPath = pathJoin($targetDir,$fileName);
- if(! fileCopy($filePath,$targetPath) ){
- logError($repoName,"copy common file failed",$filePath,'-->',$targetPath);
- return false;
- }
- }
- }
- return true;
- }
-
- //下载包vendor文件
- private static function fetchVendorFiles($packageInfo)
- {
- $toolDir = $packageInfo['toolDir'];
- $downClient = $packageInfo['downClient'];
- $cacheDir = $packageInfo['cacheDir'];
- $repoName = $packageInfo['repoName'];
- $version = $packageInfo['version'];
- $vendorDir = $packageInfo['vendorDir'];
- $ossHost = $packageInfo['ossHost'];
- $vendorFiles = $packageInfo['helper']['vendor-files']? : array();
- foreach($vendorFiles as $fileInfo){
- $fileName = $fileInfo['name'];
- $fileMd5 = $fileInfo['md5'];
- $fileSize = intval($fileInfo['size']);
- $target = $fileInfo['target'];
- //下载文件到缓存区
- $filePath = downloadToDir($toolDir,$downClient,$ossHost,$repoName,$fileName,$fileMd5,$fileSize,$cacheDir);
- if(! $filePath ){
- logError($repoName,"fetch vendor file failed",$fileName);
- return false;
- }
- logInfo("start to fetch vendor file --",$repoName,$fileName);
- // 解压或拷贝文件
- if( isZipFile($fileName) ){
- $targetDir = pathJoin($vendorDir,$target);
- if(! unzipFile($toolDir,$filePath,$targetDir)) {
- logError($repoName,"unzip vendor file failed",$fileName);
- return false;
- }
- }else{
- $targetPath = pathJoin($vendorDir,$repoName,$fileName);
- if(! fileCopy($filePath,$targetPath) ){
- logError($repoName,"offpkg file copy failed",$filePath,'-->',$targetPath);
- return false;
- }
- }
- }
- return true;
- }
- //拷贝config文件
- /*
- private static function copyConfigFiles($packageInfo)
- {
- $cacheDir = $packageInfo['cacheDir'];
- $repoName = $packageInfo['repoName'];
- $version = $packageInfo['version'];
- $configDir = $packageInfo['configDir'];
- $moduleDir = $packageInfo['moduleDir'];
- $configFiles = $packageInfo['helper']['config-files'] ? : array();
- foreach($configFiles as $fileInfo){
- $fileName = $fileInfo['name'];
- $targetName = $fileInfo['target'];
- $filePath = pathJoin($moduleDir,$fileName);
- if(! file_exists($filePath) ){
- logError($repoName,"config file not exists",$filePath);
- return false;
- }
- if(!$fileInfo['override'] && file_exists($targetPath)){
- logInfo($repoName,"skip copy config file",$targetPath);
- continue;
- }
- $targetPath = pathJoin($configDir,$targetName);
- if(! fileCopy($filePath,$targetPath) ){
- logError($repoName,"config file copy failed",$filePath);
- return false;
- }
- }
- return true;
- }*/
-
- private static function removeProcess($packageInfo)
- {
- $app = self::$app;
- $cacheDir = $packageInfo['cacheDir'];
- $repoName = $packageInfo['repoName'];
- $version = $packageInfo['version'];
- $rootDir = $packageInfo['rootDir'];
- $removeProcess = $app["distribute-root"]["remove-process"] ? : array();
- $proc = new WinProcess(DIST_DIR);
- foreach($removeProcess as $process){
- $name = $process['name'];
- //获取进程PIDs
- $pids = $proc->find($name);
- if( $pids === false ){
- logError("failed to find process, action failed.",$name);
- return false;
- }
- if( count($pids) === 0 ){
- logInfo("process not exists.no need to remove process",$name);
- continue;
- }
- //移除进程
- $ret = $proc->remove($name);
- if( $ret === false ){
- logError("failed to remove process, remove action failed.",$name);
- return false;
- }
- else{
- logInfo("succeeded to remove process",$name);
- }
- }
- return true;
- }
- //拷贝copy-files文件
- private static function copyFiles($packageInfo)
- {
- $app = self::$app;
- $cacheDir = $packageInfo['cacheDir'];
- $repoName = $packageInfo['repoName'];
- $version = $packageInfo['version'];
- $rootDir = $packageInfo['rootDir'];
- $copyFiles = $app["distribute-root"]["copy-files"] ? : array();
- foreach($copyFiles as $fileInfo){
- $fileName = $fileInfo['path'];
- $targetName = $fileInfo['target'];
- $filePath = pathJoin($rootDir,$fileName);
- $targetPath = pathJoin($rootDir,$targetName);
- if(! file_exists($filePath) ){
- logError("failed to copy file, file not exists.",$filePath);
- return false;
- }
- if(!$fileInfo['override'] && file_exists($targetPath)){
- logInfo("skip copy file, file already exists",$targetPath);
- continue;
- }
- if( filedirCopy($filePath,$targetPath) ){
- logInfo("succeeded to copy file",$fileName," -> ",$targetName);
- }
- else{
- logError("failed to copy file, copy action failed.",$filePath);
- return false;
- }
- }
- return true;
- }
- private static function macoFiles($packageInfo)
- {
- $app = self::$app;
- $cacheDir = $packageInfo['cacheDir'];
- $repoName = $packageInfo['repoName'];
- $version = $packageInfo['version'];
- $rootDir = $packageInfo['rootDir'];
- $macroFiles = $app["distribute-root"]["macro-files"] ? : array();
-
- $appDir = str_replace('\\','/',$rootDir);
- $rootDirUp2 = dirname(dirname($rootDir));
- $appdataDir = pathJoin($rootDirUp2,'appdata');
- $tmpdataDir = pathJoin($rootDirUp2,'tmpdata');
- $logDir = getLysis3LogDir();
- $macros = array(
- '{sis31.appdir}' => $appDir,
- '{sis31.appdata}' => $appdataDir,
- '{sis31.tmpdata}' => $tmpdataDir,
- '{sis31.logdir}' => $logDir,
- );
- foreach($macroFiles as $fileInfo){
- $fileName = $fileInfo['path'];
- $filePath = pathJoin($rootDir,$fileName);
- if(! file_exists($filePath) ){
- logError("failed to replace macro file, file not exists.",$filePath);
- return false;
- }
- $targetName = $fileInfo['target'];
- $targetPath = pathJoin($rootDir,$targetName);
- if( replaceFileMacro($filePath,$targetPath,$macros) ){
- logInfo("succeeded to replace macro file",$fileName);
- }
- else{
- logError("failed to replace macro file",$filePath);
- return false;
- }
- }
- return true;
- }
- private static function registerPath($packageInfo)
- {
- $app = self::$app;
- $rootDir = $packageInfo['rootDir'];
-
- $removePath = $app["distribute-root"]["remove-path"] ? : array();
- $registerPath = $app["distribute-root"]["register-path"] ? : array();
-
- $arrRemovePattern = array();
- foreach($removePath as $item){
- $pattern = $item['pattern'];
- array_push($arrRemovePattern,$pattern);
- }
- $arrAddPath = array();
- foreach($registerPath as $item){
- $path = pathJoin($rootDir,$item['path']);
- array_push($arrAddPath,$path);
- }
-
- $removePathes = array();
- $env = new WinEnvPath();
- if(! $env->updatePath($arrRemovePattern,$arrAddPath,$removePathes) ){
- logError('failed to register path');
- return false;
- }
- foreach($removePathes as $path){
- logInfo('succeeded to remove path',$path);
- }
- foreach($arrAddPath as $path){
- logInfo('succeeded to add path',$path);
- }
- return true;
- }
-
- private static function registerAutorun($packageInfo)
- {
- $app = self::$app;
- $rootDir = $packageInfo['rootDir'];
-
- $removeAutorun = $app["distribute-root"]["remove-autorun"] ? : array();
- $regAutorun = $app["distribute-root"]["register-autorun"] ? : array();
-
- $auto = new WinAutorun();
- foreach($removeAutorun as $item){
- if(! $auto->remove($item['name']) ){
- logError('failed to remove autorun',$item['name']);
- return false;
- }
- logInfo('succeeded to remove autorun',$item['name']);
- }
- foreach($regAutorun as $item){
- $cmd = pathJoin($rootDir,$item['path']);
- $cmd = toOsSlashes($cmd);
- if(! $auto->register($item['name'],$cmd) ){
- logError('failed to register autorun',$item['name']);
- return false;
- }
- logInfo('succeeded to register autorun',$item['name']);
- }
- return true;
- }
-
- private static function registerService($packageInfo)
- {
- $app = self::$app;
- $rootDir = $packageInfo['rootDir'];
-
- $removeService = $app["distribute-root"]["remove-service"] ? : array();
- $regService = $app["distribute-root"]["register-service"] ? : array();
-
- $service = new WinService(DIST_DIR);
- foreach($removeService as $item){
- if(! $service->remove($item['name']) ){
- logError('failed to remove autorun',$item['name']);
- return false;
- }
- logInfo('succeeded to remove autorun',$item['name']);
- }
- foreach($regService as $item){
- $path = pathJoin($rootDir,$item['path']);
- $path = toOsSlashes($path);
- if(! $service->register($item['name'],$path) ){
- logError('failed to register autorun',$item['name']);
- return false;
- }
- logInfo('succeeded to register autorun',$item['name']);
- }
- return true;
- }
-
- private static function registerShortcut($packageInfo)
- {
- $app = self::$app;
- $rootDir = $packageInfo['rootDir'];
-
- $removeShortcut = $app["distribute-root"]["remove-shortcut"] ? : array();
- $regShortcut = $app["distribute-root"]["register-shortcut"] ? : array();
-
- $sc = new WinDesktopShortcut();
- foreach($removeShortcut as $item){
- if(! $sc->remove($item['name']) ){
- logError('failed to remove shortcut',$item['name']);
- return false;
- }
- logInfo('succeeded to remove shortcut',$item['name']);
- }
- foreach($regShortcut as $item){
- $path = pathJoin($rootDir,$item['path']);
- if(! $sc->register($item['name'],$path,$item['desc']) ){
- logError('failed to register shortcut',$item['name']);
- return false;
- }
- logInfo('succeeded to register shortcut',$item['name']);
- }
- return true;
- }
- }
|