Skip to content

Commit 2036092

Browse files
authored
Merge pull request #119 from knguyen99/InstallDirCustomization
add recursive functionality for finding INSTALLDIR
2 parents ed63b6f + e69da2e commit 2036092

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/com/inet/gradle/setup/msi/WxsFileBuilder.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ void build() throws Exception {
152152
Element directory = getOrCreateChildById( product, "Directory", "TARGETDIR" );
153153
addAttributeIfNotExists( directory, "Name", "SourceDir" );
154154
Element programFiles = getOrCreateChildById( directory, "Directory", task.is64Bit() ? "ProgramFiles64Folder" : "ProgramFilesFolder" );
155-
Element appDirectory = getOrCreateChildById( programFiles, "Directory", "INSTALLDIR" );
155+
Element appDirectory = getChildRecursive(programFiles, "Directory", "Id", "INSTALLDIR");
156+
if( appDirectory == null ) {
157+
appDirectory = getOrCreateChildById( programFiles, "Directory", "INSTALLDIR" );
158+
}
156159
addAttributeIfNotExists( appDirectory, "Name", setup.getApplication() );
157160

158161
//Files

src/com/inet/gradle/setup/util/XmlFileBuilder.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,28 @@ public Element getOrCreateChildByKeyValue( Node parent, String name, String key,
196196
return child;
197197
}
198198

199+
/**
200+
* Get a child element (recursive search).
201+
*
202+
* @param parent the parent node in which we search and create
203+
* @param name The tag name of the element
204+
* @param key the name of an attribute, can't be null
205+
* @param value the value, can be null for not existing
206+
* @return the foudn element or null
207+
*/
208+
public Element getChildRecursive( Node parent, String name, String key, String value) {
209+
if( name.equals( parent.getNodeName() ) ) {
210+
if( Objects.equals( value, ((Element)parent).getAttribute( key ) ) || (value == null && !((Element)parent).hasAttribute( key )) ) {
211+
return (Element)parent;
212+
}
213+
}
214+
215+
Node first = parent.getFirstChild();
216+
Element res = null;
217+
for( Node child = first; child != null && res == null; child = child.getNextSibling() ) {
218+
res = getChildRecursive(child, name, key, value);
219+
}
220+
return (Element)res;
221+
}
222+
199223
}

0 commit comments

Comments
 (0)