type t_compile_config=class(tdcreateform) uses tslvcl; bt_ok:tbtn; gp_dir:tgroupbox; bt_f_dir:tbtn; bt_s_dir:tbtn; gp_filter:tgroupbox; lb_s_type:tlabel; ed_s_type:tedit; bt_i_f:tbtn; bt_d_f:tbtn; gp_out:tgroupbox; lb_ype:tlabel; cb_type:tcombobox; lb_output:tlabel; ed_output:tedit; bt_cancel:tbtn; gp_other:tgroupbox; ck_gui:tcheckbtn; ck_strong:tcheckbtn; ck_s_rp:tcheckbtn; bt_i_s:tbtn; lb_ico:tlabel; ed_ico:tedit; bt_ico:tbtn; bt_output:tbtn; f_op:topenfileadlg; lb_input:tlabel; e_script:tedit; bt_script:tbtn; bt_outputname:tbtn; lb_output_f:tlabel; ed_out_f:tedit; label1:tlabel; ed_f_dirs:tedit; label2:tlabel; ed_s_dirs:tedit; label3:tlabel; ed_include_s:tedit; label4:tlabel; ed_include_f:tedit; label5:tlabel; ed_exclude_f:tedit; lb_tsg:tlabel; ed_tsg:tedit; bt_tsgadd:tbtn; bt_cmd:tbtn; l_namespace:tlabel; e_namespace:tedit; function Create(AOwner);override; //构造 begin f_sep := iofileseparator(); fbasedirarray := array(); inherited; //set_base_dir(%% E:\TSUIGROUP\designer\ctl_mgr\%%); dir_list := new t_dir_list(self); dir_list.Visible := false; dir_list.parent := self; m_list_editor := new t_m_list_editor(self); m_list_editor.Visible := false; m_list_editor.parent := self; end function bt_cmd_clk(o;e); begin s := format_build_params(get_config()); if not fcmd_shower then begin fcmd_shower := new t_bconfig_cmd_shower(self); fcmd_shower.Visible := false; fcmd_shower.parent := self; end fcmd_shower.Left := Left; fcmd_shower.top := top+200; fcmd_shower.set_config_text(s); fcmd_shower.ShowModal(); end function bt_tsgadd_clk(o;e);virtual; begin tp := array("tsg库":"*.tsg"); if show_dir_list(s_to_array(ed_tsg.text,true),tp)then begin ed_tsg.text := array_to_s(dir_list.get_dirs(),true); end end function bt_cancel_clk(o;e);virtual; begin EndModal(0); end function bt_ok_clk(o;e);virtual; begin EndModal(1); end function set_config(r); begin clear_config(); if not ifarray(r) then return ; case r["build"] of "--buildlib":cb_type.ItemIndex := 1; "--build":cb_type.ItemIndex := 2; else cb_type.ItemIndex := 0; end flibpath := r["libpath"]; e_script.text := r["buildfile"]; ed_output.text := r["output"]; ed_out_f.text := r["exports"] ; ed_f_dirs.text := r["dependsdir"]; ed_include_f.text := r["depends"]; ed_exclude_f.text := r["excludes"]; ed_s_dirs.text := r["resourcedir"]; ed_s_type.text := r["resourcepat"]; ed_include_s.text := r["extresource"]; ck_strong.Checked := r["strong"] ; ck_gui.Checked := r["buildgui"] ; ed_ico.text := r["buildico"]; ed_tsg.text := r["pkg"]; e_namespace.text := r["nspace"]; //ck_s_rp.Checked := r["resourcekeepdir"]; end function get_config(); begin r := array(); case cb_type.ItemIndex of 0: r["build"] := "--buildexe"; 1: r["build"] := "--buildlib"; 2: r["build"] := "--build"; end r["buildfile"] := e_script.text; r["output"] := ed_output.text; r["libpath"] := flibpath; r["exports"] := ed_out_f.text; r["dependsdir"]:=ed_f_dirs.text; r["depends"]:=ed_include_f.text; r["excludes"] := ed_exclude_f.text; r["resourcedir"] := ed_s_dirs.text; r["resourcepat"] := ed_s_type.text; r["extresource"]:=ed_include_s.text; r["strong"] := ck_strong.Checked; r["buildgui"] := ck_gui.Checked; r["buildico"] := ed_ico.text; r["resourcekeepdir"] := ck_s_rp.Checked; r["pgk"] := trim(ed_tsg.text); r["nspace"] := trim(e_namespace.text); return r; end function clear_config();//清理 begin e_script.text := ""; ed_output.text := ""; ed_out_f.text := ""; ed_f_dirs.text := ""; ed_include_f.text := ""; ed_exclude_f.text := ""; ed_s_dirs.text := ""; ed_s_type.text := ""; ed_include_s.text := ""; ck_strong.Checked := false; ck_gui.Checked := false; ed_ico.text := ""; ck_s_rp.Checked := false; e_namespace.text := ""; flibpath := ""; end function bt_outputname_clk(o;e);virtual; begin f_op.filter := array(get_type():"*"+get_type()); if f_op.OpenDlg()then begin ed_output.text :=relative_path( f_op.filename); end end function cb_type_sel(o;e);virtual; begin ab := 0 = o.ItemIndex; bt_ico.Enabled := ab; ed_ico.Enabled := ab; bt_output.Enabled := not ab; ed_out_f.Enabled := not ab; lb_output_f.Enabled := not ab; ed_output.text := createoutputname(ed_output.text); end function bt_script_clk(o;e);virtual; begin f_op.filter := array("tsl脚本":"*.tsf;*.tsl"); if f_op.OpenDlg()then begin e_script.text := relative_path( f_op.filename); end end function bt_ico_clk(o;e);virtual; begin f_op.filter := array("ico图标":"*.ico"); if f_op.OpenDlg()then begin ed_ico.text := relative_path( f_op.filename); end end function bt_d_f_clk(o;e);virtual; begin if show_m_editor(s_to_array(ed_exclude_f.text))then begin ed_exclude_f.text := array_to_s(m_list_editor.get_data()); end end function bt_i_f_clk(o;e);virtual; begin if show_m_editor(s_to_array(ed_include_f.text))then begin ed_include_f.text := array_to_s(m_list_editor.get_data()); end end function bt_i_s_clk(o;e);virtual; begin if show_m_editor(s_to_array(ed_include_s.text))then begin ed_include_s.text := array_to_s(m_list_editor.get_data()); end end function bt_output_clk(o;e); begin if show_m_editor(s_to_array(ed_out_f.text))then begin ed_out_f.text := array_to_s(m_list_editor.get_data()); end end function bt_s_dir_clk(o;e); begin if show_dir_list(s_to_array(ed_s_dirs.text,true))then begin ed_s_dirs.text := array_to_s(dir_list.get_dirs(),true); end end function bt_f_dir_clk(o;e); begin if show_dir_list(s_to_array(ed_f_dirs.text,true))then begin ed_f_dirs.text := array_to_s(dir_list.get_dirs(),true); end end function compile_config_close(o;e);virtual; begin e.skip := true; EndModal(0); end function Recycling();override; //回收变量 begin inherited; ci := self.classinfo(); //将成员变量赋值为nil避免循环引用 for i,v in ci["members"] do begin if v["const"]then continue; if v["static"]then continue; invoke(self,v["name"],nil); end end function show_dir_list(data,filetype); begin dir_list.Left := Left-20; dir_list.top := top+50; dir_list.set_dirs(data); dir_list.fopentype := filetype; return dir_list.ShowModal(); end function show_m_editor(data); begin m_list_editor.Left := Left-20; m_list_editor.top := top+50; m_list_editor.set_data(data); return m_list_editor.ShowModal(); end function enabled_script_input(f); begin e_script.Enabled := f; bt_script.Enabled := f; end function set_data(d); begin if ifarray(d) then begin f_data := d; end end published property base_dir read fbasedir write set_base_dir; dir_list; m_list_editor; private fbasedir; fbasedirarray; f_data; f_sep; function s_to_array(s,ph); begin data := array(); for i,v in str2array( s,",") do begin vi := trim(v); if vi then data[length(data)] := ph? abstruct_path(v):v; end return data; end function array_to_s(data,ph); begin r := ""; for i,v in data do begin r+= (ph?relative_path(v):v)+","; end lr := length(r); if lr>2 and r[lr]="," and (r[lr-1]<>"\\") then begin r := r[1:(lr-1)]; end return r; end function relative_path(d); begin if not(fbasedirarray) then return d; da := str2array(d, f_sep); for i := 0 to min(length(da),length(fbasedirarray))-1 do begin if dirnequ(da[i],fbasedirarray[i]) then begin if i>0 then begin return createpdir(length(fbasedirarray)-i-1)+ array2str( da[i:],f_sep); end else begin return d; end end end if i>0 then begin return array2str( da[i:],f_sep); end return d; end function abstruct_path(d);//绝对路径 begin if not(fbasedirarray) then return d; da := str2array(d,f_sep); for i := 0 to length(da)-1 do begin if i=0 and da[i]="." then begin return array2str((fbasedirarray[0:(length(fbasedirarray)-2)] union da[1:]),f_sep); end if da[i]<>".."then begin if i>0 then return array2str( fbasedirarray[0:(length(fbasedirarray)-i-2)] union da[i:],f_sep); else return d; end end return d; end function createpdir(n); begin r :=""; if n<1 then return "."+f_sep; for i:=1 to n do begin r+=".."+f_sep; end return r; end function dirnequ(v1,v2); begin {$ifdef linux} return v1<>v2; {$else} return lowercase(v1)<>lowercase(v2); {$endif} end function get_type(); begin idx := cb_type.ItemIndex; {$ifdef linux} case idx of 0:tp:=".out"; 1:tp:=".so"; 2:tp:=".tsg"; end; {$else} case idx of 0:tp:=".exe"; 1:tp:=".dll"; 2:tp:=".tsg"; end; {$endif} return tp; end function createoutputname(n); begin tp := get_type(); sp := iofileseparator(); for i:= length(n) downto 1 do begin if n[i]="." and i>1 then begin nv := n[1:(i-1)]; break; end end if not nv then nv := "."+sp+"default"; return nv+tp; end function set_base_dir(v); begin if fbasedir<>v then begin fbasedir := v; fbasedirarray := str2array(v,f_sep); end end function format_build_params(d); begin r := d["build"]+"="+format('"%s" ',d["buildfile"]); lbp := d["libpath"]; if lbp and ifstring(lbp) then begin r+='\r\n-libpath "'+lbp+'" '; end else r+="\r\n-libpath ."+ioFileseparator()+" "; r+="\r\n"; r += f_b_a_param(d,"exports"); r += f_b_a_param(d,"dependsdir"); r += f_b_a_param(d,"depends"); r += f_b_a_param(d,"excludes"); r += f_b_a_param(d,"pkg"); r += f_b_a_param(d,"resourcedir"); r += f_b_a_param(d,"resourcepat"); r += f_b_a_param(d,"extresource"); r += f_b_a_param(d,"buildico"); r += f_b_a_param(d,"output"); if d["strong"] then r+= " -strong"; if d["buildgui"] then r+= " -buildgui"; {$ifdef linux} {$else} if r[length(r)]="\n" then r +=format('--manifest="%s" ',d["buildfile"]+".manifest"); else r +=format('\r\n--manifest="%s" ',d["buildfile"]+".manifest"); {$endif} if d["nspace"] then begin if r[length(r)]="\n" then r+=format("--setpkg2ns=%s ",d["nspace"]); else r+=format("\r\n--setpkg2ns=%s ",d["nspace"]); end return r; end function f_b_a_param(d,n); begin dn := d[n]; if not ifstring(dn) then return ""; v :=trim( dn); r :=""; if v then begin if v[length(v)]="\\" then v+=","; r :=format( "--%s=",n)+format('"%s" ',v); r+="\r\n"; end return r; end fcmd_shower; flibpath; end