freemyipod r830 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r829‎ | r830 | r831 >
Date:16:03, 25 December 2011
Author:theseven
Status:new
Tags:
Comment:
iPod Classic boot menu: Add confirmation prompts to destructive operations
Modified paths:
  • /apps/bootmenu-ipodclassic/SOURCES (modified) (history)
  • /apps/bootmenu-ipodclassic/confirmchooser.c (added) (history)
  • /apps/bootmenu-ipodclassic/confirmchooser.h (added) (history)
  • /apps/bootmenu-ipodclassic/main.c (modified) (history)
  • /apps/bootmenu-ipodclassic/main.h (modified) (history)
  • /apps/bootmenu-ipodclassic/toolchooser.c (modified) (history)
  • /apps/bootmenu-ipodclassic/tools.c (modified) (history)

Diff [purge]

Index: apps/bootmenu-ipodclassic/tools.c
@@ -26,10 +26,12 @@
2727 #include "tools.h"
2828 #include "util.h"
2929 #include "main.h"
 30+#include "confirmchooser.h"
3031
3132
3233 void run_clearcfg(void** firmware, void** app, int* size)
3334 {
 35+ if (!run_confirmchooser("Really clear Rockbox config?")) return;
3436 remove("/.rockbox/config.cfg");
3537 memcpy(framebuf, bg, 320 * 240 * 3);
3638 message(97, "Rockbox configuration", " has been cleared. ");
@@ -37,6 +39,7 @@
3840
3941 void run_cleardb(void** firmware, void** app, int* size)
4042 {
 43+ if (!run_confirmchooser("Really clear Rockbox database?")) return;
4144 remove("/.rockbox/database_0.tcd");
4245 remove("/.rockbox/database_1.tcd");
4346 remove("/.rockbox/database_2.tcd");
@@ -68,6 +71,7 @@
6972
7073 void run_reformat(void** firmware, void** app, int* size)
7174 {
 75+ if (!run_confirmchooser("Really reformat data partition?")) return;
7276 memcpy(framebuf, bg, 320 * 240 * 3);
7377 rendertext(framebuf, 70, 125, 320, 0xff7fffff, 0, "Reformatting data partition...");
7478 update_display(NULL);
Index: apps/bootmenu-ipodclassic/toolchooser.c
@@ -250,7 +250,7 @@
251251
252252 void run_toolchooser(void** firmware, void** app, int* size)
253253 {
254 - while (true)
 254+ while (!*firmware && !*app)
255255 {
256256 const struct chooser_item* result = ui->chooser_run(&toolchooser);
257257 if (!result || !result->user) return;
@@ -257,7 +257,6 @@
258258 void (*selected_function)(void** firmware, void** app, int* size);
259259 selected_function = (void(*)(void** firmware, void** app, int* size))(result->user);
260260 selected_function(firmware, app, size);
261 - if (firmware || app) return;
262261 }
263262 }
264263
Index: apps/bootmenu-ipodclassic/SOURCES
@@ -2,6 +2,7 @@
33 mainchooser.c
44 toolchooser.c
55 settingchooser.c
 6+confirmchooser.c
67 boot.c
78 tools.c
89 util.c
Index: apps/bootmenu-ipodclassic/confirmchooser.c
@@ -0,0 +1,213 @@
 2+//
 3+//
 4+// Copyright 2011 TheSeven
 5+//
 6+//
 7+// This file is part of emCORE.
 8+//
 9+// emCORE is free software: you can redistribute it and/or
 10+// modify it under the terms of the GNU General Public License as
 11+// published by the Free Software Foundation, either version 2 of the
 12+// License, or (at your option) any later version.
 13+//
 14+// emCORE is distributed in the hope that it will be useful,
 15+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 16+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 17+// See the GNU General Public License for more details.
 18+//
 19+// You should have received a copy of the GNU General Public License along
 20+// with emCORE. If not, see <http://www.gnu.org/licenses/>.
 21+//
 22+//
 23+
 24+
 25+#include "emcoreapp.h"
 26+#include "libui.h"
 27+#include "confirmchooser.h"
 28+#include "main.h"
 29+#include "util.h"
 30+
 31+
 32+static struct chooser_renderer_list_itemdata confirmchooser_rparams_yes =
 33+{
 34+ .size = LIBUI_POINT(260, 10),
 35+ .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(260, 10)),
 36+ .fill_color = 0xa0000000,
 37+ .fill_color_selected = 0xa00000ff,
 38+ .icon_pos = LIBUI_POINT_NULL,
 39+ .icon = LIBUI_SURFACE_NULL,
 40+ .icon_opacity = 0,
 41+ .icon_selected = LIBUI_SURFACE_NULL,
 42+ .icon_selected_opacity = 0,
 43+ .text = "Yes",
 44+ .text_pos = LIBUI_POINT(1, 1),
 45+ .text_color = 0xff0000ff,
 46+ .text_color_selected = 0xff3f7fff,
 47+ .render = NULL
 48+};
 49+
 50+static struct chooser_renderer_list_itemdata confirmchooser_rparams_no =
 51+{
 52+ .size = LIBUI_POINT(260, 10),
 53+ .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(260, 10)),
 54+ .fill_color = 0xa0000000,
 55+ .fill_color_selected = 0x60ffffff,
 56+ .icon_pos = LIBUI_POINT_NULL,
 57+ .icon = LIBUI_SURFACE_NULL,
 58+ .icon_opacity = 0,
 59+ .icon_selected = LIBUI_SURFACE_NULL,
 60+ .icon_selected_opacity = 0,
 61+ .text = "No",
 62+ .text_pos = LIBUI_POINT(1, 1),
 63+ .text_color = 0xffffffff,
 64+ .text_color_selected = 0xff7fffff,
 65+ .render = NULL
 66+};
 67+
 68+static struct chooser_renderer_list_params confirmchooser_rparams =
 69+{
 70+ .version = CHOOSER_RENDERER_LIST_PARAMS_VERSION,
 71+ .copy_dest = LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 0)),
 72+ .copy_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 0)),
 73+ LIBUI_POINT(320, 240)),
 74+ .bg_dest = LIBUI_LOCATION_NULL,
 75+ .bg_src = LIBUI_SURFACE_NULL,
 76+ .bg_opacity = 0,
 77+ .fill_dest = LIBUI_SURFACE_NULL,
 78+ .fill_color = 0,
 79+ .viewport = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(30, 70)),
 80+ LIBUI_POINT(260, 140)),
 81+ .blit_dest = LIBUI_POINT(0, 0),
 82+ .blit_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 320), LIBUI_POINT(0, 0)),
 83+ LIBUI_POINT(320, 240)),
 84+ .preblit = update_display,
 85+ .postblit = NULL
 86+};
 87+
 88+static struct chooser_action_handler_wheel_params confirmchooser_aparams =
 89+{
 90+ .version = CHOOSER_ACTION_HANDLER_WHEEL_PARAMS_VERSION,
 91+ .stepsperitem = 128,
 92+ .eventfilter = NULL,
 93+ .timeout_initial = TIMEOUT_BLOCK,
 94+ .timeout_idle = TIMEOUT_BLOCK,
 95+ .timeout_item = 0,
 96+ .tick_force_redraw = true,
 97+ .buttoncount = 5,
 98+ .buttonmap =
 99+ {
 100+ CHOOSER_ACTION_HANDLER_WHEEL_ACTION_SELECT,
 101+ CHOOSER_ACTION_HANDLER_WHEEL_ACTION_SELECT,
 102+ CHOOSER_ACTION_HANDLER_WHEEL_ACTION_CANCEL,
 103+ CHOOSER_ACTION_HANDLER_WHEEL_ACTION_NEXT,
 104+ CHOOSER_ACTION_HANDLER_WHEEL_ACTION_PREV
 105+ }
 106+};
 107+
 108+static struct chooser_info confirmchooser =
 109+{
 110+ .version = CHOOSER_INFO_VERSION,
 111+ .actionhandler = NULL,
 112+ .actionhandlerparams = &confirmchooser_aparams,
 113+ .renderer = NULL,
 114+ .rendererparams = &confirmchooser_rparams,
 115+ .userparams = NULL,
 116+ .tickinterval = 10000000,
 117+ .itemcount = 14,
 118+ .defaultitem = 0,
 119+ .items =
 120+ {
 121+ {
 122+ .user = NULL,
 123+ .actionparams = NULL,
 124+ .renderparams = &confirmchooser_rparams_no
 125+ },
 126+ {
 127+ .user = NULL,
 128+ .actionparams = NULL,
 129+ .renderparams = &confirmchooser_rparams_no
 130+ },
 131+ {
 132+ .user = NULL,
 133+ .actionparams = NULL,
 134+ .renderparams = &confirmchooser_rparams_no
 135+ },
 136+ {
 137+ .user = NULL,
 138+ .actionparams = NULL,
 139+ .renderparams = &confirmchooser_rparams_no
 140+ },
 141+ {
 142+ .user = NULL,
 143+ .actionparams = NULL,
 144+ .renderparams = &confirmchooser_rparams_no
 145+ },
 146+ {
 147+ .user = NULL,
 148+ .actionparams = NULL,
 149+ .renderparams = &confirmchooser_rparams_no
 150+ },
 151+ {
 152+ .user = NULL,
 153+ .actionparams = NULL,
 154+ .renderparams = &confirmchooser_rparams_no
 155+ },
 156+ {
 157+ .user = NULL,
 158+ .actionparams = NULL,
 159+ .renderparams = &confirmchooser_rparams_no
 160+ },
 161+ {
 162+ .user = NULL,
 163+ .actionparams = NULL,
 164+ .renderparams = &confirmchooser_rparams_no
 165+ },
 166+ {
 167+ .user = (void*)1,
 168+ .actionparams = NULL,
 169+ .renderparams = &confirmchooser_rparams_yes
 170+ },
 171+ {
 172+ .user = NULL,
 173+ .actionparams = NULL,
 174+ .renderparams = &confirmchooser_rparams_no
 175+ },
 176+ {
 177+ .user = NULL,
 178+ .actionparams = NULL,
 179+ .renderparams = &confirmchooser_rparams_no
 180+ },
 181+ {
 182+ .user = NULL,
 183+ .actionparams = NULL,
 184+ .renderparams = &confirmchooser_rparams_no
 185+ },
 186+ {
 187+ .user = NULL,
 188+ .actionparams = NULL,
 189+ .renderparams = &confirmchooser_rparams_no
 190+ }
 191+ }
 192+};
 193+
 194+bool run_confirmchooser(const char* message)
 195+{
 196+ memcpy(framebuf2, bg, 320 * 240 * 3);
 197+ ui->blendcolor(260, 20, 0xa0000000, framebuf2, 30, 50, 320, framebuf2, 30, 50, 320);
 198+ rendertext(framebuf2, 31, 51, 320, 0xff3333ff, 0, message);
 199+ const struct chooser_item* result = ui->chooser_run(&confirmchooser);
 200+ if (!result || !result->user) return false;
 201+ return true;
 202+}
 203+
 204+void confirmchooser_init()
 205+{
 206+ confirmchooser.actionhandler = ui->chooser_action_handler_wheel;
 207+ confirmchooser.renderer = ui->chooser_renderer_list;
 208+ confirmchooser_rparams.copy_dest.buf.addr = framebuf;
 209+ confirmchooser_rparams.copy_src.loc.buf.addr = framebuf2;
 210+ confirmchooser_rparams.viewport.loc.buf.addr = framebuf;
 211+ confirmchooser_rparams.blit_src.loc.buf.addr = framebuf;
 212+ confirmchooser_rparams_yes.render = ui->chooser_renderer_list_show_arrow_right;
 213+ confirmchooser_rparams_no.render = ui->chooser_renderer_list_show_arrow_left;
 214+}
Index: apps/bootmenu-ipodclassic/main.c
@@ -34,6 +34,7 @@
3535 struct libboot_api* boot;
3636 struct libui_api* ui;
3737 void* framebuf;
 38+void* framebuf2;
3839 void* bg;
3940 void* icons;
4041 void* rbxlogo;
@@ -83,13 +84,17 @@
8485
8586 framebuf = malloc(320 * 240 * 3);
8687 if (!framebuf) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer!");
 88+ framebuf2 = malloc(320 * 240 * 3);
 89+ if (!framebuf2) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer 2!");
8790
8891 mainchooser_init();
8992 toolchooser_init();
9093 settingchooser_init();
 94+ confirmchooser_init();
9195
9296 run_mainchooser(&firmware, &app, &size);
9397
 98+ free(framebuf2);
9499 free(framebuf);
95100 free(rbxlogo);
96101 free(icons);
Index: apps/bootmenu-ipodclassic/confirmchooser.h
@@ -0,0 +1,35 @@
 2+//
 3+//
 4+// Copyright 2011 TheSeven
 5+//
 6+//
 7+// This file is part of emCORE.
 8+//
 9+// emCORE is free software: you can redistribute it and/or
 10+// modify it under the terms of the GNU General Public License as
 11+// published by the Free Software Foundation, either version 2 of the
 12+// License, or (at your option) any later version.
 13+//
 14+// emCORE is distributed in the hope that it will be useful,
 15+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 16+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 17+// See the GNU General Public License for more details.
 18+//
 19+// You should have received a copy of the GNU General Public License along
 20+// with emCORE. If not, see <http://www.gnu.org/licenses/>.
 21+//
 22+//
 23+
 24+
 25+#ifndef __APP_CONFIRMCHOOSER_H__
 26+#define __APP_CONFIRMCHOOSER_H__
 27+
 28+
 29+#include "emcoreapp.h"
 30+
 31+
 32+extern bool run_confirmchooser(const char* message);
 33+extern void confirmchooser_init();
 34+
 35+
 36+#endif
Index: apps/bootmenu-ipodclassic/main.h
@@ -35,6 +35,7 @@
3636 extern struct libboot_api* boot;
3737 extern struct libui_api* ui;
3838 extern void* framebuf;
 39+extern void* framebuf2;
3940 extern void* bg;
4041 extern void* icons;
4142 extern void* rbxlogo;