Skip to content

Commit

Permalink
support the new .zevtc file extension for compressed logs
Browse files Browse the repository at this point in the history
Newer versions of ArcDPS since 20181212 now compress the EVTC files using
the new .zevtc file extension.

To support this, add two helper functions to the library module for
checking if a filename is an EVTC file, and for determining the
uncompressed name that we want to associate it with.

This simplifies the code in upload-logs.ps1 and avoids needing to further
duplicate some of the logic. Additionally this should allow future new
filename changes to be a bit easier to handle.

Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
  • Loading branch information
jacob-keller committed Dec 12, 2018
1 parent 6a9e00a commit f92a0f5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
47 changes: 46 additions & 1 deletion l0g-101086.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ Function ConvertFrom-UTC {
[TimeZone]::CurrentTimeZone.ToLocalTime($time)
}


<#
.Synopsis
Convert a Unix timestamp to a DateTime object
Expand Down Expand Up @@ -121,6 +120,52 @@ Function ConvertTo-UnixDate {
(New-TimeSpan -Start $UnixEpoch -End $Date).TotalSeconds
}

<#
.Synopsis
Check if a filename extension is for a (un)compressed EVTC file
.Description
Return $true if the given filename matches one of the known EVTC file
extensions for compressed or uncompressed EVTC log files.
.Parameter filename
The filename to check the extension of
#>
Function ExtensionIs-EVTC {
[CmdletBinding()]
param([Parameter(Mandatory)][string]$filename)
return ($filename -Like "*.evtc.zip" -or $filename -Like "*.evtc" -or $filename -Like "*.zevtc")
}

<#
.Synopsis
Given the EVTC file name, determine the uncompressed EVTC name
.Description
Determine the uncompressed name of the EVTC file, based on the file name.
.Parameter filename
The EVTC file to determine the uncompressed name of
#>
Function Get-UncompressedEVTC-Name {
[CmdletBinding()]
param([Parameter(Mandatory)][string]$filename)

if ($filename -Like "*.evtc") {
# This filename is uncompressed already
return $filename
} elseif ($filename -Like "*.evtc") {
# We have two extensions, so remove the first one
return [io.path]::GetFileNameWithoutExtension($filename)
} elseif ($filename -Like "*.zevtc") {
# Strip the ".zevtc", and add back ".evtc"
$name = [io.path]::GetFileNameWithoutExtension($filename)
return "${name}.evtc"
} else {
throw "${filename} has an unrecognized extension"
}
}

<#
.Synopsis
Check simpleArcParse version to ensure it is compatible with the script
Expand Down
12 changes: 6 additions & 6 deletions upload-logs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ $arcdps_release_date = (Get-Date -Date ($arcdps_headers['Last-Modified'])).Date
# last write time, and then we return the full path of that file.
if (Test-Path $last_upload_file) {
$last_upload_time = Get-Content -Raw -Path $last_upload_file | ConvertFrom-Json | Select-Object -ExpandProperty "DateTime" | Get-Date
$files = @(Get-ChildItem -Recurse -File -LiteralPath $arcdps_logs | Where-Object { ( $_.Name -Like "*.evtc.zip" -or $_.Name -Like "*.evtc" ) -and $_.LastWriteTime -gt $last_upload_time} | Sort-Object -Property LastWriteTime | ForEach-Object {$_.FullName})
$files = @(Get-ChildItem -Recurse -File -LiteralPath $arcdps_logs | Where-Object { ( ExtensionIs-EVTC $_.Name ) -and $_.LastWriteTime -gt $last_upload_time} | Sort-Object -Property LastWriteTime | ForEach-Object {$_.FullName})
} else {
$files = @(Get-ChildItem -Recurse -File -LiteralPath $arcdps_logs | Where-Object { $_.Name -Like "*.evtc.zip" -or $_.Name -Like "*.evtc" } | Sort-Object -Property LastWriteTime | ForEach-Object {$_.FullName})
$files = @(Get-ChildItem -Recurse -File -LiteralPath $arcdps_logs | Where-Object { ExtensionIs-EVTC $_.Name } | Sort-Object -Property LastWriteTime | ForEach-Object {$_.FullName})
}

$next_upload_time = Get-Date
Expand All @@ -130,7 +130,7 @@ Log-Output "~~~"

# Main loop to generate and upload gw2raidar and dps.report files
ForEach($f in $files) {
$name = [io.path]::GetFileNameWithoutExtension($f)
$name = Get-UncompressedEVTC-Name $f
Log-Output "---"
Log-Output "Saving ancillary data for ${name}..."

Expand All @@ -143,18 +143,18 @@ ForEach($f in $files) {
# Make the ancillary data directory
New-Item -ItemType Directory -Path $dir

if ($f -Like "*.evtc.zip") {
if ($f -ne $name) {
# simpleArcParse cannot deal with compressed data, so we must uncompress
# it first, before passing the file to the simpleArcParse program
[io.compression.zipfile]::ExtractToDirectory($f, $dir) | Out-Null
$evtc = Join-Path -Path $dir -ChildPath $name

# Sometimes the evtc.zip file stores the uncompressed file suffixed with .tmp
# Sometimes the zip file stores the uncompressed file suffixed with .tmp
if (-not (X-Test-Path $evtc)) {
$evtc = Join-Path -Path $dir -ChildPath "${name}.tmp"
}

# Sometimes the evtc.zip stores the uncompressed file without the .evtc
# Sometimes the zip file stores the uncompressed file without the .evtc
if (-not (X-Test-Path $evtc)) {
$evtc = Join-Path -Path $dir -ChildPath ([io.fileinfo]$name).basename
}
Expand Down

0 comments on commit f92a0f5

Please sign in to comment.