Skip to content

Latest commit

 

History

History
638 lines (525 loc) · 17.4 KB

gui_stdio.c

File metadata and controls

638 lines (525 loc) · 17.4 KB
 
May 12, 2007
May 12, 2007
1
2
3
4
5
6
7
8
/**
* MojoSetup; a portable, flexible installation application.
*
* Please see the file LICENSE.txt in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/
Dec 9, 2006
Dec 9, 2006
9
10
11
12
#if !SUPPORT_GUI_STDIO
#error Something is wrong in the build system.
#endif
Mar 25, 2006
Mar 25, 2006
13
#define BUILDING_EXTERNAL_PLUGIN 1
May 8, 2007
May 8, 2007
14
#include "gui.h"
Mar 27, 2006
Mar 27, 2006
15
Dec 7, 2006
Dec 7, 2006
16
17
18
19
20
21
MOJOGUI_PLUGIN(stdio)
#if !GUI_STATIC_LINK_STDIO
CREATE_MOJOGUI_ENTRY_POINT(stdio)
#endif
22
23
#include <ctype.h>
May 20, 2007
May 20, 2007
24
static char *lastProgressType = NULL;
May 7, 2007
May 7, 2007
25
26
27
static char *lastComponent = NULL;
static uint32 percentTicks = 0;
Dec 27, 2006
Dec 27, 2006
28
29
30
31
32
33
34
35
36
37
38
39
40
static int read_stdin(char *buf, int len)
{
if (fgets(buf, len, stdin) == NULL)
return -1;
len = strlen(buf) - 1;
while ( (len >= 0) && ((buf[len] == '\n') || (buf[len] == '\r')) )
buf[len--] = '\0';
return len+1;
} // read_stdin
Dec 28, 2006
Dec 28, 2006
41
42
static int readstr(const char *prompt, char *buf, int len,
boolean back, boolean fwd)
Dec 27, 2006
Dec 27, 2006
43
{
Dec 5, 2007
Dec 5, 2007
44
45
46
47
// !!! FIXME: if read_stdin() returns -1, we return 0, which makes it
// !!! FIXME: indistinguishable from "user hit enter" ... maybe we should
// !!! FIXME: abort in read_stdin() if i/o fails?
Dec 27, 2006
Dec 27, 2006
48
int retval = 0;
Mar 2, 2008
Mar 2, 2008
49
char *backstr = (back) ? xstrdup(_("back")) : NULL;
Dec 27, 2006
Dec 27, 2006
50
51
52
53
54
55
if (prompt != NULL)
printf("%s\n", prompt);
if (back)
{
Mar 2, 2008
Mar 2, 2008
56
57
char *fmt = xstrdup(_("Type '%0' to go back."));
char *msg = format(fmt, backstr);
Jan 12, 2008
Jan 12, 2008
58
59
60
printf("%s\n", msg);
free(msg);
free(fmt);
Dec 27, 2006
Dec 27, 2006
61
62
} // if
Dec 28, 2006
Dec 28, 2006
63
64
if (fwd)
{
Jun 15, 2009
Jun 15, 2009
65
printf("%s", _("Press enter to continue."));
Dec 28, 2006
Dec 28, 2006
66
67
68
printf("\n");
} // if
Jun 15, 2009
Jun 15, 2009
69
printf("%s",_("> "));
Dec 27, 2006
Dec 27, 2006
70
71
72
73
fflush(stdout);
if ((retval = read_stdin(buf, len)) >= 0)
{
Dec 5, 2007
Dec 5, 2007
74
if ((back) && (strcmp(buf, backstr) == 0)) // !!! FIXME: utf8casecmp?
Dec 27, 2006
Dec 27, 2006
75
76
77
retval = -1;
} // if
Jan 12, 2008
Jan 12, 2008
78
free(backstr);
Dec 27, 2006
Dec 27, 2006
79
return retval;
Dec 5, 2007
Dec 5, 2007
80
} // readstr
Dec 27, 2006
Dec 27, 2006
81
82
Nov 21, 2007
Nov 21, 2007
83
static uint8 MojoGui_stdio_priority(boolean istty)
Nov 21, 2007
Nov 21, 2007
85
86
87
88
89
90
91
92
// if not a tty and no other GUI plugins worked out, let the base
// application try to spawn a terminal and try again. If it can't do so,
// it will panic() and thus end the process, so we don't end up blocking
// on some prompt the user can't see.
if (!istty)
return MOJOGUI_PRIORITY_NEVER_TRY;
May 18, 2007
May 18, 2007
93
return MOJOGUI_PRIORITY_TRY_ABSOLUTELY_LAST; // always a last resort.
Dec 27, 2006
Dec 27, 2006
94
95
} // MojoGui_stdio_priority
Dec 7, 2006
Dec 7, 2006
97
static boolean MojoGui_stdio_init(void)
May 7, 2007
May 7, 2007
99
percentTicks = 0;
Nov 21, 2007
Nov 21, 2007
100
return true; // always succeeds.
Dec 27, 2006
Dec 27, 2006
101
102
} // MojoGui_stdio_init
Dec 7, 2006
Dec 7, 2006
104
static void MojoGui_stdio_deinit(void)
May 20, 2007
May 20, 2007
106
free(lastProgressType);
May 12, 2007
May 12, 2007
107
free(lastComponent);
May 20, 2007
May 20, 2007
108
lastProgressType = NULL;
May 12, 2007
May 12, 2007
109
lastComponent = NULL;
Dec 27, 2006
Dec 27, 2006
110
111
} // MojoGui_stdio_deinit
Dec 7, 2006
Dec 7, 2006
113
static void MojoGui_stdio_msgbox(const char *title, const char *text)
Dec 27, 2006
Dec 27, 2006
115
char buf[128];
Mar 2, 2008
Mar 2, 2008
116
117
char *fmt = xstrdup(_("NOTICE: %0\n[hit enter]"));
char *msg = format(fmt, text);
Jan 12, 2008
Jan 12, 2008
118
119
120
printf("%s\n", msg);
free(msg);
free(fmt);
121
fflush(stdout);
Dec 27, 2006
Dec 27, 2006
122
read_stdin(buf, sizeof (buf));
Dec 20, 2006
Dec 20, 2006
123
} // MojoGui_stdio_msgbox
Dec 27, 2006
Dec 27, 2006
125
Jul 2, 2007
Jul 2, 2007
126
127
static boolean MojoGui_stdio_promptyn(const char *title, const char *text,
boolean defval)
Dec 27, 2006
Dec 27, 2006
129
130
boolean retval = false;
if (!feof(stdin))
Mar 2, 2008
Mar 2, 2008
132
133
134
135
136
const char *_fmt = ((defval) ? _("%0 [Y/n]: ") : _("%0 [y/N]: "));
char *fmt = xstrdup(_fmt);
char *msg = format(fmt, text);
char *localized_no = xstrdup(_("N"));
char *localized_yes = xstrdup(_("Y"));
Dec 27, 2006
Dec 27, 2006
137
boolean getout = false;
Dec 20, 2006
Dec 20, 2006
138
char buf[128];
Dec 5, 2007
Dec 5, 2007
139
Dec 27, 2006
Dec 27, 2006
140
while (!getout)
Dec 20, 2006
Dec 20, 2006
141
{
Dec 5, 2007
Dec 5, 2007
142
143
144
int rc = 0;
getout = true; // we may reset this later.
Jan 23, 2008
Jan 23, 2008
145
printf("%s", msg);
Dec 20, 2006
Dec 20, 2006
146
fflush(stdout);
Dec 5, 2007
Dec 5, 2007
147
148
149
150
151
152
rc = read_stdin(buf, sizeof (buf));
if (rc < 0)
retval = false;
else if (rc == 0)
retval = defval;
Dec 27, 2006
Dec 27, 2006
153
else if (strcasecmp(buf, localized_no) == 0)
Dec 5, 2007
Dec 5, 2007
154
retval = false;
Dec 20, 2006
Dec 20, 2006
155
else if (strcasecmp(buf, localized_yes) == 0)
Dec 5, 2007
Dec 5, 2007
156
157
158
retval = true;
else
getout = false; // try again.
Dec 20, 2006
Dec 20, 2006
159
} // while
Dec 5, 2007
Dec 5, 2007
160
Jan 12, 2008
Jan 12, 2008
161
162
163
164
free(localized_yes);
free(localized_no);
free(msg);
free(fmt);
Dec 27, 2006
Dec 27, 2006
165
} // if
Dec 27, 2006
Dec 27, 2006
167
return retval;
Dec 20, 2006
Dec 20, 2006
168
} // MojoGui_stdio_promptyn
May 7, 2007
May 7, 2007
170
Jul 2, 2007
Jul 2, 2007
171
172
static MojoGuiYNAN MojoGui_stdio_promptynan(const char *title, const char *txt,
boolean defval)
May 17, 2007
May 17, 2007
173
174
175
176
{
MojoGuiYNAN retval = MOJOGUI_NO;
if (!feof(stdin))
{
Mar 2, 2008
Mar 2, 2008
177
178
179
180
181
182
char *fmt = xstrdup(_("%0\n[y/n/Always/Never]: "));
char *msg = format(fmt, txt);
char *localized_no = xstrdup(_("N"));
char *localized_yes = xstrdup(_("Y"));
char *localized_always = xstrdup(_("Always"));
char *localized_never = xstrdup(_("Never"));
May 17, 2007
May 17, 2007
183
184
boolean getout = false;
char buf[128];
Dec 5, 2007
Dec 5, 2007
185
May 17, 2007
May 17, 2007
186
187
while (!getout)
{
Dec 5, 2007
Dec 5, 2007
188
189
190
int rc = 0;
getout = true; // we may reset this later.
Jan 12, 2008
Jan 12, 2008
191
printf("%s\n", msg);
May 17, 2007
May 17, 2007
192
fflush(stdout);
Dec 5, 2007
Dec 5, 2007
193
194
195
196
197
198
rc = read_stdin(buf, sizeof (buf));
if (rc < 0)
retval = MOJOGUI_NO;
else if (rc == 0)
retval = (defval) ? MOJOGUI_YES : MOJOGUI_NO;
May 17, 2007
May 17, 2007
199
else if (strcasecmp(buf, localized_no) == 0)
Dec 5, 2007
Dec 5, 2007
200
retval = MOJOGUI_NO;
May 17, 2007
May 17, 2007
201
202
203
204
205
206
else if (strcasecmp(buf, localized_yes) == 0)
retval = MOJOGUI_YES;
else if (strcasecmp(buf, localized_always) == 0)
retval = MOJOGUI_ALWAYS;
else if (strcasecmp(buf, localized_never) == 0)
retval = MOJOGUI_NEVER;
Dec 5, 2007
Dec 5, 2007
207
208
else
getout = false; // try again.
May 17, 2007
May 17, 2007
209
} // while
Dec 5, 2007
Dec 5, 2007
210
Jan 12, 2008
Jan 12, 2008
211
212
213
214
215
216
free(localized_never);
free(localized_always);
free(localized_yes);
free(localized_no);
free(msg);
free(fmt);
May 17, 2007
May 17, 2007
217
218
219
220
221
222
} // if
return retval;
} // MojoGui_stdio_promptynan
Nov 24, 2007
Nov 24, 2007
223
224
static boolean MojoGui_stdio_start(const char *title,
const MojoGuiSplash *splash)
Dec 12, 2006
Dec 12, 2006
225
226
227
{
printf("%s\n", title);
return true;
Dec 20, 2006
Dec 20, 2006
228
} // MojoGui_stdio_start
Dec 12, 2006
Dec 12, 2006
229
230
Dec 20, 2006
Dec 20, 2006
231
static void MojoGui_stdio_stop(void)
Dec 12, 2006
Dec 12, 2006
232
233
{
// no-op.
Dec 20, 2006
Dec 20, 2006
234
235
236
} // MojoGui_stdio_stop
Dec 5, 2007
Dec 5, 2007
237
238
239
static void dumb_pager(const char *name, const char *data, size_t datalen)
{
const int MAX_PAGE_LINES = 21;
Mar 2, 2008
Mar 2, 2008
240
char *fmt = xstrdup(_("(%0-%1 of %2 lines, see more?)"));
Dec 5, 2007
Dec 5, 2007
241
242
243
int i = 0;
int w = 0;
int linecount = 0;
Dec 27, 2006
Dec 27, 2006
244
boolean getout = false;
Mar 3, 2008
Mar 3, 2008
245
char **lines = splitText(data, 80, &linecount, &w);
Dec 5, 2007
Dec 5, 2007
246
247
assert(linecount >= 0);
Dec 27, 2006
Dec 27, 2006
248
Dec 5, 2007
Dec 5, 2007
249
250
251
252
253
printf("%s\n", name);
if (lines == NULL) // failed to parse?!
printf("%s\n", data); // just dump it all. Oh well.
else
Dec 27, 2006
Dec 27, 2006
254
{
Dec 5, 2007
Dec 5, 2007
255
256
int printed = 0;
do
May 10, 2007
May 10, 2007
257
{
Dec 5, 2007
Dec 5, 2007
258
for (i = 0; (i < MAX_PAGE_LINES) && (printed < linecount); i++)
Aug 8, 2008
Aug 8, 2008
259
printf("%s", lines[printed++]);
Dec 5, 2007
Dec 5, 2007
260
261
262
263
264
if (printed >= linecount)
getout = true;
else
{
Jan 12, 2008
Jan 12, 2008
265
char *msg = NULL;
Dec 5, 2007
Dec 5, 2007
266
printf("\n");
Mar 2, 2008
Mar 2, 2008
267
268
msg = format(fmt, numstr((printed-i)+1),
numstr(printed), numstr(linecount));
Jan 12, 2008
Jan 12, 2008
269
270
getout = !MojoGui_stdio_promptyn("", msg, true);
free(msg);
Dec 5, 2007
Dec 5, 2007
271
272
273
printf("\n");
} // else
} while (!getout);
Oct 24, 2011
Oct 24, 2011
274
275
276
277
for (i = 0; i < linecount; i++)
free(lines[i]);
free(lines);
Dec 27, 2006
Dec 27, 2006
278
279
} // while
Dec 5, 2007
Dec 5, 2007
280
281
282
283
284
285
286
287
288
289
290
291
292
free(fmt);
} // dumb_pager
static int MojoGui_stdio_readme(const char *name, const uint8 *_data,
size_t datalen, boolean can_back,
boolean can_fwd)
{
const char *data = (const char *) _data;
char buf[256];
int retval = -1;
boolean failed = true;
Dec 5, 2007
Dec 5, 2007
293
294
// !!! FIXME: popen() isn't reliable.
#if 0 //PLATFORM_UNIX
Dec 5, 2007
Dec 5, 2007
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
const size_t namelen = strlen(name);
const char *programs[] = { getenv("PAGER"), "more", "less -M", "less" };
int i = 0;
// flush streams, so output doesn't mingle with the popen()'d process.
fflush(stdout);
fflush(stderr);
for (i = 0; i < STATICARRAYLEN(programs); i++)
{
const char *cmd = programs[i];
if (cmd != NULL)
{
FILE *io = popen(cmd, "w");
if (io != NULL)
{
failed = false;
if (!failed) failed = (fwrite("\n", 1, 1, io) != 1);
if (!failed) failed = (fwrite(name, namelen, 1, io) != 1);
if (!failed) failed = (fwrite("\n", 1, 1, io) != 1);
if (!failed) failed = (fwrite(data, datalen, 1, io) != 1);
if (!failed) failed = (fwrite("\n", 1, 1, io) != 1);
failed |= (pclose(io) != 0); // call whether we failed or not.
if (!failed)
break; // it worked, we're done!
} // if
} // if
} // for
#endif // PLATFORM_UNIX
if (failed) // We're not Unix, or none of the pagers worked?
dumb_pager(name, data, datalen);
Dec 16, 2007
Dec 16, 2007
328
329
330
// Put up the "hit enter to continue (or 'back' to go back)" prompt,
// but only if there's an choice to be made here.
if ((!can_back) || (readstr(NULL, buf, sizeof (buf), can_back, true) >= 0))
Dec 5, 2007
Dec 5, 2007
331
332
retval = 1;
Dec 27, 2006
Dec 27, 2006
333
return retval;
Dec 20, 2006
Dec 20, 2006
334
} // MojoGui_stdio_readme
Dec 12, 2006
Dec 12, 2006
335
Dec 27, 2006
Dec 27, 2006
336
Dec 27, 2006
Dec 27, 2006
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
static void toggle_option(MojoGuiSetupOptions *parent,
MojoGuiSetupOptions *opts, int *line, int target)
{
if ((opts != NULL) && (target > *line))
{
if (!opts->is_group_parent)
{
if (++(*line) == target)
{
const boolean toggled = ((opts->value) ? false : true);
// "radio buttons" in a group?
if ((parent) && (parent->is_group_parent))
{
if (toggled) // drop unless we weren't the current toggle.
{
// set all siblings to false...
MojoGuiSetupOptions *i = parent->child;
while (i != NULL)
{
i->value = false;
i = i->next_sibling;
} // while
opts->value = true; // reset us to be true.
} // if
} // if
else // individual "check box" was chosen.
{
opts->value = toggled;
} // else
return; // we found it, bail.
} // if
} // if
if (opts->value) // if option is toggled on, descend to children.
toggle_option(opts, opts->child, line, target);
toggle_option(parent, opts->next_sibling, line, target);
} // if
} // toggle_option
Dec 27, 2006
Dec 27, 2006
380
381
382
383
384
385
386
static void print_options(MojoGuiSetupOptions *opts, int *line, int level)
{
if (opts != NULL)
{
int i;
int spacing = 1;
if (opts->is_group_parent)
May 12, 2007
May 12, 2007
387
spacing += 6;
Dec 27, 2006
Dec 27, 2006
388
else
Dec 27, 2006
Dec 27, 2006
389
390
{
(*line)++;
Dec 27, 2006
Dec 27, 2006
391
printf("%2d [%c]", *line, opts->value ? 'X' : ' ');
Dec 27, 2006
Dec 27, 2006
392
} // else
Dec 27, 2006
Dec 27, 2006
393
May 12, 2007
May 12, 2007
394
for (i = 0; i < (level + spacing); i++)
Dec 27, 2006
Dec 27, 2006
395
396
putchar(' ');
May 12, 2007
May 12, 2007
397
printf("%s%s\n", opts->description, opts->is_group_parent ? ":" : "");
Dec 27, 2006
Dec 27, 2006
398
May 12, 2007
May 12, 2007
399
if ((opts->value) || (opts->is_group_parent))
Dec 27, 2006
Dec 27, 2006
400
print_options(opts->child, line, level+1);
Dec 27, 2006
Dec 27, 2006
401
402
403
404
405
print_options(opts->next_sibling, line, level);
} // if
} // print_options
May 10, 2007
May 10, 2007
406
static int MojoGui_stdio_options(MojoGuiSetupOptions *opts,
May 10, 2007
May 10, 2007
407
boolean can_back, boolean can_fwd)
Dec 27, 2006
Dec 27, 2006
408
{
Mar 2, 2008
Mar 2, 2008
409
410
const char *inst_opts_str = xstrdup(_("Options"));
const char *prompt = xstrdup(_("Choose number to change."));
May 10, 2007
May 10, 2007
411
int retval = -1;
Dec 27, 2006
Dec 27, 2006
412
413
414
415
416
417
418
419
420
boolean getout = false;
char buf[128];
int len = 0;
while (!getout)
{
int line = 0;
printf("\n\n");
Jun 15, 2009
Jun 15, 2009
421
printf("%s", inst_opts_str);
Dec 27, 2006
Dec 27, 2006
422
423
424
425
printf("\n");
print_options(opts, &line, 1);
printf("\n");
May 10, 2007
May 10, 2007
426
if ((len = readstr(prompt, buf, sizeof (buf), can_back, true)) < 0)
Dec 27, 2006
Dec 27, 2006
427
428
getout = true;
else if (len == 0)
May 10, 2007
May 10, 2007
429
430
431
432
{
getout = true;
retval = 1;
} // else if
Dec 27, 2006
Dec 27, 2006
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
else
{
char *endptr = NULL;
int target = (int) strtol(buf, &endptr, 10);
if (*endptr == '\0') // complete string was a valid number?
{
line = 0;
toggle_option(NULL, opts, &line, target);
} // if
} // else
} // while
free((void *) inst_opts_str);
free((void *) prompt);
return retval;
Dec 27, 2006
Dec 27, 2006
449
450
} // MojoGui_stdio_options
Dec 28, 2006
Dec 28, 2006
451
May 10, 2007
May 10, 2007
452
453
454
static char *MojoGui_stdio_destination(const char **recommends, int recnum,
int *command, boolean can_back,
boolean can_fwd)
Dec 28, 2006
Dec 28, 2006
455
{
Mar 2, 2008
Mar 2, 2008
456
const char *instdeststr = xstrdup(_("Destination"));
Dec 28, 2006
Dec 28, 2006
457
458
459
460
const char *prompt = NULL;
char *retval = NULL;
boolean getout = false;
char buf[128];
Dec 28, 2006
Dec 28, 2006
461
int len = 0;
Dec 28, 2006
Dec 28, 2006
462
463
int i = 0;
May 10, 2007
May 10, 2007
464
465
466
*command = -1;
if (recnum > 0)
Mar 2, 2008
Mar 2, 2008
467
prompt = xstrdup(_("Choose install destination by number (hit enter for #1), or enter your own."));
Dec 28, 2006
Dec 28, 2006
468
else
Mar 2, 2008
Mar 2, 2008
469
prompt = xstrdup(_("Enter path where files will be installed."));
Dec 28, 2006
Dec 28, 2006
470
471
472
473
while (!getout)
{
printf("\n\n%s\n", instdeststr);
May 10, 2007
May 10, 2007
474
for (i = 0; i < recnum; i++)
Dec 28, 2006
Dec 28, 2006
475
476
477
printf(" %2d %s\n", i+1, recommends[i]);
printf("\n");
May 10, 2007
May 10, 2007
478
if ((len = readstr(prompt, buf, sizeof (buf), can_back, false)) < 0)
Dec 28, 2006
Dec 28, 2006
479
getout = true;
May 17, 2007
May 17, 2007
480
481
482
else if ((len == 0) && (recnum > 0)) // default to first in list.
{
Mar 2, 2008
Mar 2, 2008
483
retval = xstrdup(recommends[0]);
May 17, 2007
May 17, 2007
484
485
486
487
*command = 1;
getout = true;
} // else if
Dec 28, 2006
Dec 28, 2006
488
else if (len > 0)
Dec 28, 2006
Dec 28, 2006
489
490
491
492
{
char *endptr = NULL;
int target = (int) strtol(buf, &endptr, 10);
// complete string was a valid number?
May 10, 2007
May 10, 2007
493
if ((*endptr == '\0') && (target > 0) && (target <= recnum))
Mar 2, 2008
Mar 2, 2008
494
retval = xstrdup(recommends[target-1]);
Dec 28, 2006
Dec 28, 2006
495
else
Mar 2, 2008
Mar 2, 2008
496
retval = xstrdup(buf);
Dec 28, 2006
Dec 28, 2006
497
May 10, 2007
May 10, 2007
498
*command = 1;
Dec 28, 2006
Dec 28, 2006
499
500
501
502
503
504
505
506
507
508
getout = true;
} // else
} // while
free((void *) prompt);
free((void *) instdeststr);
return retval;
} // MojoGui_stdio_destination
Apr 21, 2007
Apr 21, 2007
509
Apr 25, 2009
Apr 25, 2009
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
static int MojoGui_stdio_productkey(const char *desc, const char *fmt,
char *buf, const int buflen,
boolean can_back, boolean can_fwd)
{
const char *prompt = xstrdup(_("Please enter your product key"));
char *defval = ((*buf) ? xstrdup(buf) : NULL);
boolean getout = false;
int retval = -1;
char *msg = NULL;
if (defval != NULL)
{
char *locfmt = xstrdup(_("(just press enter to use '%0')"));
msg = format(locfmt, defval);
free(locfmt);
} // if
while (!getout)
{
int len;
printf("\n\n%s\n", desc);
if (msg != NULL)
printf("%s\n", msg);
if ((len = readstr(prompt, buf, buflen, can_back, false)) < 0)
getout = true;
else
{
if ((len == 0) && (defval != NULL))
strcpy(buf, defval);
Apr 25, 2009
Apr 25, 2009
540
if (isValidProductKey(fmt, buf))
Apr 25, 2009
Apr 25, 2009
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
{
retval = 1;
getout = true;
} // else if
else
{
// We can't check the input character-by-character, so reuse
// the failed-verification localized string.
printf("\n%s\n\n",
_("That key appears to be invalid. Please try again."));
} // else
} // else
} // while
free(msg);
free(defval);
free((void *) prompt);
return retval;
} // MojoGui_stdio_productkey
Apr 21, 2007
Apr 21, 2007
563
564
565
static boolean MojoGui_stdio_insertmedia(const char *medianame)
{
char buf[32];
Mar 2, 2008
Mar 2, 2008
566
567
568
char *fmt = xstrdup(_("Please insert '%0'"));
char *msg = format(fmt, medianame);
printf("%s\n", _("Media change"));
Jan 12, 2008
Jan 12, 2008
569
570
571
printf("%s\n", msg);
free(msg);
free(fmt);
Apr 22, 2007
Apr 22, 2007
572
return (readstr(NULL, buf, sizeof (buf), false, true) >= 0);
Apr 21, 2007
Apr 21, 2007
573
574
} // MojoGui_stdio_insertmedia
Apr 22, 2007
Apr 22, 2007
575
Feb 20, 2008
Feb 20, 2008
576
577
578
579
580
581
582
static void MojoGui_stdio_progressitem(void)
{
// force new line of output on next call to MojoGui_stdio_progress()
percentTicks = 0;
} // MojoGui_stdio_progressitem
May 7, 2007
May 7, 2007
583
static boolean MojoGui_stdio_progress(const char *type, const char *component,
Jan 24, 2008
Jan 24, 2008
584
585
int percent, const char *item,
boolean can_cancel)
Apr 22, 2007
Apr 22, 2007
586
{
Mar 2, 2008
Mar 2, 2008
587
const uint32 now = ticks();
May 20, 2007
May 20, 2007
588
589
590
591
592
if ( (lastComponent == NULL) ||
(strcmp(lastComponent, component) != 0) ||
(lastProgressType == NULL) ||
(strcmp(lastProgressType, type) != 0) )
May 7, 2007
May 7, 2007
593
{
May 20, 2007
May 20, 2007
594
free(lastProgressType);
May 7, 2007
May 7, 2007
595
free(lastComponent);
Mar 2, 2008
Mar 2, 2008
596
597
lastProgressType = xstrdup(type);
lastComponent = xstrdup(component);
May 9, 2007
May 9, 2007
598
printf("%s\n%s\n", type, component);
May 7, 2007
May 7, 2007
599
600
} // if
Feb 20, 2008
Feb 20, 2008
601
602
603
// limit update spam... will only write every one second, tops,
// on any given filename, but it writes each filename at least once
// so it doesn't look like we only installed a few things.
May 7, 2007
May 7, 2007
604
605
if (percentTicks <= now)
{
Jan 12, 2008
Jan 12, 2008
606
607
char *fmt = NULL;
char *msg = NULL;
May 9, 2007
May 9, 2007
608
percentTicks = now + 1000;
May 17, 2007
May 17, 2007
609
if (percent < 0)
Jan 12, 2008
Jan 12, 2008
610
printf("%s\n", item);
May 17, 2007
May 17, 2007
611
else
Jan 12, 2008
Jan 12, 2008
612
{
Mar 2, 2008
Mar 2, 2008
613
614
fmt = xstrdup(_("%0 (total progress: %1%%)"));
msg = format(fmt, item, numstr(percent));
Jan 12, 2008
Jan 12, 2008
615
616
617
618
printf("%s\n", msg);
free(msg);
free(fmt);
} // else
May 7, 2007
May 7, 2007
619
} // if
Apr 22, 2007
Apr 22, 2007
620
May 7, 2007
May 7, 2007
621
622
return true;
} // MojoGui_stdio_progress
Apr 22, 2007
Apr 22, 2007
623
May 12, 2007
May 12, 2007
624
Aug 10, 2020
Aug 10, 2020
625
626
627
628
629
630
static void MojoGui_stdio_pump(void)
{
// no-op in this UI target.
} // MojoGui_stdio_pump
May 12, 2007
May 12, 2007
631
632
633
634
635
636
static void MojoGui_stdio_final(const char *msg)
{
printf("%s\n\n", msg);
fflush(stdout);
} // MojoGui_stdio_final
Mar 27, 2006
Mar 27, 2006
637
// end of gui_stdio.c ...