-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCleanMetadata
executable file
·112 lines (93 loc) · 2.95 KB
/
CleanMetadata
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
#!/data/data/com.termux/files/usr/bin/bash
# Find orphaned assets from games that have been deleted.
##### Config #####
# Don't edit the configuration in this file as it would be overwritten on updates.
# Create the file .config/pegasus_android_helpers.conf and override the variables.
# leave empty to scan every directory in each platform
assetdirs="covers marquees screenshots videos wheels"
# delete all orphaned assets. Dangerous!
autodelete=no # automatically delete orphaned assets (yes|no)
# script created to delete orphan assets
orphansfile=~/pegasus_rm_orphans.sh
##################
if [[ -f ~/.config/pegasus_android_helpers.conf ]]; then
source ~/.config/pegasus_android_helpers.conf
fi
function find_match {
platform=$1
asset=$2
game=${asset#$pdir$adir/}
game=${game%.*}
game="$(printf '%q' "${game}")" # escapes special characters
res=$(find "$rompath/$platform" -name "${game}.*" |wc -l)
if [[ "$res" == "0" ]]; then
echo "rm \"$asset\"" >> $orphansfile
fi
}
# Make sure there is no leftover script from a previous run
rm -f $orphansfile
inputline=$(grep -m 1 inputFolder ~/.skyscraper/config.ini)
if [[ "$inputline" == "" ]]; then
echo "Couldn't find 'inputFolder' in Skyscraper's config file."
quit 1
fi
rompath=${inputline##*=}
rompath="${rompath%\"}"
rompath="${rompath#\"}"
echo Looking for ROMs in $rompath
inputline=$(grep -m 1 mediaFolder ~/.skyscraper/config.ini)
if [[ "$inputline" == "" ]]; then
inputline=$(grep -m 1 gameListFolder ~/.skyscraper/config.ini)
if [[ "$inputline" == "" ]]; then
inputline=$rompath
fi
fi
mediapath=${inputline##*=}
mediapath="${mediapath%\"}"
mediapath="${mediapath#\"}"
echo Looking for media in $mediapath
# Check that the ROM dir is available
# if not it could delete all assets!
numplatforms=$(ls -d $rompath/*/ 2>/dev/null |wc -l)
if [[ "$numplatforms" == "0" ]]; then
echo "The ROM directory is empty or not available. Aborting to avoid deleting all assets."
exit 0
fi
for pdir in $mediapath/*/
do
platform=$(basename $pdir)
# if assetdirs is empty scan all
if [[ "$assetdirs" == "" ]]; then
cd $pdir
assetdirs=$( ls -d */ )
assetdirs=${assetdirs//\/}
cd -
fi
for adir in $assetdirs
do
if [[ -d $pdir$adir ]]; then
fdir=$pdir$adir
for asset in $fdir/*
do
# Special case: directory is empty
if [[ "$asset" != "$fdir/*" ]]; then
find_match "$platform" "$asset"
fi
done
else
echo "No $adir for $pdir"
fi
done
done
num_orphans=$(cat $orphansfile 2>/dev/null |wc -l)
if [[ "$num_orphans" == "0" ]]; then
echo "No orphaned assets found."
read -n 1 -r -s -p "Press any key to continue..." key
echo ""
exit 0
fi
echo $num_orphans orphaned assets.
if [[ "$autodelete" == "yes" ]]; then
source $orphansfile
rm $orphansfile
fi