#!/bin/sh
I4J_INSTALL_LOCATION="/opt/pdfstudioviewer2024"
cd "$I4J_INSTALL_LOCATION"
if [ "$1" = "configure" ]; then
ln -sf "$I4J_INSTALL_LOCATION/pdfstudioviewer2024" /usr/local/bin/
/bin/echo -e "#!/usr/bin/env xdg-open
[Desktop Entry]
Type=Application
Name=PDF Studio Viewer 2024
Categories=XFCE;Office;Graphics;
Exec=/bin/sh \"$I4J_INSTALL_LOCATION/pdfstudioviewer2024\" %U
StartupWMClass=install4j-com-qoppa-pdfStudioViewer-pub-PDFStudioViewer
Icon=$I4J_INSTALL_LOCATION/.install4j/pdfstudioviewer2024.png
" > "$I4J_INSTALL_LOCATION/.install4j/install4j_jplhj9-pdfstudioviewer2024.desktop"
xdg-desktop-menu install --mode system "$I4J_INSTALL_LOCATION/.install4j/install4j_jplhj9-pdfstudioviewer2024.desktop" 2>/dev/null
cp "$I4J_INSTALL_LOCATION/.install4j/install4j_jplhj9-pdfstudioviewer2024.desktop" "$I4J_INSTALL_LOCATION/pdfstudioviewer2024.desktop"
chmod +x "$I4J_INSTALL_LOCATION/pdfstudioviewer2024.desktop"
ln -sf "$I4J_INSTALL_LOCATION/updater" /usr/local/bin/
ln -sf "$I4J_INSTALL_LOCATION/pdfstudiosu" /usr/local/bin/

if [ -d "$I4J_INSTALL_LOCATION/jre/lib" ]; then
  old_pwd200=`pwd`
  cd "$I4J_INSTALL_LOCATION/jre"
  for pack_file in lib/*.jar.pack
  do
    if [ -f "$pack_file" ]; then
      jar_file=`echo "$pack_file" | awk '{ print substr($0,1,length($0)-5) }'`
      bin/unpack200 -r "$pack_file" "$jar_file" > /dev/null 2>&1
    fi
  done
  for pack_file in lib/ext/*.jar.pack
  do
    if [ -f "$pack_file" ]; then
      jar_file=`echo "$pack_file" | awk '{ print substr($0,1,length($0)-5) }'`
      bin/unpack200 -r "$pack_file" "$jar_file" > /dev/null 2>&1
    fi
  done
  bin/java -Xshare:dump >/dev/null 2>&1
  cd "$old_pwd200"
fi

fi
exit 0
