-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake-update.ps1
135 lines (111 loc) · 3.18 KB
/
make-update.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# Made with Love by Marcos https://github.com/rijuma
# Repo: https://github.com/rijuma/mu-scripts
$yamlModule = "powershell-yaml"
try {
Import-Module $yamlModule -ErrorAction Stop
} catch {
" ERROR: $yamlModule module not found."
""
" This script depends on it to work properly."
" Plese run open a PowerShell terminal as an admin and install the module with:"
""
" Install-Module ""$yamlModule"""
""
exit
}
$configFile = 'config.yml'
try {
$config = Get-Content $configFile -ErrorAction Stop | ConvertFrom-Yaml
} catch {
""
" Error parsing '$configFile'. Please check the config file exists or copy the example one."
""
exit 1
}
$baseClientPath = $config.baseClientPath
$installerClientPath = $config.updater.installerClientPath
$updatePath = $config.updater.updatePath
# Ensure Reference Client path exists
if (!(Test-Path -Path "$baseClientPath")) {
"Base Client path is wrong: '$baseClientPath' in '$configFile'."
exit
}
# Ensure Installer path exists
if (!(Test-Path -Path "$installerClientPath")) {
"Installer path is wrong: '$installerClientPath' in '$configFile'."
exit
}
# Ensure Update Path is set
if (!$updatePath) {
"Missing updated.updatePath in '$configFile'."
exit
}
# Create Update dir if not exists
New-Item -ItemType Directory -Force -Path $updatePath | out-null
# Delete all files and folders inside Update Path
Remove-Item "$updatePath\*" -Recurse -Force
# Exclude accesory files, sound and music (saved in a different folder in the installer).
$exclude = $config.updater.exclude
# Get all files from Test Client
Push-Location -Path $baseClientPath
$files = Get-ChildItem "." -File -Exclude $exclude -Recurse | Resolve-Path -Relative
Pop-Location
$files
$added = 0
$updated = 0
$warn = 0
foreach ($file in $files) {
$basePath = "$baseClientPath\$file"
$baseFile = Get-Item $basePath
$installerPath = "$installerClientPath\$file"
if (Test-Path -Path $installerPath) {
$refFile = Get-Item $installerPath
}
$destFile = "$updatePath\$file"
# If the file does not exists in the installer, or has a different size, or has a different modification time, then we add it to the update.
if (!$refFile -or ($baseFile.Length -ne $refFile.Length) -or ($baseFile.LastWriteTime -ne $refFile.LastWriteTime)) {
if (!$refFile) {
"[new] $file."
$added++
} else {
"[edit] $file."
$updated++
}
if ($refFile -and ($baseFile.LastWriteTime -lt $refFile.LastWriteTime)) {
"[Warning] '$file' is newer in the installer client."
$warn++
}
$dir = Split-Path -Parent $destFile
New-Item -ItemType Directory -Force -Path $dir | out-null
Copy-Item $baseFile $destFile
}
}
""
if (($added + $updated) -gt 0) {
"Update created."
if ($added) {
if ($added -eq 1) {
"- $added new file."
} else {
"- $added new files."
}
}
if ($updated) {
if ($updated -eq 1) {
"- $updated updated file."
} else {
"- $updated updated files."
}
}
if ($warn) {
if ($warn -eq 1) {
"- Make sure to check the warning above."
} else {
"- Make sure to check the $warn warnings above."
}
}
} else {
"Base client is up to date."
}
""
[Console]::ResetColor()