organization

This commit is contained in:
Nick Chan committed 2023-01-29 13:08:48 +08:00
1 parent 40bfe1ecc3
commit 516e78e1f9
8 files changed
+190 -86

No files matched your search

+14 -2
View File
@@ -18,7 +18,10 @@
#define MAIN_START "Start"
#define MAIN_EXIT "Exit"
enum tui_screens {
#define MSG_COLOR 1
#define ICON_COLOR 2
typedef enum tui_screens {
ERROR_SCREEN = -1,
EXIT_SCREEN = 0,
MAIN_SCREEN = 1,
@@ -26,6 +29,15 @@ enum tui_screens {
ENTER_DFU_SCREEN = 3,
JAILBREAKING_SCREEN = 4,
ENTER_RECOVERY_SCREEN = 5
};
} tui_screen_t;
tui_screen_t tui_screen_main();
tui_screen_t tui_screen_options();
tui_screen_t tui_screen_enter_recovery();
tui_screen_t tui_screen_enter_dfu();
tui_screen_t tui_screen_jailbreak();
int redraw_screen();
#endif
+4 -2
View File
@@ -1,9 +1,11 @@
all: palera1n
OBJECTS = main.o dfuhelper.o devhelper.o lockdown_helper.o exec_checkra1n.o
OBJECTS += pongo_usb.o optparse.o override_file.o pongo_helper.o log.o window.o
OBJECTS += pongo_usb.o optparse.o override_file.o pongo_helper.o log.o
OBJECTS += xxd-checkra1n.o xxd-checkra1n-kpf-pongo.o xxd-ramdisk.dmg.o
OBJECTS += xxd-binpack.dmg.o
OBJECTS += xxd-binpack.dmg.o tui_main.o tui_screen_options.o
OBJECTS += tui_screen_enter_recovery.o tui_screen_enter_dfu.o
OBJECTS += tui_screen_jailbreak.o tui_screen_main.o
CHECKRA1N_VERSION ?= 0.1337.1
LIPO = lipo
+91
View File
@@ -0,0 +1,91 @@
#define NCURSES_WIDECHAR 1
#include <ncurses.h>
#include <form.h>
#include <menu.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <locale.h>
#include <unistd.h>
#include <assert.h>
#include <common.h>
#include <tui.h>
int redraw_screen() {
erase();
resizeterm(24, 80);
box(stdscr, 0, 0);
mvaddstr(0, 80 - strlen("[palera1n version " PALERAIN_VERSION "]") - 2 , "[palera1n version " PALERAIN_VERSION "]");
return 0;
}
int destroy_window() {
endwin();
return 0;
}
int init_window() {
setlocale(LC_ALL, NULL);
initscr();
if (has_colors() == TRUE) {
start_color();
init_pair(MSG_COLOR, COLOR_YELLOW, COLOR_BLACK);
init_pair(ICON_COLOR, COLOR_WHITE, COLOR_BLACK);
}
int height, width;
getmaxyx(stdscr, height, width);
if (width < 80 || height < 24) {
LOG(LOG_ERROR, "Terminal size must be at least 80x24");
return -1;
}
if (has_colors() == FALSE) {
LOG(LOG_VERBOSE2, "Terminal without color support detected");
}
cbreak();
noecho();
keypad(stdscr, TRUE);
return 0;
}
int tui() {
int ret = MAIN_SCREEN;
init_window();
while (1) {
redraw_screen();
switch (ret) {
case ERROR_SCREEN:
goto out;
break;
case EXIT_SCREEN:
goto out;
break;
case MAIN_SCREEN:
ret = tui_screen_main();
break;
case OPTIONS_SCREEN:
ret = tui_screen_options();
break;
case ENTER_RECOVERY_SCREEN:
ret = tui_screen_enter_recovery();
break;
case ENTER_DFU_SCREEN:
ret = tui_screen_enter_dfu();
break;
case JAILBREAKING_SCREEN:
ret = tui_screen_jailbreak();
break;
default:
assert(0);
goto out;
}
}
out:
destroy_window();
return ret;
}
+20
View File
@@ -0,0 +1,20 @@
#define NCURSES_WIDECHAR 1
#include <ncurses.h>
#include <form.h>
#include <menu.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <locale.h>
#include <unistd.h>
#include <assert.h>
#include <common.h>
#include <tui.h>
tui_screen_t tui_screen_enter_dfu() { return JAILBREAKING_SCREEN; }
+20
View File
@@ -0,0 +1,20 @@
#define NCURSES_WIDECHAR 1
#include <ncurses.h>
#include <form.h>
#include <menu.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <locale.h>
#include <unistd.h>
#include <assert.h>
#include <common.h>
#include <tui.h>
tui_screen_t tui_screen_enter_recovery() { return ENTER_DFU_SCREEN; }
+20
View File
@@ -0,0 +1,20 @@
#define NCURSES_WIDECHAR 1
#include <ncurses.h>
#include <form.h>
#include <menu.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <locale.h>
#include <unistd.h>
#include <assert.h>
#include <common.h>
#include <tui.h>
tui_screen_t tui_screen_jailbreak() { return EXIT_SCREEN; }
+1 -82
View File
@@ -17,18 +17,7 @@
#include <common.h>
#include <tui.h>
#define MSG_COLOR 1
#define ICON_COLOR 2
int redraw_screen() {
erase();
resizeterm(24, 80);
box(stdscr, 0, 0);
mvaddstr(0, 80 - strlen("[palera1n version " PALERAIN_VERSION "]") - 2 , "[palera1n version " PALERAIN_VERSION "]");
return 0;
}
int display_main_menu() {
tui_screen_t tui_screen_main() {
int ret = -1;
mvaddstr(1, 2, "Welcome to palera1n!");
move(2,1);
@@ -118,73 +107,3 @@ end:
refresh();
return ret;
}
int display_enter_dfu_screen() { return JAILBREAKING_SCREEN; }
int display_enter_recovery_screen() { return ENTER_DFU_SCREEN; }
int display_options_screen() { return MAIN_SCREEN; }
int display_jailbreaking_screen() { return EXIT_SCREEN; }
int init_window() {
setlocale(LC_ALL, NULL);
initscr();
if (has_colors() == TRUE) {
start_color();
init_pair(MSG_COLOR, COLOR_YELLOW, COLOR_BLACK);
init_pair(ICON_COLOR, COLOR_WHITE, COLOR_BLACK);
}
int height, width;
getmaxyx(stdscr, height, width);
if (width < 80 || height < 24) {
LOG(LOG_ERROR, "Terminal size must be at least 80x24");
return -1;
}
if (has_colors() == FALSE) {
LOG(LOG_VERBOSE2, "Terminal without color support detected");
}
cbreak();
noecho();
keypad(stdscr, TRUE);
return 0;
}
int destroy_window() {
endwin();
return 0;
}
int tui() {
int ret = MAIN_SCREEN;
init_window();
while (1) {
redraw_screen();
switch (ret) {
case ERROR_SCREEN:
goto out;
break;
case EXIT_SCREEN:
goto out;
break;
case MAIN_SCREEN:
ret = display_main_menu();
break;
case OPTIONS_SCREEN:
ret = display_options_screen();
break;
case ENTER_RECOVERY_SCREEN:
ret = display_enter_recovery_screen();
break;
case ENTER_DFU_SCREEN:
ret = display_enter_dfu_screen();
break;
case JAILBREAKING_SCREEN:
ret = display_jailbreaking_screen();
break;
default:
assert(0);
goto out;
}
}
out:
destroy_window();
return ret;
}
+20
View File
@@ -0,0 +1,20 @@
#define NCURSES_WIDECHAR 1
#include <ncurses.h>
#include <form.h>
#include <menu.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <locale.h>
#include <unistd.h>
#include <assert.h>
#include <common.h>
#include <tui.h>
tui_screen_t tui_screen_options() { return MAIN_SCREEN; }