Skip to content

Commit 3ccf575

Browse files
committed
fix(compress_unreal2_maps): streamline file removal and compression process
1 parent fc4b2f3 commit 3ccf575

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

lgsm/modules/compress_unreal2_maps.sh

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,38 @@ if ! fn_prompt_yn "Start compression?" Y; then
2525
core_exit.sh
2626
fi
2727
mkdir -pv "${compressedmapsdir}" > /dev/null 2>&1
28-
rm -rfv "${serverfiles:?}/Maps/"*.ut2.uz2
29-
cd "${systemdir}" || exit
30-
for map in "${serverfiles}/Maps/"*; do
31-
./ucc-bin compress "${map}" --nohomedir
28+
29+
# Remove old compressed files using find
30+
echo -e "Removing old compressed .uz2 files..."
31+
find "${serverfiles}" \( -name "*.ut2.uz2" -o -name "*.rom.uz2" -o -name "*.utx.uz2" -o -name "*.uax.uz2" -o -name "*.usx.uz2" -o -name "*.ukx.uz2" -o -name "*.u.uz2" -o -name "*.ogg.uz2" -o -name "*.int.uz2" \) -type f -exec rm -fv {} \;
32+
33+
echo -e "Searching for Unreal Engine files to compress..."
34+
echo -e "Look in game config file for maps"
35+
36+
# mapext=$(awk -F= '/^[[:space:]]*MapExt[[:space:]]*=/ {gsub(/^[ \t"]+|[ \t"]+$/, "", $2); print $2; exit}' "${servercfgfullpath}")
37+
# echo "Detected map extension: $mapext"
38+
39+
# List of extensions to compress (excluding .ogg)
40+
exts="ut2 kfm rom u ucl upl ini int utx uax ukx usx"
41+
42+
# Remove old compressed files for these extensions
43+
for ext in $exts; do
44+
find "${serverfiles}" -name "*.${ext}.uz2" -type f -exec rm -fv {} \;
3245
done
33-
mv -fv "${serverfiles}/Maps/"*.ut2.uz2 "${compressedmapsdir}"
46+
47+
cd "${systemdir}" || exit
48+
49+
# Find and compress files, then move .uz2 to compressedmapsdir
50+
find "${serverfiles}" \( "$(for ext in $exts; do echo -name "*.${ext}" -o; done | sed 's/ -o$//')" \) -type f \
51+
-exec sh -c '
52+
compressedmapsdir="$1"
53+
file="$2"
54+
printf "Compressing: %s\n" "$file"
55+
./ucc-bin compress "$file" --nohomedir && \
56+
printf "Moving: %s -> %s\n" "$file.uz2" "$compressedmapsdir" && \
57+
mv -fv "$file.uz2" "$compressedmapsdir"
58+
' _ "${compressedmapsdir}" {} \;
59+
60+
echo -e "Compression complete. All .uz2 files moved to: ${compressedmapsdir}"
3461

3562
core_exit.sh

0 commit comments

Comments
 (0)