Skip to content

Commit cff289b

Browse files
committed
fix wix id
1 parent 82f6bd6 commit cff289b

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

xmake/plugins/pack/wix/main.lua

+26-19
Original file line numberDiff line numberDiff line change
@@ -106,25 +106,47 @@ function _get_cp_kind_table(package, cmds, opt)
106106
return result
107107
end
108108

109+
-- get id
110+
function _get_id(name)
111+
return "A" .. hash.uuid(name):gsub("-", ".")
112+
end
113+
114+
-- for each id/guid in the file wix want them to be unique
115+
-- so compute a hash for each directory based on the file that are inside
116+
function _get_dir_id(cp_table)
117+
local hashes = {}
118+
for dir, files in pairs(cp_table) do
119+
local s = ""
120+
for _, file in ipairs(files) do
121+
s = s .. table.concat(file, "")
122+
end
123+
-- wix required id to start with a letter and without any hyphen
124+
hashes[dir] = _get_id(s)
125+
end
126+
return hashes
127+
end
128+
129+
-- get custom commands
109130
function _get_other_commands(package, cmd, opt)
110131
opt = table.join(cmd.opt or {}, opt)
111132
local result = ""
112133
local kind = cmd.kind
134+
local id = _get_id()
113135
if kind == "rm" then
114136
local subdirectory = _translate_filepath(package, path.directory(cmd.filepath))
115137
subdirectory = subdirectory ~= "." and string.format([[Subdirectory="%s"]], subdirectory) or ""
116138
local on = opt.install and [[On="install"]] or [[On="uninstall"]]
117139
local filename = path.filename(cmd.filepath)
118-
result = string.format([[<RemoveFile Directory="INSTALLFOLDER" Name="%s" %s %s/>]], filename, subdirectory, on)
140+
result = string.format([[<RemoveFile Id="%s" Directory="INSTALLFOLDER" Name="%s" %s %s/>]], id, filename, subdirectory, on)
119141
elseif kind == "rmdir" then
120142
local dir = _translate_filepath(package, cmd.dir)
121143
local subdirectory = dir ~= "." and string.format([[Subdirectory="%s"]], dir) or ""
122144
local on = opt.install and [[On="install"]] or [[On="uninstall"]]
123-
result = string.format([[<RemoveFolder Directory="INSTALLFOLDER" %s %s/>]], subdirectory, on)
145+
result = string.format([[<RemoveFolder Id="%s" Directory="INSTALLFOLDER" %s %s/>]], id, subdirectory, on)
124146
elseif kind == "mkdir" then
125147
local dir = _translate_filepath(package, cmd.dir)
126148
local subdirectory = dir ~= "." and string.format([[Subdirectory="%s"]], dir) or ""
127-
result = string.format([[<CreateFolder Directory="INSTALLFOLDER" %s/>]], subdirectory)
149+
result = string.format([[<CreateFolder Id="%s" Directory="INSTALLFOLDER" %s/>]], id, subdirectory)
128150
elseif kind == "wix" then
129151
result = cmd.rawstr
130152
end
@@ -149,21 +171,6 @@ function _get_component_string(id, subdirectory)
149171
return string.format([[<Component Id="%s" Guid="%s" Directory="INSTALLFOLDER" %s>]], id:gsub("[ ()]", ""), hash.uuid(id), subdirectory)
150172
end
151173

152-
-- for each id/guid in the file wix want them to be unique
153-
-- so compute a hash for each directory based on the file that are inside
154-
function _get_dir_id(cp_table)
155-
local hashes = {}
156-
for dir, files in pairs(cp_table) do
157-
local s = ""
158-
for _, file in ipairs(files) do
159-
s = s .. table.concat(file, "")
160-
end
161-
-- wix required id to start with a letter and without any hyphen
162-
hashes[dir] = "A".. hash.uuid(s):gsub("-", ".")
163-
end
164-
return hashes
165-
end
166-
167174
-- build a feature from batchcmds
168175
function _build_feature(package, opt)
169176
opt = opt or {}
@@ -185,7 +192,7 @@ function _build_feature(package, opt)
185192
for _, file in ipairs(files) do
186193
local srcfile = file[1]
187194
local dstname = file[2]
188-
table.insert(result, string.format([[<File Source="%s" Name="%s"/>]], srcfile, dstname))
195+
table.insert(result, string.format([[<File Source="%s" Name="%s" Id="%s"/>]], srcfile, dstname, _get_id(srcfile .. dstname)))
189196
end
190197
table.insert(result, "</Component>")
191198
end

0 commit comments

Comments
 (0)