| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | ########################################################################### |
| 4 | # fheroes2: https://github.com/ihhub/fheroes2 # |
| 5 | # Copyright (C) 2022 - 2025 # |
| 6 | # # |
| 7 | # This program is free software; you can redistribute it and/or modify # |
| 8 | # it under the terms of the GNU General Public License as published by # |
| 9 | # the Free Software Foundation; either version 2 of the License, or # |
| 10 | # (at your option) any later version. # |
| 11 | # # |
| 12 | # This program is distributed in the hope that it will be useful, # |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
| 15 | # GNU General Public License for more details. # |
| 16 | # # |
| 17 | # You should have received a copy of the GNU General Public License # |
| 18 | # along with this program; if not, write to the # |
| 19 | # Free Software Foundation, Inc., # |
| 20 | # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # |
| 21 | ########################################################################### |
| 22 | |
| 23 | # Purpose: This script extracts resources from a Heroes of Might and Magic II |
| 24 | # directory or installer and copies them to the appropriate location for the fheroes2 |
| 25 | # macOS app bundle. |
| 26 | # |
| 27 | # Usage: ./extract_homm2_resources_for_app_bundle.sh [HOMM2_PATH] |
| 28 | # HOMM2_PATH: (Optional) Path to the HoMM2 installation directory or installer package. |
| 29 | # If not provided, the script will interactively prompt for the path. |
| 30 | # |
| 31 | # Example: ./extract_homm2_resources_for_app_bundle.sh /path/to/homm2 |
| 32 | # |
| 33 | # Note: This script must be run on a macOS system as it is designed for macOS app bundle. |
| 34 | |
| 35 | set -e |
| 36 | |
| 37 | PLATFORM_NAME="$(uname 2> /dev/null)" |
| 38 | if [[ "${PLATFORM_NAME}" != "Darwin" ]]; then |
| 39 | echo "This script must be run on a macOS host" |
| 40 | exit 1 |
| 41 | fi |
| 42 | |
| 43 | if [[ "$#" == "1" ]]; then |
| 44 | HOMM2_PATH="$1" |
| 45 | else |
| 46 | # Use read with -e flag for built-in tab completion |
| 47 | read -e -p "Please enter the full path to the HoMM2 directory or installer package (e.g. /home/user/homm2 or /tmp/installer.exe): " HOMM2_PATH |
| 48 | fi |
| 49 | |
| 50 | # Expand the path to handle ~ and relative paths |
| 51 | if [[ "${HOMM2_PATH}" == ~* ]]; then |
| 52 | # Use bash's built-in tilde expansion |
| 53 | HOMM2_PATH="${HOMM2_PATH/#\~/$HOME}" |
| 54 | fi |
| 55 | |
| 56 | # Verify the path exists |
| 57 | if [[ ! -e "${HOMM2_PATH}" ]]; then |
| 58 | echo "Error: The specified path does not exist: ${HOMM2_PATH}" |
| 59 | exit 1 |
| 60 | fi |
| 61 | |
| 62 | # Define user data directory |
| 63 | USER_DATA_DIR="${HOME}/Library/Application Support/fheroes2" |
| 64 | |
| 65 | # Get the directory where this script is located |
| 66 | SCRIPT_DIR=$(dirname "$0") |
| 67 | |
| 68 | # Call the resource extraction script for user data directory |
| 69 | echo "Extracting resources to user data directory..." |
| 70 | "${SCRIPT_DIR}/extract_homm2_resources.sh" "${HOMM2_PATH}" "${USER_DATA_DIR}" |
| 71 | |
| 72 | echo "Resource extraction complete. Files have been copied to: ${USER_DATA_DIR}" |