//Cab压缩打包工具
import win.ui;
/*DSG{{*/
var winform = win.form( bottom=399;parent=...;text="CabQuicker -  压缩打包工具";border="resizable";right=599 )
winform.add( 
tab={ dr=1;dl=1;bottom=389;right=587;left=9;dt=1;top=8;z=1;db=1;edge=1;cls="tab" }
)
/*}}*/

var frmCompress,frmUnCompress 

/*压缩工具{{*/
frmCompress = winform.tab.add( text="压缩";acceptfiles=1;bottom=363;parent=...;right=590 )
frmCompress.add( 
editDst={ dl=1;bottom=147;right=344;left=41;dt=1;top=120;z=3;text="/test.cab";edge=1;cls="edit" };
btnCompress={ dr=1;bottom=345;text="生成压缩文件";left=393;top=305;z=8;db=1;right=553;cls="button" };
static={ dl=1;bottom=48;right=309;left=41;dt=1;top=26;transparent=1;text="请拖放需要压缩的目录或文件到下面输入框中";z=2;cls="static" };
staticDst={ dl=1;bottom=118;right=309;left=41;dt=1;top=96;transparent=1;text="请选择cab文件存储路径";z=5;cls="static" };
cmbType={ dr=1;bottom=334;right=377;left=314;text="LZX";
items={ "LZX";"MSZIP" };top=314;z=7;db=1;mode="dropdown";edge=1;cls="combobox" };
staticType={ dr=1;bottom=339;align="right";text="压缩算法:";left=238;top=317;z=6;db=1;right=309;transparent=1;cls="static" };
editSrc={ dl=1;bottom=77;right=549;left=41;dt=1;top=48;z=1;edge=1;cls="edit" };
btnBrowser={ dl=1;bottom=149;right=465;left=349;dt=1;top=116;z=4;text="浏览...";cls="button" };
chkConsole={ dr=1;bottom=339;text="使用控制台窗口显示进度";left=82;top=315;z=10;db=1;right=243;cls="checkbox" };
editLog={ dr=1;dl=1;bottom=289;vscroll=1;right=550;left=38;multiline=1;top=171;dt=1;z=9;db=1;hscroll=1;edge=1;cls="edit" }
)
frmCompress.btnCompress.oncommand = function(id,event){
	frmCompress.btnCompress.disabled = true;
	var tmId = 	frmCompress.addtimer(  1000, function(hwnd,msg,id,tick){
			frmCompress.editLog.text = frmCompress.editLog.text + "."
	} )
 
	win.invoke(
		function(hwnd,path,target,showConsole,compressType){
			import win.ui;
			import fsys.cab.maker;
			if( showConsole ){
				io.open();
			}
			var edit = win.ui.ctrl.edit();
			edit.hwnd = hwnd;
			edit.text = "正在计算文件数目......"
			fsys.cab.maker.onProgress = function(folder,total,progress){ 
				edit.text = '已压缩:' + folder + '\r\n子目录总数:' + total + " 已处理:" + progress + '\r\n' + edit.text;
			} 
			fsys.cab.maker.showConsole = showConsole;
			ok,err = fsys.cab.maker.compress(path,target,compressType)
			if(ok){
				edit.text = '已生成' + err + '\r\n全部操作已完成\r\n' + edit.text; 
			}
			else {
				edit.text = edit.text + '\r\n' + err;
			}
		},frmCompress.editLog.hwnd,frmCompress.editSrc.text,frmCompress.editDst.text
		,frmCompress.chkConsole.checked/*,frmCompress.cmbType.text*/
	)
	frmCompress.killtimer(tmId)
	frmCompress.btnCompress.disabled = false;
} 
import fsys.dlg;
frmCompress.btnBrowser.oncommand = function(id,event){
	frmCompress.editDst.text = fsys.dlg.save( "*.cab|*.cab||","请选择cab文件存储目录",,frmCompress.hwnd)
} 
frmCompress.wndproc = function(hwnd,message,wParam,lParam){
	select(message) {//判断消息类型
		case 0x233/*_WM_DROPFILES*/ { 
			frmCompress.editSrc.text = win.getDropFile(wParam )[1]; 
			var tPath =  io.splitpath(frmCompress.editSrc.text)
			frmCompress.editDst.text = tPath.dir + tPath.name + ".cab"
			frmUnCompress.editSrc.text = frmCompress.editDst.text;
		} 
	}
} 
/*}}*/

/*解压缩工具{{*/
frmUnCompress = winform.tab.add( text="解压缩";acceptfiles=1;bottom=363;parent=...;right=590 )
frmUnCompress.add( 
editDst={ dl=1;bottom=147;right=381;left=41;dt=1;top=120;z=3;text="/";edge=1;cls="edit" };
editSrc={ dl=1;bottom=77;right=549;left=41;dt=1;top=48;z=1;edge=1;cls="edit" };
btnBrowser={ dl=1;bottom=150;right=522;left=406;dt=1;top=117;z=4;text="浏览...";cls="button" };
progress={ dl=1;bottom=198;max=100;right=554;left=41;dt=1;top=178;z=7;cls="progress";min=0;edge=1;hide=1 };
static={ dl=1;bottom=48;text="请拖放需要压缩的文件到下面输入框中";left=41;dt=1;top=26;transparent=1;right=309;z=2;cls="static" };
staticDst={ dl=1;bottom=118;text="请选择存储目录";left=41;dt=1;top=96;transparent=1;right=309;z=5;cls="static" };
btnUnCompress={ dl=1;bottom=257;text="解压缩文件";left=308;dt=1;top=217;z=6;right=468;cls="button" }
)

frmUnCompress.btnUnCompress.oncommand = function(id,event){
	frmUnCompress.btnUnCompress.disabled = true;
	frmUnCompress.progress.hide = false
	var tmId = 	frmUnCompress.addtimer(  50, function(hwnd,msg,id,tick){
		frmUnCompress.progress.pos ++;
	} )
 
	win.invoke(
		function( path,target ){ 
			import fsys.cab 
			fsys.cab.extract(path,target)
		},frmUnCompress.editSrc.text,frmUnCompress.editDst.text 
	)
	frmUnCompress.killtimer(tmId)
	frmUnCompress.progress.hide = true;
	frmUnCompress.btnUnCompress.disabled = false;
} 
import fsys.dlg;
frmUnCompress.btnBrowser.oncommand = function(id,event){
	frmUnCompress.editDst.text = fsys.dlg.opendir( frmUnCompress.editDst.text,frmUnCompress.hwnd )
}

frmUnCompress.wndproc = function(hwnd,message,wParam,lParam){
	select(message) {//判断消息类型
		case 0x233/*_WM_DROPFILES*/ { 
			frmUnCompress.editSrc.text = win.getDropFile(wParam )[1]; 
			var tPath =  io.splitpath(frmUnCompress.editSrc.text)
			frmUnCompress.editDst.text = tPath.dir + tPath.name 
		} 
	}
} 

/*}}*/

/*查看本程序源码{{*/
var frmWeb = winform.tab.add( scroll=1;bottom=399;parent=...;text="源代码";right=599 )
frmWeb.add(  )
import web.form; 
//创建web窗体
var wb = web.form( frmWeb  ); 
//打开目标网站
wb.go("http://www.aau.cn/thread-5438-1-1.html")
/*}}*/ 
 
winform.show() 
win.loopMessage();
