forked from detain/skyscraper
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathdeploy_mandatory_files.ps1
More file actions
88 lines (81 loc) · 2.58 KB
/
deploy_mandatory_files.ps1
File metadata and controls
88 lines (81 loc) · 2.58 KB
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
param([string]$src_dir,[string]$skyscraper_home)
# These may be customized by user, thus do not overwrite with the repo files.
# The (newer) repo file will then get '.dist' extension appended in target dir.
$user_cfg_files = @(
'artwork.xml'
'aliasMap.csv'
'batocera-artwork.xml'
'peas.json'
'platforms_idmap.csv'
)
$folders = @(
'.',
'cache'
'import'
'import/covers'
'import/maquees'
'import/screenshots'
'import/textual'
'import/textures'
'import/videos'
'import/wheels'
'import/backcovers'
'import/fanarts'
'import/manuals'
'resources'
)
$dmap = @{
'config' = '.'
'examples' = '.'
'cacheexamples' = 'cache'
'impexamples' = 'import'
'resexamples' = 'resources'
}
# ignore: unix.supplementary.files and unix.target.files
# key: value from dmap, value: unix.($dmap.key).files= from skyscraper.pro
$fmap = @{}
# Prepare map $fmap with files to copy for each folder
$regex = 'unix:(?<key>[^.]+)\.files=(?<deployfiles>.+?)unix'
(Get-Content $src_dir/skyscraper.pro) -join ' ' -replace '\\' |
Select-String $regex -AllMatches | ForEach-Object {
$g = $_.Matches.Groups |
Where-Object { $_.Name -eq 'key' -or $_.Name -eq 'deployfiles' } |
Select-Object -Property Value
for ($i = 0; $i -lt $g.length; $i += 2) {
$v = $g[$i].Value.Trim()
if (-not [string]::IsNullOrEmpty($v) -and $dmap.ContainsKey($v)) {
$deployfiles = ($g[$i + 1].Value -replace ('\s+',' ')).Trim().Split(' ')
if ($fmap.ContainsKey($dmap.$v)) {
$deployfiles += $fmap.($dmap.$v)
$fmap.($dmap.$v) = $deployfiles
} else {
$fmap.Add($dmap.$v,$deployfiles)
}
}
}
}
# Copy files
$folders | ForEach-Object {
$subfolder = $_
mkdir -Force "$skyscraper_home/$subfolder" | Out-Null
if ($fmap.ContainsKey($subfolder)) {
"[*] Install folder '$subfolder':"
$fmap.$subfolder | Sort-Object –CaseSensitive | ForEach-Object {
$cf = $_.Split('/')[-1]
if (($cf -in $user_cfg_files) -and `
(Test-Path $skyscraper_home/$subfolder/$cf)) {
$cf_dist = "{0}.dist" -f $cf
$cf_print = "$skyscraper_home/$subfolder/$cf"
$cf_print = $cf_print.Replace("/","\").Replace("\.\","\")
" {0} exists. Copying new file to $cf_dist" -f $cf_print
Copy-Item -Force -Path "$src_dir/$_" `
"$skyscraper_home/$subfolder/$cf_dist"
} else {
$cf_print = (("$skyscraper_home/$subfolder".Replace("/","\")) `
-replace ('\.$','')) -replace ('([a-z])$','$1\')
" Copy $_ to $cf_print"
Copy-Item -Path "$src_dir/$_" "$skyscraper_home/$subfolder"
}
}
}
}