forked from 00-Evan/shattered-pixel-dungeon-gdx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert-upstream-patch.sh
executable file
·41 lines (32 loc) · 1.27 KB
/
convert-upstream-patch.sh
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
#!/usr/bin/env bash
function echo_exit() {
echo -e "$1\n"
exit $2
}
# Exit with instructions on how to use if a valid file isn't supplied as input
[[ ! -f "$1" ]] && echo_exit 'Run with patch from non-GDX version as input' 0
# Set the backup name and if it already exists, increment the backup number and try again
COUNT=1
BACKUP="${1}.${COUNT}.bak"
while [[ -f "$BACKUP" ]]; do
COUNT=$(expr $COUNT + 1)
BACKUP="${1}.${COUNT}.bak"
done
# Create a backup of the patch before converting
echo
cp "$1" "$BACKUP" \
&& echo "Created backup @ $BACKUP" \
|| echo_exit "Error: Couldn't create backup @ $BACKUP" 1
# Convert /src/com/* to /core/src/com/*
sed -i -re 's|([ab])(/src/com/)|\1/core\2|g' "$1"
# Convert /assets/* to /android/assets/*
sed -i -re 's|([ab])(/assets/)|\1/android\2|g' "$1"
# Convert /res/* to /android/res/*
sed -i -re 's|([ab])(/res/)|\1/android\2|g' "$1"
# Convert pixeldungeon locations to shatteredpixeldungeon ones
sed -i 's|com/watabou/pixeldungeon|com/shatteredpixel/shatteredpixeldungeon|g' "$1"
# Exit and report whether updates have been made, deleting the backup if they haven't
[[ ! $(diff "$1" "$BACKUP") ]] \
&& rm "$BACKUP" \
&& echo_exit "Deleting backup as no changes were made when converting" 0 \
|| echo "Your patch has been successfully updated"