//转义字符串生成器

import win.ui; 
import fsys.dlg
import string.ex;
import win.clip;
/*DSG{{*/
var winform = win.form( bgcolor=16496028;bottom=482;max=1;right=528;left=0;min=1;top=0;acceptfiles=1;topmost=1;text="转义字符串生成器";border="dialog frame" )
winform.add( 
btnCpyCpp={ dr=1;bottom=476;align="";right=370;left=273;color=0;top=449;acceptfiles=1;tabstop=1;db=1;text="复制到C++";z=7;cls="button" };
btnDump={ dr=1;bottom=126;color=0;text="使用\x转义符进行转换";left=363;dt=1;top=99;acceptfiles=1;z=0;align="";right=508;tabstop=1;cls="button" };
btnRestore={ dr=1;bottom=476;align="";right=262;left=158;color=0;top=449;acceptfiles=1;tabstop=1;db=1;text="还原并复制";z=6;cls="button" };
btnCpy={ dr=1;bottom=476;align="";text="复制到AAuto";left=385;color=0;top=449;acceptfiles=1;tabstop=1;db=1;right=466;z=5;cls="button" };
progress={ disabled=1;color=0;right=503;left=18;cls="progress";tabstop=1;bottom=152;max=100;text="progress";min=0;acceptfiles=1;z=1;bgcolor=0;edge=1;top=132 };
static={ dl=1;bottom=118;color=0;right=352;left=21;dt=1;top=104;acceptfiles=1;tabstop=1;text="AAuto在单引号中可以使用转义符表示字符串,支持二进制字符.
";z=2;transparent=1;cls="static" };
editpath={ dr=1;dl=1;color=0;right=507;left=21;dt=1;cls="edit";bottom=87;align="";text="外部文件直接拖放到这里，然后点击转换按钮即可
也可以在这里直接输入要转换的文本";multiline=1;top=14;tabstop=1;edge=1;z=3 };
editResult={ dr=1;dl=1;vscroll=1;right=507;left=16;dt=1;db=1;cls="richedit";bottom=443;text="也可以直接将外部文件拖放到快手的代码编辑器中、使用$操作符直接包含文件。
点击编译按钮即可将外部文件嵌入AAU文件中。";multiline=1;top=168;z=4;hscroll=1;edge=1 }
)
/*}}*/

winform.btnRestore.oncommand = function(id,event){
	var str = string.trim(winform.editResult.text,'\'"');
	var func = assert(loadcode("return '"+ str + "'") );
	str = func(str);
	
	win.clip.write( str )
	
	if(#str<1000)
		winform.editpath.text = str;
	 
	winform.static.text = "                  谢谢使用 ,已复制到剪贴板!"
	
}//endproc


winform.btnCpyCpp.oncommand = function(id,event){
	var str = string.trim(winform.editResult.text,'\'"'); 
	win.clip.write( '"' + str + '"')
}//endproc
 

winform.btnCpy.oncommand = function(id,event){ 
	win.clip.write(winform.editResult.text)
	
}//endproc


winform.wndproc = function(hwnd,message,wparam,lparam){
	select(message) {//判断消息类型
		case 0x233/*_WM_DROPFILES*/ 
		{ 
		winform.editpath.text = win.getDropFile(wparam )[1];  
		} 
		
	}
}//endproc
 
 
winform.btnDump.oncommand = function(hwnd,event){
	//win.msgbox( winform.btnbuild.text );
	if( winform.editpath.text == ""){
		winform.static.text = "注意,请选中或输入要编译的文件路径!"
		winform.redraw();
		return ;
	}
	
	conv = function(path,hwnd){
		import string.ex
		import win;
		var fullpath = io.exist(path)
		var str = fullpath? string.load(fullpath) : path;
		str = string.ex.dump( str ) 
		win.setText(hwnd,str); 
	}
	
	winform.static.text = "正在转换......";
	h = thread.create(conv,winform.editpath.text,winform.editResult.hwnd )  
 
 　 //加点效果
    winform.progress.hide = false;//显示进度条
	while( thread.getExitCode(h)!=0 ){ //循还从1到10
	    winform.progress.pos += 10 //增加进度 
	    win.delay(100) 
	}  
	 
	winform.progress.hide = true;//隐藏进度条
	winform.static.text = "                  谢谢使用 ,转换完成!"
	winform.redraw()
	
} 
	
winform.btndlg.oncommand = function(hwnd,event){
	//win.msgbox( winform.btndlg.text );
	var str  = fsys.dlg.open("AAuto文件|*.aau|AAuto文件|*.aau||","请选择AAuto代码文件")
	if( str)
		winform.editpath.text = str;
}//end callback

winform.show(true) 
win.loopMessage( winform );


