<commit_before>
# See https://blogs.msdn.microsoft.com/vcblog/2016/02/16/\
#try-out-the-latest-c-compiler-toolset-without-waiting-for-the-next-update-of-visual-studio/


$ClangbuilderRoot = Split-Path $PSScriptRoot
$ViusalCppAtomURL = "https://visualcpp.myget.org/F/dailymsvc/api/v2"
$VisualCppToolsInstallDir = "$ClangbuilderRoot\utils\msvc"

$NuGetDir = "$ClangbuilderRoot\pkgs\Nuget"

$env:PATH = "$NuGetDir;${env:PATH}"

Push-Location $PWD

if (!(Test-Path $VisualCppToolsInstallDir)) {
    New-Item -Force -ItemType Directory $VisualCppToolsInstallDir 
}

Set-Location $VisualCppToolsInstallDir

Function CompareVersion() {
    param(
        [String]$Pre,
        [String]$Next
    )

}

$xmlfeed = $null
try {
    $xmlfeed = [xml](Invoke-WebRequest -UseBasicParsing -Uri "$ViusalCppAtomURL/Packages").Content
}
catch {
    Write-Host -Forceground Red "Checking VisualCpp Feed $_"
    exit 1
}


$VisualCppPackageName = $null
$VisualCppToolsVersion = $null

if ($xmlfeed.feed.entry.GetType().IsArray) {
    [int]$index = 0;
    [int]$mindex = 0;
    [int]$build = 1;
    foreach ($_ in $xmlfeed.feed.entry) {
        $version = $_.properties.Version.Split("-")[0]; # 14.11.25615-Pre
        $ver = [System.Version]::Parse($version)
        if ($ver.build -gt $build) {
            $build = $ver.build
            $mindex = $index
        }
        $index++
    }
    $VisualCppPackageName = $xmlfeed.feed.entry[$mindex].title.'#text'
    $VisualCppToolsVersion = $xmlfeed.feed.entry[$mindex].properties.Version
}
else {
    $VisualCppPackageName = $xmlfeed.feed.entry.title.'#text'
    $VisualCppToolsVersion = $xmlfeed.feed.entry.properties.Version
}

Write-Output "Latest $VisualCppPackageName version is $VisualCppToolsVersion"
if ((Test-Path "$VisualCppToolsInstallDir/VisualCppTools.lock.json")) {
    $Pkglock = Get-Content "$VisualCppToolsInstallDir/VisualCppTools.lock.json" |ConvertFrom-Json
    if ($Pkglock.Version -eq $VisualCppToolsVersion) {
        Write-Host "VisualCppTools is up to date, Version: $VisualCppToolsVersion"
        return ;
    }
}


Write-Output "NuGet Install $VisualCppPackageName $VisualCppToolsVersion ......"

&nuget install $VisualCppPackageName -Source $ViusalCppAtomURL -Prerelease

if ((Test-Path "$VisualCppToolsInstallDir\$VisualCppPackageName.$VisualCppToolsVersion")) {
    $vccache = @{}
    $vccache["Name"] = $VisualCppPackageName
    $vccache["Version"] = $VisualCppToolsVersion
    $vccache["Path"] = "$VisualCppPackageName.$VisualCppToolsVersion"
    ConvertTo-Json $vccache |Out-File -Encoding utf8 -Force -FilePath "$VisualCppToolsInstallDir\VisualCppTools.lock.json"
    ### clangbuilderui use it !
    "VisualCppTools.Community.Daily $VisualCppToolsVersion"|Out-File -Encoding unicode -Force -FilePath  "$VisualCppToolsInstallDir\VisualCppTools.lock.txt"
}

Pop-Location 
<commit_msg>fix DownloadDailyCompiler.ps1<commit_after>
# See https://blogs.msdn.microsoft.com/vcblog/2016/02/16/\
#try-out-the-latest-c-compiler-toolset-without-waiting-for-the-next-update-of-visual-studio/


$ClangbuilderRoot = Split-Path $PSScriptRoot
$ViusalCppAtomURL = "https://visualcpp.myget.org/F/dailymsvc/api/v2"
$VisualCppToolsInstallDir = "$ClangbuilderRoot\utils\msvc"

$NuGetDir = "$ClangbuilderRoot\pkgs\Nuget"

$env:PATH = "$NuGetDir;${env:PATH}"

Push-Location $PWD

if (!(Test-Path $VisualCppToolsInstallDir)) {
    New-Item -Force -ItemType Directory $VisualCppToolsInstallDir 
}

Set-Location $VisualCppToolsInstallDir

Function CompareVersion() {
    param(
        [String]$Pre,
        [String]$Next
    )

}

$xmlfeed = $null
try {
    $xmlfeed = [xml](Invoke-WebRequest -UseBasicParsing -Uri "$ViusalCppAtomURL/Packages").Content
}
catch {
    Write-Host -Forceground Red "Checking VisualCpp Feed $_"
    exit 1
}


$VisualCppPackageName = $null
$VisualCppToolsVersion = $null

if ($xmlfeed.feed.entry.GetType().IsArray) {
    [int]$index = 0;
    [int]$mindex = 0;
    [int]$build = 1;
    foreach ($_ in $xmlfeed.feed.entry) {
        $version = $_.properties.Version.Split("-")[0]; # 14.11.25615-Pre
        $ver = [System.Version]::Parse($version)
        if ($ver.build -gt $build) {
            $build = $ver.build
            $mindex = $index
        }
        $index++
    }
    $VisualCppPackageName = $xmlfeed.feed.entry[$mindex].properties.Id
    $VisualCppToolsVersion = $xmlfeed.feed.entry[$mindex].properties.Version
}
else {
    $VisualCppPackageName = $xmlfeed.feed.entry.properties.Id
    $VisualCppToolsVersion = $xmlfeed.feed.entry.properties.Version
}

Write-Output "Latest $VisualCppPackageName version is $VisualCppToolsVersion"
if ((Test-Path "$VisualCppToolsInstallDir/VisualCppTools.lock.json")) {
    $Pkglock = Get-Content "$VisualCppToolsInstallDir/VisualCppTools.lock.json" |ConvertFrom-Json
    if ($Pkglock.Version -eq $VisualCppToolsVersion) {
        Write-Host "VisualCppTools is up to date, Version: $VisualCppToolsVersion"
        return ;
    }
}


Write-Output "NuGet Install $VisualCppPackageName $VisualCppToolsVersion ......"

&nuget install $VisualCppPackageName -Source $ViusalCppAtomURL -Prerelease

if ((Test-Path "$VisualCppToolsInstallDir\$VisualCppPackageName.$VisualCppToolsVersion")) {
    $vccache = @{}
    $vccache["Name"] = $VisualCppPackageName
    $vccache["Version"] = $VisualCppToolsVersion
    $vccache["Path"] = "$VisualCppPackageName.$VisualCppToolsVersion"
    ConvertTo-Json $vccache |Out-File -Encoding utf8 -Force -FilePath "$VisualCppToolsInstallDir\VisualCppTools.lock.json"
    ### clangbuilderui use it !
    "VisualCppTools.Community.Daily $VisualCppToolsVersion"|Out-File -Encoding unicode -Force -FilePath  "$VisualCppToolsInstallDir\VisualCppTools.lock.txt"
}

Pop-Location 

{'fraction_non_alphanumeric': 0.1340924541128484, 'fraction_numerical': 0.00832766825288919, 'mean_word_length': 3.5444015444015444, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 18}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5298103', 'n_tokens_mistral': 2036, 'n_tokens_neox': 1980, 'n_words': 307}