### 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 HTC HD2 ROM Script Configuration
#   (C) 2024 by Ali Beyaz (symbuzzer)
#
###


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


##
# Initializing Rom Information
##
ini_set("rom_name",             "AOSP 2.3.7");
ini_set("rom_version",          "v1.0.7");
ini_set("rom_author",           "Ali Beyaz (symbuzzer)");
ini_set("rom_device",           "HTC HD2");
ini_set("rom_date",             "08/09/2024");


##
# 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
#
zipexec("kernel/checksys.sh");
setvar("bootloader", file_getprop("/tmp/nfo.prop", "bootloader"));
zipexec("kernel/rom.sh");
setvar("systemsize", file_getprop("/tmp/rom.prop", "systemsize"));

ini_set("text_next", "Install");

viewbox(
  #-- Title
    "ROM Installation Wizard",

  #-- Text
    "You are about to Install the below ROM\n\n"+

    "  Device\t: <b><#selectbg_g>"+ini_get("rom_device")+"</#></b>\n"+
    "  ROM\t\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"+
    "  System Size\t: <b><#selectbg_g>"+getvar("systemsize")+" MB</#></b>\n"+
    "  Build Date\t: <b><#selectbg_g>"+ini_get("rom_date")+"</#></b>\n\n\n"+

    "Bootloader\t: "+getvar("bootloader")+"\n"+
    "System Size\t: "+getdisksize("/system","m")+" MB\n"+
    "SD Card Size\t: "+getdisksize("/sdcard","m")+" MB / "+getdiskfree("/sdcard","m")+" MB\n"+
    "SD-EXT Size\t: "+getdisksize("/sd-ext","m")+" MB / "+getdiskfree("/sd-ext","m")+" MB\n",

  #-- Icon
    "icons/welcome"
);

###################################################################################################################
#
# SHOW CHANGELOG
#

 textdialog(
    #-- Title
    "Changelog",
	#-- Text
    resread("changelog.txt"),
    #-- Custom OK Button Text (Optional)
    "Close"
 );

###################################################################################################################
#
# SHOW FEATURES
#

 textdialog(
    #-- Title
    "Features",
	#-- Text
    resread("features.txt"),
    #-- Custom OK Button Text (Optional)
    "Close"
 );


###################################################################################################################
#
# STEP 4 - SHOW SELECTBOX - ROM Mods
#
selectbox(
  #-- Title
    "Install Options - 1/3",
  
  #-- Sub Title
    "Please Select Connection Protocol and Wipe Options:",
  
  #-- Icon
    "icons/personalize",
  
  #-- Will be saved in /tmp/aroma/mods.prop
    "mods.prop",
 
  #-- Group 1
    "Connection Protocol","",2,
      "RMNET Connection",
        "Only MAGLDR supports RMNET."+
        "\nMore stable.",                         0,
      "PPP Connection",
        "All bootloaders support PPP.",           1,
 
  #-- Group 2
    "Wipe","",2,
      "Wipe Dalvik-Cache",
        "Select it to wipe Dalvik-Cache.",        0,
      "Wipe Data/Factory Reset",
        "Select it to wipe data/factory reset.",  1,
      "No Wipe",
        "Select it to keep everything.",          0
);


###################################################################################################################
#
# STEP 5 - SHOW SELECTBOX - Language
#
selectbox(
  #-- Title
    "Startup Language - 2/3",

  #-- Sub Title
    "Please Select Startup Language: \nThere are many language options in the ROM. You can change it later in Settings.",

  #-- Icon
    "icons/apps",

  #-- Will be saved in /tmp/aroma/language.prop
    "language.prop",
 
  #-- Group 1
    "Startup Language", "", 2,                                                    #-- Group 1. key = "selected.1"

    "English",
      "Device will start in English",    1, #-- selected.1 = 1

    "Turkish",
      "Device will start in Turkish", 0 #-- selected.1 = 2
);


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

if prop("mods.prop", "selected.1") == "1" then
  setvar("fconnnectiontype", "RMNET");
endif;
if prop("mods.prop", "selected.1") == "2" then
  setvar("fconnnectiontype", "PPP");
endif;

if prop("mods.prop", "selected.2") == "1" then
  setvar("fwipetype", "Dalvik-Cache");
endif;
if prop("mods.prop", "selected.2") == "2" then
  setvar("fwipetype", "Factory Reset");
endif;
if prop("mods.prop", "selected.2") == "3" then
  setvar("fwipetype", "None");
endif;

if prop("language.prop", "selected.1") == "1" then
  setvar("fstartuplanguage", "EN");
endif;
if prop("language.prop", "selected.1") == "2" then
  setvar("fstartuplanguage", "TR");
endif;

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

viewbox(
  "Confirm - 3/3",

  "All information has been collected for installation:\n\n"+

    "Connection\t: "+getvar("fconnnectiontype")+"\n"+
    "Wipe\t\t: "+getvar("fwipetype")+"\n"+
    "Language\t: "+getvar("fstartuplanguage")+"\n"+

  "\n\n<#selectbg_g><b>Press Start to install...</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",

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

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