# ================================================== # Left 4 Dead Addons Checker by KorgKurzweil # https://h-eatqore.sessionsphere.com # Helper Tool for finding mismatched versions of custom campaigns # ================================================== # ========================= # CONFIG # ========================= $url = "https://h-eatqore.sessionsphere.com/?action=cmap_stats" $localDir = $PSScriptRoot Write-Host "" Write-Host "Checking addons..." Write-Host "URL: $url" # ========================= # OUTPUT ARRAYS # ========================= $NONEXISTINGFILE = @() $TO_UPDATE = @() $UPDATED_FILES = @() $ExpectedVpkFiles = @() $UNLISTED_VPK_FILES = @() # ========================= # GET JSON DATA # ========================= $data = Invoke-RestMethod -Uri $url -Method Get if ($data -isnot [System.Array]) { $data = @($data) } # ========================= # PROCESS # ========================= foreach ($item in $data) { $fileName = $item.gameserverfile if ([string]::IsNullOrWhiteSpace($fileName)) { continue } # Add ALL campaign files, regardless of updated status $ExpectedVpkFiles += $fileName.ToLower() # Only process updated items if ($item.updated -ne 1) { continue } $fileName = $item.gameserverfile if ([string]::IsNullOrWhiteSpace($fileName)) { continue } $localFile = Join-Path $localDir $fileName # Common object we'll add to the lists $fileInfo = [PSCustomObject]@{ Name = $item.name "File Name" = $fileName "Server Date" = ([datetime]$item.version_lastcheck_lastupdated).ToString("yyyy-MM-dd") "Local Date" = if (Test-Path $localFile) { (Get-Item $localFile).LastWriteTime.ToString("yyyy-MM-dd") } else { "-" } Link = $item.external_link } # ========================= # FILE DOES NOT EXIST # ========================= if (!(Test-Path $localFile)) { $NONEXISTINGFILE += $fileInfo continue } # ========================= # FILE EXISTS # ========================= $remoteDate = ([datetime]$item.version_lastcheck_lastupdated).Date $localDate = (Get-Item $localFile).LastWriteTime.Date # Allow local file to be up to 1 day behind if ($localDate.AddDays(1) -lt $remoteDate) { $TO_UPDATE += $fileInfo } else { $UPDATED_FILES += $fileInfo } } # ========================= # FIND LOCAL VPK FILES NOT IN CAMPAIGN LIST # ========================= $LocalVpkFiles = Get-ChildItem -Path $localDir -Filter *.vpk -File foreach ($file in $LocalVpkFiles) { if ($file.Name.ToLower() -notin $ExpectedVpkFiles) { $UNLISTED_VPK_FILES += [PSCustomObject]@{ "File Name" = $file.Name Modified = $file.LastWriteTime } } } # ========================= # RESULTS # ========================= Write-Host "" Write-Host "=====================================" -ForegroundColor Green Write-Host "UPDATED FILES ($($UPDATED_FILES.Count))" -ForegroundColor Green if ($UPDATED_FILES.Count -gt 0) { $TableText = $UPDATED_FILES | Sort-Object Name | Format-Table Name, "File Name", "Server Date", "Local Date", Link -AutoSize | Out-String Write-Host $TableText -ForegroundColor Green } else { Write-Host "None" } if ($UNLISTED_VPK_FILES.Count -gt 0) { Write-Host "" Write-Host "=====================================" -ForegroundColor Cyan Write-Host "UNLISTED VPK FILES ($($UNLISTED_VPK_FILES.Count))" -ForegroundColor Cyan $TableText = $UNLISTED_VPK_FILES | Sort-Object "File Name" | Format-Table "File Name", Modified -AutoSize | Out-String Write-Host $TableText -ForegroundColor Cyan } if ($NONEXISTINGFILE.Count -gt 0) { Write-Host "" Write-Host "=====================================" -ForegroundColor DarkRed Write-Host "NON EXISTING FILES ($($NONEXISTINGFILE.Count))" -ForegroundColor DarkRed $TableText = $NONEXISTINGFILE | Sort-Object Name | Format-Table Name, "File Name", "Server Date", "Local Date", Link -AutoSize | Out-String Write-Host $TableText -ForegroundColor DarkRed } if ($TO_UPDATE.Count -gt 0) { Write-Host "" Write-Host "=====================================" -ForegroundColor DarkYellow Write-Host "TO UPDATE ($($TO_UPDATE.Count))" -ForegroundColor DarkYellow $TableText = $TO_UPDATE | Sort-Object Name | Format-Table Name, "File Name", "Server Date", "Local Date", Link -AutoSize | Out-String Write-Host $TableText -ForegroundColor DarkYellow } if (-not $NONEXISTINGFILE.Count -and -not $TO_UPDATE.Count) { Write-Host "" Write-Host "=====================================" -ForegroundColor Green Write-Host "All files are updated" -ForegroundColor Green Write-Host "=====================================" -ForegroundColor Green }