<commit_before>[<AutoOpen>]
/// Contains tasks to create msi installers using the [WiX toolset](http://wixtoolset.org/)
module Fake.WiXHelper

open System
open System.IO

let mutable internal fileCount = 0
let mutable internal dirCount = 0

/// Creates a WiX File tag from the given FileInfo
let wixFile (fileInfo:FileInfo) =
    fileCount <- fileCount + 1
    sprintf "<File Id=\"fi_%d\" Name=\"%s\" Source=\"%s\" />" fileCount fileInfo.Name fileInfo.FullName

/// Creates WiX File tags from the given files
let getFilesAsWiXString files =
    files
      |> Seq.map (fileInfo >> wixFile)
      |> toLines

/// Creates recursive WiX directory and file tags from the given DirectoryInfo
let rec wixDir fileFilter asSubDir (directoryInfo:DirectoryInfo) =
    dirCount <- dirCount + 1
    let dirs =
      directoryInfo
        |> subDirectories
        |> Seq.map (wixDir fileFilter true)
        |> toLines

    let files =
      directoryInfo
        |> filesInDir
        |> Seq.filter fileFilter
        |> Seq.map wixFile
        |> toLines

    let compo =
      if files = "" then "" else
      sprintf "<Component Id=\"%s\" Guid=\"%s\">\r\n%s\r\n</Component>\r\n" directoryInfo.Name (Guid.NewGuid().ToString()) files

    if asSubDir then
        sprintf "<Directory Id=\"di_%d\" Name=\"%s\">\r\n%s%s\r\n</Directory>\r\n" dirCount directoryInfo.Name dirs compo
    else
        sprintf "%s%s" dirs compo

/// Creates WiX ComponentRef tags from the given DirectoryInfo
let rec wixComponentRefs (directoryInfo:DirectoryInfo) =
    let compos =
      directoryInfo
        |> subDirectories
        |> Seq.map wixComponentRefs
        |> toLines

    if (filesInDir directoryInfo).Length > 0 then sprintf "%s<ComponentRef Id=\"%s\"/>\r\n" compos directoryInfo.Name else compos

open System

/// WiX parameter type
type WiXParams = { 
      ToolDirectory: string
      TimeOut: TimeSpan
      AdditionalCandleArgs: string list<commit_msg>Make the WiX dirs unique<commit_after>[<AutoOpen>]
/// Contains tasks to create msi installers using the [WiX toolset](http://wixtoolset.org/)
module Fake.WiXHelper

open System
open System.IO
open System.Collections.Generic

let mutable internal fileCount = 0

let mutable internal dirs = Dictionary()

let dirName dir =
    match dirs.TryGetValue dir with
    | true,n -> dirs.[dir] <- n+1; dir + n.ToString()
    | _ -> dirs.[dir] <- 1; dir

let mutable internal compRefs = Dictionary()

let compRefName compRef =
    match compRefs.TryGetValue compRef with
    | true,n -> compRefs.[compRef] <- n+1; compRef + n.ToString()
    | _ -> compRefs.[compRef] <- 1; compRef

let mutable internal comps = Dictionary()

let compName comp =
    match comps.TryGetValue comp with
    | true,n -> comps.[comp] <- n+1; comp + n.ToString()
    | _ -> comps.[comp] <- 1; comp



/// Creates a WiX File tag from the given FileInfo
let wixFile (fileInfo:FileInfo) =
    fileCount <- fileCount + 1
    sprintf "<File Id=\"fi_%d\" Name=\"%s\" Source=\"%s\" />" fileCount fileInfo.Name fileInfo.FullName

/// Creates WiX File tags from the given files
let getFilesAsWiXString files =
    files
      |> Seq.map (fileInfo >> wixFile)
      |> toLines

/// Creates recursive WiX directory and file tags from the given DirectoryInfo
let rec wixDir fileFilter asSubDir (directoryInfo:DirectoryInfo) =
    let dirs =
      directoryInfo
        |> subDirectories
        |> Seq.map (wixDir fileFilter true)
        |> toLines

    let files =
      directoryInfo
        |> filesInDir
        |> Seq.filter fileFilter
        |> Seq.map wixFile
        |> toLines

    let compo =
      if files = "" then "" else
      sprintf "<Component Id=\"%s\" Guid=\"%s\">\r\n%s\r\n</Component>\r\n" (compName directoryInfo.Name) (Guid.NewGuid().ToString()) files

    if asSubDir then
        sprintf "<Directory Id=\"%s\" Name=\"%s\">\r\n%s%s\r\n</Directory>\r\n" (dirName directoryInfo.Name) directoryInfo.Name dirs compo
    else
        sprintf "%s%s" dirs compo

/// Creates WiX ComponentRef tags from the given DirectoryInfo
let rec wixComponentRefs (directoryInfo:DirectoryInfo) =
    let compos =
      directoryInfo
        |> subDirectories
        |> Seq.map wixComponentRefs
        |> toLines

    if (filesInDir directoryInfo).Length > 0 then sprintf "%s<ComponentRef Id=\"%s\"/>\r\n" compos (compRefName directoryInfo.Name) else compos

open System

/// WiX parameter type
type WiXParams = { 
      ToolDirectory: string
      TimeOut: TimeSpan
      AdditionalCandleArgs: string list
{'fraction_non_alphanumeric': 0.11662971175166297, 'fraction_numerical': 0.0031042128603104213, 'mean_word_length': 2.885443583118002, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2947572', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1395, 'n_words': 416}