forked from Based-Skid/iLaunchELF
-
Notifications
You must be signed in to change notification settings - Fork 5
/
menu.c
248 lines (201 loc) · 5.09 KB
/
menu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#include "VTSPS2-HBDL.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "include/gui.h"
#include "include/menu.h"
#include "include/pad.h"
typedef struct menu_item
{
char *text;
int id;
} menu_item_t;
typedef struct menu_list
{
struct menu_item item;
struct menu_list *prev, *next, *current, *pagestart;
} menu_list_t;
static menu_list_t *menu;
// CLEAN UP vv
extern char action[32], device[32], path[256], fn[16];
static char ELF_NO_EXT[128];
static char PATH_ELF[256];
static char PATH_APP[256];
// CLEAN UP ^^
static menu_list_t *menuAllocItem(char *text, int id)
{
menu_list_t *it = (menu_list_t *)malloc(sizeof(menu_list_t));
it->prev = NULL;
it->next = NULL;
it->item.text = text;
it->item.id = id;
return it;
}
static menu_list_t *menuAddItem(menu_list_t **menu, char *text, int id)
{
if (*menu == NULL) {
*menu = menuAllocItem(text, id);
return *menu;
}
menu_list_t *cur = *menu;
// traverse till the end
while (cur->next)
cur = cur->next;
// create new item
menu_list_t *newitem = menuAllocItem(text, id);
// link
cur->next = newitem;
newitem->prev = cur;
return newitem;
}
static void menuDestroy(menu_list_t **menu)
{
int i;
menu_list_t *cur = *menu;
for (i = 0; i < NUM_APPS; i++) {
free(downloadableApps[i].size);
free(downloadableApps[i].version);
free(downloadableApps[i].rcrc);
}
while (cur) {
menu_list_t *td = cur;
cur = cur->next;
free(td);
}
*menu = NULL;
}
void menuInitMenu(void)
{
int i;
for (i = 0; i < NUM_APPS; i++)
menuAddItem(&menu, downloadableApps[i].longName, i);
menu->current = menu;
menu->pagestart = menu->current;
}
void menuEnd(void)
{
if (menu)
menuDestroy(&menu);
}
void menuRender(void)
{
menu_list_t *ps = menu->pagestart;
u64 color;
int others = 0;
int spacing = 20;
int y = 96;
while (ps && (others++ < 15))
{
if (ps == menu->current)
color = Blue;
else
color = WhiteFont;
drawFont(35, y, 0.45f, color, downloadableApps[ps->item.id].longName);
drawFont(315, y, 0.45f, color, downloadableApps[ps->item.id].version);
drawFont(535, y, 0.45f, color, downloadableApps[ps->item.id].size);
y += spacing;
ps = ps->next;
}
}
static void menuNavDown(void)
{
menu_list_t *cur = menu->current;
if (cur && cur->next) {
menu->current = cur->next;
// if the current item is beyond the page start, move the page start one page down
cur = menu->pagestart;
int itms = 15 + 1;
while (--itms && cur)
if (menu->current == cur)
return;
else
cur = cur->next;
menu->pagestart = menu->current;
}
}
static void menuNavUp(void)
{
menu_list_t *cur = menu->current;
if (cur && cur->prev) {
menu->current = cur->prev;
// if the current item is on the page start, move the page start one page up
if (menu->pagestart == cur) {
int itms = 15 + 1; // +1 because the selection will move as well
while (--itms && menu->pagestart->prev)
menu->pagestart = menu->pagestart->prev;
}
}
}
void menuHandleInput(void)
{
//check to see if the pad is still connected
checkPadConnected();
//read pad 0
buttonStatts(0, 0);
if(new_pad & PAD_SQUARE) {
if (strcmp(action,"CHECK") == 0) {
strcpy(action, "DOWNLOAD");
} else if (strcmp(action,"DOWNLOAD") == 0) {
strcpy(action, "LAUNCH");
} else if (strcmp(action,"LAUNCH") == 0) {
strcpy(action, "CHECK");
}
}
if (new_pad & PAD_UP)
menuNavUp();
if (new_pad & PAD_DOWN)
menuNavDown();
if(new_pad & PAD_CIRCLE) {
int id = menu->current->item.id;
strcpy(fn, downloadableApps[id].elfName);
if (strcmp(path,"APPS/") == 0) {
substring(fn,ELF_NO_EXT,1,(strlen(fn)-4));
sprintf(path,"APP_%s/",ELF_NO_EXT);
strcpy(PATH_APP,path);
} else if (strcmp(path,PATH_APP) == 0) {
substring(fn,ELF_NO_EXT,1,(strlen(fn)-4));
sprintf(path,"%s/",ELF_NO_EXT);
strcpy(PATH_ELF,path);
} else if ((strcmp(path,PATH_ELF) == 0) && (strcmp(fn,"BOOT.ELF") != 0)) {
//substring(fn,ELF_NO_EXT,1,(strlen(fn)-4));
//sprintf(path,"%s/",ELF_NO_EXT);
strcpy(path,"BOOT/");
} else if (strcmp(path,"BOOT/") == 0) {
strcpy(path,"APPS/");
} else if (strcmp(path,PATH_ELF) == 0) {
substring(fn,ELF_NO_EXT,1,(strlen(fn)-4));
strcpy(path,"APPS/");
} else {
strcpy(path,"APPS/");
}
}
if(new_pad & PAD_TRIANGLE) {
if (strcmp(device,"mc0:/") == 0) {
strcpy(device,"mc1:/");
} else if (strcmp(device,"mc1:/") == 0) {
strcpy(device,"mass:/");
} else {
strcpy(device,"mc0:/");
}
}
if (new_pad & PAD_R1)
deinit(1);
if (new_pad & PAD_L1) {
if (http_mirror == 0) {
http_mirror = 1;
} else if (http_mirror == 1) {
http_mirror = 0;
}
}
if (new_pad & PAD_CROSS) {
int id = menu->current->item.id;
strcpy(fn, downloadableApps[id].elfName);
if (strcmp(action,"CHECK") == 0) {
DoTask(1, id);
} else if (strcmp(action,"DOWNLOAD") == 0) {
DoTask(2, id);
} else if (strcmp(action,"LAUNCH") == 0) {
DoTask(3, id);
}
}
}