Allow flashing of images via the GUI

- Use the Images... button in the lower right of the zip install
  page
- Unify image flashing functions between restore and image flash
- boot and recovery partitions are flashable by default
- use fstab flag flashimg=1 or 0 to override defaults
- file system partitions are currently not flashable

Change-Id: I822dc446030543c55d2153e219d67a1292374ffc
diff --git a/gui/action.cpp b/gui/action.cpp
index 750d73b..96f6209 100644
--- a/gui/action.cpp
+++ b/gui/action.cpp
@@ -201,6 +201,7 @@
 		mf["decrypt_backup"] = &GUIAction::decrypt_backup;
 		mf["repair"] = &GUIAction::repair;
 		mf["changefilesystem"] = &GUIAction::changefilesystem;
+		mf["flashimage"] = &GUIAction::flashimage;
 	}
 
 	// First, get the action
@@ -1651,6 +1652,24 @@
 	return 0;
 }
 
+int GUIAction::flashimage(std::string arg)
+{
+	int op_status = 0;
+
+	operation_start("Flash Image");
+	string path, filename, full_filename;
+	DataManager::GetValue("tw_zip_location", path);
+	DataManager::GetValue("tw_file", filename);
+	full_filename = path + "/" + filename;
+	if (PartitionManager.Flash_Image(full_filename))
+		op_status = 0; // success
+	else
+		op_status = 1; // fail
+
+	operation_end(op_status);
+	return 0;
+}
+
 int GUIAction::getKeyByName(std::string key)
 {
 	if (key == "home")			return KEY_HOME;
diff --git a/gui/devices/1024x600/res/ui.xml b/gui/devices/1024x600/res/ui.xml
index 7b7ad8c..1669d45 100644
--- a/gui/devices/1024x600/res/ui.xml
+++ b/gui/devices/1024x600/res/ui.xml
@@ -192,6 +192,7 @@
 		<variable name="button_fill_half_height" value="50" />
 		<variable name="button_fill_quarter_height" value="30" />
 		<variable name="button_full_center_x" value="256" />
+		<variable name="flash_list_height" value="200" />
 		<variable name="backup_list_x" value="23" />
 		<variable name="backup_list_y" value="105" />
 		<variable name="backup_list_width" value="486" />
diff --git a/gui/devices/1024x768/res/ui.xml b/gui/devices/1024x768/res/ui.xml
index b5ce1b4..253ae07 100644
--- a/gui/devices/1024x768/res/ui.xml
+++ b/gui/devices/1024x768/res/ui.xml
@@ -192,6 +192,7 @@
 		<variable name="button_fill_half_height" value="50" />
 		<variable name="button_fill_quarter_height" value="30" />
 		<variable name="button_full_center_x" value="256" />
+		<variable name="flash_list_height" value="200" />
 		<variable name="backup_list_x" value="23" />
 		<variable name="backup_list_y" value="105" />
 		<variable name="backup_list_width" value="486" />
diff --git a/gui/devices/1080x1920/res/ui.xml b/gui/devices/1080x1920/res/ui.xml
index 1367015..ddab4f3 100644
--- a/gui/devices/1080x1920/res/ui.xml
+++ b/gui/devices/1080x1920/res/ui.xml
@@ -81,6 +81,7 @@
 		<variable name="row17_text_y" value="1455" />
 		<variable name="row18_text_y" value="1530" />
 		<variable name="zip_status_y" value="922" />
+		<variable name="flash_list_height" value="500" />
 		<variable name="tz_selected_y" value="240" />
 		<variable name="tz_set_y" value="1500" />
 		<variable name="tz_current_y" value="1425" />
diff --git a/gui/devices/1200x1920/res/ui.xml b/gui/devices/1200x1920/res/ui.xml
index 77af05b..c02032f 100644
--- a/gui/devices/1200x1920/res/ui.xml
+++ b/gui/devices/1200x1920/res/ui.xml
@@ -84,6 +84,7 @@
 		<variable name="row17_text_y" value="1455" />
 		<variable name="row18_text_y" value="1530" />
 		<variable name="zip_status_y" value="922" />
+		<variable name="flash_list_height" value="500" />
 		<variable name="tz_selected_y" value="240" />
 		<variable name="tz_set_y" value="1500" />
 		<variable name="tz_current_y" value="1425" />
diff --git a/gui/devices/1280x800/res/ui.xml b/gui/devices/1280x800/res/ui.xml
index 716dadc..94d0bf9 100644
--- a/gui/devices/1280x800/res/ui.xml
+++ b/gui/devices/1280x800/res/ui.xml
@@ -192,6 +192,7 @@
 		<variable name="button_fill_half_height" value="53" />
 		<variable name="button_fill_quarter_height" value="40" />
 		<variable name="button_full_center_x" value="320" />
+		<variable name="flash_list_height" value="220" />
 		<variable name="backup_list_x" value="28" />
 		<variable name="backup_list_y" value="105" />
 		<variable name="backup_list_width" value="609" />
diff --git a/gui/devices/1440x2560/res/ui.xml b/gui/devices/1440x2560/res/ui.xml
index 4fc6996..52bf207 100644
--- a/gui/devices/1440x2560/res/ui.xml
+++ b/gui/devices/1440x2560/res/ui.xml
@@ -81,6 +81,7 @@
 		<variable name="row17_text_y" value="1935" />
 		<variable name="row18_text_y" value="2035" />
 		<variable name="zip_status_y" value="1375" />
+		<variable name="flash_list_height" value="650" />
 		<variable name="tz_selected_y" value="319" />
 		<variable name="tz_set_y" value="1995" />
 		<variable name="tz_current_y" value="1895" />
diff --git a/gui/devices/1600x2560/res/ui.xml b/gui/devices/1600x2560/res/ui.xml
index 7621792..b85803b 100644
--- a/gui/devices/1600x2560/res/ui.xml
+++ b/gui/devices/1600x2560/res/ui.xml
@@ -84,6 +84,7 @@
 		<variable name="row17_text_y" value="1935" />
 		<variable name="row18_text_y" value="2035" />
 		<variable name="zip_status_y" value="1250" />
+		<variable name="flash_list_height" value="650" />
 		<variable name="tz_selected_y" value="319" />
 		<variable name="tz_set_y" value="1995" />
 		<variable name="tz_current_y" value="1895" />
diff --git a/gui/devices/1920x1200/res/ui.xml b/gui/devices/1920x1200/res/ui.xml
index e36d0ae..4bd85a2 100644
--- a/gui/devices/1920x1200/res/ui.xml
+++ b/gui/devices/1920x1200/res/ui.xml
@@ -192,6 +192,7 @@
 		<variable name="button_fill_half_height" value="80" />
 		<variable name="button_fill_quarter_height" value="60" />
 		<variable name="button_full_center_x" value="480" />
+		<variable name="flash_list_height" value="300" />
 		<variable name="backup_list_x" value="50" />
 		<variable name="backup_list_y" value="160" />
 		<variable name="backup_list_width" value="900" />
diff --git a/gui/devices/240x240/res/ui.xml b/gui/devices/240x240/res/ui.xml
index d157f85..7448ae5 100644
--- a/gui/devices/240x240/res/ui.xml
+++ b/gui/devices/240x240/res/ui.xml
@@ -75,6 +75,7 @@
 		<variable name="row12_text_y" value="192" />
 		<variable name="row13_text_y" value="208" />
 		<variable name="zip_status_y" value="224" />
+		<variable name="flash_list_height" value="120" />
 		<variable name="backup_text_y" value="60" />
 		<variable name="tz_set_y" value="200" />
 		<variable name="tz_current_y" value="184" />
diff --git a/gui/devices/2560x1600/res/ui.xml b/gui/devices/2560x1600/res/ui.xml
index 12a2d55..6da373e 100644
--- a/gui/devices/2560x1600/res/ui.xml
+++ b/gui/devices/2560x1600/res/ui.xml
@@ -192,6 +192,7 @@
 		<variable name="button_fill_half_height" value="107" />
 		<variable name="button_fill_quarter_height" value="80" />
 		<variable name="button_full_center_x" value="640" />
+		<variable name="flash_list_height" value="450" />
 		<variable name="backup_list_x" value="50" />
 		<variable name="backup_list_y" value="210" />
 		<variable name="backup_list_width" value="1200" />
diff --git a/gui/devices/280x280/res/ui.xml b/gui/devices/280x280/res/ui.xml
index 971e637..ae8c27d 100644
--- a/gui/devices/280x280/res/ui.xml
+++ b/gui/devices/280x280/res/ui.xml
@@ -74,6 +74,7 @@
 		<variable name="row11_text_y" value="209" />
 		<variable name="row12_text_y" value="228" />
 		<variable name="row13_text_y" value="237" />
+		<variable name="flash_list_height" value="140" />
 		<variable name="zip_status_y" value="265" />
 		<variable name="backup_text_y" value="50" />
 		<variable name="col_progressbar_x" value="31" />
diff --git a/gui/devices/320x320/res/ui.xml b/gui/devices/320x320/res/ui.xml
index 4678e85..4a03855 100644
--- a/gui/devices/320x320/res/ui.xml
+++ b/gui/devices/320x320/res/ui.xml
@@ -75,6 +75,7 @@
 		<variable name="row12_text_y" value="284" />
 		<variable name="row13_text_y" value="306" />
 		<variable name="zip_status_y" value="300" />
+		<variable name="flash_list_height" value="160" />
 		<variable name="backup_text_y" value="60" />
 		<variable name="col_progressbar_x" value="34" />
 		<variable name="row_progressbar_y" value="285" />
diff --git a/gui/devices/320x480/res/ui.xml b/gui/devices/320x480/res/ui.xml
index dd4cdbc..70d33e6 100644
--- a/gui/devices/320x480/res/ui.xml
+++ b/gui/devices/320x480/res/ui.xml
@@ -77,6 +77,7 @@
 		<variable name="row17_text_y" value="389" />
 		<variable name="row18_text_y" value="408" />
 		<variable name="zip_status_y" value="350" />
+		<variable name="flash_list_height" value="150" />
 		<variable name="tz_selected_y" value="66" />
 		<variable name="tz_set_y" value="348" />
 		<variable name="tz_current_y" value="438" />
diff --git a/gui/devices/480x800/res/ui.xml b/gui/devices/480x800/res/ui.xml
index 0e0f65d..895cfaa 100644
--- a/gui/devices/480x800/res/ui.xml
+++ b/gui/devices/480x800/res/ui.xml
@@ -77,6 +77,7 @@
 		<variable name="row17_text_y" value="620" />
 		<variable name="row18_text_y" value="650" />
 		<variable name="zip_status_y" value="585" />
+		<variable name="flash_list_height" value="210" />
 		<variable name="tz_selected_y" value="110" />
 		<variable name="tz_set_y" value="580" />
 		<variable name="tz_current_y" value="730" />
diff --git a/gui/devices/480x854/res/ui.xml b/gui/devices/480x854/res/ui.xml
index 26d8b28..dd7efd7 100644
--- a/gui/devices/480x854/res/ui.xml
+++ b/gui/devices/480x854/res/ui.xml
@@ -76,6 +76,7 @@
 		<variable name="row17_text_y" value="630" />
 		<variable name="row18_text_y" value="660" />
 		<variable name="zip_status_y" value="585" />
+		<variable name="flash_list_height" value="210" />
 		<variable name="tz_selected_y" value="110" />
 		<variable name="tz_set_y" value="580" />
 		<variable name="tz_current_y" value="730" />
diff --git a/gui/devices/540x960/res/ui.xml b/gui/devices/540x960/res/ui.xml
index dc647ce..eb6d671 100644
--- a/gui/devices/540x960/res/ui.xml
+++ b/gui/devices/540x960/res/ui.xml
@@ -77,6 +77,7 @@
 		<variable name="row17_text_y" value="780" />
 		<variable name="row18_text_y" value="820" />
 		<variable name="zip_status_y" value="696" />
+		<variable name="flash_list_height" value="260" />
 		<variable name="tz_selected_y" value="110" />
 		<variable name="tz_set_y" value="720" />
 		<variable name="tz_current_y" value="895" />
@@ -311,7 +312,7 @@
 
 			<object type="button">
 				<placement x="%sort_col1_button_x%" y="%sort_asc_button_y%" />
-				<font resource="UItext" color="%button_text_color%" />
+				<font resource="mediumfont" color="%button_text_color%" />
 				<text>Name</text>
 				<image resource="sort_button" />
 				<action function="set">tw_gui_sort_order=1</action>
@@ -319,7 +320,7 @@
 
 			<object type="button">
 				<placement x="%sort_col2_button_x%" y="%sort_asc_button_y%" />
-				<font resource="UItext" color="%button_text_color%" />
+				<font resource="mediumfont" color="%button_text_color%" />
 				<text>Date</text>
 				<image resource="sort_button" />
 				<action function="set">tw_gui_sort_order=2</action>
@@ -327,7 +328,7 @@
 
 			<object type="button">
 				<placement x="%sort_col3_button_x%" y="%sort_asc_button_y%" />
-				<font resource="UItext" color="%button_text_color%" />
+				<font resource="mediumfont" color="%button_text_color%" />
 				<text>Size</text>
 				<image resource="sort_button" />
 				<action function="set">tw_gui_sort_order=3</action>
@@ -341,7 +342,7 @@
 
 			<object type="button">
 				<placement x="%sort_col1_button_x%" y="%sort_desc_button_y%" />
-				<font resource="UItext" color="%button_text_color%" />
+				<font resource="mediumfont" color="%button_text_color%" />
 				<text>Name</text>
 				<image resource="sort_button" />
 				<action function="set">tw_gui_sort_order=-1</action>
@@ -349,7 +350,7 @@
 
 			<object type="button">
 				<placement x="%sort_col2_button_x%" y="%sort_desc_button_y%" />
-				<font resource="UItext" color="%button_text_color%" />
+				<font resource="mediumfont" color="%button_text_color%" />
 				<text>Date</text>
 				<image resource="sort_button" />
 				<action function="set">tw_gui_sort_order=-2</action>
@@ -357,7 +358,7 @@
 
 			<object type="button">
 				<placement x="%sort_col3_button_x%" y="%sort_desc_button_y%" />
-				<font resource="UItext" color="%button_text_color%" />
+				<font resource="mediumfont" color="%button_text_color%" />
 				<text>Size</text>
 				<image resource="sort_button" />
 				<action function="set">tw_gui_sort_order=-3</action>
diff --git a/gui/devices/720x1280/res/ui.xml b/gui/devices/720x1280/res/ui.xml
index 2f1fbc7..3020daa 100644
--- a/gui/devices/720x1280/res/ui.xml
+++ b/gui/devices/720x1280/res/ui.xml
@@ -81,6 +81,7 @@
 		<variable name="row17_text_y" value="970" />
 		<variable name="row18_text_y" value="1020" />
 		<variable name="zip_status_y" value="615" />
+		<variable name="flash_list_height" value="330" />
 		<variable name="tz_selected_y" value="160" />
 		<variable name="tz_set_y" value="950" />
 		<variable name="tz_current_y" value="1180" />
diff --git a/gui/devices/800x1280/res/ui.xml b/gui/devices/800x1280/res/ui.xml
index 03b6144..6f49bf7 100644
--- a/gui/devices/800x1280/res/ui.xml
+++ b/gui/devices/800x1280/res/ui.xml
@@ -78,6 +78,7 @@
 		<variable name="row17_text_y" value="%row16_text_y%+%text_row_height%" />
 		<variable name="row18_text_y" value="%row17_text_y%+%text_row_height%" />
 		<variable name="zip_status_y" value="640" />
+		<variable name="flash_list_height" value="330" />
 		<variable name="tz_selected_y" value="160" />
 		<variable name="tz_set_y" value="955" />
 		<variable name="tz_current_y" value="1185" />
diff --git a/gui/devices/800x480/res/ui.xml b/gui/devices/800x480/res/ui.xml
index ed1c842..b80ed3b 100644
--- a/gui/devices/800x480/res/ui.xml
+++ b/gui/devices/800x480/res/ui.xml
@@ -192,6 +192,7 @@
 		<variable name="button_fill_half_height" value="40" />
 		<variable name="button_fill_quarter_height" value="30" />
 		<variable name="button_full_center_x" value="200" />
+		<variable name="flash_list_height" value="140" />
 		<variable name="backup_list_x" value="23" />
 		<variable name="backup_list_y" value="80" />
 		<variable name="backup_list_width" value="367" />
diff --git a/gui/devices/landscape/res/landscape.xml b/gui/devices/landscape/res/landscape.xml
index 8f557aa..f66eb8b 100644
--- a/gui/devices/landscape/res/landscape.xml
+++ b/gui/devices/landscape/res/landscape.xml
@@ -148,6 +148,17 @@
 
 			<object type="template" name="sort_options" />
 
+			<object type="button">
+				<highlight color="%highlight_color%" />
+				<placement x="%filemanager_select_x%" y="%filemanager_select_y%" />
+				<font resource="font" color="%button_text_color%" />
+				<text>Images...</text>
+				<image resource="main_button" />
+				<actions>
+					<action function="page">install_image</action>
+				</actions>
+			</object>
+
 			<object type="action">
 				<condition var1="tw_filename" op="modified" />
 				<actions>
@@ -390,6 +401,172 @@
 			</object>
 		</page>
 
+		<page name="install_image">
+			<object type="template" name="header" />
+
+			<object type="text" color="%text_color%">
+				<font resource="font" />
+				<placement x="%center_x%" y="%row1_text_y%" placement="5" />
+				<text>Select Image to Flash</text>
+			</object>
+
+			<object type="button">
+				<highlight color="%highlight_color%" />
+				<fill color="%button_fill_color%" />
+				<placement x="%button_full_center_x%" y="%zipstorage_text_y%" w="%button_fill_full_width%" h="%button_fill_quarter_height%" />
+				<font resource="font" color="%button_text_color%" />
+				<text>Storage: %tw_storage_display_name% (%tw_storage_free_size% MB)</text>
+				<actions>
+					<action function="set">tw_back=install_image</action>
+					<action function="page">selectstorage</action>
+				</actions>
+			</object>
+
+			<object type="fileselector">
+				<highlight color="%fileselector_highlight_color%" />
+				<placement x="%fileselector_folder_x%" y="%fileselector_install_y%" w="%fileselector_folder_width%" h="%fileselector_install_height%" />
+				<header background="%fileselector_header_background%" textcolor="%fileselector_header_textcolor%" separatorcolor="%fileselector_header_separatorcolor%" separatorheight="%fileselector_header_separatorheight%" />
+				<fastscroll linecolor="%fastscroll_linecolor%" rectcolor="%fastscroll_rectcolor%" w="%fastscroll_w%" linew="%fastscroll_linew%" rectw="%fastscroll_rectw%" recth="%fastscroll_recth%" />
+				<text>Folders:</text>
+				<separator color="%fileselector_separatorcolor%" height="%fileselector_separatorheight%" />
+				<sort name="tw_gui_sort_order" />
+				<icon folder="folder_icon" file="file_icon" />
+				<background color="%fileselector_background%" />
+				<font resource="font" spacing="%fileselector_spacing%" color="%text_color%" highlightcolor="%fileselector_highlight_font_color%" />
+				<filter folders="1" files="0" />
+				<path name="tw_zip_location" default="/sdcard" />
+				<data name="select" />
+			</object>
+
+			<object type="fileselector">
+				<highlight color="%fileselector_highlight_color%" />
+				<placement x="%fileselector_file_x%" y="%fileselector_install_y%" w="%fileselector_file_width%" h="%fileselector_install_height%" />
+				<header background="%fileselector_header_background%" textcolor="%fileselector_header_textcolor%" separatorcolor="%fileselector_header_separatorcolor%" separatorheight="%fileselector_header_separatorheight%" />
+				<fastscroll linecolor="%fastscroll_linecolor%" rectcolor="%fastscroll_rectcolor%" w="%fastscroll_w%" linew="%fastscroll_linew%" rectw="%fastscroll_rectw%" recth="%fastscroll_recth%" />
+				<text>%tw_zip_location%</text>
+				<separator color="%fileselector_separatorcolor%" height="%fileselector_separatorheight%" />
+				<sort name="tw_gui_sort_order" />
+				<icon folder="folder_icon" file="file_icon" />
+				<background color="%fileselector_background%" />
+				<font resource="font" spacing="%fileselector_spacing%" color="%text_color%" highlightcolor="%fileselector_highlight_font_color%" />
+				<filter extn=".img" folders="0" files="1" />
+				<path name="tw_zip_location" />
+				<data name="tw_filename" />
+				<selection name="tw_file" />
+			</object>
+
+			<object type="template" name="sort_options" />
+
+			<object type="button">
+				<highlight color="%highlight_color%" />
+				<placement x="%filemanager_select_x%" y="%filemanager_select_y%" />
+				<font resource="font" color="%button_text_color%" />
+				<text>Zips...</text>
+				<image resource="main_button" />
+				<actions>
+					<action function="page">install</action>
+				</actions>
+			</object>
+
+			<object type="action">
+				<condition var1="tw_filename" op="modified" />
+				<action function="page">flashimage_confirm</action>
+			</object>
+
+			<object type="action">
+				<touch key="back" />
+				<action function="page">install</action>
+			</object>
+
+			<object type="action">
+				<touch key="home" />
+				<action function="page">main</action>
+			</object>
+
+			<object type="template" name="footer" />
+		</page>
+
+		<page name="flashimage_confirm">
+			<object type="template" name="header" />
+
+			<object type="partitionlist">
+				<highlight color="%fileselector_highlight_color%" />
+				<placement x="%col2_x%" y="%row1_text_y%" w="%listbox_width%" h="%flash_list_height%" />
+				<header background="%fileselector_header_background%" textcolor="%fileselector_header_textcolor%" separatorcolor="%fileselector_header_separatorcolor%" separatorheight="%fileselector_header_separatorheight%" />
+				<fastscroll linecolor="%fastscroll_linecolor%" rectcolor="%fastscroll_rectcolor%" w="%fastscroll_w%" linew="%fastscroll_linew%" rectw="%fastscroll_rectw%" recth="%fastscroll_recth%" />
+				<text>Select Partition to Flash Image:</text>
+				<icon selected="radio_true" unselected="radio_false" />
+				<separator color="%fileselector_separatorcolor%" height="%fileselector_separatorheight%" />
+				<background color="%listbox_background%" />
+				<font resource="font" spacing="%fileselector_spacing%" color="%text_color%" highlightcolor="%fileselector_highlight_font_color%" />
+				<data name="tw_flash_partition" />
+				<listtype name="flashimg" />
+			</object>
+
+			<object type="text" color="%text_color%">
+				<font resource="font" />
+				<placement x="%center_x%" y="%row8_text_y%" placement="5" />
+				<text>Folder:</text>
+			</object>
+
+			<object type="text" color="%text_color%">
+				<font resource="font" />
+				<placement x="%center_x%" y="%row9_text_y%" placement="5" />
+				<text>%tw_zip_location%</text>
+			</object>
+
+			<object type="text" color="%text_color%">
+				<font resource="font" />
+				<placement x="%center_x%" y="%row10_text_y%" placement="5" />
+				<text>File to flash:</text>
+			</object>
+
+			<object type="text" color="%text_color%">
+				<font resource="font" />
+				<placement x="%center_x%" y="%row11_text_y%" placement="5" />
+				<text>%tw_file%</text>
+			</object>
+
+			<object type="slider">
+				<placement x="%slider_x%" y="%slider_y%" placement="5" />
+				<resource base="slider" used="slider-used" touch="slider-touch" />
+				<actions>
+					<action function="set">tw_back=flashimage_confirm</action>
+					<action function="set">tw_action=flashimage</action>
+					<action function="set">tw_has_action2=0</action>
+					<action function="set">tw_action_text1=Flashing Image...</action>
+					<action function="set">tw_action_text2=</action>
+					<action function="set">tw_complete_text1=Image Flashed</action>
+					<action function="page">action_page</action>
+				</actions>
+				<action function="flashimage"></action>
+			</object>
+
+			<object type="text" color="%text_color%">
+				<font resource="font" />
+				<placement x="%center_x%" y="%slider_text_y%" placement="4" />
+				<text>Swipe to Confirm Flash</text>
+			</object>
+
+			<object type="action">
+				<touch key="back" />
+				<actions>
+					<action function="set">tw_clear_destination=install_image</action>
+					<action function="page">clear_vars</action>
+				</actions>
+			</object>
+
+			<object type="action">
+				<touch key="home" />
+				<actions>
+					<action function="set">tw_clear_destination=main2</action>
+					<action function="page">clear_vars</action>
+				</actions>
+			</object>
+
+			<object type="template" name="footer" />
+		</page>
+
 		<page name="clear_vars">
 			<object type="action">
 				<action function="set">tw_operation_state=0</action>
diff --git a/gui/devices/portrait/res/portrait.xml b/gui/devices/portrait/res/portrait.xml
index 0642c30..b732974 100644
--- a/gui/devices/portrait/res/portrait.xml
+++ b/gui/devices/portrait/res/portrait.xml
@@ -133,6 +133,17 @@
 
 			<object type="template" name="sort_options" />
 
+			<object type="button">
+				<highlight color="%highlight_color%" />
+				<placement x="%filemanager_select_x%" y="%filemanager_select_y%" />
+				<font resource="font" color="%button_text_color%" />
+				<text>Images...</text>
+				<image resource="medium_button" />
+				<actions>
+					<action function="page">install_image</action>
+				</actions>
+			</object>
+
 			<object type="action">
 				<condition var1="tw_filename" op="modified" />
 				<actions>
@@ -403,6 +414,156 @@
 			</object>
 		</page>
 
+		<page name="install_image">
+			<object type="template" name="header" />
+
+			<object type="text" color="%text_color%">
+				<font resource="font" />
+				<placement x="%center_x%" y="%row1_header_y%" placement="5" />
+				<text>Select Image to Install</text>
+			</object>
+
+			<object type="button">
+				<highlight color="%highlight_color%" />
+				<fill color="%button_fill_color%" />
+				<placement x="%col1_x%" y="%row1_text_y%" w="%button_fill_full_width%" h="%button_fill_quarter_height%" />
+				<font resource="font" color="%button_text_color%" />
+				<text>Storage: %tw_storage_display_name% (%tw_storage_free_size% MB)</text>
+				<actions>
+					<action function="set">tw_back=install_image</action>
+					<action function="page">selectstorage</action>
+				</actions>
+			</object>
+
+			<object type="fileselector">
+				<highlight color="%fileselector_highlight_color%" />
+				<placement x="%fileselector_x%" y="%row3_text_y%" w="%fileselector_width%" h="%fileselector_install_height%" />
+				<header background="%fileselector_header_background%" textcolor="%fileselector_header_textcolor%" separatorcolor="%fileselector_header_separatorcolor%" separatorheight="%fileselector_header_separatorheight%" />
+				<fastscroll linecolor="%fastscroll_linecolor%" rectcolor="%fastscroll_rectcolor%" w="%fastscroll_w%" linew="%fastscroll_linew%" rectw="%fastscroll_rectw%" recth="%fastscroll_recth%" />
+				<text>%tw_zip_location%</text>
+				<separator color="%fileselector_separatorcolor%" height="%fileselector_separatorheight%" />
+				<sort name="tw_gui_sort_order" />
+				<icon folder="folder_icon" file="file_icon" />
+				<background color="%fileselector_background%" />
+				<font resource="filelist" spacing="%fileselector_spacing%" color="%text_color%" highlightcolor="%fileselector_highlight_font_color%" />
+				<filter extn=".img" folders="1" files="1" />
+				<path name="tw_zip_location" default="/sdcard" />
+				<data name="tw_filename" />
+				<selection name="tw_file" />
+			</object>
+
+			<object type="template" name="sort_options" />
+
+			<object type="button">
+				<highlight color="%highlight_color%" />
+				<placement x="%filemanager_select_x%" y="%filemanager_select_y%" />
+				<font resource="font" color="%button_text_color%" />
+				<text>Zips...</text>
+				<image resource="medium_button" />
+				<actions>
+					<action function="page">install</action>
+				</actions>
+			</object>
+
+			<object type="action">
+				<condition var1="tw_filename" op="modified" />
+				<action function="page">flashimage_confirm</action>
+			</object>
+
+			<object type="action">
+				<touch key="back" />
+				<action function="page">install</action>
+			</object>
+
+			<object type="action">
+				<touch key="home" />
+				<action function="page">main</action>
+			</object>
+
+			<object type="template" name="footer" />
+		</page>
+
+		<page name="flashimage_confirm">
+			<object type="template" name="header" />
+
+			<object type="partitionlist">
+				<highlight color="%fileselector_highlight_color%" />
+				<placement x="%listbox_x%" y="%row1_header_y%" w="%listbox_width%" h="%flash_list_height%" />
+				<header background="%fileselector_header_background%" textcolor="%fileselector_header_textcolor%" separatorcolor="%fileselector_header_separatorcolor%" separatorheight="%fileselector_header_separatorheight%" />
+				<fastscroll linecolor="%fastscroll_linecolor%" rectcolor="%fastscroll_rectcolor%" w="%fastscroll_w%" linew="%fastscroll_linew%" rectw="%fastscroll_rectw%" recth="%fastscroll_recth%" />
+				<text>Select Partition to Flash Image:</text>
+				<icon selected="radio_true" unselected="radio_false" />
+				<separator color="%fileselector_separatorcolor%" height="%fileselector_separatorheight%" />
+				<background color="%listbox_background%" />
+				<font resource="filelist" spacing="%fileselector_spacing%" color="%text_color%" highlightcolor="%fileselector_highlight_font_color%" />
+				<data name="tw_flash_partition" />
+				<listtype name="flashimg" />
+			</object>
+
+			<object type="text" color="%text_color%">
+				<font resource="font" />
+				<placement x="%center_x%" y="%row8_text_y%" placement="5" />
+				<text>Folder:</text>
+			</object>
+
+			<object type="text" color="%text_color%">
+				<font resource="mediumfont" />
+				<placement x="%center_x%" y="%row9_text_y%" placement="5" />
+				<text>%tw_zip_location%</text>
+			</object>
+
+			<object type="text" color="%text_color%">
+				<font resource="font" />
+				<placement x="%center_x%" y="%row10_text_y%" placement="5" />
+				<text>File to flash:</text>
+			</object>
+
+			<object type="text" color="%text_color%">
+				<font resource="mediumfont" />
+				<placement x="%center_x%" y="%row11_text_y%" placement="5" />
+				<text>%tw_file%</text>
+			</object>
+
+			<object type="slider">
+				<placement x="%slider_x%" y="%slider_y%" placement="5" />
+				<resource base="slider" used="slider-used" touch="slider-touch" />
+				<actions>
+					<action function="set">tw_back=flashimage_confirm</action>
+					<action function="set">tw_action=flashimage</action>
+					<action function="set">tw_has_action2=0</action>
+					<action function="set">tw_action_text1=Flashing Image...</action>
+					<action function="set">tw_action_text2=</action>
+					<action function="set">tw_complete_text1=Image Flashed</action>
+					<action function="page">action_page</action>
+				</actions>
+				<action function="flashimage"></action>
+			</object>
+
+			<object type="text" color="%text_color%">
+				<font resource="font" />
+				<placement x="%center_x%" y="%slider_text_y%" placement="4" />
+				<text>Swipe to Confirm Flash</text>
+			</object>
+
+			<object type="action">
+				<touch key="back" />
+				<actions>
+					<action function="set">tw_clear_destination=install_image</action>
+					<action function="page">clear_vars</action>
+				</actions>
+			</object>
+
+			<object type="action">
+				<touch key="home" />
+				<actions>
+					<action function="set">tw_clear_destination=main2</action>
+					<action function="page">clear_vars</action>
+				</actions>
+			</object>
+
+			<object type="template" name="footer" />
+		</page>
+
 		<page name="clear_vars">
 			<object type="action">
 				<action function="set">tw_operation_state=0</action>
diff --git a/gui/devices/watch/res/watch.xml b/gui/devices/watch/res/watch.xml
index 38de230..03effde 100644
--- a/gui/devices/watch/res/watch.xml
+++ b/gui/devices/watch/res/watch.xml
@@ -22,10 +22,7 @@
 				<font resource="font" color="%button_text_color%" />
 				<text>Install</text>
 				<image resource="main_button" />
-				<actions>
-					<action function="queueclear"></action>
-					<action function="page">install</action>
-				</actions>
+				<action function="page">install_select</action>
 			</object>
 
 			<object type="button">
@@ -95,6 +92,45 @@
 			<object type="template" name="footer" />
 		</page>
 
+		<page name="install_select">
+			<object type="template" name="twrpheader" />
+
+			<object type="template" name="header" />
+
+			<object type="button">
+				<highlight color="%highlight_color%" />
+				<placement x="%col1_x%" y="%row1_home_y%" />
+				<font resource="font" color="%button_text_color%" />
+				<text>Install Zips</text>
+				<image resource="main_button" />
+				<actions>
+					<action function="queueclear"></action>
+					<action function="page">install</action>
+				</actions>
+			</object>
+
+			<object type="button">
+				<highlight color="%highlight_color%" />
+				<placement x="%col2_x%" y="%row1_home_y%" />
+				<font resource="font" color="%button_text_color%" />
+				<text>Install Images</text>
+				<image resource="main_button" />
+				<action function="page">install_image</action>
+			</object>
+
+			<object type="action">
+				<touch key="back" />
+				<action function="page">main</action>
+			</object>
+
+			<object type="action">
+				<touch key="home" />
+				<action function="page">main</action>
+			</object>
+
+			<object type="template" name="footer" />
+		</page>
+
 		<page name="install">
 			<object type="template" name="header" />
 
@@ -145,7 +181,7 @@
 
 			<object type="action">
 				<touch key="back" />
-				<action function="page">main</action>
+				<action function="page">install_select</action>
 			</object>
 
 			<object type="action">
@@ -385,6 +421,143 @@
 			</object>
 		</page>
 
+		<page name="install_image">
+			<object type="template" name="header" />
+
+			<object type="text" color="%text_color%">
+				<font resource="font" />
+				<placement x="%center_x%" y="%row1_header_y%" placement="5" />
+				<text>Select Image to Install</text>
+			</object>
+
+			<object type="button">
+				<highlight color="%highlight_color%" />
+				<fill color="%button_fill_color%" />
+				<placement x="%col1_x%" y="%row1_text_y%" w="%button_fill_full_width%" h="%button_fill_quarter_height%" />
+				<font resource="font" color="%button_text_color%" />
+				<text>Storage: %tw_storage_display_name% (%tw_storage_free_size% MB)</text>
+				<actions>
+					<action function="set">tw_back=install_image</action>
+					<action function="page">selectstorage</action>
+				</actions>
+			</object>
+
+			<object type="fileselector">
+				<highlight color="%fileselector_highlight_color%" />
+				<placement x="%fileselector_x%" y="%row3_text_y%" w="%fileselector_width%" h="%fileselector_install_height%" />
+				<header background="%fileselector_header_background%" textcolor="%fileselector_header_textcolor%" separatorcolor="%fileselector_header_separatorcolor%" separatorheight="%fileselector_header_separatorheight%" />
+				<fastscroll linecolor="%fastscroll_linecolor%" rectcolor="%fastscroll_rectcolor%" w="%fastscroll_w%" linew="%fastscroll_linew%" rectw="%fastscroll_rectw%" recth="%fastscroll_recth%" />
+				<text>%tw_zip_location%</text>
+				<separator color="%fileselector_separatorcolor%" height="%fileselector_separatorheight%" />
+				<sort name="tw_gui_sort_order" />
+				<icon folder="folder_icon" file="file_icon" />
+				<background color="%fileselector_background%" />
+				<font resource="filelist" spacing="%fileselector_spacing%" color="%text_color%" highlightcolor="%fileselector_highlight_font_color%" />
+				<filter extn=".img" folders="1" files="1" />
+				<path name="tw_zip_location" default="/sdcard" />
+				<data name="tw_filename" />
+				<selection name="tw_file" />
+			</object>
+
+			<object type="template" name="sort_options" />
+
+			<object type="action">
+				<condition var1="tw_filename" op="modified" />
+				<action function="page">flashimage_confirm</action>
+			</object>
+
+			<object type="action">
+				<touch key="back" />
+				<action function="page">install_select</action>
+			</object>
+
+			<object type="action">
+				<touch key="home" />
+				<action function="page">main</action>
+			</object>
+
+			<object type="template" name="footer" />
+		</page>
+
+		<page name="flashimage_confirm">
+			<object type="template" name="header" />
+
+			<object type="partitionlist">
+				<highlight color="%fileselector_highlight_color%" />
+				<placement x="%listbox_x%" y="%row1_header_y%" w="%listbox_width%" h="%flash_list_height%" />
+				<header background="%fileselector_header_background%" textcolor="%fileselector_header_textcolor%" separatorcolor="%fileselector_header_separatorcolor%" separatorheight="%fileselector_header_separatorheight%" />
+				<fastscroll linecolor="%fastscroll_linecolor%" rectcolor="%fastscroll_rectcolor%" w="%fastscroll_w%" linew="%fastscroll_linew%" rectw="%fastscroll_rectw%" recth="%fastscroll_recth%" />
+				<text>Select Partition to Flash Image:</text>
+				<icon selected="radio_true" unselected="radio_false" />
+				<separator color="%fileselector_separatorcolor%" height="%fileselector_separatorheight%" />
+				<background color="%listbox_background%" />
+				<font resource="filelist" spacing="%fileselector_spacing%" color="%text_color%" highlightcolor="%fileselector_highlight_font_color%" />
+				<data name="tw_flash_partition" />
+				<listtype name="flashimg" />
+			</object>
+
+			<object type="text" color="%text_color%">
+				<font resource="font" />
+				<placement x="%center_x%" y="%row8_text_y%" placement="5" />
+				<text>Folder:</text>
+			</object>
+
+			<object type="text" color="%text_color%">
+				<font resource="mediumfont" />
+				<placement x="%center_x%" y="%row9_text_y%" placement="5" />
+				<text>%tw_zip_location%</text>
+			</object>
+
+			<object type="text" color="%text_color%">
+				<font resource="font" />
+				<placement x="%center_x%" y="%row10_text_y%" placement="5" />
+				<text>File to flash:</text>
+			</object>
+
+			<object type="text" color="%text_color%">
+				<font resource="mediumfont" />
+				<placement x="%center_x%" y="%row11_text_y%" placement="5" />
+				<text>%tw_file%</text>
+			</object>
+
+			<object type="slider">
+				<placement x="%slider_x%" y="%slider_y%" placement="5" />
+				<resource base="slider" used="slider-used" touch="slider-touch" />
+				<actions>
+					<action function="set">tw_back=flashimage_confirm</action>
+					<action function="set">tw_action=flashimage</action>
+					<action function="set">tw_has_action2=0</action>
+					<action function="set">tw_action_text1=Flashing Image...</action>
+					<action function="set">tw_action_text2=</action>
+					<action function="set">tw_complete_text1=Image Flashed</action>
+					<action function="page">action_page</action>
+				</actions>
+				<action function="flashimage"></action>
+			</object>
+
+			<object type="text" color="%text_color%">
+				<font resource="font" />
+				<placement x="%center_x%" y="%slider_text_y%" placement="4" />
+				<text>Swipe to Confirm Flash</text>
+			</object>
+
+			<object type="action">
+				<touch key="back" />
+				<actions>
+					<action function="set">tw_clear_destination=install_image</action>
+					<action function="page">clear_vars</action>
+				</actions>
+			</object>
+
+			<object type="action">
+				<touch key="home" />
+				<actions>
+					<action function="set">tw_clear_destination=main2</action>
+					<action function="page">clear_vars</action>
+				</actions>
+			</object>
+		</page>
+
 		<page name="clear_vars">
 			<object type="action">
 				<action function="set">tw_operation_state=0</action>
diff --git a/gui/objects.hpp b/gui/objects.hpp
index 76dbb46..bb3edb3 100644
--- a/gui/objects.hpp
+++ b/gui/objects.hpp
@@ -352,6 +352,7 @@
 	int changefilesystem(std::string arg);
 	int startmtp(std::string arg);
 	int stopmtp(std::string arg);
+	int flashimage(std::string arg);
 
 	int simulate;
 };
diff --git a/gui/partitionlist.cpp b/gui/partitionlist.cpp
index 9cc6a77..3ec1548 100644
--- a/gui/partitionlist.cpp
+++ b/gui/partitionlist.cpp
@@ -793,6 +793,10 @@
 						DataManager::SetValue(mVariable, str);
 					}
 				} else {
+					if (ListType == "flashimg") { // only one item can be selected for flashing images
+						for (int i=0; i<listSize; i++)
+							mList.at(i).selected = 0;
+					}
 					if (mList.at(actualSelection).selected)
 						mList.at(actualSelection).selected = 0;
 					else