//maker 制作压缩包 import fsys; import process.popen; namespace fsys.cab.maker; folder = function(rootDir,targetPath,CompressionType="LZX"){ rootDir = ..fsys.longpath( ..io.fullpath(rootDir) ); if(!targetPath){ targetPath = ..string.trimright( rootDir,"\/" ) + ".cab" } else { targetPath = ..io.fullpath(targetPath) } if( ..io.exist(targetPath) ){ return null,'cab文件已存在:\r\n' + targetPath } var tTarget = ..io.splitpath(targetPath) var tFiles = {" .OPTION EXPLICIT .Set CabinetNameTemplate=""" + tTarget.file + """ .set DiskDirectoryTemplate=CDROM ;All cabinets go in a single directory .Set CompressionType="+CompressionType+";All files are compressed in cabinet files .Set UniqueFiles=""OFF"" .Set Cabinet=on .Set DiskDirectory1="""+..fsys.shortpath(tTarget.dir) +""" "}; ..fsys.enum( rootDir, "*.*", function(dir,file,fullpath,findData){ if(file){ ..table.push(tFiles,'"' + fullpath + '"'); } },function(dirpath,dirname){ ..table.push(tFiles,'.Set DestinationDir="' + ..fsys.path.relative(dirpath,rootDir,false) + '"'); return true; } ); var ddfPath = ..io.tmpname("ddf") ; ..string.save(ddfPath, ..string.fromto( ..string.join(tFiles,'\r\n'),65001,0) ); var prcs = ..process.popen("makecab.exe", "/V0","/F",ddfPath,"/D" ,"MaxDiskSize=CDROM","/D","CompressionType="+CompressionType,"/D","CompressionMemory=21" ,"/D","Cabinet=ON","/D","Compress=ON","/L",tTarget.dir); if(!prcs){ return null,'压缩目录时出错:\r\n' + path; } prcs.logger = self.logger; prcs.logResponse(); prcs.close(); ..io.remove(ddfPath); return true,targetPath } file = function( path,targetPath,CompressionType="LZX" ){ path = ..fsys.longpath( ..io.fullpath(path) ) if(!targetPath){ targetPath = ..string.trimright( path,"\/" ) + ".cab" } else { targetPath = ..io.fullpath(targetPath) } var tTarget = ..io.splitpath(targetPath) var prcs = ..process.popen("makecab.exe", `/V0`,`/D`,`MaxDiskSize=CDROM`,`/D` ,`CompressionType=`+CompressionType,`/D`,`CompressionMemory=21`,`/D`,`Cabinet=ON`,`/D`,`Compress=ON` ,path,`/L`,tTarget.dir,tTarget.file); if(!prcs){ return null,'压缩文件时出错:\r\n' + path; } prcs.logger = self.logger; prcs.logResponse(); prcs.close(); return true,targetPath } compress = function(path,targetPath,CompressionType="LZX"){ path = ..io.fullpath(path) if(!targetPath){ targetPath = ..string.trimright( path,"\/" ) + ".cab" } else { targetPath = ..io.fullpath(targetPath) } if(! ..string.endsWith( targetPath,".cab",true) ){ return "cab文件存储路径错误"; } ..fsys.delete(targetPath) if( ! ..fsys.isDir( path ) ){ return file(path,targetPath,CompressionType) } else{ return folder( path,targetPath,CompressionType ); } } /**intellisense(fsys.cab.maker) logger = 指定压缩进度默认回显对象\n该对象必须有 log 或 write 成员函数用于输出信息 compress(.(待压缩目录或文件,输出目录,"MSZIP") = 压缩文件名目录(路径不能包含Unicode 字符),生成 cab 文件。\n支持嵌套子目录\n参数 @2 ,参数 @3 可省略,默认使用 LZX 算法(压缩率较高).\n成功返回 true,失败返回 null,错误信息 end intellisense**/