#!/bin/bash

# Get dependencies
# obtain model and jetson_model
get_model &>/dev/null
if [[ -z "$jetson_model" ]] && [ ! -z "$__cpu_op_mode_32" ]; then
  true
else
  warning "Your system is only capable of running the ARM64 versions of Minecraft Bedrock. You will be unable to run older ARM32 versions of Minecraft Bedrock that you may find in this launcher."
fi

install_packages flatpak || exit 1

flatpak_install io.mrarm.mcpelauncher || exit 1

# transition old "game" folder files from appimage data directory if they exist

if [ -d "/home/$USER/.local/share/mcpelauncher/games" ]; then
  if [ -d "/home/$USER/.var/app/io.mrarm.mcpelauncher/data/mcpelauncher/games" ]; then
    warning "An old appimage game directory stored in /home/$USER/.local/share/mcpelauncher/games exists as well as the new flatpak game directory in /home/$USER/.var/app/io.mrarm.mcpelauncher/data/mcpelauncher/games. Your gamefiles could not be transfered over automatically because of this. Please do so manually."
  else
    mkdir -p "/home/$USER/.var/app/io.mrarm.mcpelauncher/data/mcpelauncher"
    cp -r "/home/$USER/.local/share/mcpelauncher/games" "/home/$USER/.var/app/io.mrarm.mcpelauncher/data/mcpelauncher/"
    status "Your gamefiles were automatically copied over from the old appimage game directory stored in /home/$USER/.local/share/mcpelauncher/games to the new flatpak game directory in /home/$USER/.var/app/io.mrarm.mcpelauncher/data/mcpelauncher/games. You can delete your original files in /home/$USER/.local/share/mcpelauncher/games once you have determined there has been no data loss."
  fi
fi
true
