autopsy-flatpak/build-windows-installer.xml
2024-12-17 11:07:52 -05:00

295 lines
14 KiB
XML

<project name="AutopsyInstallerTargets">
<!-- ADVANCED INSTALLER TARGETS -->
<target name="build-installer-windows" depends="getProps,init-advanced-installer"
description="Makes an installer from the opened ZIP file">
<!-- <antcall target="run-advanced-installer-32" inheritAll="true" /> -->
<antcall target="run-advanced-installer-64" inheritAll="true" />
</target>
<target name="init-advanced-installer" depends="autoAIPath,inputAIPath"
description="Find AdvancedInstaller executable.">
<fail unless="ai-exe-path" message="Could not locate Advanced Installer."/>
<property environment="env"/>
<property name="inst-path" value="${nbdist.dir}\${app.name}-installer"/>
<!-- see what JREs they have installed -->
<!-- <condition property="jre.home.32">
<isset property="env.JRE_HOME_32"/>
</condition>
<if>
<isset property="jre.home.32" />
<then>
<echo message="32-bit JRE found, 32-bit installer will be built."/>
</then>
<else>
<echo message="32-bit JRE not found. No 32-bit installer will be built. Set the JRE_HOME_32 environment variable to generate a 32-bit installer."/>
</else>
</if> -->
<property name="lib-rel-path" value="${app.name}\modules\lib" />
<!-- where libs are in build folder; forward slashes because not used directly by advanced installer -->
<property name="lib-inst-path" value="${inst-path}/${app.name}/modules/lib" />
<!-- Where photo rec is installed within installer -->
<var name="photorec-rel-path" value="${app.name}\photorec_exec"/>
<!-- Where the photo rec build folder is placed in the dist folder currently -->
<var name="photorec-inst-path" value="${inst-path}\${app.name}\photorec_exec"/>
</target>
<target name="autoAIPath" description="Attempt to find the AI path based on standard installation location">
<!-- latest taken from https://www.advancedinstaller.com/download.html -->
<property name="AI.path" value="C:\Program Files (x86)\Caphyon\Advanced Installer 22.3\bin\x86\AdvancedInstaller.com" />
<available file="${AI.path}"
property="ai-exe-path"
value="${AI.path}"/>
<echo message="${ai-exe-path}" />
</target>
<target name="inputAIPath" unless="ai-exe-path" description="Have the user input the path to the AI executable">
<input addProperty="ai-exe-path"
message="Enter the location of AdvancedInstaller.com"/>
</target>
<!-- <target name="run-advanced-installer-32" depends="setup-aip-files" unless="DoNotCreate32BitInstaller">
<antcall target="build32" inheritAll="true" />
</target> -->
<target name="run-advanced-installer-64" depends="setup-aip-files" unless="DoNotCreate64BitInstaller">
<antcall target="build64" inheritAll="true" />
</target>
<target name="setup-aip-files" description="Configure the base AIP file and then make 32- and 64-bit versions.">
<!-- Copy the template file to add details to -->
<property name="aip-path-base" value="${nbdist.dir}\installer_${app.name}_base.aip"/>
<copy file="${basedir}/installer_${app.name}/installer_${app.name}.aip" tofile="${aip-path-base}" overwrite="true"/>
<echo message="${ai-exe-path}" />
<echo>Product Version: ${app.version}</echo>
<!-- generate new product code -->
<exec executable="${ai-exe-path}">
<arg line="/edit ${aip-path-base} /SetProductCode -langid 1033"/>
</exec>
<!-- Edit the API file to update versions: manual approach allows us to use non-X.Y.Z versions -->
<replaceregexp file="${aip-path-base}"
match="ProductVersion&quot; Value=&quot;\d+\.{1}\d+\.{1}\d+"
replace="ProductVersion&quot; Value=&quot;${app.version}" />
<!-- <property name="aip-path-32" value="${nbdist.dir}\installer_${app.name}_32.aip"/>
<copy file="${aip-path-base}" tofile="${aip-path-32}" overwrite="true"/> -->
<property name="aip-path-64" value="${nbdist.dir}\installer_${app.name}_64.aip"/>
<copy file="${aip-path-base}" tofile="${aip-path-64}" overwrite="true"/>
</target>
<target name="copyJRE" description="Copy a given JRE to the installation folder">
<property environment="env"/>
<if>
<isset property="env.JDK_HOME" />
<then>
<echo message="JDK found at: ${env.JDK_HOME}."/>
</then>
<else>
<fail message="Environment variable, JDK_HOME, not set. Cannot build installer."/>
</else>
</if>
<exec executable="${env.JDK_HOME}/bin/jlink" dir="${inst-path}">
<arg value="--add-modules"/>
<arg value="ALL-MODULE-PATH"/>
<arg value="--output"/>
<arg value="jre"/>
<arg value="--no-man-pages"/>
<arg value="--no-header-files"/>
<arg value="--compress=2"/>
</exec>
</target>
<!-- <target name="build32" if="jre.home.32" description="Builds the 32 bit installer IF JRE_HOME_32 is set.">
<property environment="env"/>
<var name="aip-path" value="${aip-path-32}"/>
<var name="aut-bin-name-todelete" value="${app.name}64.exe"/>
<var name="aut-bin-name" value="${app.name}.exe"/>
<var name="gstreamer-path-todelete" value="${app.name}\gstreamer\1.0\x86_64"/> -->
<!-- The path to the correct version of photorec to use. -->
<!-- <var name="photorec-path-to-use" value="${photorec-inst-path}\bin"/>
<var name="jvm.max.mem" value="512m" />
<var name="jre-path" value="${env.JRE_HOME_32}"/>
<antcall target="copyJRE" inheritAll="true" />
<exec executable="${ai-exe-path}">
<arg line="/edit ${aip-path-base} /SetAppdir -buildname DefaultBuild -path [ProgramFilesFolder][ProductName]-${app.version}"/>
</exec>
<antcall target="ai-build" inheritAll="true" />
<delete dir="${nbdist.dir}/installer_${app.name}_32-cache"/>
<move file="${nbdist.dir}/installer_${app.name}_32-SetupFiles/installer_${app.name}_32.msi" tofile="${nbdist.dir}/${app.name}-${app.version}-32bit.msi" />
</target> -->
<target name="build64" description="Builds the 64 bit installer IF JRE_HOME_64 is set.">
<property environment="env"/>
<var name="aip-path" value="${aip-path-64}"/>
<var name="aut-bin-name" value="${app.name}64.exe"/>
<var name="aut-bin-name-todelete" value="${app.name}.exe"/>
<var name="gstreamer-path-todelete" value="autopsy\gstreamer\1.0\x86"/>
<var name="ewfexport-path-todelete" value="autopsy\ewfexport_exec\32-bit"/>
<var name="plaso-path-todelete" value="autopsy\plaso\plaso-20180818-Win32"/>
<!-- The path to the correct version of photorec to use. -->
<var name="photorec-path-to-use" value="${photorec-inst-path}\64-bit\bin"/>
<var name="lib-path-to-use" value="${lib-inst-path}/amd64"/>
<var name="jvm.max.mem" value="4G"/>
<var name="jre-path" value="${env.JRE_HOME_64}"/>
<antcall target="copyJRE" inheritAll="true" />
<echo message="aip-path: ${aip-path}" />
<exec executable="${ai-exe-path}">
<arg line="/edit ${aip-path} /SetAppdir -buildname DefaultBuild -path [ProgramFiles64Folder][ProductName]-${app.version}"/>
</exec>
<exec executable="${ai-exe-path}">
<arg line="/edit ${aip-path} /SetPackageType x64"/>
</exec>
<antcall target="ai-build" inheritAll="true" />
<delete dir="${nbdist.dir}/installer_${app.name}_64-cache"/>
<move file="${nbdist.dir}/installer_${app.name}_64-SetupFiles/installer_${app.name}_64.msi" tofile="${nbdist.dir}/${app.name}-${app.version}-64bit.msi" />
</target>
<!-- Sets Java 17 JVM parameters -->
<target name="update-config" description="Updates configuration file with correct JVM args.">
<property name="inst.property.file" value="${inst-path}/etc/${app.name}.conf" />
<!-- Sets Java 17 JVM parameters -->
<var name="jvm.args" value="&quot;--branding ${app.name} -J-Xms24m -J-XX:+UseStringDeduplication -J-Dprism.order=sw -J--add-opens=java.base/java.lang=ALL-UNNAMED -J--add-opens=java.base/java.net=ALL-UNNAMED -J--add-opens=java.desktop/javax.swing=ALL-UNNAMED -J--add-opens=javafx.controls/javafx.scene.control.skin=ALL-UNNAMED -J--add-exports=java.desktop/sun.awt=ALL-UNNAMED -J--add-exports=javafx.controls/com.sun.javafx.scene.control.inputmap=ALL-UNNAMED -J--add-exports=javafx.base/com.sun.javafx.event=ALL-UNNAMED&quot;" />
<propertyfile file="${inst.property.file}">
<entry key="default_options" value="@JVM_OPTIONS" />
<!-- Update configuration file to include runtime -->
<entry key="jdkhome" value="&quot;jre&quot;" />
<entry key="default_userdir" value="${DEFAULT_USERDIR_ROOT}" />
</propertyfile>
<!-- workaround for ant escaping : and = when setting properties -->
<replace file="${inst.property.file}" token="@JVM_OPTIONS" value="${jvm.args}" />
</target>
<target name="add-ai-files" depends="update-config" description="Add the files in the installation path to the installer file">
<foreach target="add-file-or-dir" param="theFile" inheritall="true" inheritrefs="true">
<path>
<fileset dir="${inst-path}">
<include name="*" />
</fileset>
<dirset dir="${inst-path}">
<include name="*"/>
</dirset>
</path>
</foreach>
<echo message="Removing extra Autopsy executable..."/>
<exec executable="${ai-exe-path}">
<arg line="/edit ${aip-path} /DelFile APPDIR\bin\${aut-bin-name-todelete}"/>
</exec>
<echo message="Removing extra Gstreamer binaries..."/>
<exec executable="${ai-exe-path}">
<arg line="/edit ${aip-path} /DelFolder APPDIR\${gstreamer-path-todelete}"/>
</exec>
<echo message="Placing correct PhotoRec binaries..."/>
<!-- 'Delete' the folder being relayed to advanced installer for photorec -->
<exec executable="${ai-exe-path}">
<arg line="/edit ${aip-path} /DelFolder APPDIR\${photorec-rel-path}"/>
</exec>
<!-- Replace that folder with the subfolder depending on 32-bit vs. 64-bit -->
<exec executable="${ai-exe-path}">
<arg line="/edit ${aip-path} /AddFolder APPDIR\${photorec-rel-path} ${photorec-path-to-use}"/>
</exec>
<!-- FOR 4.21.0 RELEASE ONLY! In rare circumstances on some OSs, due to
Java 17 update some of the existing legacy Java 8 JVM arguments prevent
JVM 17 from starting. Therefore we are overwiriting the Java 8 Autopsy.conf
file with a Java 17 Autopsy.conf file, just in case. This should be removed
from future Autopsy releases. -->
<exec executable="${ai-exe-path}" failonerror="yes">
<arg value="/edit"/>
<arg value="${aip-path}"/>
<arg value="/AddFolder"/>
<arg value="AppDataFolder\${app.name}"/>
<arg value="${basedir}\installer_autopsy\etc"/>
</exec>
<echo message="Removing extra ewfexport_exec binaries..."/>
<exec executable="${ai-exe-path}">
<arg line="/edit ${aip-path} /DelFolder APPDIR\${ewfexport-path-todelete}"/>
</exec>
<echo message="Removing extra plaso binaries..."/>
<exec executable="${ai-exe-path}">
<arg line="/edit ${aip-path} /DelFolder APPDIR\${plaso-path-todelete}"/>
</exec>
<echo message="Placing correct lib native binaries..."/>
<!-- 'Delete' the folder being relayed to advanced installer for lib binaries -->
<exec executable="${ai-exe-path}">
<arg line="/edit ${aip-path} /DelFolder APPDIR\${lib-rel-path}"/>
</exec>
<for param="file">
<path>
<fileset dir="${lib-path-to-use}"/>
</path>
<sequential>
<exec executable="${ai-exe-path}">
<arg line="/edit ${aip-path} /AddFile APPDIR\${lib-rel-path} @{file}"/>
</exec>
</sequential>
</for>
</target>
<target name="add-file-or-dir">
<condition property="file-or-folder" value="File" else="Folder">
<available file="${theFile}" type="file" />
</condition>
<exec executable="${ai-exe-path}">
<arg line="/edit ${aip-path} /Add${file-or-folder} APPDIR ${theFile}" />
</exec>
</target>
<!-- 32/64 specific since exec changes -->
<target name="add-ai-shortcuts" description="Configure installer to have desktop short cuts">
<echo message="Adding desktop/menu shortcuts..."/>
<exec executable="${ai-exe-path}">
<arg line='/edit ${aip-path} /NewShortcut -name "${app.title} ${app.version}" -dir DesktopFolder -target APPDIR\bin\${aut-bin-name} -icon ${inst-path}\icon.ico'/>
</exec>
<exec executable="${ai-exe-path}">
<arg line='/edit ${aip-path} /NewShortcut -name "${app.title} ${app.version}" -dir SHORTCUTDIR -target APPDIR\bin\${aut-bin-name} -icon ${inst-path}\icon.ico'/>
</exec>
</target>
<target name="ai-build" description="Build the installer based on properties set by 32/64 targets.">
<antcall target="add-ai-files" inheritAll="true" />
<antcall target="add-ai-shortcuts" inheritAll="true" />
<exec executable="${ai-exe-path}">
<arg line="/build ${aip-path}"/>
</exec>
</target>
</project>