setup factory打包工具的使用

setup factory
优点:支持大于2G的安装包打包(Inno Setup,NSIS不支持)。
缺点:原来的界面控件不能在基础上修改,只能自定义custom的对话框,但是脚本都需要自己编写,比较繁琐,只能参考用户文档和google揣摩了,下面是自己实际项目弄的一些lua脚本内容,以供参考。
1.自定义界面,然后编写脚本
OnPreload脚本: 
-- These actions are performed before the screen is shown.
DlgRadioButton.SetProperties(CTRL_RADIO_BUTTON_01, {Checked = false});
DlgRadioButton.SetProperties(CTRL_RADIO_BUTTON_02, {Checked = true});
--DlgRadioButton.SetProperties(CTRL_BUTTON_NEXT, {Enabled = false});
g_LicenseAgreementScreen_UpdateNextButton();
--用于捕获键盘事件
Screen.SetFocus(CTRL_EDIT_01);

2.捕获键盘事件
-- These actions are triggered by the controls on the screen.
--处理点击事件
if ( e_MsgID == MSGID_CLICKED ) then

   if (e_CtrlID == CTRL_RADIO_BUTTON_01) then
     -- id可以进来,g_LicenseAgreementScreen_UpdateNextButton不能从灰色变高亮
     DlgButton.SetProperties(CTRL_BUTTON_NEXT, {Enabled = true});
     --需要重置控件
     Screen.SetFocus(CTRL_EDIT_01);
   end
   
   if (e_CtrlID == CTRL_RADIO_BUTTON_02) then
  DlgButton.SetProperties(CTRL_BUTTON_NEXT, {Enabled = false});
  --需要重置控件
  Screen.SetFocus(CTRL_EDIT_01);
   end
end

--处理键盘事件,添加了一个CTRL_EDIT_01不可见类型的控件支持的
if (e_MsgID == MSGID_ONCHANGED ) then
  local tEditProperty = DlgEditField.GetProperties (CTRL_EDIT_01);
  local strInputValue = tEditProperty.Text;
  --调试用
  --Debug.ShowWindow(true);
  --Debug.Print("enter key board str: "..strInputValue.."\n");
  local asciiCode = string.byte(strInputValue);
  if(asciiCode == nil) then -- 避免为nil报错
     asciiCode = 0;
   end
   --Debug.Print("enter key board value: "..asciiCode.."\n");
   --1). A,a按键被按下
   if(asciiCode == 65 or asciiCode == 97) then
     DlgButton.SetProperties(CTRL_BUTTON_NEXT, {Enabled = true});
     DlgRadioButton.SetProperties(CTRL_RADIO_BUTTON_01, {Checked = true});
     DlgRadioButton.SetProperties(CTRL_RADIO_BUTTON_02, {Checked = false});
   end
   
   -- 2). D,d按键被按下
   if(asciiCode == 68 or asciiCode == 100) then
    DlgButton.SetProperties(CTRL_BUTTON_NEXT, {Enabled = false});
    DlgRadioButton.SetProperties(CTRL_RADIO_BUTTON_01, {Checked = false});
    DlgRadioButton.SetProperties(CTRL_RADIO_BUTTON_02, {Checked = true});
   end
   
   -- 3).界面上的B,N,C按键的支持
   -- B,b按键
   if(asciiCode == 66 or asciiCode == 98) then
     Screen.Back();
   end
   
   -- enter被按下或N,n按键被按下,且下一步高亮时候
   local tButtonProperty = DlgButton.GetProperties(CTRL_BUTTON_NEXT);
   local bNDown = (asciiCode == 78 or asciiCode == 110);
   if((asciiCode == 13 or bNDown) and tButtonProperty.Enabled ) then
     Screen.Next();
   end
   
   -- C,c按键
   if(asciiCode == 67 or asciiCode == 99) then
     if g_ConfirmSetupAbort() then
   Application.Exit(EXIT_REASON_USER_ABORTED);
  end
   end
   
  --重置控件内容为空
  tEditProperty.Text = "";
  DlgEditField.SetProperties (CTRL_EDIT_01,  tEditProperty);
 
end

3.设置安装路径
-- These actions are performed before the screen is shown.
--用于捕获键盘事件
Screen.SetFocus(CTRL_EDIT_02);
--安装到默认空间最大的盘
function GetSpaceMaxDriver()
 local Drives = Drive.Enumerate();
 local nFindDriver = "";
 local nSpaceMax = 0;
 for key, value in pairs(Drives) do
  local nCurSpace = Drive.GetFreeSpace(value);
  if nSpaceMax == 0 then
   nSpaceMax = nCurSpace;
   nFindDriver = value;
  else
   if nSpaceMax < nCurSpace then
    nSpaceMax = nCurSpace;
    nFindDriver = value;
   end
  end
 end
 
 return nFindDriver;
end

--第一次才进来设置,后面返回的不再进行设置
local tEditProperty = DlgEditField.GetProperties (CTRL_EDIT_01);
if tEditProperty.Text == "" then
    tEditProperty.Text = GetSpaceMaxDriver();
 tEditProperty.Text = tEditProperty.Text..SessionVar.Expand("%ProductName%");
 DlgEditField.SetProperties(CTRL_EDIT_01, tEditProperty);
 --设置app安装的路径
 SessionVar.Set("%AppFolder%",tEditProperty.Text);
end


-- 选择路径对话框,浏览文件夹
local target_folder = Dialog.FolderBrowse("Select a Folder", "C:\\");
  -- 返回了正确的路径才更新
  if (target_folder ~= "CANCEL") and (target_folder ~= "") then
   local tEditProperty = DlgEditField.GetProperties (CTRL_EDIT_01);
   tEditProperty.Text = target_folder..SessionVar.Expand("%ProductName%");
   DlgEditField.SetProperties(CTRL_EDIT_01, tEditProperty);
   SessionVar.Set("%AppFolder%",tEditProperty.Text);
  end

你可能感兴趣的:(setup factory打包工具的使用)