[Script] - Heroes of Might and Magic V Bundle

Författare Svar
trevorh Saturday 4 January 2014 at 7:39

A turn based stratergy game, the fifth installment in the Heroes of Might and Magic series. Upgrade your Heroes and Towns to create armies to crush your opponents and take control of the map. Single player story based campaigns and multiplayer maps (hotseat/LAN/Online).

Bundle includes the original Heroes of Might and Magic V as well as the Hammers of Fate and Tribes of the East expansions.

Extra notes:
The executable name for all three games is identical. The script includes an option to recreate the shortcuts if they have been deleted as there is currently no way of doing this through the PlayOnLinux interface.

# Date : (2014-01-04 05-42)
# Last revision : (2014-01-04 05-42)
# Wine version used : 1.6.1
# Distribution used to test : Mint Maya
# Author : Trevor Hobson, Clive Hobson
# Script licence : GPL v.3
# Program licence : Retail
# Depend : 

[ "$PLAYONLINUX" = "" ] && exit 0
source "$PLAYONLINUX/lib/sources"

TITLE=" - Heroes of Might and Magic V Bundle"

# Note: WORKING_WINE_VERSION is currently not used/enforced - see below.

#HOMM5_PATH_BASE="GOG Games/Heroes of Might and Magic V Bundle"
HOMM5_PATH="Heroes of Might and Magic V/bin"
HOMM5_HOF_PATH="Heroes of Might and Magic V/bina1"
HOMM5_TOE_PATH="Tribes of the East/bin"

HOMM5_SHORTCUT_NAME="Heroes of Might and Magic V"
HOMM5_HOF_SHORTCUT_NAME="Heroes of Might and Magic V - Hammers of Fate"
HOMM5_TOE_SHORTCUT_NAME="Heroes of Might and Magic V - Tribes of the East"

append_message() {
    if [ -z "${CLOSING_MESSAGE}" ]; then

# Initialisation


POL_SetupWindow_presentation "$TITLE" "Nival Interactive / Ubisoft" "$GOGID" "Trevor Hobson and Clive Hobson" "$PREFIX"

# Ask user which actions to perform
declare -i DO_INSTALL=0
declare -i DO_GAME_SHORTCUTS=0
POL_SetupWindow_menu_num "Choose action" "$TITLE" \
"Install (default)~Install and create map editor shortcuts~Recreate game shortcuts~Recreate game and map editor shortcuts" "~"

if [ "${APP_ANSWER}" == "0" ]; then
    # Install (and create game shortcuts)
    append_message "Selected action: Install (and create game shortcuts)"
elif [ "${APP_ANSWER}" == "1" ]; then
    # Install and create game and editor shortcuts
    append_message "Selected action: Install and create game and editor shortcuts"
elif [ "${APP_ANSWER}" == "2" ]; then
    # Create game shortcuts only (no install)
    append_message "Selected action: Recreate game shortcuts"
elif [ "${APP_ANSWER}" == "3" ]; then
    # Create game and editor shortcuts only (no install)
    append_message "Selected action: Recreate game and map editor shortcuts"
    # Logic error - user selected an option we didn't provide!
    POL_Debug_Fatal "Unhandled return value: \"${APP_ANSWER}\""

# Install
if [ ${DO_INSTALL} -eq 1 ]; then
    append_message "Install: Started"
    # md5sum setup_homm5_*
    # 9ded9fb554abbb272c875b4b14b37d56  setup_homm5_2.0.0.22.exe
    # f4223b9946fa3f01030a9c59dba213cc  setup_homm5_2.0.0.22-1.bin
    # e39bf8e0ad72a46c03d857392dfae707  setup_homm5_2.0.0.22-2.bin
    # 56311f626cd25ca00c79634d3749b584  setup_homm5_2.0.0.22-3.bin
    if false; then
        # Use POL_GoG_setup once it can:
        #  - download indices 0,1,2,5 (missing 3 and 4), and
        #  - NOT rename the downloaded files.
        POL_Call POL_GoG_setup "$GOGID" \
        "9ded9fb554abbb272c875b4b14b37d56" "f4223b9946fa3f01030a9c59dba213cc" \
        "e39bf8e0ad72a46c03d857392dfae707" "56311f626cd25ca00c79634d3749b584"
        # For now, the user must download the install files manually
        POL_SetupWindow_question "$(eval_gettext 'Do you want to download $TITLE from')" "$TITLE"
        [ "$APP_ANSWER" = "TRUE" ] && POL_Browser "$GOGID"

        # Select the downloaded files
        cd "$HOME"
        POL_SetupWindow_browse "$(eval_gettext 'Please select the setup file to run.')" "$TITLE" "" "Windows Executables (*.exe)|*.exe;*.EXE"

    POL_Wine_SelectPrefix "$PREFIX"

    # If a specific WINE version is needed, uncomment this line and set the version above.
    #POL_Wine_PrefixCreate "$WORKING_WINE_VERSION"

    if false; then
        # Use POL_GoG_install once it has an option to NOT install gdiplus
        POL_Call POL_GoG_install /nogui
        # For now, use the useful parts of the POL_GoG_install script

        # Prevent GoG installer from installing Acrobat Reader or Foxit in each prefix
        POL_Call POL_Function_SetNativeExtension "pdf"

        POL_Wine "$POL_GoG_location" "/nogui" || POL_Debug_Fatal "$(eval_gettext 'Error while installing archive')"

    # GoG work!
    Set_OS winxp

    POL_SetupWindow_VMS "2"

    # Doesn't hurt ;)

    append_message "Install: Complete"

# 1. File name pattern to search for (relative to ${WINEPREFIX}/drive_c)
# e.g. "./*doom.exe" will match ./games/windoom/windoom.exe (if it exists)
# Outputs one matching path (or nothing if no matches found)
find_file_pattern ()
    # Do this in a child shell so changing directory does not impact the caller
        # Change directory to "C:"
        cd "$WINEPREFIX" || POL_Debug_Fatal "Prefix $WINEPREFIX does not exists"
        cd drive_c || POL_Debug_Fatal "drive_c folder does not exists"

        result_path="$(find -H ./ -name windows -prune -o -type f -iwholename "${1}" -print | tail -n 1)"
        [ -z "$result_path" ] && binary_path="$(find ./windows/ -type f -iwholename "${1}" -print | tail -n 1)"

        echo "$result_path"

# Similar to POL_Shortcut except:
# 1. Pattern to use to find the exe (must start with "./")
# If no exe is found, no shortcut is created.
# If an exe is found, POL_Shortcut is called with the full exe path and all other parameters unchanged
# Note: Create shortcuts specifying the full path otherwise POL_Shortcut does its own search.
    local exe_pattern="${1}"
    local shortcut_name="${2}"
    shift 2
    local exe_path="$(find_file_pattern "${exe_pattern}")"
    #POL_Debug_Message "Shortcut \"${shortcut_name}\".  Pattern: \"${exe_pattern}\".  Result: \"${exe_path}\""
    if [ -z "${exe_path}" ]; then
        POL_Debug_Message "Not creating shortcut \"${shortcut_name}\".  Unable to find exe matching pattern: \"${exe_pattern}\"."
        append_message "    * Skipped \"${shortcut_name}\" (exe not found)"
        return 1
        POL_Shortcut "${exe_path}" "${shortcut_name}" "$@"
        append_message "    * Created \"${shortcut_name}\""
        return 0

# Can only create shortcuts if the WINE prefix exists (created by a previous install)
if [ "$(POL_Wine_PrefixExists "$PREFIX")" == "True" ]; then
    POL_Wine_SelectPrefix "$PREFIX"

    # Note: Typical install location is "C:\GOG Games\Heroes of Might and Magic V Bundle".  However, the user may install
    # any combination of the three games and they could end up in different locations.  Therefore search for the game
    # executables and silently ignore if we do not find them.

    # Create game shortcuts
    if [ ${DO_GAME_SHORTCUTS} -eq 1 ]; then
        append_message "Game shortcuts:"
        optional_shortcut "./*/${HOMM5_PATH}/${HOMM5_GAME_EXE}"     "${HOMM5_SHORTCUT_NAME}"     "" "" "Game;StrategyGame;"
        optional_shortcut "./*/${HOMM5_HOF_PATH}/${HOMM5_GAME_EXE}" "${HOMM5_HOF_SHORTCUT_NAME}" "" "" "Game;StrategyGame;"
        optional_shortcut "./*/${HOMM5_TOE_PATH}/${HOMM5_GAME_EXE}" "${HOMM5_TOE_SHORTCUT_NAME}" "" "" "Game;StrategyGame;"

    # Create editor shortcuts
    if [ ${DO_EDITOR_SHORTCUTS} -eq 1 ]; then
        append_message "Editor shortcuts:"
        optional_shortcut "./*/${HOMM5_PATH}/${HOMM5_EDITOR_EXE}"     "${HOMM5_SHORTCUT_NAME}${HOMM5_EDITOR_SUFFIX}"     "" "" "Game;StrategyGame;"
        optional_shortcut "./*/${HOMM5_HOF_PATH}/${HOMM5_EDITOR_EXE}" "${HOMM5_HOF_SHORTCUT_NAME}${HOMM5_EDITOR_SUFFIX}" "" "" "Game;StrategyGame;"
        optional_shortcut "./*/${HOMM5_TOE_PATH}/${HOMM5_EDITOR_EXE}" "${HOMM5_TOE_SHORTCUT_NAME}${HOMM5_EDITOR_SUFFIX}" "" "" "Game;StrategyGame;"
    # Prefix doesn't exist, warn the user that we cannot do as asked
    append_message "The game does not appear to be installed. (Prefix \"${PREFIX}\" does not exist.)"

POL_SetupWindow_message "Summary...\n${CLOSING_MESSAGE}" "$TITLE"

petch Saturday 4 January 2014 at 17:30

I trevorh,
This script reminds me of my early scripts, by that I mean it's full of bells and whistles (check the Outcast script for instance).
Labor of love for sure, but a pain for maintainers each time they have to repair complex scripts they didn't write.

Some complexity is justified (OMG they managed to use non-consecutive indexes for HoMM5 downloads? :( ), but stuff like overloading PlayOnLinux statements behavior (optional shortcuts, report at end of scripts, shortcuts rebuild) will not go past other maintainers for sure.

If such things have to be implemented, they'd better be inside PlayOnLinux itself, for the sake of maintenability; For example, for optional shortcuts and shortcuts rebuild, what about:
- log somewhere in the virtual drive all shortcut statements (POL_Shortcut, POL_Shortcut_QuietDebug,...) that have been attempted, with their arguments
- allow to make them optional (extra parameter?)
- have a button in the interface to rerun all those logged statements

That's just one implementation idea of course, but the point is to avoid duplicating complexity over all scripts.

With that in mind, other minor observations:

[code language=playonlinux]
        # Use POL_GoG_setup once it can:
        #  - download indices 0,1,2,5 (missing 3 and 4), and
        #  - NOT rename the downloaded files.
Grrr we'll really need to find a solution for this, but that will be a pain :(

[code language=playonlinux]
    #POL_Wine_PrefixCreate "$WORKING_WINE_VERSION"
If you don't want to enforce a specific version (actually, use system-wide installed Wine version), you must call POL_Wine_PrefixCreate without parameter, not remove its call altogether.

[code language=playonlinux]
        # Use POL_GoG_install once it has an option to NOT install gdiplus
Is that a real problem, does it break something?

[code language=playonlinux]
    POL_SetupWindow_VMS "2"
From what I found the minimum requirements are more like 64MB