From 60b16964ace5bbd1314c490c0b44d20338f7bf1d Mon Sep 17 00:00:00 2001 From: A2va <49582555+A2va@users.noreply.github.com> Date: Sun, 25 Feb 2024 21:33:53 +0100 Subject: Xpack: wix toolset --- xmake/scripts/xpack/wix/msi.wxs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 xmake/scripts/xpack/wix/msi.wxs (limited to 'xmake/scripts') diff --git a/xmake/scripts/xpack/wix/msi.wxs b/xmake/scripts/xpack/wix/msi.wxs new file mode 100644 index 000000000..1860df810 --- /dev/null +++ b/xmake/scripts/xpack/wix/msi.wxs @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${PACKAGE_INSTALLCMDS} + + + \ No newline at end of file -- cgit v1.3.1 From de6b4494189ef2975d47450290f5618e65c11b21 Mon Sep 17 00:00:00 2001 From: A2va <49582555+A2va@users.noreply.github.com> Date: Wed, 6 Mar 2024 22:44:55 +0100 Subject: Split cp kind and other ones --- xmake/plugins/pack/wix/main.lua | 68 ++++++++++++++++++++++++++++++----------- xmake/scripts/xpack/wix/msi.wxs | 4 +++ 2 files changed, 55 insertions(+), 17 deletions(-) (limited to 'xmake/scripts') diff --git a/xmake/plugins/pack/wix/main.lua b/xmake/plugins/pack/wix/main.lua index acfd9ce83..51c3c1323 100644 --- a/xmake/plugins/pack/wix/main.lua +++ b/xmake/plugins/pack/wix/main.lua @@ -50,13 +50,17 @@ function _get_wix() return wix, oldenvs end --- get command string -function _get_command_strings(package, cmd, opt) +-- translate the file path +function _translate_filepath(package, filepath) + return path.relative(filepath, package:install_rootdir()) +end + +function _get_cp_command(package, cmd, opt) opt = table.join(cmd.opt or {}, opt) local result = {} local kind = cmd.kind + if kind == "cp" then - -- https://nsis.sourceforge.io/Reference/File local srcfiles = os.files(cmd.srcpath) for _, srcfile in ipairs(srcfiles) do -- the destination is directory? append the filename @@ -71,7 +75,7 @@ function _get_command_strings(package, cmd, opt) srcfile = path.normalize(srcfile) local dstname = path.filename(dstfile) local dstdir = path.normalize(path.directory(dstfile)) - local relative_dstdir = path.relative(dstdir, package:install_rootdir()) + local relative_dstdir = _translate_filepath(package, dstdir) local subdirectory = dstdir ~= package:install_rootdir() and string.format([[Subdirectory="%s"]], relative_dstdir) or "" local component_string = string.format([["]], dstname, subdirectory) @@ -81,27 +85,45 @@ function _get_command_strings(package, cmd, opt) table.insert(result, file_string) table.insert(result, "") end - elseif kind == "rm" then - wprint("rm kind is not supported") + end + return result +end + +function _get_other_commands(package, cmd, opt) + opt = table.join(cmd.opt or {}, opt) + local result = {} + local kind = cmd.kind + + if kind == "rm" then + local filepath = _translate_filepath(package, cmd.filepath) + local subdirectory = cmd.filepath ~= package:install_rootdir() and string.format([[Subdirectory="%s"]], filepath) or "" + local on = opt.install and [[On="install"]] or [[On="uninstall"]] + + local remove_file = string.format([[]], subdirectory, on) + table.insert(result, remove_file) elseif kind == "rmdir" then - wprint("rmdir kind is not supported") - elseif kind == "mv" then - wprint("mv kind is not supported") - elseif kind == "cd" then - wprint("cd kind is not supported") + local dir = _translate_filepath(package, cmd.dir) + local subdirectory = cmd.dir ~= package:install_rootdir() and string.format([[Subdirectory="%s"]], dir) or "" + local on = opt.install and [[On="install"]] or [[On="uninstall"]] + + local remove_dir = string.format([[]], subdirectory, on) + table.insert(result, remove_dir) elseif kind == "mkdir" then - wprint("mkdir kind is not supported") - elseif kind == "wix" then - wprint("wix kind is not supported") + local dir = _translate_filepath(package, cmd.dir) + local subdirectory = cmd.dir ~= package:install_rootdir() and string.format([[Subdirectory="%s"]], dir) or "" + local make_dir = string.format([[]], subdirectory) + table.insert(result, make_dir) + else + wprint("kind %s is not supported with wix", kind) end return result end -- get commands string -function _get_commands_string(package, cmds, opt) +function _get_commands_string(package, cmds, opt, func) local cmdstrs = {} for _, cmd in ipairs(cmds) do - table.join2(cmdstrs, _get_command_strings(package, cmd, opt)) + table.join2(cmdstrs, func(package, cmd, opt)) end return table.concat(cmdstrs, "\n ") end @@ -128,9 +150,21 @@ end -- get specvars function _get_specvars(package) + local specvars = table.clone(package:specvars()) + -- install + local installcmds = batchcmds.get_installcmds(package):cmds() specvars.PACKAGE_INSTALLCMDS = function () - return _get_installcmds(package) + return _get_commands_string(package, installcmds, {install = true}, _get_cp_command) + end + specvars.PACKAGE_WIX_FILE_OPERATION_INSTALL = function () + return _get_commands_string(package, installcmds, {install = true}, _get_other_commands) + end + + -- uninstall + local uninstallcmds = batchcmds.get_uninstallcmds(package):cmds() + specvars.PACKAGE_WIX_FILE_OPERATION_UNINSTALL = function () + return _get_commands_string(package, uninstallcmds, {install = false}, _get_other_commands) end specvars.PACKAGE_WIX_UPGRADECODE = hash.uuid(package:name()) diff --git a/xmake/scripts/xpack/wix/msi.wxs b/xmake/scripts/xpack/wix/msi.wxs index 1860df810..79a5f1de6 100644 --- a/xmake/scripts/xpack/wix/msi.wxs +++ b/xmake/scripts/xpack/wix/msi.wxs @@ -30,6 +30,10 @@ + + ${PACKAGE_WIX_FILE_OPERATION_INSTALL} + ${PACKAGE_WIX_FILE_OPERATION_UNINSTALL} + ${PACKAGE_INSTALLCMDS} -- cgit v1.3.1 From 920d1187fa5392fa2363b170a202cb63e75d1c08 Mon Sep 17 00:00:00 2001 From: A2va <49582555+A2va@users.noreply.github.com> Date: Thu, 14 Mar 2024 23:00:43 +0100 Subject: Refactor cp cmd to output a better xml --- xmake/plugins/pack/wix/main.lua | 112 ++++++++++++++++++++++------------------ xmake/scripts/xpack/wix/msi.wxs | 10 +--- 2 files changed, 63 insertions(+), 59 deletions(-) (limited to 'xmake/scripts') diff --git a/xmake/plugins/pack/wix/main.lua b/xmake/plugins/pack/wix/main.lua index 51c3c1323..466f58405 100644 --- a/xmake/plugins/pack/wix/main.lua +++ b/xmake/plugins/pack/wix/main.lua @@ -55,19 +55,23 @@ function _translate_filepath(package, filepath) return path.relative(filepath, package:install_rootdir()) end -function _get_cp_command(package, cmd, opt) - opt = table.join(cmd.opt or {}, opt) - local result = {} - local kind = cmd.kind +-- get a table where the key is a directory and the value a list of files +function _get_cp_kind_table(package, cmds, opt) - if kind == "cp" then + local result = {} + for _, cmd in ipairs(cmds) do + if cmd.kind ~= "cp" then + goto continue + end + + local option = table.join(cmd.opt or {}, opt) local srcfiles = os.files(cmd.srcpath) for _, srcfile in ipairs(srcfiles) do -- the destination is directory? append the filename local dstfile = cmd.dstpath if #srcfiles > 1 or path.islastsep(dstfile) then - if opt.rootdir then - dstfile = path.join(dstfile, path.relative(srcfile, opt.rootdir)) + if option.rootdir then + dstfile = path.join(dstfile, path.relative(srcfile, option.rootdir)) else dstfile = path.join(dstfile, path.filename(srcfile)) end @@ -75,16 +79,15 @@ function _get_cp_command(package, cmd, opt) srcfile = path.normalize(srcfile) local dstname = path.filename(dstfile) local dstdir = path.normalize(path.directory(dstfile)) - local relative_dstdir = _translate_filepath(package, dstdir) - - local subdirectory = dstdir ~= package:install_rootdir() and string.format([[Subdirectory="%s"]], relative_dstdir) or "" - local component_string = string.format([["]], dstname, subdirectory) - local file_string = string.format([[]], srcfile, dstname) + dstdir = _translate_filepath(package, dstdir) - table.insert(result, component_string) - table.insert(result, file_string) - table.insert(result, "") + if result[dstdir] then + table.insert(result[dstdir], {srcfile, dstname}) + else + result[dstdir] = {{srcfile, dstname}} + end end + ::continue:: end return result end @@ -119,53 +122,60 @@ function _get_other_commands(package, cmd, opt) return result end --- get commands string -function _get_commands_string(package, cmds, opt, func) - local cmdstrs = {} - for _, cmd in ipairs(cmds) do - table.join2(cmdstrs, func(package, cmd, opt)) - end - return table.concat(cmdstrs, "\n ") +function _get_feature_string(name, opt) + local level = opt.default and 1 or 0 + local description = opt.description or "" + local allow_absent = opt.force and "false" or "true" + local allow_advertise = opt.force and "false" or "true" + local typical_default = opt.force and [[TypicalDefault=install"]] or "" + local feature = string.format([[]], name, name, description, level, allow_advertise, allow_absent, typical_default) + return feature end --- get install commands -function _get_installcmds(package) - return _get_commands_string(package, batchcmds.get_installcmds(package):cmds(), {install = true}) -end +function _get_component_string(id, subdirectory) + local subdirectory = (subdirectory ~= ".") and string.format([[Subdirectory="%s"]], subdirectory) or "" + return string.format([[]], id, hash.uuid(id), subdirectory) +end --- get uninstall commands -function _get_uninstallcmds(package) - return _get_commands_string(package, batchcmds.get_uninstallcmds(package):cmds(), {install = false}) -end +function _build_feature(package, opt) + opt = opt or {} + local default = opt.default or package:get("default") --- get install commands of component -function _get_component_installcmds(component) - return _get_commands_string(component, batchcmds.get_installcmds(component):cmds(), {install = true}) -end + local result = {} + table.insert(result, _get_feature_string(package:title(), {default = default, force = opt.force, description = package:description()})) --- get uninstall commands of component -function _get_component_uninstallcmds(component) - return _get_commands_string(component, batchcmds.get_uninstallcmds(component):cmds(), {install = false}) -end + local installcmds = batchcmds.get_installcmds(package):cmds() + local uninstallcmds = batchcmds.get_uninstallcmds(package):cmds() + + local cp_table = _get_cp_kind_table(package, installcmds, opt) + + for dir, files in pairs(cp_table) do + local d = path.join(package:install_rootdir(), dir) + table.insert(result, _get_component_string(d:gsub(path.sep(), "_"), dir)) + for _, file in ipairs(files) do + local srcfile = file[1] + local dstname = file[2] + table.insert(result, string.format([[]], srcfile, dstname)) + end + table.insert(result, "") + end + + table.insert(result, _get_component_string("OtherCmds")) + table.insert(result, "") + table.insert(result, "") + return result +end -- get specvars function _get_specvars(package) - local specvars = table.clone(package:specvars()) - -- install local installcmds = batchcmds.get_installcmds(package):cmds() - specvars.PACKAGE_INSTALLCMDS = function () - return _get_commands_string(package, installcmds, {install = true}, _get_cp_command) - end - specvars.PACKAGE_WIX_FILE_OPERATION_INSTALL = function () - return _get_commands_string(package, installcmds, {install = true}, _get_other_commands) - end + local specvars = table.clone(package:specvars()) - -- uninstall - local uninstallcmds = batchcmds.get_uninstallcmds(package):cmds() - specvars.PACKAGE_WIX_FILE_OPERATION_UNINSTALL = function () - return _get_commands_string(package, uninstallcmds, {install = false}, _get_other_commands) - end + local features = {} + table.join2(features, _build_feature(package, {default = true, force = true})) + + specvars.PACKAGE_CMDS = table.concat(features, "\n ") specvars.PACKAGE_WIX_UPGRADECODE = hash.uuid(package:name()) diff --git a/xmake/scripts/xpack/wix/msi.wxs b/xmake/scripts/xpack/wix/msi.wxs index 79a5f1de6..0e4727117 100644 --- a/xmake/scripts/xpack/wix/msi.wxs +++ b/xmake/scripts/xpack/wix/msi.wxs @@ -22,19 +22,13 @@ - + - - - ${PACKAGE_WIX_FILE_OPERATION_INSTALL} - ${PACKAGE_WIX_FILE_OPERATION_UNINSTALL} - - ${PACKAGE_INSTALLCMDS} - + ${PACKAGE_CMDS} \ No newline at end of file -- cgit v1.3.1 From cd3b9b037ece3d8dce7711f4143351733ce2a2ba Mon Sep 17 00:00:00 2001 From: A2va <49582555+A2va@users.noreply.github.com> Date: Wed, 8 May 2024 13:36:40 +0200 Subject: Fixes --- xmake/plugins/pack/wix/main.lua | 6 +++--- xmake/scripts/xpack/wix/msi.wxs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'xmake/scripts') diff --git a/xmake/plugins/pack/wix/main.lua b/xmake/plugins/pack/wix/main.lua index 5455b7cfc..403ccca3e 100644 --- a/xmake/plugins/pack/wix/main.lua +++ b/xmake/plugins/pack/wix/main.lua @@ -125,7 +125,7 @@ function _get_feature_string(name, opt) local description = opt.description or "" local allow_absent = opt.force and "false" or "true" local allow_advertise = opt.force and "false" or "true" - local typical_default = opt.force and [[TypicalDefault="install"]] or "" + local typical_default = [[TypicalDefault="install"]] local directory = opt.config_dir and [[ConfigurableDirectory="INSTALLFOLDER"]] or "" local feature = string.format([[]], name, name, description, level, allow_advertise, allow_absent, typical_default, directory) return feature @@ -179,7 +179,7 @@ function _add_to_path(package) local result = {} table.insert(result, _get_feature_string("PATH", {default = false, force = false, description = "Add to PATH"})) table.insert(result, _get_component_string("PATH")) - table.insert(result, [[]]) + table.insert(result, [[]]) table.insert(result, "") table.insert(result, "") return result @@ -199,7 +199,7 @@ function _get_specvars(package) table.join2(features, _build_feature(component, {name = "Install " .. name})) end - specvars.PACKAGE_CMDS = table.concat(features, "\n ") + specvars.PACKAGE_WIX_CMDS = table.concat(features, "\n ") specvars.PACKAGE_WIX_UPGRADECODE = hash.uuid(package:name()) -- company cannot be empty with wix diff --git a/xmake/scripts/xpack/wix/msi.wxs b/xmake/scripts/xpack/wix/msi.wxs index 0e4727117..6bbab6457 100644 --- a/xmake/scripts/xpack/wix/msi.wxs +++ b/xmake/scripts/xpack/wix/msi.wxs @@ -29,6 +29,6 @@ - ${PACKAGE_CMDS} + ${PACKAGE_WIX_CMDS} \ No newline at end of file -- cgit v1.3.1 From ec28f1ef6eddce80c7cd86f1e57a19532d3e681c Mon Sep 17 00:00:00 2001 From: A2va <49582555+A2va@users.noreply.github.com> Date: Wed, 8 May 2024 14:53:25 +0200 Subject: Handle license --- xmake/plugins/pack/wix/main.lua | 27 ++++++++++++++++++++++++++- xmake/scripts/xpack/wix/msi.wxs | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'xmake/scripts') diff --git a/xmake/plugins/pack/wix/main.lua b/xmake/plugins/pack/wix/main.lua index 403ccca3e..938cb424f 100644 --- a/xmake/plugins/pack/wix/main.lua +++ b/xmake/plugins/pack/wix/main.lua @@ -55,6 +55,20 @@ function _translate_filepath(package, filepath) return path.relative(filepath, package:install_rootdir()) end +function _to_rtf_string(str) + if str == "" then + return str + end + + local escape_text = str:gsub("\\", "\\\\") + escape_text = escape_text:gsub("{", "\\{") + escape_text = escape_text:gsub("}", "\\}") + + local rtf = "{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard "; + rtf = rtf .. escape_text:gsub("\r\n", " \\par ") .. "}" + return rtf +end + -- get a table where the key is a directory and the value a list of files -- used to regroup all files that are placed in the same directory under the same component. function _get_cp_kind_table(package, cmds, opt) @@ -199,6 +213,18 @@ function _get_specvars(package) table.join2(features, _build_feature(component, {name = "Install " .. name})) end + specvars.PACKAGE_LICENSEFILE = function () + local rtf_string = "" + local licensefile = package:get("licensefile") + if licensefile then + rtf_string = _to_rtf_string(io.readfile(licensefile)) + end + + local rtf_file = path.join(package:buildir(), "license.rtf") + io.writefile(rtf_file, rtf_string) + return rtf_file + end + specvars.PACKAGE_WIX_CMDS = table.concat(features, "\n ") specvars.PACKAGE_WIX_UPGRADECODE = hash.uuid(package:name()) @@ -257,7 +283,6 @@ function main(package) end cprint("packing %s", package:outputfile()) - -- get wix local wix, oldenvs = _get_wix() diff --git a/xmake/scripts/xpack/wix/msi.wxs b/xmake/scripts/xpack/wix/msi.wxs index 6bbab6457..82ec2e88a 100644 --- a/xmake/scripts/xpack/wix/msi.wxs +++ b/xmake/scripts/xpack/wix/msi.wxs @@ -23,6 +23,7 @@ + -- cgit v1.3.1 From 28322db9b0c5ccee35c1445dfc567bea0d8ff072 Mon Sep 17 00:00:00 2001 From: A2va <49582555+A2va@users.noreply.github.com> Date: Fri, 24 May 2024 18:13:50 +0200 Subject: Add icon banner Then file icon is not working --- xmake/scripts/xpack/wix/msi.wxs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'xmake/scripts') diff --git a/xmake/scripts/xpack/wix/msi.wxs b/xmake/scripts/xpack/wix/msi.wxs index 82ec2e88a..dda4978a7 100644 --- a/xmake/scripts/xpack/wix/msi.wxs +++ b/xmake/scripts/xpack/wix/msi.wxs @@ -20,7 +20,11 @@ - + + + + + -- cgit v1.3.1