### LICENSE:
#
# Copyright (C) 2011-2012 Ahmad Amarullah ( http://amarullz.com/ )
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
### FILE INFO:
#
# AROMA Installer for NexusHD2 ROM Script Configuration
#   (C) 2012-2014 by tytung - xda-developers (tytung @ gmail.com)
#   added option to flash boot.img on multiboot in cLK bootloader for NativeSD installation (sboot, tboot, etc)
#
###


##
# Forcing Device Pixelate Size
#  defaut: floor( min( width, height ) / 160 )
#
ini_set("dp","3"); #-- HDPI ( 480x800 / WVGA )


##
# Initializing Rom Information
##
ini_set("rom_name",             "Unofficial Ressurection Remix");
ini_set("rom_version",          "1");
ini_set("rom_author",           "thinhx2");
ini_set("rom_device",           "HTC HD2");
ini_set("rom_date",             "May 18th, 2016");


##
# Show Simple Splash
#
#splash(
  #-- Duration 2000ms / 2 seconds
    #2000,
  
  #-- <AROMA Resource Dir>/sample.png
    #"sample"
#);


##
# Set Small Font to Support all fonts
#
fontresload( "0", "ttf/Roboto-Regular.ttf;ttf/DroidSansArabic.ttf;ttf/DroidSansFallback.ttf;", "12" ); #-- Use sets of font (Font Family)


##
# Set Language & Font Family
#
loadlang("langs/en.lang");
fontresload( "0", "ttf/Roboto-Regular.ttf", "12" ); #-- "0" = Small Font
fontresload( "1", "ttf/Roboto-Regular.ttf", "18" ); #-- "1" = Big Font


###################################################################################################################
#
# STEP 1 - SELECT THEME
#
theme("ics");


###################################################################################################################
#
# STEP 2 - SHOW ROM INFORMATION
#
# Extract ROM_NAME.prop to /tmp/aroma/ROM_NAME.prop
ziptotmp("install/bin/ROM_NAME.prop", "ROM_NAME.prop");

zipexec("install/bin/checksys.sh");
setvar("bootloader", file_getprop("/tmp/nfo.prop", "bootloader"));

viewbox(
  #-- Title
    "Welcome!",

  #-- Text
    "You are about to install the below ROM for <b>"+ini_get("rom_device")+"</b>.\n\n"+

    "  ROM Name\t: <b><#selectbg_g>"+ini_get("rom_name")+"</#></b>\n"+
    "  Version\t: <b><#selectbg_g>"+ini_get("rom_version")+"</#></b>\n"+
    "  Author\t: <b><#selectbg_g>"+ini_get("rom_author")+"</#></b>\n"+
    "  Update\t: <b><#selectbg_g>"+ini_get("rom_date")+"</#></b>\n\n\n"+

    "Bootloader\t: "+getvar("bootloader")+"\n\n"+

    "System NAND\t: "+getdisksize("/system","m")+" MB\n"+
    "\t Free\t: "+    getdiskfree("/system","m")+" MB\n\n"+

    "Data   NAND\t: "+getdisksize("/data","m")+" MB\n"+
    "\t Free\t: "+    getdiskfree("/data","m")+" MB\n\n"+

    "SD Card Size\t: "+getdisksize("/sdcard","m")+" MB\n"+
    "\t Free\t: "+     getdiskfree("/sdcard","m")+" MB\n\n"+

    " SD-EXT Size\t: "+getdisksize("/sd-ext","m")+" MB\n"+
    "\t Free\t: "+     getdiskfree("/sd-ext","m")+" MB\n\n\n"+

    "Press Next to Continue the Installation...",

  #-- Icon
    "icons/welcome"
);


###################################################################################################################
#
# STEP 3 - SHOW SELECTBOX - Install Type
#

  pleasewait("Mounting the SD-EXT Partition...");
  zipexec("install/bin/DirectSD_mounter.sh");

  if file_getprop("/tmp/mount.prop", "status") != "mounted" then

    #######################
    # No SD-EXT Partition #
    #######################

    # Set Next Text to 'Exit'
    ini_set("text_next", "Exit");

    textbox(
      "Mounting sd-ext/sdext2 partition failed!",
      "Missing Partition!!\nOR\nIncorrect filesytem detected!!",
      "icons/alert",
      "Error messages:\n\nPlease create\n\n\n 2 EXT4 partition\n\n\n OR\n\n\n 2 F2FS partition."
    );

    #-- Back to Menu
    back("1");

  endif;

###################################################################################################################
#
# STEP 4 - SHOW SELECTBOX - ROM Mods
#
selectbox(
  #-- Title
    "ROM Mods",
  
  #-- Sub Title
    "Please Select the ROM Mods:",
  
  #-- Icon
    "icons/personalize",
  
  #-- Will be saved in /tmp/aroma/mods.prop
    "mods.prop",

  #-- Group 1
    "Softkeys (Navbar)","",2,
      "Enable softkeys",
        "Select it to enable softkeys.",          1,
      "Disable softkeys",
        "Select it to disable softkeys.",         0,
 
  #-- Group 2
    "Wipe","",2,
      "Wipe Dalvik-Cache",
        "Select it to wipe Dalvik-Cache.",        1,
      "Wipe Data/Factory Reset",
        "Select it to wipe data/factory reset.",  0,

  #-- Group 3
    "Gapps","",2,
      "Install Core Gapps",
        "Installs minimal Google apps.", 1,
      "Do not install Gapps",
        "Do not install Google apps.", 0
);

#########
# Ready #
#########

# Set Next Text to 'Start'
ini_set("text_next", "Start");

viewbox(
  "Ready To Install",

  "All information has been collected for installation.\n\n"+
  "<#selectbg_g><b>Press Start to continue...</b></#>",

  "icons/info"
);

###########
# Install #
###########

# Set Next Text to 'Next'
ini_set("text_next", "Next");

install(
  "Installing",
  "Installing ROM...\nPlease wait...",
  "icons/install"
);

##########
# Finish #
##########

# Set Next Text to 'Finish'
ini_set("text_next", "Finish");

checkviewbox(
  "Installation Complete",

  "<#selectbg_g><b>Congratulation</b></#>\n\n"+
  "Install complete.\n\n"+
  "Please make sure to set your SD boot folder to DirectSD.\n\n\n\n\n",

  "icons/info",
  "Reboot your device now.", "1", "reboot_it"
);

#-- Check if reboot checkbox was checked
if getvar("reboot_it") == "1" then
  reboot("onfinish");
endif;
