Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed two bugs #32

Merged
merged 1 commit into from
Sep 3, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ trait GenericPackageSettings
} yield ComponentFile(name, editable = (name startsWith "conf"))
val corePackage =
WindowsFeature(
id=WixHelper.cleanStringForId(name+"_core"),
id=WixHelper.cleanStringForId(name + "_core").takeRight(38), // Must be no longer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I thought the cleanStringForId would takeRight in the past... In any case, great catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

title=name,
desc="All core files.",
absent="disallow",
Expand Down
46 changes: 27 additions & 19 deletions src/main/scala/com/typesafe/sbt/packager/windows/WixHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,32 @@ case class AddShortCuts(
object WixHelper {
/** Generates a windows friendly GUID for use in random locations in the build. */
def makeGUID: String = java.util.UUID.randomUUID.toString

// TODO - Fragment out this function a bit so it's not so ugly/random.
def makeWixProductConfig(name: String, product: WindowsProductInfo, features: Seq[WindowsFeature], license: Option[File] = None): scala.xml.Node = {
// TODO - First we find directories...
val filenames =
// Adds all subdirectories... there was a bug when there were directories with only subdirs and no files in the tree,
// so there was a gap and dirXml failed to create some directories
def allParentDirs(f: File): Seq[File] = if(f == null) Seq() else Seq(f) ++ allParentDirs(f.getParentFile)
val filenamesPrep =
for {
f <- features
ComponentFile(name, _) <- f.components
} yield name.replaceAll("\\\\","/")
} yield allParentDirs(file(name))
val filenames = filenamesPrep.flatten.map(_.toString.replaceAll("\\\\","/")).filter(_ != "")
// Now for directories...
def parentDir(filename: String) = filename take (filename lastIndexOf '/')
def parentDir(filename: String) = {/*println("xxxxxxxxxxx: " + (filename take (filename lastIndexOf '/')));*/ filename take (filename lastIndexOf '/') }
def simpleName(filename: String) = {
val lastSlash = filename lastIndexOf '/'
filename drop (lastSlash + 1)
}
val dirs = (filenames map parentDir).distinct
val dirs = (filenames map parentDir).distinct;
// TODO println("DDDDDDDDDDDDDDD:" + dirs.toString)
// Now we need our directory tree xml?
val dirToChilren = dirs groupBy parentDir
def dirXml(currentDir: String): scala.xml.Node = if(!currentDir.isEmpty){
val children = dirToChilren.getOrElse(currentDir, Seq.empty)
val dirToChildren = dirs groupBy parentDir;
// TODO println("CCCCCCCCCCCCCCC:" + dirToChildren.toString)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remove the commented out printlns after merge would that bug you?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops..

def dirXml(currentDir: String): scala.xml.Node = if(!currentDir.isEmpty) {
val children = dirToChildren.getOrElse(currentDir, Seq.empty)
<Directory Id={cleanStringForId(currentDir)} Name={simpleName(currentDir)}>
{
children map dirXml
Expand All @@ -88,7 +94,7 @@ object WixHelper {
val pathAddition =
if(dir.isEmpty) "%"+homeEnvVar+"%"
else "[INSTALLDIR]\\"+dir.replaceAll("\\/", "\\\\")
val id = cleanStringForId(dir) + "PathC"
val id = cleanStringForId(dir).takeRight(65) + "PathC"
val guid = makeGUID
val xml =
<DirectoryRef Id={dirRef}>
Expand All @@ -104,11 +110,11 @@ object WixHelper {
val dir = parentDir(uname)
val dirRef = if(dir.isEmpty) "INSTALLDIR" else cleanStringForId(dir)
val fname = simpleName(uname)
val id = cleanStringForId(uname)
val id = cleanStringForId(uname).takeRight(67) // Room for "fl_"
val xml =
<DirectoryRef Id={dirRef}>
<Component Id={id} Guid={makeGUID}>
<File Id={"file_" + id} Name={cleanFileName(fname)} DiskId='1' Source={cleanFileName(uname)}>
<File Id={"fl_" + id} Name={cleanFileName(fname)} DiskId='1' Source={cleanFileName(uname)}>
{
if(editable) {
<xml:group>
Expand All @@ -122,15 +128,15 @@ object WixHelper {
</DirectoryRef>
ComponentInfo(id, xml)
case AddShortCuts(targets, workingDir) =>
val id = cleanStringForId("shortcut_"+makeGUID)
val id = cleanStringForId("shortcut_" + makeGUID).takeRight(67) // Room for "_SC"
val xml =
<DirectoryRef Id="ApplicationProgramsFolder">
<Component Id={id} Guid={makeGUID}>
{
for(target <- targets) yield {
val name = simpleName(target)
val desc = "Edit configuration file: " + name
<Shortcut Id={id+"_Shortcut"}
<Shortcut Id={id+"_SC"}
Name={name}
Description={desc}
Target={"[INSTALLDIR]\\" + target.replaceAll("\\/", "\\\\")}
Expand Down Expand Up @@ -161,7 +167,7 @@ object WixHelper {
</Directory>
<Directory Id='ProgramFilesFolder' Name='PFiles'>
<Directory Id='INSTALLDIR' Name={name}>
{dirToChilren("") map dirXml}
{dirToChildren("") map dirXml}
</Directory>
</Directory>
</Directory>
Expand Down Expand Up @@ -218,17 +224,19 @@ object WixHelper {
InstallScope={product.installScope}
InstallerVersion={product.installerVersion}
Compressed={if(product.compressed) "yes" else "no"} />
<Media Id='1' Cabinet={cleanStringForId(name.toLowerCase)+".cab"} EmbedCab='yes' />
<Media Id='1' Cabinet={cleanStringForId(name.toLowerCase).takeRight(66)+".cab"} EmbedCab='yes' />
{rest}
</Product>
</Wix>
}
/** Modifies a string to be Wix ID friendly by removing all the bad

/** Modifies a string to be Wix ID friendly by removing all the bad
* characters and replacing with _. Also limits the width to 70 (rather than
* 72) so we can safely add a few later. We assume that's unique enough.
* 72) so we can safely add a few later.
*/
def cleanStringForId(n: String) = n.replaceAll("[^0-9a-zA-Z_]", "_").takeRight(70)
def cleanStringForId(n: String) = {
n.replaceAll("[^0-9a-zA-Z_]", "_").takeRight(50) + (math.abs(n.hashCode).toString + "xxxxxxxxxxxxxxxxxxx").substring(0, 19)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use a formatter: "%20x".format(math.abs(n.hashCode)) if you wanted here. Otherwise, looks great!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, nicer.
It just occured to me that abs(hashCode).toString can not be longer than 10 chars. So takeRight(60) and substring(0, 9) is enough. Though it shouldn't hurt this way...

}

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