Skip to content

Commit 894db6d

Browse files
committed
Fixes handling of directories with numbers. Fixes sbt#946
1 parent e1ee640 commit 894db6d

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/main/scala/com/typesafe/sbt/packager/windows/WixHelper.scala

+16-7
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ object WixHelper {
100100
val pathAddition =
101101
if (dir.isEmpty) "%" + homeEnvVar + "%"
102102
else "[INSTALLDIR]" + dir.replaceAll("\\/", "\\\\")
103-
val id = cleanStringForId(dir).takeRight(65) + "PathC"
103+
val id = cleanStringWithPostfix(dir, 64, "PathC")
104104
val guid = makeGUID
105105
val xml =
106106
<DirectoryRef Id={ dirRef }>
@@ -116,7 +116,7 @@ object WixHelper {
116116
val dir = parentDir(uname).replaceAll("//", "/").stripSuffix("/").stripSuffix("/")
117117
val dirRef = if (dir.isEmpty) "INSTALLDIR" else cleanStringForId(dir)
118118
val fname = simpleName(uname)
119-
val id = cleanStringForId(uname).takeRight(67) // Room for "fl_"
119+
val id = cleanStringWithPostfix(uname, 66, "") // Room for "fl_"
120120
val xml =
121121
<DirectoryRef Id={ dirRef }>
122122
<Component Id={ id } Guid={ makeGUID }>
@@ -140,7 +140,7 @@ object WixHelper {
140140
// that we remove all menu items.
141141
case AddShortCuts(targets, workingDir) =>
142142
val targetSize = targets.size.toString.size
143-
val id = cleanStringForId("shortcut_" + makeGUID).takeRight(67 - targetSize) // Room for "_SC"+incremental number
143+
val id = cleanStringWithPostfix("shortcut_" + makeGUID, 67 - targetSize, "") // Room for "_SC"+incremental number
144144
val xml =
145145
<DirectoryRef Id="ApplicationProgramsFolder">
146146
<Component Id={ id } Guid={ makeGUID }>
@@ -167,7 +167,7 @@ object WixHelper {
167167
}).toMap
168168

169169
val removeId =
170-
cleanStringForId("ApplicationProgramsFolderRemove").takeRight(67)
170+
cleanStringWithPostfix("ApplicationProgramsFolderRemove", 67, "")
171171
<xml:group>
172172
<!-- Define the directories we use -->
173173
<Directory Id='TARGETDIR' Name='SourceDir'>
@@ -228,7 +228,7 @@ object WixHelper {
228228
<Wix xmlns={ namespaceDefinitions.namespace } xmlns:util={ namespaceDefinitions.utilExtension }>
229229
<Product Id={ product.id } Name={ product.title } Language='1033' Version={ product.version } Manufacturer={ product.maintainer } UpgradeCode={ product.upgradeId }>
230230
<Package Description={ product.description } Comments={ product.comments } Manufacturer={ product.maintainer } InstallScope={ product.installScope } InstallerVersion={ product.installerVersion } Compressed={ if (product.compressed) "yes" else "no" }/>
231-
<Media Id='1' Cabinet={ cleanStringForId(name.toLowerCase).takeRight(66) + ".cab" } EmbedCab='yes'/>
231+
<Media Id='1' Cabinet={ cleanStringWithPostfix(name.toLowerCase, 65, ".cab") } EmbedCab='yes'/>
232232
{ rest }
233233
</Product>
234234
</Wix>
@@ -256,8 +256,17 @@ object WixHelper {
256256
* characters and replacing with _. Also limits the width to 70 (rather than
257257
* 72) so we can safely add a few later.
258258
*/
259-
def cleanStringForId(n: String) =
260-
n.replaceAll("[^0-9a-zA-Z_]", "_").takeRight(60) + (math.abs(n.hashCode).toString + "xxxxxxxxx").substring(0, 9)
259+
def cleanStringForId(n: String) = {
260+
val x = n.replaceAll("[^0-9a-zA-Z_]", "_").takeRight(59) + (math.abs(n.hashCode).toString + "xxxxxxxxx").substring(0, 9)
261+
if (x startsWith "_") x
262+
else "_" + x
263+
}
264+
265+
def cleanStringWithPostfix(n: String, num: Int, postfix: String): String = {
266+
val x = cleanStringForId(n).takeRight(num) + postfix
267+
if (x startsWith "_") x
268+
else "_" + x
269+
}
261270

262271
/** Cleans a file name for the Wix pre-processor. Every $ should be doubled. */
263272
def cleanFileName(n: String) =

0 commit comments

Comments
 (0)