-
Notifications
You must be signed in to change notification settings - Fork 4
/
gui.c
2686 lines (2418 loc) · 91 KB
/
gui.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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
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
328
329
330
331
332
333
334
335
336
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
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
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//----------------------------------------------------------------------------
// gui.c:
//
// MUI based GUI. On non Amiga systems this is, except for some stdout prints
// to aid testing, a stub.
//----------------------------------------------------------------------------
// Copyright (C) 2018, Ola Söder. All rights reserved.
// Licensed under the AROS PUBLIC LICENSE (APL) Version 1.1
//----------------------------------------------------------------------------
#include "gui.h"
#include "resource.h"
#ifdef AMIGA
#include <libraries/asl.h>
#include <libraries/mui.h>
#include <proto/alib.h>
#include <proto/debug.h>
#include <proto/exec.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/muimaster.h>
#endif /* AMIGA */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <limits.h>
#include <sys/time.h>
#ifdef AMIGA
//----------------------------------------------------------------------------
// MUI helper macros
//----------------------------------------------------------------------------
#ifdef __MORPHOS__
# define DISPATCH_GATE(C) &C ## Gate
# define DISPATCH_ARGS void
# define DISPATCH_HEAD \
Class *cls = (Class *) REG_A0; \
Object *obj = (Object *) REG_A2; \
Msg msg = (Msg) REG_A1
# define CLASS_DEF(C) \
static IPTR C ## Dispatch (void); \
struct MUI_CustomClass * C ## Class; \
const struct EmulLibEntry C ## Gate = \
{ TRAP_LIB, 0, (void (*) (void)) C ## Dispatch }; \
struct C ## Data
#else
# define DoSuperNew(C,O,...) DoSuperNewTags(C,O,NULL,__VA_ARGS__)
# define DISPATCH_HEAD
# define DISPATCH_ARGS Class *cls, Object *obj, Msg msg
# define DISPATCH_GATE(C) C ## Dispatch
# define CLASS_DEF(C) \
struct MUI_CustomClass * C ## Class; \
struct C ## Data
#endif
#define DISPATCH(C) static IPTR C ## Dispatch (DISPATCH_ARGS)
#define CLASS_DATA(C) C ## Data
#define TAGBASE_LG (TAG_USER | 27<<16)
#define MUIDSP static inline __attribute__((always_inline))
//----------------------------------------------------------------------------
// Debug and logging macros
//----------------------------------------------------------------------------
#define GPUT(E,S) KPrintF((CONST_STRPTR)"%s:\t%s\t(%s)\n",E,S,__func__)
#define GERR(S) GPUT("ERR",S)
#define WARN(S) if(LLVL>0) GPUT("WARN",S)
#define INFO(S) if(LLVL>1) GPUT("INFO",S)
//----------------------------------------------------------------------------
// The installer window
//----------------------------------------------------------------------------
Object *Win;
//----------------------------------------------------------------------------
// InstallerGui - Class members
//----------------------------------------------------------------------------
CLASS_DEF(InstallerGui)
{
// Timer.
struct MUI_InputHandlerNode Ticker;
// Widgets.
Object *ExpertLevel, *UserLevel, *Progress,
*Complete, *Pretend, *Bottom, *String,
*Number, *Empty, *Root, *Text, *List,
*Log, *Top, *Ask, *Yes, *No;
};
//----------------------------------------------------------------------------
// InstallerGui - Public methods
//----------------------------------------------------------------------------
#define MUIM_InstallerGui_Init (TAGBASE_LG + 101)
#define MUIM_InstallerGui_Welcome (TAGBASE_LG + 102)
#define MUIM_InstallerGui_CopyFilesStart (TAGBASE_LG + 104)
#define MUIM_InstallerGui_CopyFilesSetCur (TAGBASE_LG + 105)
#define MUIM_InstallerGui_CopyFilesEnd (TAGBASE_LG + 106)
#define MUIM_InstallerGui_Exit (TAGBASE_LG + 107)
#define MUIM_InstallerGui_Complete (TAGBASE_LG + 108)
#define MUIM_InstallerGui_Ticker (TAGBASE_LG + 109)
#define MUIM_InstallerGui_CopyFilesAdd (TAGBASE_LG + 110)
#define MUIM_InstallerGui_Confirm (TAGBASE_LG + 111)
#define MUIM_InstallerGui_Message (TAGBASE_LG + 112)
#define MUIM_InstallerGui_Radio (TAGBASE_LG + 114)
#define MUIM_InstallerGui_Bool (TAGBASE_LG + 115)
#define MUIM_InstallerGui_String (TAGBASE_LG + 116)
#define MUIM_InstallerGui_Number (TAGBASE_LG + 117)
#define MUIM_InstallerGui_CheckBoxes (TAGBASE_LG + 118)
#define MUIM_InstallerGui_AskFile (TAGBASE_LG + 119)
#define MUIM_InstallerGui_PageSet (TAGBASE_LG + 120)
//----------------------------------------------------------------------------
// InstallerGui - Init parameters
//----------------------------------------------------------------------------
struct MUIP_InstallerGui_Init
{
ULONG MethodID;
};
//----------------------------------------------------------------------------
// InstallerGui - Welcome parameters
//----------------------------------------------------------------------------
struct MUIP_InstallerGui_Welcome
{
ULONG MethodID;
ULONG Message;
ULONG Level;
ULONG Log;
ULONG Pretend;
ULONG MinLevel;
ULONG NoPretend;
ULONG NoLog;
};
//----------------------------------------------------------------------------
// InstallerGui - CopyFilesStart parameters
//----------------------------------------------------------------------------
struct MUIP_InstallerGui_CopyFilesStart
{
ULONG MethodID;
ULONG Message;
ULONG Help;
ULONG List;
ULONG Confirm;
};
//----------------------------------------------------------------------------
// InstallerGui - CopyFilesSetCur parameters
//----------------------------------------------------------------------------
struct MUIP_InstallerGui_CopyFilesSetCur
{
ULONG MethodID;
ULONG File;
ULONG NoGauge;
};
//----------------------------------------------------------------------------
// InstallerGui - Exit parameters
//----------------------------------------------------------------------------
struct MUIP_InstallerGui_Exit
{
ULONG MethodID;
ULONG Message;
};
//----------------------------------------------------------------------------
// InstallerGui - Complete parameters
//----------------------------------------------------------------------------
struct MUIP_InstallerGui_Complete
{
ULONG MethodID;
ULONG Progress;
};
//----------------------------------------------------------------------------
// InstallerGui - CopyFilesAdd parameters
//----------------------------------------------------------------------------
struct MUIP_InstallerGui_CopyFilesAdd
{
ULONG MethodID;
ULONG File;
};
//----------------------------------------------------------------------------
// InstallerGui - Run parameters
//----------------------------------------------------------------------------
struct MUIP_InstallerGui_Confirm
{
ULONG MethodID;
ULONG Message;
ULONG Help;
};
//----------------------------------------------------------------------------
// InstallerGui - Message parameters
//----------------------------------------------------------------------------
struct MUIP_InstallerGui_Message
{
ULONG MethodID;
ULONG Message;
ULONG Immediate;
};
//----------------------------------------------------------------------------
// InstallerGui - Radio parameters
//----------------------------------------------------------------------------
struct MUIP_InstallerGui_Radio
{
ULONG MethodID;
ULONG Message;
ULONG Help;
ULONG Names;
ULONG Default;
ULONG Halt;
};
//----------------------------------------------------------------------------
// InstallerGui - Bool parameters
//----------------------------------------------------------------------------
struct MUIP_InstallerGui_Bool
{
ULONG MethodID;
ULONG Message;
ULONG Help;
ULONG Yes;
ULONG No;
};
//----------------------------------------------------------------------------
// InstallerGui - String parameters
//----------------------------------------------------------------------------
struct MUIP_InstallerGui_String
{
ULONG MethodID;
ULONG Message;
ULONG Help;
ULONG Default;
ULONG Halt;
};
//----------------------------------------------------------------------------
// InstallerGui - Number parameters
//----------------------------------------------------------------------------
struct MUIP_InstallerGui_Number
{
ULONG MethodID;
ULONG Message;
ULONG Help;
ULONG Min;
ULONG Max;
ULONG Default;
ULONG Halt;
};
//----------------------------------------------------------------------------
// InstallerGui - CheckBoxes parameters
//----------------------------------------------------------------------------
struct MUIP_InstallerGui_CheckBoxes
{
ULONG MethodID;
ULONG Message;
ULONG Help;
ULONG Names;
ULONG Default;
ULONG Halt;
};
//----------------------------------------------------------------------------
// InstallerGui - AskFile parameters
//----------------------------------------------------------------------------
struct MUIP_InstallerGui_AskFile
{
ULONG MethodID;
ULONG Message;
ULONG Help;
ULONG NewPath;
ULONG Disk;
ULONG Assign;
ULONG Default;
ULONG Dir;
};
//----------------------------------------------------------------------------
// InstallerGui - PageSet parameters
//----------------------------------------------------------------------------
struct MUIP_InstallerGui_PageSet
{
ULONG MethodID;
ULONG Message;
ULONG Help;
ULONG Top;
ULONG Bottom;
};
//----------------------------------------------------------------------------
// InstallerGui - private values
//----------------------------------------------------------------------------
#define MUIV_InstallerGui_FirstButton (TAGBASE_LG + 200)
#define MUIV_InstallerGui_Proceed (TAGBASE_LG + 200)
#define MUIV_InstallerGui_Abort (TAGBASE_LG + 201)
#define MUIV_InstallerGui_Yes (TAGBASE_LG + 202)
#define MUIV_InstallerGui_No (TAGBASE_LG + 203)
#define MUIV_InstallerGui_Tick (TAGBASE_LG + 204)
#define MUIV_InstallerGui_AbortOnly (TAGBASE_LG + 205)
#define MUIV_InstallerGui_ProceedRun (TAGBASE_LG + 206)
#define MUIV_InstallerGui_SkipRun (TAGBASE_LG + 207)
#define MUIV_InstallerGui_AbortRun (TAGBASE_LG + 208)
#define MUIV_InstallerGui_ProceedOnly (TAGBASE_LG + 209)
#define MUIV_InstallerGui_LastButton (TAGBASE_LG + 209)
// Pages
#define P_WELCOME 0
#define P_COPYFILES 1
#define P_FILEDEST 2
#define P_PRETEND_LOG 3
#define P_MESSAGE 4
#define P_STRING 5
#define P_NUMBER 6
#define P_ASKFILE 7
// Buttons
#define B_PROCEED_ABORT 0
#define B_YES_NO 1
#define B_ABORT 2
#define B_PROCEED_SKIP_ABORT 3
#define B_PROCEED 4
#define B_NONE 5
//----------------------------------------------------------------------------
// InstallerGuiWait - [PRIVATE] Wait for notification(s)
// Input: ULONG notif: Start notification value
// ULONG range: Number of values to check for
// Return: Notifcation val. / zero on return id quit
//----------------------------------------------------------------------------
MUIDSP ULONG InstallerGuiWait(Object *obj, ULONG notif, ULONG range)
{
ULONG sig = 0,
ret = 0, n;
// Set cycle chain for all buttons
// within the notification range.
for(n = 0; n < range; n++)
{
// Filter out ticks.
if(notif + n != MUIV_InstallerGui_Tick)
{
// Find current button.
Object *but = (Object *) DoMethod
(
obj, MUIM_FindUData,
notif + n
);
// Don't trust the caller.
if(but)
{
// Add button to cycle chain.
set(but, MUIA_CycleChain, TRUE);
}
else
{
// Button doesn't exist.
GERR(tr(S_UNER));
}
}
}
// Get MUI input.
ret = DoMethod(_app(obj), MUIM_Application_NewInput, &sig);
// Enter the message loop.
while(ret != MUIV_Application_ReturnID_Quit)
{
// Iterate over all signals that we're
// waiting for.
for(n = 0; n < range; n++)
{
// Did we get what we're waiting for?
if(ret == notif + n)
{
// Remove buttons within the range
// from the cycle chain.
for(n = 0; n < range; n++)
{
// Filter out ticks.
if(notif + n != MUIV_InstallerGui_Tick)
{
// Find current button.
Object *but = (Object *) DoMethod
(
obj, MUIM_FindUData,
notif + n
);
// Don't trust the caller.
if(but)
{
set(but, MUIA_CycleChain, FALSE);
}
}
}
// Return notifier value.
return ret;
}
}
// It wasn't for us. Go to sleep again.
if(sig)
{
sig = Wait(sig | SIGBREAKF_CTRL_C);
// Are we getting killed?
if(sig & SIGBREAKF_CTRL_C)
{
break;
}
}
// Get new input.
ret = DoMethod(_app(obj), MUIM_Application_NewInput, &sig);
}
// Quit application.
return 0;
}
//----------------------------------------------------------------------------
// InstallerGuiInit - Initialize all the things
// Input: -
// Return: On success TRUE, FALSE otherwise.
//----------------------------------------------------------------------------
MUIDSP IPTR InstallerGuiInit(Class *cls,
Object *obj)
{
static ULONG i = MUIV_InstallerGui_FirstButton;
// Have we already done this?
if(i != MUIV_InstallerGui_LastButton)
{
struct InstallerGuiData *my = INST_DATA(cls, obj);
// Set notifications on all buttons.
while(i <= MUIV_InstallerGui_LastButton)
{
// Find current button.
Object *but = (Object *) DoMethod(obj, MUIM_FindUData, i);
// Set notification if it exists.
if(but)
{
DoMethod
(
but, MUIM_Notify,
MUIA_Pressed, FALSE, _app(obj), 2,
MUIM_Application_ReturnID, i
);
}
// Next button.
i++;
}
// Enter in string gadget = proceed.
DoMethod
(
my->String, MUIM_Notify,
MUIA_String_Acknowledge,
MUIV_EveryTime, _app(obj), 2,
MUIM_Application_ReturnID,
MUIV_InstallerGui_Proceed
);
// Exit upon close request.
DoMethod
(
obj, MUIM_Notify, MUIA_Window_CloseRequest,
TRUE, _app(obj), 2, MUIM_Application_ReturnID,
MUIV_Application_ReturnID_Quit
);
// All done.
return TRUE;
}
else
{
// Unknown error.
GERR(tr(S_UNER));
return FALSE;
}
}
//----------------------------------------------------------------------------
// InstallerGuiPageSet - [PRIVATE] Set page / buttons and display text
// Input: int top: Top page
// int btm: Button page
// ULONG msg: Top text message
// Return: TRUE on success, FALSE otherwise
//----------------------------------------------------------------------------
//
MUIDSP IPTR InstallerGuiPageSet(Class *cls,
Object *obj,
struct MUIP_InstallerGui_PageSet *msg)
{
struct InstallerGuiData *my = INST_DATA(cls, obj);
// Always a valid message string.
const char *src = msg->Message ? (const char *)
msg->Message : "";
// Select top and buttons.
set(my->Top, MUIA_Group_ActivePage, msg->Top);
set(my->Bottom, MUIA_Group_ActivePage, msg->Bottom);
// NULL will disable the help bubble.
set(my->Root, MUIA_ShortHelp, msg->Help);
// Wrap at 50 for now, even though
// we make room for more below.
size_t cnt = strlen(src), len = 50;
// Allow no more than 80 columns
// and 10 lines of text, newline
// characters are included. More
// than this would be to much in
// a single page.
static char dst[80 * 10];
// Cap the size of the message.
cnt = cnt < (sizeof(dst) - 1) ?
cnt : (sizeof(dst) - 1);
// Copy for wrapping.
memcpy(dst, src, cnt);
// Do we need to word wrap?
if(cnt > len)
{
// Start from the first point
// where we need to wrap.
size_t cur = len;
// As long we have characters.
while(cur < cnt)
{
// Last wrapping point.
size_t ref = cur - len;
// Go backwards from where we are
// to a point where we can wrap.
while(cur > ref && dst[cur] > 33)
{
cur--;
}
// If we ended up where we started
// we failed. Wrap in the middle of
// the word in that case. This will
// only happen with words >= len.
if(cur == ref)
{
// Restore the previous point.
cur += len;
}
else
{
// If we found a wrapping point
// we must make sure that no NL
// exists before this point but
// after the previous point.
while(++ref < cur)
{
if(dst[ref] == '\n')
{
// Skip wrap.
cur = ref;
break;
}
}
}
// Wrap and continue.
dst[cur] = '\n';
cur += len;
}
}
// Terminate string.
dst[cnt] = '\0';
// Show the message.
set(my->Text, MUIA_ShowMe, FALSE);
set(my->Text, MUIA_Text_Contents, dst);
set(my->Text, MUIA_ShowMe, TRUE);
// Always.
return TRUE;
}
//----------------------------------------------------------------------------
// InstallerGuiWelcome - Show welcome message. The Level, Log, and Pretend
// parameters are int pointers that act as both input
// and output.
// Input: Message - the welcome message text
// Level - User level
// Log - Log to file
// Pretend - Pretend mode
// MinLevel - Minimum user level
// NoPretend - Disable pretend mode
// NoLog - Disable logging
// Return: 1 on success, 0 on abort
//----------------------------------------------------------------------------
MUIDSP IPTR InstallerGuiWelcome(Class *cls,
Object *obj,
struct MUIP_InstallerGui_Welcome *msg)
{
// Show welcome page.
if(DoMethod(obj, MUIM_InstallerGui_PageSet, msg->Message,
NULL, P_WELCOME, B_PROCEED_ABORT))
{
struct InstallerGuiData *my = INST_DATA(cls, obj);
// If the minimum user level is set to 'expert',
// disable radio buttons to indicate that there
// is no choice to be made.
if(msg->MinLevel == 2)
{
set(my->UserLevel, MUIA_Disabled, TRUE);
}
// If the minimum user level is set to 'average',
// show 'average' and 'expert' only.
else if(msg->MinLevel == 1)
{
// Hide the full one.
set(my->UserLevel, MUIA_ShowMe, FALSE);
set(my->ExpertLevel, MUIA_ShowMe, TRUE);
// Take minimum user level into account.
set(my->ExpertLevel, MUIA_Radio_Active, *((int *) msg->Level) - 1);
}
// Set the current user level.
set(my->UserLevel, MUIA_Radio_Active, *((int *) msg->Level));
// Wait for proceed or abort.
if(InstallerGuiWait(obj, MUIV_InstallerGui_Proceed, 2)
== MUIV_InstallerGui_Proceed)
{
// Get the selected user level value. If we have
// a minimum user level of 'average' we're using
// a different set of radio buttons. Fetch from
// the right object and adjust the return value.
if(msg->MinLevel == 1)
{
// Minimum user level 'average'.
get(my->ExpertLevel, MUIA_Radio_Active, (int *) msg->Level);
(*((int *) msg->Level))++;
}
else
{
// Minimum user level 'novice' or 'expert'.
get(my->UserLevel, MUIA_Radio_Active, (int *) msg->Level);
}
// Disable the pretend choice if the NOPRETEND
// tooltype is used. The default behaviour is
// to install for real, not to pretend.
SetAttrs
(
my->Pretend,
MUIA_Radio_Active,
msg->NoPretend ? 0 : *((int *) msg->Pretend),
MUIA_Disabled, msg->NoPretend ? TRUE : FALSE,
TAG_END
);
// Disable the 'log to file' choice if the NOLOG
// tooltype is used. The default behaviour is to
// not write to a log file.
SetAttrs
(
my->Log,
MUIA_Radio_Active,
msg->NoLog ? 0 : *((int *) msg->Log),
MUIA_Disabled, msg->NoLog ? TRUE : FALSE,
TAG_END
);
// Don't show logging and pretend mode settings
// to 'Novice' users.
if(*((int *) msg->Level))
{
// Show pretend / log page.
if(DoMethod(obj, MUIM_InstallerGui_PageSet, NULL,
NULL, P_PRETEND_LOG, B_PROCEED_ABORT))
{
// Wait for proceed or abort.
if(InstallerGuiWait(obj, MUIV_InstallerGui_Proceed, 2)
== MUIV_InstallerGui_Proceed)
{
// Get pretend and log settings.
get(my->Pretend, MUIA_Radio_Active, (int *) msg->Pretend);
get(my->Log, MUIA_Radio_Active, (int *) msg->Log);
}
else
{
// Abort.
return 0;
}
}
else
{
// Unknown error.
GERR(tr(S_UNER));
return 0;
}
}
// Done.
return 1;
}
else
{
// Abort.
return 0;
}
}
// Unknown error.
GERR(tr(S_UNER));
return 0;
}
//----------------------------------------------------------------------------
// InstallerGuiAskFile - Show file / directory requester
// Input: Message - The prompt
// Help - Help text
// NewPath - Allow non-existent defaults
// Disk - Show drive list first
// Assign - Logical assign OK as dir
// Default - Default file / directory
// Dir - Ask for directory
// Return: File / directory name or NULL
//----------------------------------------------------------------------------
MUIDSP IPTR InstallerGuiAskFile(Class *cls,
Object *obj,
struct MUIP_InstallerGui_AskFile *msg)
{
// Show file requester page.
if(DoMethod(obj, MUIM_InstallerGui_PageSet, msg->Message,
msg->Help, P_ASKFILE, B_PROCEED_ABORT))
{
// Create ASL file requester
Object *str, *pop = (Object *) MUI_NewObject
(
MUIC_Popasl,
MUIA_Popasl_Type, ASL_FileRequest,
ASLFR_DrawersOnly, msg->Dir,
ASLFR_InitialShowVolumes, msg->Disk,
ASLFR_TitleText, msg->Dir ? tr(S_SDIR) : tr(S_SFLE),
MUIA_Popstring_String, str = (Object *) MUI_MakeObject(MUIO_String, NULL, PATH_MAX),
MUIA_Popstring_Button, (Object *) MUI_MakeObject(MUIO_PopButton, MUII_PopDrawer),
TAG_END
);
// Open the requester after adding it
// to the current group.
if(pop)
{
struct InstallerGuiData *my = INST_DATA(cls, obj);
// Set default file / dir.
set(str, MUIA_String_Contents, msg->Default);
// Prepare before adding requester.
if(DoMethod(my->Ask, MUIM_Group_InitChange))
{
char *ret = NULL;
static char buf[PATH_MAX];
// Add pop up requester.
DoMethod(my->Ask, OM_ADDMEMBER, pop);
// We're done adding things.
DoMethod(my->Ask, MUIM_Group_ExitChange);
// Wait for proceed or abort.
if(InstallerGuiWait(obj, MUIV_InstallerGui_Proceed, 2)
== MUIV_InstallerGui_Proceed)
{
// Get filename from requester.
get(str, MUIA_String_Contents, &ret);
if(ret)
{
// We need to create a copy of the filename
// string since we're about to free the pop
// up requester.
int n = snprintf(buf, sizeof(buf), "%s", ret);
// Make sure that we succeded in creating a
// copy of the filename.
if(n >= 0 && n < sizeof(buf))
{
ret = buf;
}
}
if(!ret)
{
// Unknown error.
GERR(tr(S_UNER));
}
}
// Prepare before removing requester.
if(DoMethod(my->Ask, MUIM_Group_InitChange))
{
// Remove pop up requester.
DoMethod(my->Ask, OM_REMMEMBER, pop);
// We're done removing things.
DoMethod(my->Ask, MUIM_Group_ExitChange);
// Free ASL requester.
MUI_DisposeObject(pop);
// Return filename.
return (IPTR) ret;
}
}
// Free ASL requester.
MUI_DisposeObject(pop);
}
}
// Unknown error.
GERR(tr(S_UNER));
return (IPTR) NULL;
}
//----------------------------------------------------------------------------
// InstallerGuiCopyFilesStart - Show file copy requester
// Input: Message - The prompt
// List - File / dir list
// Confirm - User confirmation
// Return: TRUE to start copy, FALSE to cancel
//----------------------------------------------------------------------------
MUIDSP IPTR InstallerGuiCopyFilesStart(Class *cls,
Object *obj,
struct MUIP_InstallerGui_CopyFilesStart *msg)
{
struct InstallerGuiData *my = INST_DATA(cls, obj);
int n = 0;
pnode_p cur = (pnode_p) msg->List,
lst = cur;
// For all files and directories to be copied; count
// the files, and if confirmation is needed, add them
// to the selection / deselection list.
while(cur)
{
// Is this a file?
if(cur->type == 1)
{
// Do we need confirmation?
if(msg->Confirm)
{
// Add file to the selection / deselection list.
DoMethod(Win, MUIM_InstallerGui_CopyFilesAdd, cur->name);
}
// Increase the total file count.
n++;
}
// Next file / directory.
cur = cur->next;
}
if(msg->Confirm && n)
{
// Show the file selection page.
if(DoMethod(Win, MUIM_InstallerGui_PageSet, msg->Message,
msg->Help, P_FILEDEST, B_PROCEED_SKIP_ABORT))
{
ULONG b;
LONG id = MUIV_List_NextSelected_Start;
// Wait for confirmation / skip / abort.
b = InstallerGuiWait(Win, MUIV_InstallerGui_ProceedRun, 3);
// Did the user confirm?
if(b == MUIV_InstallerGui_ProceedRun)
{
// For all files in the selection / deselection
// list, tag the ones that we're going to copy.
for(;;)
{
// Get the first element in the list.
DoMethod(my->List, MUIM_List_NextSelected, &id);
// Are we done with all of the files?
if(id != MUIV_List_NextSelected_End)
{
// Get name of current file?
char *ent = NULL;
DoMethod(my->List, MUIM_List_GetEntry, id, &ent);
if(ent)
{
// Find the corresponding file node
// in 'our' list.
for(cur = lst; cur;
cur = cur->next)
{
// If we find it, and it's a file,
// give it a 'copy' tag.
if(cur->type == 1 &&
!strcmp(ent, cur->name))
{
cur->type = -1;
break;
}
}
}
}
else
{
// We're done with all files in the
// selection / deselection list.
break;
}
}
// Iterate over nodes in 'our' list and tag
// everything that we're NOT going to copy.
for(cur = lst; cur;
cur = cur->next)
{
// Is this a file that's not going to be
// copied?
if(cur->type == 1)
{
// Give it an 'ignore' tag and decrease
// the number of files to be copied.
n--;
cur->type = 0;
}
// Is this a file that's going to be copied?
else if(cur->type == -1)
{
// Restore the file type so that the
// rest of the world understands that
// this is a file.
cur->type = 1;
}
}
}
else
{
// Are we going to skip the file copy or are
// we going to abort?
return b == MUIV_InstallerGui_SkipRun ?
0 : -1;
}
}
}
// Show file copy page.
if(DoMethod(obj, MUIM_InstallerGui_PageSet, msg->Message,
NULL, P_COPYFILES, B_ABORT))
{
// Install a timer to create a time slice
// where the user has a chance to abort.
DoMethod(_app(obj), MUIM_Application_AddInputHandler, &my->Ticker);
// Configure gauge so that one tick == one file.
SetAttrs(my->Progress, MUIA_Gauge_Max, n,
MUIA_Gauge_Current, 0, TAG_END);
// Always true.
return (IPTR) TRUE;
}
else
{
// Unknown error.
GERR(tr(S_UNER));
return FALSE;
}
}
//----------------------------------------------------------------------------
// InstallerGuiCopyFilesSetCur - Show current file
// Input: File - filename
// NoGauge - Hide file gauge