#!/bin/sh
# SPDX-License-Identifier: ACSL
# SPDX-FileCopyrightText: © 2020 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
# SPDX-FileCopyrightText: © 2022 Antoine Le Gonidec <vv221@dotslashplay.it>
set -o errexit

###
# Populous: The Beginning
# send your bug reports to bugs@dotslashplay.it
###

script_version=20260319.5

PLAYIT_COMPATIBILITY_LEVEL='2.35'

GAME_ID='populous-3'
GAME_NAME='Populous: The Beginning'

ARCHIVE_BASE_2_NAME='setup_populous_the_beginning_1.02_d3dfix_(76526).exe'
ARCHIVE_BASE_2_MD5='fbe841301914a95b46ba2e9ef4da2150'
ARCHIVE_BASE_2_TYPE='innosetup'
ARCHIVE_BASE_2_SIZE='501872'
ARCHIVE_BASE_2_VERSION='1.02-gog76526'
ARCHIVE_BASE_2_URL='https://www.gog.com/game/populous_the_beginning'

ARCHIVE_BASE_1_NAME='setup_populous_the_beginning_1.02_depfix2_(48318).exe'
ARCHIVE_BASE_1_MD5='12cb9973783ad50789b7531e60bfcb24'
ARCHIVE_BASE_1_TYPE='innosetup'
ARCHIVE_BASE_1_SIZE='510000'
ARCHIVE_BASE_1_VERSION='1.02-gog48318'
ARCHIVE_BASE_1_URL='https://www.gog.com/game/populous_the_beginning'

ARCHIVE_BASE_0_NAME='setup_populous_the_beginning_2.0.0.5.exe'
ARCHIVE_BASE_0_MD5='7e4545d04a3d00193507aa82dea14e50'
ARCHIVE_BASE_0_VERSION='1.02-gog2.0.0.2'
ARCHIVE_BASE_0_TYPE='innosetup'
ARCHIVE_BASE_0_SIZE='430000'

CONTENT_PATH_DEFAULT='.'
CONTENT_PATH_DEFAULT_0='app'
CONTENT_GAME_BIN_FILES='
popTB.exe
D3DPopTB.exe'
# TODO: Move Undiscovered Worlds to a dedicated package.
CONTENT_GAME0_BIN_FILES='
popTBUW.exe
D3DPopTBUW.exe'
# TODO: Check if the following binay is required.
CONTENT_GAME1_BIN_FILES='
dxcfg.exe'
# TODO: Drop unused libraries.
# TODO: Install libraries in a standard path.
CONTENT_GAME2_BIN_FILES='
ddraw.dll
msapi.dll
QMixer.dll
WEANETR.dll'
CONTENT_GAME_DATA_FILES='
data
Fmv
levels
objects
rddata
Sound
language/lang??.dat'
# TODO: Move Undiscovered Worlds to a dedicated package.
CONTENT_GAME0_DATA_FILES='
levluw
language/lang??UW.dat'
CONTENT_DOC_DATA_FILES='
Manual.pdf
Quick Reference Card.pdf
readme.txt
ReadMePatch1.01.txt'

USER_PERSISTENT_DIRECTORIES='
SAVE'

# Set required registry keys.
install_drive='C:'
install_directory="\\\\${GAME_ID}"
install_path="${install_drive}${install_directory}"
WINE_REGISTRY_INIT='
[HKEY_LOCAL_MACHINE\Software\Bullfrog Productions Ltd\Populous: The Beginning]
"BuildTypeCode"=dword:00000001
"InstallDirectory"="'"${install_directory}"'"
"InstallDrive"="'"${install_drive}"'"
"InstallPath"="'"${install_path}"'"
"Language"=dword:00000009
"Version"="1.01"'

# TODO: Add a launcher for Undiscovered Worlds expansion.
APP_MAIN_EXE='popTB.exe'

PACKAGES_LIST='
PKG_BIN
PKG_DATA'

PKG_BIN_ARCH='32'
PKG_BIN_DEPENDENCIES_SIBLINGS='
PKG_DATA'

PKG_DATA_ID="${GAME_ID}-data"
PKG_DATA_DESCRIPTION='data'

# Load common functions.

if [ -z "$PLAYIT_LIB2" ]; then
	for playit_lib_dir in \
		"$PWD" \
		"${HOME}/.local/lib/play.it" \
		'/usr/local/lib/play.it' \
		'/usr/lib/play.it'
	do
		playit_lib_path="${playit_lib_dir}/libplayit.sh.2"
		if [ -e "$playit_lib_path" ]; then
			PLAYIT_LIB2="$playit_lib_path"
			break
		fi
	done
fi
if [ -z "$PLAYIT_LIB2" ]; then
	printf '\n\033[1;31mError:\033[0m\n'
	printf 'libplayit2.sh not found.\n'
	exit 1
fi
# shellcheck source=libplayit2.sh
. "$PLAYIT_LIB2"

# Run default initialisation actions.

initialization_default "$@"

# Extract game data.

archive_extraction_default

# Include game data.

content_inclusion_icons 'PKG_DATA'
content_inclusion_default

# Write launchers.

launchers_generation

# Build packages.

packages_generation
print_instructions

# Clean up.

working_directory_cleanup

exit 0
