#!/usr/bin/env bash # Copy the 40250 Client/ directory into the Android app's private files/ (SDL_GetPrefPath), where # native_render looks for files/Client/pack/Index. Needs the debug APK installed (run-as). # ./push-android-client.sh [--locale XX] [CLIENT_DIR] # --locale XX writes the pushed locale.cfg from CLIENT_DIR/locale_XX.cfg. --locale zh defaults # CLIENT_DIR to build/zh-locale/Client (script/build_zh_locale.py), whose pack/ registers locale_zh. # Symbolic links in CLIENT_DIR (the zh client links the original packs) are copied as their targets. set -euo pipefail cd "$(dirname "$0")" PKG=org.metin2port.client LOCALE="" if [ "${1:-}" = "--locale" ]; then LOCALE="${2:?--locale needs a locale code}" shift 2 fi if [ "$LOCALE" = zh ]; then CLIENT="${1:-build/zh-locale/Client}" else CLIENT="${1:-Client}" fi [ -f "$CLIENT/pack/Index" ] || { echo "$CLIENT/pack/Index not found" >&2; exit 1; } # The archive's top directory is basename(CLIENT DIR); the app reads files/Client. [ "$(basename "$CLIENT")" = Client ] || { echo "CLIENT_DIR must be named Client" >&2; exit 1; } if [ -n "$LOCALE" ]; then [ -f "$CLIENT/locale_$LOCALE.cfg" ] || { echo "$CLIENT/locale_$LOCALE.cfg not found" >&2; exit 1; } pack="$(cut -d' ' -f3 < "$CLIENT/locale_$LOCALE.cfg" | tr -d '\r\n')" tr -d '\r' < "$CLIENT/pack/Index" | grep -qxF "locale_$pack" || { echo "locale_$pack is not registered in $CLIENT/pack/Index" >&2; exit 1; } fi TMP=/data/local/tmp/mt-client.tar echo "packing $CLIENT ..." tar -h -C "$(dirname "$CLIENT")" -cf - "$(basename "$CLIENT")" | adb shell "cat > $TMP" echo "unpacking into $PKG files/ ..." adb shell "run-as $PKG sh -c 'mkdir -p files && rm -rf files/Client && cd files && tar -xf $TMP' && rm -f $TMP" if [ -n "$LOCALE" ]; then adb shell "run-as $PKG sh -c 'cp files/Client/locale_$LOCALE.cfg files/Client/locale.cfg'" echo "locale.cfg: $(adb shell "run-as $PKG cat files/Client/locale.cfg")" fi adb shell "run-as $PKG ls files/Client/pack/Index" >/dev/null && echo "done: files/Client"