forked from DragonMinded/ACIOLauncher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenu.cpp
More file actions
250 lines (215 loc) · 4.79 KB
/
Copy pathMenu.cpp
File metadata and controls
250 lines (215 loc) · 4.79 KB
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
249
250
#include <stdio.h>
#include <windows.h>
#include "Menu.h"
#include "Debug.h"
Menu::Menu(_TCHAR *inifile)
{
/* Read settings */
settings = LoadSettings( inifile, &num_programs );
/* Set up pagination */
start = 0;
end = num_programs < GAMES_PER_PAGE ? num_programs : GAMES_PER_PAGE;
selected = 0;
/* For exiting on defaults */
ftime(&beginning);
/* No cursor please! */
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursorInfo;
GetConsoleCursorInfo(out, &cursorInfo);
cursorInfo.bVisible = false;
SetConsoleCursorInfo(out, &cursorInfo);
}
Menu::~Menu(void)
{
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cursorInfo;
GetConsoleCursorInfo(out, &cursorInfo);
cursorInfo.bVisible = true;
SetConsoleCursorInfo(out, &cursorInfo);
}
void Menu::DisplayPrompt()
{
/* Prompt the user */
if (!debug) { system("cls"); }
printf( "Make a selection on the reader to boot a game.\n" );
printf( "%s will boot in %d seconds.\n\n", settings[0].name, TIMEOUT_SECONDS );
}
void Menu::DisplayGames()
{
for (unsigned int i = start; i < end; i++)
{
printf( "[%d] %s\n", (i - start) + 1, settings[i].name );
}
printf( "\n" );
if (start > 0)
{
printf( "[0] Previous Page\n" );
}
if (end < num_programs)
{
printf( "[00] Next Page\n" );
}
}
void Menu::PageDown()
{
if (end < num_programs)
{
/* Move up one page */
start = start + GAMES_PER_PAGE;
end = start + GAMES_PER_PAGE;
end = end >= num_programs ? num_programs : end;
/* print games */
DisplayPrompt();
DisplayGames();
}
}
void Menu::PageUp()
{
if (start > 0)
{
/* Move up one page */
start = start - GAMES_PER_PAGE;
start = start < 0 ? 0 : start;
end = start + GAMES_PER_PAGE;
end = end >= num_programs ? num_programs : end;
/* print games */
DisplayPrompt();
DisplayGames();
}
}
void Menu::ResetTimeout()
{
ftime(&beginning);
}
void Menu::Tick()
{
ftime(¤t);
}
bool Menu::ShouldBootDefault()
{
ftime(¤t);
return (current.time - beginning.time) > TIMEOUT_SECONDS;
}
bool Menu::SelectGame(unsigned int game)
{
if (game < 1 || game > 9)
{
/* Out of bounds */
return false;
}
/* Zero-based instead of one-based, and account for pagination */
game--;
game += start;
if (game >= num_programs)
{
return false;
}
else
{
selected = game;
return true;
}
}
/**
* Loads an INI file with the following format:
*
* [Name of game to launch]
* launch=<location of batch/executable>
*/
launcher_program_t *Menu::LoadSettings( _TCHAR *ini_file, unsigned int *final_length )
{
launcher_program_t *progs = 0;
*final_length = 0;
unsigned int got_name = 0;
launcher_program_t temp;
// Open the file
HANDLE hFile = CreateFile(ini_file, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
char buffer[16384];
unsigned int eof = 0;
unsigned int eol = 0;
unsigned int buflen = 0;
if (hFile == 0)
{
return progs;
}
memset( &temp, 0, sizeof(temp) );
memset( buffer, 0, sizeof(buffer) );
while( !eof )
{
DWORD length;
ReadFile( hFile, buffer + buflen, 1, &length, 0 );
if (length == 0)
{
eof = 1;
eol = 1;
}
else if( *(buffer + buflen) == '\r' )
{
/* Ignore \r completely */
*(buffer + buflen) = 0;
}
else if( *(buffer + buflen) == '\n' )
{
/* End of line */
*(buffer + buflen) = 0;
eol = 1;
}
else
{
/* Valid thing */
buflen++;
}
if ( eol == 1 )
{
/* Process line */
if (buffer[0] == '[' && buffer[buflen - 1] == ']' && buflen > 2)
{
buffer[buflen - 1] = 0;
char *game = buffer + 1;
/* Copy this into temp structure */
strcpy_s( temp.name, MAX_GAME_NAME_LENGTH, game );
got_name = 1;
}
else
{
if (strncmp(buffer, "launch", 6) == 0) {
unsigned int loc = 6;
// Find equals sign after space
while (loc < buflen && (buffer[loc] == ' ' || buffer[loc] == '\t')) { loc++; }
if (loc < buflen)
{
if (buffer[loc] == '=')
{
loc++;
while (loc < buflen && (buffer[loc] == ' ' || buffer[loc] == '\t')) { loc++; }
if (loc < buflen)
{
char *launch = buffer + loc;
if( got_name == 1 )
{
/* We have a name to associate with this */
strcpy_s( temp.location, MAX_GAME_LOCATION_LENGTH, launch );
got_name = 0;
/* Make a new spot for this, copy in */
(*final_length)++;
progs = (launcher_program_t *)realloc( progs, sizeof(launcher_program_t) * (*final_length) );
memcpy( progs + ((*final_length) - 1), &temp, sizeof(launcher_program_t) );
memset( &temp, 0, sizeof(temp) );
}
}
}
}
}
}
/* Reset buffer */
if (buflen > 0)
{
memset( buffer, 0, sizeof(buffer) );
buflen = 0;
}
/* Not end of line anymore */
eol = 0;
}
}
return progs;
}