diff options
| author | ruki <[email protected]> | 2023-11-15 23:39:08 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-11-15 23:39:08 +0800 |
| commit | 355df6fd41db138b340dee56248f8c3fe0dcc75f (patch) | |
| tree | cb65f33b54de72ad3e275060437dd10c37c6ae98 | |
| parent | 3e5f3c41e0eebf9103118b5127a0b78f5df6873f (diff) | |
add nsis sections
| -rw-r--r-- | tests/plugins/pack/xmake.lua | 8 | ||||
| -rw-r--r-- | xmake/includes/xpack/xmake.lua | 9 | ||||
| -rw-r--r-- | xmake/plugins/pack/nsis/main.lua | 37 | ||||
| -rw-r--r-- | xmake/scripts/xpack/nsis/makensis.nsi | 4 |
4 files changed, 54 insertions, 4 deletions
diff --git a/tests/plugins/pack/xmake.lua b/tests/plugins/pack/xmake.lua index 94ad97409..f964d58bc 100644 --- a/tests/plugins/pack/xmake.lua +++ b/tests/plugins/pack/xmake.lua @@ -26,12 +26,20 @@ xpack("test") set_basename("test-$(plat)-$(arch)-v$(version)") add_installfiles("src/(assets/*.png)", {prefixdir = "images"}) set_iconfile("src/assets/xmake.ico") + after_installcmd(function (package, batchcmds) batchcmds:cp("src/assets/*.txt", "resources/", {rootdir = "src"}) batchcmds:mkdir("stub") end) + after_uninstallcmd(function (package, batchcmds) batchcmds:rmdir("resources") batchcmds:rmdir("stub") end) + add_nsis_sections("Enable Long Path", [[ + ${If} $NoAdmin == "false" + ; Enable long path + WriteRegDWORD ${HKLM} "SYSTEM\CurrentControlSet\Control\FileSystem" "LongPathsEnabled" 1 + ${EndIf}]], {description = "Increases the maximum path length limit, up to 32,767 characters (before 256)."}) + diff --git a/xmake/includes/xpack/xmake.lua b/xmake/includes/xpack/xmake.lua index 5314e90ea..a8ce5f0fb 100644 --- a/xmake/includes/xpack/xmake.lua +++ b/xmake/includes/xpack/xmake.lua @@ -79,7 +79,14 @@ local apis = { }, keyvalues = { -- set the spec variable - "xpack.set_specvar" + "xpack.set_specvar", + -- add nsis sections, e.g. + --[[ + add_nsis_sections("Enable Long Path", + 'WriteRegDWORD ${HKLM} "SYSTEM\CurrentControlSet\Control\FileSystem" "LongPathsEnabled" 1', + {description = "Increases the maximum path length limit, up to 32,767 characters (before 256)."}) + --]] + "xpack.add_nsis_sections" } } interp_add_scopeapis(apis) diff --git a/xmake/plugins/pack/nsis/main.lua b/xmake/plugins/pack/nsis/main.lua index 2925eb82e..ada5b667c 100644 --- a/xmake/plugins/pack/nsis/main.lua +++ b/xmake/plugins/pack/nsis/main.lua @@ -53,8 +53,10 @@ function _get_makensis() return makensis, oldenvs end --- copy files or directories and we can reserve the source directory structure --- e.g. os.cp("src/**.h", "/tmp/", {rootdir = "src", symlink = true}) +-- get unique tag +function _get_unique_tag(content) + return hash.uuid(content):split("-", {plain = true})[1]:lower() +end -- get command string function _get_command_strings(package, cmd) @@ -92,7 +94,7 @@ function _get_command_strings(package, cmd) file_not_found_or_end: --]] local filepath = path.normalize(path.join("$InstDir", cmd.filepath)) - local tag = hash.uuid(filepath):split("-", {plain = true})[1]:lower() + local tag = _get_unique_tag(filepath) table.insert(result, string.format("IfFileExists \"%s\" file_found_%s file_not_found_or_end_%s", filepath, tag, tag)) table.insert(result, string.format("file_found_%s:", tag)) table.insert(result, string.format(" Delete \"%s\"", filepath)) @@ -533,6 +535,35 @@ function _get_specvars(package) specvars.PACKAGE_UNINSTALLCMDS = function () return _get_uninstallcmds(package) end + specvars.PACKAGE_NSIS_SECTIONS = function () + local result = {} + local sections = package:get("nsis_sections") + for name, section in pairs(sections) do + local tag = _get_unique_tag(name) + table.insert(result, string.format('Section "%s" %s', name, tag)) + table.insert(result, section) + table.insert(result, "SectionEnd") + end + return table.concat(result, "\n ") + end + specvars.PACKAGE_NSIS_DESCS = function () + local result = {} + local sections = package:get("nsis_sections") + for name, section in pairs(sections) do + local tag = _get_unique_tag(name) + table.insert(result, string.format('LangString DESC_%s ${LANG_ENGLISH} "%s"', tag, name)) + end + return table.concat(result, "\n ") + end + specvars.PACKAGE_NSIS_DESCRIPTION_TEXTS = function () + local result = {} + local sections = package:get("nsis_sections") + for name, section in pairs(sections) do + local tag = _get_unique_tag(name) + table.insert(result, string.format('!insertmacro MUI_DESCRIPTION_TEXT ${%s} $(DESC_%s)', tag, tag)) + end + return table.concat(result, "\n ") + end return specvars end diff --git a/xmake/scripts/xpack/nsis/makensis.nsi b/xmake/scripts/xpack/nsis/makensis.nsi index cbe70366f..d201a655e 100644 --- a/xmake/scripts/xpack/nsis/makensis.nsi +++ b/xmake/scripts/xpack/nsis/makensis.nsi @@ -247,14 +247,18 @@ Section "Add to PATH" InstallPath SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000 SectionEnd +${PACKAGE_NSIS_SECTIONS} + ; define language strings LangString DESC_InstallExeutable ${LANG_ENGLISH} "${PACKAGE_DESCRIPTION}" LangString DESC_InstallPath ${LANG_ENGLISH} "Add ${PACKAGE_NAME} to PATH" +${PACKAGE_NSIS_DESCS} ; assign language strings to sections !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN !insertmacro MUI_DESCRIPTION_TEXT ${InstallExeutable} $(DESC_InstallExeutable) !insertmacro MUI_DESCRIPTION_TEXT ${InstallPath} $(DESC_InstallPath) +${PACKAGE_NSIS_DESCRIPTION_TEXTS} !insertmacro MUI_FUNCTION_DESCRIPTION_END ; setup uninstaller |
