
import win.ui;
/*DSG{{*/
var winform = win.form( text="快手(AAuto Quicker) -  已生成EXE文件";bottom=165;parent=...;right=496;max=false )
winform.add( 
btnClose={ bottom=145;right=456;left=375;top=113;z=2;text="关闭(ESC)";cls="button" };
editPublishPath={ bottom=77;right=470;left=33;top=48;z=4;readonly=1;edge=1;cls="edit" };
lbTitle={ bottom=49;text="已成功生成EXE文件";left=33;right=148;top=23;z=5;transparent=1;cls="static" };
btnExplorer={ bottom=145;right=369;left=227;top=113;z=1;text="打开发布目录(Enter)";cls="button" };
btnRun={ bottom=145;right=220;left=98;top=113;z=3;text="运行EXE文件(F5)";cls="button" };
chkLostFocusClose={ checked=1;bottom=101;text="对话框失去焦点自动关闭";left=33;top=88;z=6;right=208;cls="checkbox" }
)
/*}}*/

import ide;
import fsys;
import process;
import config;

winform.chkLostFocusClose.checked = config.publish.chkLostFocusClose 

getPublisDir = function(){
	var dir = ide.getProjectProperty("publishDir")
	if( dir[1] == '\\'# || dir[1] == '/'# ){
		dir = fsys.joinpath(ide.getProjectDir(),dir )
	}
	return dir;
}

winform.editPublishPath.text = fsys.joinpath( 
	getPublisDir(),
	ide.getProjectProperty("name") + ".exe" 
);

winform.show() 

var exe  = raw.loadDll(winform.editPublishPath.text)
if( !exe ){
	win.msgboxErr("生成EXE失败","快手(AAuto Quicker)" );
	return;
}

var resLibs = {};
import fsys.res;
fsys.res.enum(
	function(module,resType,resName){  
		resName = ..string.lower(resName)
		table.push(resLibs,..string.lower(resName) )
		resLibs[resName] = true;
		..io.print( resName )
		return true;
	},"LIB",exe.gethandle()
)

if( resLibs["java"] ){
	winform.text = "请稍候,正在复制jre运行库......"
	winform.btnRun.disabled = true;
	winform.btnExplorer.disabled = true;
	win.invoke(
		function(publisDir){
			import fsys;
			fsys.copy( fsys.joinpath(io._exedir,"/java/") ,publisDir );
		},getPublisDir() 
	)
	winform.text = "快手(AAuto Quicker) -  已完成"
	winform.btnRun.disabled = false;
	winform.btnExplorer.disabled = false;
}
 
winform.btnClose.oncommand = function(id,event){
	winform.close()
}
 
winform.btnRun.oncommand = function(id,event){
	winform.btnRun.text = "请稍候..."
	winform.btnRun.disabled = true;
	process.execute(winform.editPublishPath.text);
	winform.close();
}
 
winform.btnExplorer.oncommand = function(id,event){
	winform.btnExplorer.text = "请稍候..."
	winform.btnExplorer.disabled = true;
	process.explore_select( winform.editPublishPath.text )
	winform.close();
}

winform.wndproc = function(hwnd,message,wParam,lParam){
	select( message ) { 
		case 0x1C/*_WM_ACTIVATEAPP*/ {
			if(!wParam){
				if( winform.chkLostFocusClose.checked ){
					winform.close();
				}
			}
		} 
		case 0x100/*_WM_KEYDOWN*/{
			if( wParam = 0x74/*_VK_F5*/ ){
				winform.btnRun.oncommand();
			}
		}
	} 
}

winform.onClose = function(hwnd,message,wParam,lParam){
    config.publish.chkLostFocusClose = winform.chkLostFocusClose.checked
}
 
win.loopMessage();


