### 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-2013 by tytung - xda-developers (tytung @ gmail.com)
#
###


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


##
# Initializing Rom Information
##
ini_set("rom_name",             "NexusHD2-JellyBean");
ini_set("rom_version",          "v3.1");
ini_set("rom_author",           "tytung");
ini_set("rom_device",           "HTC HD2");
ini_set("rom_date",             "Sep. 7, 2013");


##
# 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("boot/ROM_NAME.prop", "ROM_NAME.prop");

zipexec("boot/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
#
selectbox(
  #-- Title
    "Install Type",

  #-- Sub Title
    "Please Select the install type:",

  #-- Icon
    "icons/apps",

  #-- Will be saved in /tmp/aroma/installtype.prop
    "installtype.prop",
 
  #-- Group 1
    "Install Location", "", 2,                                                    #-- Group 1. key = "selected.1"

    "NAND",
      "system@NAND, data@NAND, boot@NAND\nFor T-Mobile USA HD2 (LEO 1024)",    0, #-- selected.1 = 1

    "NAND with DataOnEXT",
      "system@NAND, data@EXT4, boot@NAND\nFor EU/International HD2 (LEO 512)", 0, #-- selected.1 = 2

    "NativeSD (Everything on the SD card)",
      "system@EXT4, data@EXT4, boot@FAT32\nFor high speed read/write SD Card", 1  #-- selected.1 = 3
);

if prop("installtype.prop", "selected.1") == "3" then
  writetmpfile("kernel.prop", "NAND=no");
else
  writetmpfile("kernel.prop", "NAND=yes");
endif;

##############################
# Mount the SD-EXT partition #
##############################

if (prop("installtype.prop", "selected.1") == "2" ||
    prop("installtype.prop", "selected.1") == "3") then

  pleasewait("Mounting the SD-EXT Partition...");
  zipexec("boot/SD-EXT_mounter.sh");
  setvar("mount_result", getvar("exec_buffer"));

  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 failed!",
      "Please create an EXT4 partition (mmcblk0p2) on the SD Card first.",
      "icons/alert",
      "Error messages:\n\n"+getvar("mount_result")
    );

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

  endif;

endif;


###################################################################################################################
#
# STEP 4 - SHOW MENUBOX - Setup Wizard
#
menubox(
  #-- Title
    "Setup Wizard",

  #-- Sub Title
    "Please select the setup type:",

  #-- Icon
    "icons/setup",

  #-- Will be saved in /tmp/aroma/type.prop
    "type.prop",
 
  #-------------------------+-----------------[ Menubox Items ]-------------------------+---------------#
  # TITLE                   |  SUBTITLE                                                 |   Item Icons  #
  #-------------------------+-----------------------------------------------------------+---------------#
  "Full Install",           "Need ~265 Mb free space on the system partition.", "icons/default",  #-- selected = 1
  "Custom Install",         "Unselect some apps to save the system space.",     "icons/customize" #-- selected = 2
);


###################################################################################################################
#
# STEP 5 - SHOW CHECKBOX - Custom Install
#
if (prop("type.prop", "selected") == "1") then

  #-- IF "Full Install"
  writetmpfile(
    #-- Prop file will write to /tmp/aroma/customize.prop
      "customize.prop",

    #-- Default Values
      "item.0.1=1\n"+    #-- Google TTS (Text-To-Speech)
      "item.0.2=1\n"+    #-- PICO TTS (en-US only)
      "item.0.3=1\n"+    #-- Live Wallpapers
      "item.0.4=1\n"+    #-- Audio - Notifications
      "item.0.5=1\n"+    #-- Audio - Ringtones
      "item.0.6=1\n"     #-- DSP Manager
  );

else

  #-- IF Not "Full Install", show Custom Install Selection
  checkbox(
    #-- Title
      "Custom Install",

    #-- Sub Title
      "Please select the options to install them. Unselect all to save 25.2 MB.",

    #-- Icon
      "icons/customize",

    #-- Will be saved in /tmp/aroma/customize.prop
      "customize.prop",

    #-----------------------------------------[ Checkbox Without Group ]----------------------------------#
    # TITLE            |  SUBTITLE                                                        | Initial Value #
    #------------------+------------------------------------------------------------------+---------------#
    "Google TTS (Text-To-Speech)",    "Size:  ~9.1 MB",                                    0, #-- item.0.1
    "PICO TTS (Text-To-Speech)",      "Size:  ~1.4 MB",                                    0, #-- item.0.2
    "Live Wallpapers",                "Size:  ~2.7 MB\n"+
                                      "Check it to install all Live Wallpapers.\n"+
                                      "Otherwise No Live Wallpapers.",                     0, #-- item.0.3
    "Audio - Notifications",          "Size:  ~1.4 MB\n"+
                                      "Check it to install all notification audios.\n"+
                                      "Otherwise only install one default audio.",         0, #-- item.0.4
    "Audio - Ringtones",              "Size: ~10.1 MB\n"+
                                      "Check it to install all ringtones.\n"+
                                      "Otherwise only install one default audio.",         0, #-- item.0.5
    "DSP Manager App",                "Size:  ~0.4 MB",                                    0  #-- item.0.6
  );

endif;


###################################################################################################################
#
# STEP 6 - 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
    "Default Connection Type","",2,
      "RMNET Connection",
        "Only MAGLDR bootloader supports RMNET."+
        "\nMore stable.",                         1,
      "PPP Connection",
        "All bootloaders support PPP.",           0,
 
  #-- Group 2
    "Softkeys (Navbar)","",2,
      "Enable softkeys",
        "Select it to enable softkeys.",          1,
      "Disable softkeys",
        "Select it to disable softkeys.",         0,
 
  #-- Group 3
    "Wipe","",2,
      "Wipe Dalvik-Cache",
        "Select it to wipe Dalvik-Cache.",        1,
      "Wipe Data/Factory Reset",
        "Select it to wipe data/factory reset.",  0,
      "No Wipe",
        "Select it to keep everything.",          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"+
  "For MAGLDR NativeSD users, make sure to set your SD boot folder to NativeSD.\n\n"+
  "For cLK NativeSD users, make sure to run your flash_sboot_v2.zip script.\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;
