-
Notifications
You must be signed in to change notification settings - Fork 0
/
RA_cores_updater.ps1
73 lines (62 loc) · 2.4 KB
/
RA_cores_updater.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Retroarch Core updater for Windows
#
# Based on linux script of github.com/cpinkus
#
# Alfredo Monclús (2017)
cls
# Location variables
$cores_url="http://buildbot.libretro.com/nightly/windows/x86_64/latest"
$cores_path="$env:appdata\retroarch\cores"
$logfile="$env:appdata\retroarch\cores\cores_updater.log"
# Prepare files
if(-not(Test-Path "$cores_path\.timestamps.old")){$null > "$cores_path\.timestamps.old"}
if(-not(Test-Path "$cores_path\.timestamps.new")){$null > "$cores_path\.timestamps.new"}
mv "$cores_path\.timestamps.new" "$cores_path\.timestamps.old" -Force
# Grab timestamps from URL
Start-BitsTransfer -Source $cores_url/.index-extended -Destination $cores_path\.timestamps.new -TransferType Download
# Check if downloaded
if ($(Test-Path "$cores_path\.timestamps.new"))
{
# Make space because the progress-bar covers things up
for ($i=0; $i -lt 10; $i++) {Write-Host "."}
# New logfile entry
echo "-- $(date) --" >> "$logfile"
# Download and replace cores
$cores = Get-ChildItem $cores_path -File *.dll
for ($i=0; $i -lt $cores.Count; $i++) {
if (-not($cores[$i].name.Contains("_libretro"))) {continue}
$corename=$cores[$i].name
$timestamp_old=$(Get-Content "$cores_path\.timestamps.old" | Select-String -simplematch $corename)
$timestamp_new=$(Get-Content "$cores_path\.timestamps.new"| Select-String -simplematch $corename)
$current_timestamp=$timestamp_new.ToString($timestamp_new).Split(" ")[0]
if ( "$timestamp_new" -eq "$timestamp_old" )
{
#Write-Host $current_timestamp,"SKIPPED ",$corename -ForegroundColor Gray
Write-output $current_timestamp`t"SKIPPED "`t$corename >> $logfile
continue
}
$core_full_url=$cores_url + "/" + $corename + ".zip"
Start-BitsTransfer -Source $core_full_url -Destination $cores_path\$corename.zip -TransferType Download
# Check if downloaded
if ($(Test-Path $cores_path\$corename.zip))
{
rm "$cores_path\$corename"
Expand-Archive "$cores_path\$corename.zip" "$cores_path" -force
rm "$cores_path\$corename.zip"
Write-Host $current_timestamp,"UPDATED ",$corename -ForegroundColor Green
Write-output $current_timestamp`t"UPDATED "`t$corename >> $logfile
}
else
{
Write-Host $current_timestamp,"FAILED ",$corename -ForegroundColor Red
Write-output $current_timestamp`t"FAILED "`t$corename >> $logfile
}
}
echo "Done"
}
else
{
Write-Host "FAILED to download timestamps" -ForegroundColor Red
}
sleep 4
pause