OpenRCT2/scripts/build-portable

70 lines
1.9 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
set -e
if [[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" ]]; then
# Create a Windows symbols archive for OpenRCT2
basedir="$(readlink -f `dirname $0`/..)"
cd $basedir/bin
destination=../artifacts/openrct2-portable-$CONFIGURATION-$PLATFORM.zip
# Check 7z is available
if ! [ -x "$(command -v 7z)" ]; then
echo -e >&2 "\033[0;7z not found\033[0m"
exit 1
fi
echo -e "\033[0;36mCreating portable zip for Windows OpenRCT2...\033[0m"
if [[ -f $destination ]]; then
rm $destination
fi
7z a -r $destination \
Remove exe / com wrapper around openrct2.dll for Windows (#10727) We get repeated reports of people saying the game is incorrectly reported as a virus. It is becoming more inconvenient for players and even myself, because when we attempt to download a build, it is immediately deleted by scanners (including the default for Windows: Windows Defender). One scanner is not too much of an issue, but the game is flagged by almost half of available scanners as reported by VirusTotal. So why is it being flagged? Windows has a very annoying concept, the subsystem for a binary. The console subsystem allows stdin / stdout as you would expect, just like posix. Unfortunately if a user runs a console subsystem binary from the desktop or explorer, the game will be opened under conhost and thus you get a console showing alongside the game window. This is not a good user experience for most players. To resolve this, you can use the windows subsystem, but this will detach stdin and stdout immediately on launch. There are hacks that can be done in code to allocate a new console but I found this to not work very well with stdin or other terminal emulators. My solution to the problem was to have two binaries: openrct2.exe and openrct2.com. Both are executable but openrct2.exe is windows subsystem, openrct2.com is console subsystem. The desktop shortcut opens openrct2.exe with no console window showing. Typing openrct2 on the command line will execute openrct2.com (as .com has higher PATH precedence than .exe by default) with working stdin and stdout. In order to reduce the size, I have the entire game inside openrct2.dll and then supply two tiny wrapper EXEs that simply route main(...) into the DLL. These wrapper EXEs are the problem, they are very small and do nothing but call into a DLL, this must match virus signatures too closely and their size probably reduces the data available for the scanner to analyse. So as I can not find any other way of achieving my goal of a cli and gui version of OpenRCT2, this changes the build to publish openrct2 as a single executable (rather than a DLL + wrapper EXE), and then duplicate the entire ~10MB exe again and flip the subsystem flag. The installer and zip size won't be affected as this extra size will be completely compressed out, but when unpacked will lead to an extra ~10MB on disc. But I think it is a fair compromise. VirusTotal now reports all artefacts as safe, for now anyway.
2020-02-18 12:35:27 +01:00
openrct2.exe openrct2.com data \
../contributors.md \
../licence.txt \
../distribution/changelog.txt \
../distribution/readme.txt \
../distribution/scripting.md \
../distribution/openrct2.d.ts
destination=$(cygpath -w $(readlink -f $destination))
printf '\033[0;32m%s\033[0m\n' "${destination} created successfully"
else
if [[ "$#" -ne 2 ]]; then
echo 'Turn an OpenRCT2 cmake install into a portable tar.gz.'
echo ''
echo 'Usage: build-portable <output-file> <install-path>'
exit 1
fi
output=$1
install=$2
echo -e "\033[0;36mCreating $output...\033[0m"
outputdir=$(dirname $output)
if ! [[ -d $outputdir ]]; then
mkdir -p $outputdir
fi
workdir=$output-temp
if [[ -d "$workdir" ]]
then
rm -rf $workdir
fi
mkdir -p $workdir/OpenRCT2
cp -r $install/bin/* $workdir/OpenRCT2
if [[ "$OSTYPE" == "darwin"* ]]; then
cp -R $install/lib/ $workdir/OpenRCT2
fi
cp -r $install/share/doc/openrct2 $workdir/OpenRCT2/doc
cp -r $install/share/openrct2 $workdir/OpenRCT2/data
pushd $workdir > /dev/null
tar -czf output.tar.gz OpenRCT2
popd > /dev/null
mv $workdir/output.tar.gz $output
rm -rf $workdir
echo -e "\033[0;32m$output created successfully\033[0m"
fi