revert between 56095 -> 55830 in arch
[AROS.git] / workbench / tools / InstallAROS / main.c
blob351c1ba0da6147d0cd8c86fb843452252d8c5151
1 /*
2 Copyright © 2003-2019, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define INTUITION_NO_INLINE_STDARG
8 #define DEBUG 1
9 #include <aros/debug.h>
11 #include <libraries/mui.h>
13 #include <dos/dos.h>
14 #include <exec/types.h>
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <string.h>
19 #include <clib/alib_protos.h>
21 #include <intuition/gadgetclass.h>
22 #include <intuition/icclass.h>
23 #include <gadgets/colorwheel.h>
25 #include <libraries/asl.h>
26 #include <libraries/expansionbase.h>
28 #include <devices/trackdisk.h>
29 #include <devices/scsidisk.h>
31 #include <proto/exec.h>
32 #include <proto/intuition.h>
33 #include <proto/dos.h>
34 #include <proto/partition.h>
35 #include <proto/muimaster.h>
36 #include <proto/graphics.h>
37 #include <proto/utility.h>
39 #include <mui/TextEditor_mcc.h>
41 #include "install.h"
45 #define kBufSize (4*65536)
46 #define kExallBufSize (4096)
48 #define SYS_PART_NAME "DH0"
49 #define WORK_PART_NAME "DH1"
50 #define USB_SYS_PART_NAME "DU0"
51 #define USB_WORK_PART_NAME "DU1"
52 #define SYS_VOL_NAME "AROS"
53 #define WORK_VOL_NAME "Work"
54 #define USB_SYS_VOL_NAME "AROS Live Drive"
55 #define USB_WORK_VOL_NAME "Briefcase"
57 #define MAX_FFS_SIZE (4L * 1024)
58 #define MAX_SFS_SIZE (124L * 1024)
60 #define INSTALLER_TMP_PATH "T:Installer"
61 #define INSTALLAROS_TMP_PATH "T:Installer/InstallAROS"
63 #define localeFile_path "Prefs/Locale\""
64 #define inputFile_path "Prefs/Input\""
65 #define prefssrc_path "ENV:SYS"
66 #define prefs_path "Prefs/Env-Archive/SYS"
67 #define ARCH_PATH "boot/pc"
68 #define GRUB_PATH "grub"
70 #define locale_prfs_file "locale.prefs" /* please note the suffixed \" */
71 #define input_prfs_file "input.prefs"
73 #define DEF_INSTALL_IMAGE "IMAGES:Logos/install.logo"
74 #define DEF_BACK_IMAGE "IMAGES:Logos/install.logo"
75 #define DEF_LIGHTBACK_IMAGE "IMAGES:Logos/install.logo"
77 #define POST_INSTALL_SCRIPT "PROGDIR:InstallAROS-Post-Install"
78 #define AROS_BOOT_FILE "AROS.boot"
80 #define GRUB_COPY_FILE_LOOP(files) \
81 SET(data->gauge2, MUIA_Gauge_Current, 0); \
83 while (files[file_count] != NULL && data->inst_success == MUIV_Inst_InProgress) \
84 { \
85 ULONG newSrcLen = strlen(srcPath) + strlen(files[file_count]) + 2; \
86 ULONG newDstLen = strlen(dstPath) + strlen(files[file_count + 1]) + 2; \
88 TEXT srcFile[newSrcLen]; \
89 TEXT dstFile[newDstLen]; \
91 sprintf(srcFile, "%s", srcPath); \
92 sprintf(dstFile, "%s", dstPath); \
93 AddPart(srcFile, files[file_count], newSrcLen); \
94 AddPart(dstFile, files[file_count + 1], newDstLen); \
96 DoMethod(self, MUIM_IC_CopyFile, srcFile, dstFile); \
98 file_count += 2; \
100 if (numgrubfiles > 0) \
102 SET(data->gauge2, MUIA_Gauge_Current, \
103 (LONG)((100.0 / numgrubfiles) * (file_count / 2.0))); \
107 #if 0
108 #define OPTION_PREPDRIVES 1
109 #define OPTION_FORMAT 2
110 #define OPTION_LANGUAGE 3
111 #define OPTION_CORE 4
112 #define OPTION_EXTRAS 5
113 #define OPTION_BOOTLOADER 6
114 #endif
116 #define INSTV_TITLE 101001
117 #define INSTV_LOGO 101002
118 #define INSTV_PAGE 101003
120 #define INSTV_TEXT 101004
121 #define INSTV_SPACE 101005
122 #define INSTV_BOOL 101006
123 #define INSTV_RETURN 101007
125 #define INSTV_CURR 101100
127 enum BootLoaderTypes
129 BOOTLOADER_NONE = -1,
130 BOOTLOADER_GRUB1,
131 BOOTLOADER_GRUB2
134 /* Files to check for. Must be in the same order as enum values before */
135 STRPTR BootLoaderFiles[] = {
136 "boot/grub/stage1",
137 "boot/grub/i386-pc/core.img",
138 NULL
141 #define BOOTLOADER_PATH_LEN 20 /* Length of the largest string in BootLoaders array plus 2 */
143 struct ExpansionBase *ExpansionBase = NULL;
145 char *source_Path = NULL; /* full path to source "tree" */
146 char *extras_source = NULL;
148 char *dest_Path = NULL; /* DOS DEVICE NAME of part used to store "aros" */
149 char *work_Path = NULL; /* DOS DEVICE NAME of part used to store "work" */
150 TEXT *extras_path = NULL; /* DOS DEVICE NAME of part used to store extras */
152 char *boot_Device = "ahci.device";
153 ULONG boot_Unit = 0;
155 Object *check_copytowork = NULL;
156 Object *check_work = NULL;
157 Object *show_formatsys = NULL;
158 Object *show_formatwork = NULL;
159 Object *check_formatsys = NULL;
160 Object *check_formatwork = NULL;
161 Object *cycle_fstypesys = NULL;
162 Object *cycle_fstypework = NULL;
163 Object *cycle_sysunits = NULL;
164 Object *cycle_workunits = NULL;
166 Object *dest_volume = NULL;
167 Object *work_volume = NULL;
169 Object *dest_device = NULL;
170 Object *cycle_drivetype = NULL;
171 Object *dest_unit = NULL;
172 Object *show_sizesys = NULL;
173 Object *show_sizework = NULL;
174 Object *check_sizesys = NULL;
175 Object *check_sizework = NULL;
176 Object *check_creatework = NULL;
177 Object *sys_size = NULL;
178 Object *work_size = NULL;
179 Object *sys_devname = NULL;
180 Object *work_devname = NULL;
182 Object *grub_device = NULL;
183 Object *grub_unit = NULL;
185 Object *reboot_group = NULL;
186 LONG BootLoaderType;
187 BOOL gfx_font_exists;
189 ULONG GuessFirstHD(CONST_STRPTR device);
190 static struct FileSysStartupMsg *getDiskFSSM(CONST_STRPTR path);
191 static LONG GetPartitionSize(BOOL get_work);
192 static LONG FindWindowsPartition(STRPTR device, LONG unit);
193 LONG CopyDirArray(Class * CLASS, Object * self, CONST_STRPTR sourcePath,
194 CONST_STRPTR destinationPath, CONST_STRPTR directories[]);
196 IPTR Install__OM_NEW(Class * CLASS, Object * self, struct opSet *message)
198 self = (Object *) DoSuperMethodA(CLASS, self, (Msg) message);
200 struct Install_DATA *data = INST_DATA(CLASS, self);
201 BPTR lock = NULL;
202 char sys_path[100];
204 /* We will generate this info shortly */
206 /* IO Related */
208 data->IO_Always_overwrite = IIO_Overwrite_Ask;
210 /* Main stuff */
212 data->welcomeMsg =
213 (APTR) GetTagData(MUIA_WelcomeMsg, (IPTR) NULL,
214 message->ops_AttrList);
215 data->doneMsg =
216 (APTR) GetTagData(MUIA_FinishedMsg, (IPTR) NULL,
217 message->ops_AttrList);
219 data->page =
220 (APTR) GetTagData(MUIA_Page, (IPTR) NULL, message->ops_AttrList);
221 data->gauge1 =
222 (APTR) GetTagData(MUIA_Gauge1, (IPTR) NULL, message->ops_AttrList);
223 data->gauge2 =
224 (APTR) GetTagData(MUIA_Gauge2, (IPTR) NULL, message->ops_AttrList);
225 data->label =
226 (APTR) GetTagData(MUIA_Install, (IPTR) NULL, message->ops_AttrList);
228 data->installer =
229 (APTR) GetTagData(MUIA_OBJ_Installer, (IPTR) NULL,
230 message->ops_AttrList);
232 data->window =
233 (APTR) GetTagData(MUIA_OBJ_Window, (IPTR) NULL,
234 message->ops_AttrList);
235 data->contents =
236 (APTR) GetTagData(MUIA_OBJ_WindowContent, (IPTR) NULL,
237 message->ops_AttrList);
239 data->pagetitle =
240 (APTR) GetTagData(MUIA_OBJ_PageTitle, (IPTR) NULL,
241 message->ops_AttrList);
242 data->pageheader =
243 (APTR) GetTagData(MUIA_OBJ_PageHeader, (IPTR) NULL,
244 message->ops_AttrList);
246 data->actioncurrent =
247 (APTR) GetTagData(MUIA_OBJ_CActionStrng, (IPTR) NULL,
248 message->ops_AttrList);
249 data->back =
250 (APTR) GetTagData(MUIA_OBJ_Back, (IPTR) NULL,
251 message->ops_AttrList);
252 data->proceed =
253 (APTR) GetTagData(MUIA_OBJ_Proceed, (IPTR) NULL,
254 message->ops_AttrList);
255 data->cancel =
256 (APTR) GetTagData(MUIA_OBJ_Cancel, (IPTR) NULL,
257 message->ops_AttrList);
259 data->instc_lic_file =
260 (char *)GetTagData(MUIA_IC_License_File, (IPTR) NULL,
261 message->ops_AttrList);
262 data->instc_copt_licensemandatory =
263 (BOOL) GetTagData(MUIA_IC_License_Mandatory, (IPTR) FALSE,
264 message->ops_AttrList);
266 data->instc_options_main =
267 (APTR) GetTagData(MUIA_List_Options, (IPTR) NULL,
268 message->ops_AttrList);
269 data->instc_options_grub =
270 (APTR) GetTagData(MUIA_Grub_Options, (IPTR) NULL,
271 message->ops_AttrList);
273 data->instc_copt_undoenabled =
274 (BOOL) GetTagData(MUIA_IC_EnableUndo, (IPTR) FALSE,
275 message->ops_AttrList);
277 data->instc_options_main->partitioned = FALSE;
278 data->instc_options_main->bootloaded = FALSE;
279 data->instc_options_grub->bootinfo = FALSE;
281 GET(data->window, MUIA_Window_Width, &data->cur_width);
282 GET(data->window, MUIA_Window_Height, &data->cur_height);
284 SET(data->welcomeMsg, MUIA_Text_Contents, KMsgWelcome);
285 SET(data->back, MUIA_Disabled, TRUE);
287 data->instc_stage_next = EPartitionOptionsStage;
289 data->inst_success = FALSE;
290 data->disable_back = FALSE;
292 data->instc_cflag_driveset = (BOOL) DoMethod(self, MUIM_FindDrives);
294 /* Default to USB if a USB system volume appears to be present and we
295 * haven't booted from it */
297 lock = Lock("SYS:", SHARED_LOCK);
298 NameFromLock(lock, sys_path, 100);
299 if (getDiskFSSM(USB_SYS_PART_NAME ":") != NULL
300 && strncmp(sys_path, USB_SYS_VOL_NAME ":",
301 strlen(USB_SYS_VOL_NAME) + 1))
303 SET(dest_volume, MUIA_String_Contents, USB_SYS_PART_NAME);
304 SET(work_volume, MUIA_String_Contents, USB_WORK_PART_NAME);
306 SET(cycle_drivetype, MUIA_Cycle_Active, 2);
308 UnLock(lock);
310 boot_Unit = GuessFirstHD(boot_Device);
312 DoMethod(data->proceed, MUIM_Notify, MUIA_Pressed, FALSE, (IPTR) self,
313 1, MUIM_IC_NextStep);
314 DoMethod(data->back, MUIM_Notify, MUIA_Pressed, FALSE, (IPTR) self, 1,
315 MUIM_IC_PrevStep);
316 DoMethod(data->cancel, MUIM_Notify, MUIA_Pressed, FALSE, (IPTR) self, 1,
317 MUIM_IC_CancelInstall);
319 DoMethod(self, MUIM_Notify, MUIA_InstallComplete, TRUE, (IPTR) self, 1,
320 MUIM_Reboot);
322 /* set up the license info */
324 if (data->instc_lic_file)
326 register struct FileInfoBlock *fib = NULL;
327 BPTR from = NULL;
328 LONG s = 0;
330 lock = (BPTR) Lock(data->instc_lic_file, SHARED_LOCK);
331 if (lock != NULL)
333 fib = (void *)AllocVec(sizeof(*fib), MEMF_PUBLIC);
334 Examine(lock, fib);
337 if ((from = Open(data->instc_lic_file, MODE_OLDFILE)))
339 D(bug
340 ("[INSTALLER.i] Allocating buffer [%d] for license file '%s'!",
341 fib->fib_Size, data->instc_lic_file));
342 data->instc_lic_buffer =
343 AllocVec(fib->fib_Size + 1, MEMF_CLEAR | MEMF_PUBLIC);
344 if ((s = Read(from, data->instc_lic_buffer,
345 fib->fib_Size)) == -1)
347 D(bug("[INSTALLER.i] Error processing license file!"));
348 if ((BOOL) data->instc_copt_licensemandatory)
350 Close(from);
351 UnLock(lock);
352 return 0;
355 else
357 DoMethod(data->instc_options_main->opt_lic_box,
358 MUIM_TextEditor_InsertText, data->instc_lic_buffer,
359 MUIV_TextEditor_InsertText_Top);
361 Close(from);
364 if (lock != NULL)
366 if (fib)
367 FreeVec(fib);
368 UnLock(lock);
371 if (!data->instc_copt_licensemandatory)
372 SET(data->instc_options_main->opt_lic_mgrp, MUIA_ShowMe, FALSE);
373 else
374 DoMethod(data->instc_options_main->opt_license, MUIM_Notify,
375 MUIA_Selected, MUIV_EveryTime, (IPTR) data->proceed, 3,
376 MUIM_Set, MUIA_Disabled, MUIV_NotTriggerValue);
379 /* UNDO Record */
381 if (data->instc_copt_undoenabled)
383 lock = 0;
384 NEWLIST((struct List *)&data->instc_undorecord);
385 D(bug("[INSTALLER.i] Prepared UNDO list @ %p\n",
386 &data->instc_undorecord));
388 if ((lock = Lock(INSTALLER_TMP_PATH, ACCESS_READ)) != NULL)
390 D(bug("[INSTALLER.i] Dir '%s' Exists - no nead to create\n",
391 INSTALLER_TMP_PATH));
392 UnLock(lock);
394 else
396 lock = CreateDir(INSTALLER_TMP_PATH);
397 if (lock != NULL)
398 UnLock(lock);
399 else
401 D(bug("[INSTALLER.i] Failed to create dir '%s'!!\n",
402 INSTALLER_TMP_PATH));
403 data->inst_success = MUIV_Inst_Failed;
404 return 0;
408 if ((lock = Lock(INSTALLAROS_TMP_PATH, ACCESS_READ)) != NULL)
410 D(bug("[INSTALLER.i] Dir '%s' Exists - no nead to create\n",
411 INSTALLAROS_TMP_PATH));
412 UnLock(lock);
414 else
416 lock = CreateDir(INSTALLAROS_TMP_PATH);
417 if (lock != NULL)
418 UnLock(lock);
419 else
421 D(bug("[INSTALLER.i] Failed to create dir '%s'!!\n",
422 INSTALLAROS_TMP_PATH));
423 data->inst_success = MUIV_Inst_Failed;
424 return 0;
429 return (IPTR) self;
432 /* make page */
434 ULONG AskRetry(Class * CLASS, Object * self, CONST_STRPTR message,
435 CONST_STRPTR file, CONST_STRPTR opt1, CONST_STRPTR opt2,
436 CONST_STRPTR opt3)
438 struct Install_DATA *data = INST_DATA(CLASS, self);
439 STRPTR finalmessage = NULL;
440 STRPTR finaloptions = NULL;
441 ULONG result = -1;
443 finalmessage =
444 AllocVec(strlen(message) + strlen(file) + 2,
445 MEMF_CLEAR | MEMF_PUBLIC);
446 finaloptions =
447 AllocVec(strlen(opt1) + strlen(opt2) + strlen(opt3) + 5,
448 MEMF_CLEAR | MEMF_PUBLIC);
450 sprintf(finalmessage, message, file);
451 sprintf(finaloptions, "%s|%s|%s", opt1, opt2, opt3);
453 result =
454 MUI_RequestA(data->installer, data->window, 0,
455 "IO Error has occured", finaloptions, finalmessage, NULL);
456 FreeVec(finalmessage);
457 FreeVec(finaloptions);
459 return result - 1;
462 /* Return the unit number of the drive that's likely to be the first in the
463 * system, or zero if none found */
464 ULONG GuessFirstHD(CONST_STRPTR device)
466 struct PartitionHandle *ph;
467 ULONG i;
468 BOOL found = FALSE;
470 for (i = 0; i < 8 && !found; i++)
472 ph = OpenRootPartition(device, i);
473 if (ph != NULL)
475 found = TRUE;
476 CloseRootPartition(ph);
479 if (!found)
480 i = 1;
482 return i - 1;
485 /* Return TRUE if we suspect a floppy disk */
486 BOOL myCheckFloppy(struct DosEnvec * DriveEnv)
488 switch (DriveEnv->de_HighCyl)
490 case 79:
491 /* Standard Floppy size
492 for PC floppies, DD = 9, HD = 18
493 for Amiga floppies, DD = 11, HD = 22
495 if ((DriveEnv->de_BlocksPerTrack == 18) ||
496 (DriveEnv->de_BlocksPerTrack == 9) ||
497 (DriveEnv->de_BlocksPerTrack == 22) ||
498 (DriveEnv->de_BlocksPerTrack == 11))
499 return TRUE;
501 break;
502 case 2890:
503 /* Standard Zip (95Mb) */
504 if ((DriveEnv->de_BlocksPerTrack == 60) ||
505 (DriveEnv->de_BlocksPerTrack == 68))
506 return TRUE;
507 case 196601:
508 case 196607:
509 /* Standard Zip & LS120 sizes */
510 if (DriveEnv->de_BlocksPerTrack == 1)
511 return TRUE;
512 default:
513 break;
515 /* OK - shouldn't be a floppy... */
516 return FALSE;
519 /* Returns the first AROS-supported filesystem's name */
520 char *FindPartition(struct PartitionHandle *root)
522 struct PartitionHandle *partition = NULL;
523 char *success = NULL;
524 char *name = NULL;
525 struct PartitionType *type = NULL;
527 ForeachNode(&root->table->list, partition)
529 D(bug("[INSTALLER.fp] checking part\n"));
530 if (OpenPartitionTable(partition) == 0)
532 D(bug("[INSTALLER.fp] checking Child Parts... \n"));
533 success = FindPartition(partition);
534 ClosePartitionTable(partition);
535 D(bug("[INSTALLER.fp] Children Done...\n"));
536 if (success != NULL)
538 D(bug("[INSTALLER.fp] Found '%s'\n", success));
539 break;
542 else
544 D(bug("[INSTALLER.fp] checking PARTITION\n"));
545 struct PartitionType pttype;
547 name = AllocVec(100, MEMF_CLEAR | MEMF_PUBLIC);
549 GetPartitionAttrsTags
550 (partition,
551 PT_NAME, (IPTR) name, PT_TYPE, (IPTR) & pttype, TAG_DONE);
553 type = &pttype;
555 if (type->id_len == 4)
557 D(bug("[INSTALLER.fp] Found RDB Partition!\n"));
558 if ((type->id[0] == 68) && (type->id[1] == 79)
559 && (type->id[2] == 83))
561 D(bug("[INSTALLER.fp] Found AFFS Partition! '%s'\n",
562 name));
563 success = name;
564 break;
566 if ((type->id[0] == 83) && (type->id[1] == 70)
567 && (type->id[2] == 83))
569 D(bug("[INSTALLER.fp] Found SFS Partition! '%s'\n",
570 name));
571 success = name;
572 break;
578 if ((!success) && (name))
579 FreeVec(name);
581 return success;
584 IPTR Install__MUIM_FindDrives(Class * CLASS, Object * self, Msg message)
586 struct BootNode *CurBootNode = NULL;
587 struct PartitionHandle *root;
589 struct DevInfo *devnode = NULL;
590 struct FileSysStartupMsg *StartMess = NULL;
591 struct DosEnvec *DriveEnv = NULL;
593 char *result = NULL;
594 BOOL founddisk = FALSE;
596 ForeachNode(&ExpansionBase->MountList, CurBootNode)
598 devnode = CurBootNode->bn_DeviceNode;
599 StartMess = devnode->dvi_Startup;
600 if (!StartMess)
601 continue;
602 D(bug("[INSTALLER.fd] Drive found [%s unit %d]\n",
603 StartMess->fssm_Device, StartMess->fssm_Unit));
605 DriveEnv = StartMess->fssm_Environ;
607 if (!myCheckFloppy(DriveEnv))
609 if ((root =
610 OpenRootPartition(StartMess->fssm_Device,
611 StartMess->fssm_Unit)) != NULL)
613 if (!founddisk)
615 /* First drive in system - save its info for grub */
616 D(bug
617 ("[INSTALLER.fd] First DRIVE found [%s unit %d]...\n",
618 StartMess->fssm_Device, StartMess->fssm_Unit));
619 founddisk = TRUE;
620 // boot_Device = StartMess->fssm_Device;
621 // boot_Unit = StartMess->fssm_Unit;
624 if (OpenPartitionTable(root) == 0)
626 result = FindPartition(root);
627 D(bug("[INSTALLER.fd] Partition '%s'\n", result));
628 ClosePartitionTable(root);
630 CloseRootPartition(root);
635 return (IPTR) result;
638 static struct FileSysStartupMsg *getDiskFSSM(CONST_STRPTR path)
640 struct DosList *dl;
641 struct DeviceNode *dn;
642 TEXT dname[32];
643 UBYTE i;
645 D(bug("[install] getDiskFSSM('%s')\n", path));
647 for (i = 0; (path[i]) && (path[i] != ':'); i++)
648 dname[i] = path[i];
649 if (path[i] == ':')
651 dname[i] = 0;
652 dl = LockDosList(LDF_READ);
653 if (dl)
655 dn = (struct DeviceNode *)FindDosEntry(dl, dname, LDF_DEVICES);
656 UnLockDosList(LDF_READ);
657 if (dn)
659 if (IsFileSystem(dname))
661 return (struct FileSysStartupMsg *)BADDR(dn->
662 dn_Startup);
664 else
665 printf("device '%s' doesn't contain a file system\n",
666 dname);
668 // else
669 // PrintFault(ERROR_OBJECT_NOT_FOUND, dname);
672 else
673 printf("'%s' doesn't contain a device name\n", path);
674 return NULL;
677 IPTR Install__MUIM_IC_NextStep(Class * CLASS, Object * self, Msg message)
679 struct Install_DATA *data = INST_DATA(CLASS, self);
680 IPTR this_page = 0, next_stage = 0, option = 0;
682 GET(data->page, MUIA_Group_ActivePage, &this_page);
684 if ((EDoneStage == this_page) && (this_page == data->instc_stage_next))
685 set(self, MUIA_InstallComplete, TRUE); //ALL DONE!!
687 SET(data->back, MUIA_Disabled, (BOOL) data->disable_back);
689 next_stage = data->instc_stage_next;
690 data->instc_stage_prev = this_page;
692 SET(data->back, MUIA_Selected, FALSE);
693 SET(data->proceed, MUIA_Selected, FALSE);
694 SET(data->cancel, MUIA_Selected, FALSE);
696 switch (data->instc_stage_next)
699 case ELicenseStage:
700 if (data->instc_lic_file)
702 if (data->instc_copt_licensemandatory)
704 /* Force acceptance of the license */
705 SET(data->instc_options_main->opt_license, MUIA_Selected,
706 FALSE);
707 SET(data->proceed, MUIA_Disabled, TRUE);
709 data->instc_stage_next = EInstallOptionsStage;
710 next_stage = ELicenseStage;
711 break;
713 /* if no license we ignore this step... and go to partition options */
715 case EPartitionOptionsStage:
716 if (data->instc_cflag_driveset)
717 SET(data->instc_options_main->opt_partmethod, MUIA_Radio_Active,
719 else
720 SET(dest_unit, MUIA_String_Integer, boot_Unit);
721 data->instc_stage_next = EPartitioningStage;
722 next_stage = EPartitionOptionsStage;
723 break;
725 case EInstallOptionsStage:
726 SET(data->welcomeMsg, MUIA_Text_Contents, KMsgInstallOptions);
727 data->instc_stage_next = EDestOptionsStage;
728 next_stage = EInstallOptionsStage;
729 break;
731 case EDestOptionsStage:
732 if ((BOOL) XGET(data->instc_options_main->opt_format,
733 MUIA_Selected))
735 SET(show_formatsys, MUIA_ShowMe, TRUE);
736 SET(show_formatwork, MUIA_ShowMe, TRUE);
738 else
740 SET(check_formatsys, MUIA_Selected, FALSE);
741 SET(check_formatwork, MUIA_Selected, FALSE);
742 SET(show_formatsys, MUIA_ShowMe, FALSE);
743 SET(show_formatwork, MUIA_ShowMe, FALSE);
745 data->instc_stage_next = EInstallMessageStage;
746 next_stage = EDestOptionsStage;
747 break;
749 case EInstallMessageStage:
750 /* PARTITION DRIVES */
752 /* have we already done this? */
753 if (!data->instc_options_main->partitioned)
755 data->instc_options_main->partitioned = TRUE;
756 data->instc_stage_next = EPartitioningStage;
757 next_stage = EPartitionOptionsStage;
758 data->instc_stage_prev = this_page;
759 break;
762 /* BOOTLOADER */
764 option = 0;
766 GET(data->instc_options_main->opt_bootloader, MUIA_Selected,
767 &option);
768 if (option != 0)
770 //have we already done this?
771 if (!data->instc_options_main->bootloaded)
773 data->instc_options_main->bootloaded = TRUE;
775 if (!data->instc_options_grub->bootinfo)
777 #if 0
778 char *tmp_drive = NULL;
779 char *tmp_device = NULL;
780 #endif
781 char *tmp_grub = NULL;
782 #if 0
783 struct IOStdReq *ioreq = NULL;
784 struct MsgPort *mp = NULL;
785 #endif
786 struct FileSysStartupMsg *fssm;
788 data->instc_options_grub->bootinfo = TRUE;
790 #if 0
791 tmp_drive = AllocVec(100, MEMF_CLEAR | MEMF_PUBLIC);
792 tmp_device = AllocVec(100, MEMF_CLEAR | MEMF_PUBLIC);
793 #endif
794 tmp_grub = AllocVec(100, MEMF_CLEAR | MEMF_PUBLIC);
796 GET(dest_volume, MUIA_String_Contents, &option);
797 sprintf(tmp_grub, "%s:"ARCH_PATH"/"GRUB_PATH,
798 (CONST_STRPTR) option);
800 /* Guess the best disk to install GRUB's bootblock to */
801 fssm = getDiskFSSM(tmp_grub);
802 if (fssm != NULL)
804 boot_Device = fssm->fssm_Device;
805 if (strcmp(fssm->fssm_Device, "ahci.device") != 0
806 && strcmp(fssm->fssm_Device, "ata.device") != 0)
807 boot_Unit = fssm->fssm_Unit;
809 else
810 boot_Device = "";
812 SET(grub_device, MUIA_String_Contents,
813 (IPTR) boot_Device);
814 SET(grub_unit, MUIA_String_Integer, boot_Unit);
816 #if 0
817 mp = CreateMsgPort();
818 if (mp)
820 ioreq =
821 (struct IOStdReq *)CreateIORequest(mp,
822 sizeof(struct IOStdReq));
823 if (ioreq)
825 if (OpenDevice(boot_Device, boot_Unit,
826 (struct IORequest *)ioreq, 0) == 0)
828 identify(ioreq, tmp_drive);
829 sprintf(tmp_device, "%s [%s unit %d]",
830 tmp_drive, boot_Device, boot_Unit);
831 CloseDevice((struct IORequest *)ioreq);
833 else
834 sprintf(tmp_device,
835 "Unknown Drive [%s unit %d]",
836 boot_Device, boot_Unit);
837 DeleteIORequest((struct IORequest *)ioreq);
839 else
840 sprintf(tmp_device,
841 "Unknown Drive [%s unit %d]", boot_Device,
842 boot_Unit);
843 DeleteMsgPort(mp);
845 else
846 sprintf(tmp_device, "Unknown Drive [%s unit %d]",
847 boot_Device, boot_Unit);
849 SET(data->instc_options_grub->gopt_drive,
850 MUIA_Text_Contents, tmp_device);
851 #endif
852 SET(data->instc_options_grub->gopt_grub,
853 MUIA_Text_Contents, tmp_grub);
856 data->instc_stage_next = EInstallMessageStage;
857 next_stage = EGrubOptionsStage;
858 data->instc_stage_prev = EInstallOptionsStage;
859 break;
861 else if (strlen((STRPTR) XGET(grub_device,
862 MUIA_String_Contents)) == 0)
864 /* Go back if user hasn't entered a device name for GRUB */
865 MUI_RequestA(data->installer, data->window, 0, "Error",
866 "OK", KMsgNoGrubDevice, NULL);
867 data->instc_stage_next = EInstallMessageStage;
868 next_stage = EGrubOptionsStage;
869 data->instc_stage_prev = EInstallOptionsStage;
870 return 0;
874 if (XGET(check_formatsys, MUIA_Selected)
875 || XGET(check_formatwork, MUIA_Selected))
876 SET(data->welcomeMsg, MUIA_Text_Contents,
877 KMsgBeginWithPartition);
878 else
879 SET(data->welcomeMsg, MUIA_Text_Contents,
880 KMsgBeginWithoutPartition);
881 data->instc_stage_next = EInstallStage;
882 next_stage = EMessageStage;
883 break;
885 case EPartitioningStage:
886 get(data->instc_options_main->opt_partmethod, MUIA_Radio_Active,
887 &option);
888 if ((int)option == 0 || (int)option == 1)
890 LONG syssize, worksize;
891 IPTR systype = 0, worktype = 0;
893 /* Let user try again if either partition size is too big.
894 Note that C:Partition will ensure that automatically sized
895 partitions are within size limits */
896 syssize = GetPartitionSize(FALSE);
897 worksize = GetPartitionSize(TRUE);
899 get(cycle_fstypesys, MUIA_Cycle_Active, &systype);
900 get(cycle_fstypework, MUIA_Cycle_Active, &worktype);
902 if (syssize > (systype ? MAX_SFS_SIZE : MAX_FFS_SIZE) ||
903 worksize > (worktype ? MAX_SFS_SIZE : MAX_FFS_SIZE))
905 TEXT msg[sizeof(KMsgPartitionTooBig) + 40];
906 sprintf(msg, KMsgPartitionTooBig,
907 MAX_SFS_SIZE / 1024, MAX_SFS_SIZE,
908 MAX_FFS_SIZE / 1024, MAX_FFS_SIZE);
909 MUI_RequestA(data->installer, data->window, 0, "Error",
910 "OK", msg, NULL);
911 return 0;
914 /* Warn user about using non FFS-Intl filesystem for system
915 partition with GRUB */
916 if ((BootLoaderType == BOOTLOADER_GRUB1) && (systype != 0))
918 if (MUI_RequestA(data->installer, data->window, 0,
919 "Warning",
920 "Continue Partitioning|*Cancel Partitioning",
921 KMsgGRUBNonFFSWarning, NULL) != 1)
922 return 0;
925 data->disable_back = TRUE;
927 SET(data->page, MUIA_Group_ActivePage, EPartitioningStage);
929 switch (option)
931 case 0:
932 case 1:
933 if (DoMethod(self, MUIM_Partition) != RETURN_OK)
935 D(bug("[INSTALLER] Partitioning FAILED!!!!\n"));
936 data->disable_back = FALSE;
937 SET(data->page, MUIA_Group_ActivePage,
938 EInstallMessageStage);
939 data->instc_stage_next = EPartitioningStage;
940 data->instc_options_main->partitioned = FALSE;
941 MUI_RequestA(data->installer, data->window, 0, "Error",
942 "Quit", KMsgPartitioningFailed, NULL);
943 DoMethod(self, MUIM_IC_QuitInstall);
944 return 0;
946 data->instc_options_main->partitioned = TRUE;
947 next_stage = EDoneStage;
948 DoMethod(data->page, MUIM_Group_InitChange);
949 if (XGET(cycle_drivetype, MUIA_Cycle_Active) != 2)
950 SET(data->doneMsg, MUIA_Text_Contents, KMsgDoneReboot);
951 else
952 SET(data->doneMsg, MUIA_Text_Contents, KMsgDoneUSB);
953 SET(reboot_group, MUIA_ShowMe, TRUE);
954 if (XGET(cycle_drivetype, MUIA_Cycle_Active) != 2)
955 SET(data->instc_options_main->opt_reboot, MUIA_Selected,
956 TRUE);
957 DoMethod(data->page, MUIM_Group_ExitChange);
958 SET(data->back, MUIA_Disabled, TRUE);
959 SET(data->cancel, MUIA_Disabled, TRUE);
960 data->instc_stage_next = EDoneStage;
961 break;
962 case 2:
963 data->disable_back = FALSE;
964 data->instc_options_main->partitioned = TRUE;
965 data->instc_stage_next = EDestOptionsStage;
966 next_stage = EInstallOptionsStage;
967 break;
968 default:
969 D(bug("[INSTALLER] Launching QuickPart...\n"));
970 Execute("SYS:Tools/QuickPart", NULL, NULL);
971 break;
973 break;
975 case EInstallStage:
976 data->disable_back = TRUE;
977 SET(data->page, MUIA_Group_ActivePage, EInstallStage);
979 DoMethod(self, MUIM_IC_Install);
981 next_stage = EDoneStage;
982 SET(data->back, MUIA_Disabled, TRUE);
983 SET(data->cancel, MUIA_Disabled, TRUE);
984 data->instc_stage_next = EDoneStage;
985 break;
987 default:
988 break;
991 SET(data->page, MUIA_Group_ActivePage, next_stage);
992 return 0;
995 IPTR Install__MUIM_IC_PrevStep(Class * CLASS, Object * self, Msg message)
997 struct Install_DATA *data = INST_DATA(CLASS, self);
998 IPTR this_page = 0;
1000 GET(data->page, MUIA_Group_ActivePage, &this_page);
1001 SET(data->back, MUIA_Selected, FALSE);
1002 SET(data->proceed, MUIA_Selected, FALSE);
1003 SET(data->cancel, MUIA_Selected, FALSE);
1005 SET(data->back, MUIA_Disabled, (BOOL) data->disable_back);
1006 data->instc_stage_next = this_page;
1008 switch (this_page)
1010 case EMessageStage:
1011 /* BACK should only be possible when page != first_page */
1012 if (data->instc_stage_prev != EMessageStage)
1014 SET(data->welcomeMsg, MUIA_Text_Contents,
1015 KMsgBeginWithPartition);
1016 if (data->instc_stage_prev == EDestOptionsStage)
1018 SET(data->page, MUIA_Group_ActivePage, EDestOptionsStage);
1020 data->instc_stage_prev = EInstallOptionsStage;
1022 else
1024 if (!data->instc_options_grub->bootinfo)
1026 SET(data->page, MUIA_Group_ActivePage,
1027 EPartitionOptionsStage);
1029 else
1031 SET(data->page, MUIA_Group_ActivePage,
1032 EGrubOptionsStage);
1034 data->instc_stage_prev = EDestOptionsStage;
1036 data->instc_stage_next = EInstallMessageStage;
1038 break;
1040 case EPartitionOptionsStage:
1041 if (data->instc_lic_file)
1043 SET(data->instc_options_main->opt_license, MUIA_Selected,
1044 FALSE);
1045 SET(data->proceed, MUIA_Disabled, TRUE);
1046 SET(data->page, MUIA_Group_ActivePage, EPartitionOptionsStage);
1047 data->instc_stage_prev = ELicenseStage;
1048 break;
1051 case ELicenseStage:
1052 SET(data->proceed, MUIA_Disabled, FALSE);
1053 SET(data->back, MUIA_Disabled, TRUE);
1054 SET(data->welcomeMsg, MUIA_Text_Contents, KMsgWelcome);
1055 SET(data->page, MUIA_Group_ActivePage, EMessageStage);
1056 data->instc_stage_prev = EMessageStage;
1057 break;
1059 case EInstallOptionsStage:
1060 SET(data->instc_options_main->opt_license, MUIA_Selected, FALSE);
1061 SET(data->page, MUIA_Group_ActivePage, EPartitionOptionsStage);
1062 data->instc_stage_prev = ELicenseStage;
1063 data->instc_stage_next = EPartitioningStage;
1064 break;
1066 case EDestOptionsStage:
1067 SET(data->page, MUIA_Group_ActivePage, EInstallOptionsStage);
1068 data->instc_stage_next = EDestOptionsStage;
1069 data->instc_stage_prev = EMessageStage;
1070 break;
1072 case EGrubOptionsStage:
1073 SET(data->page, MUIA_Group_ActivePage, EDestOptionsStage);
1074 data->instc_options_main->bootloaded = FALSE;
1075 data->instc_options_grub->bootinfo = FALSE;
1076 data->instc_stage_next = EInstallMessageStage;
1077 data->instc_stage_prev = EInstallOptionsStage;
1078 break;
1080 case EInstallMessageStage:
1082 /* Back is disabled from here on... */
1084 case EPartitioningStage:
1085 case EInstallStage:
1086 case EDoneStage:
1087 default:
1088 break;
1091 return TRUE;
1094 IPTR Install__MUIM_IC_CancelInstall
1095 (Class * CLASS, Object * self, Msg message)
1097 struct Install_DATA *data = INST_DATA(CLASS, self);
1098 struct optionstmp *backupOptions = NULL;
1099 IPTR this_page = 0;
1100 const char *cancelmessage = NULL;
1102 if ((backupOptions = data->instc_options_backup) == NULL)
1104 backupOptions =
1105 AllocMem(sizeof(struct optionstmp), MEMF_CLEAR | MEMF_PUBLIC);
1106 data->instc_options_backup = backupOptions;
1109 GET(data->page, MUIA_Group_ActivePage, &this_page);
1111 GET(data->back, MUIA_Disabled, &data->status_back);
1112 GET(data->proceed, MUIA_Disabled, &data->status_proceed);
1113 GET(data->cancel, MUIA_Disabled, &data->status_cancel);
1115 switch (this_page)
1117 case EPartitioningStage:
1118 case EInstallStage:
1119 case EDoneStage:
1120 cancelmessage = KMsgCancelDanger;
1121 break;
1123 case EInstallOptionsStage:
1124 GET(data->instc_options_main->opt_format, MUIA_Disabled,
1125 &backupOptions->opt_format);
1126 GET(data->instc_options_main->opt_locale, MUIA_Disabled,
1127 &backupOptions->opt_locale);
1128 GET(data->instc_options_main->opt_copycore, MUIA_Disabled,
1129 &backupOptions->opt_copycore);
1130 GET(data->instc_options_main->opt_copyextra, MUIA_Disabled,
1131 &backupOptions->opt_copyextra);
1132 GET(data->instc_options_main->opt_developer, MUIA_Disabled,
1133 &backupOptions->opt_developer);
1134 GET(data->instc_options_main->opt_bootloader, MUIA_Disabled,
1135 &backupOptions->opt_bootloader);
1136 GET(data->instc_options_main->opt_reboot, MUIA_Disabled,
1137 &backupOptions->opt_reboot);
1139 SET(data->instc_options_main->opt_format, MUIA_Disabled, TRUE);
1140 SET(data->instc_options_main->opt_locale, MUIA_Disabled, TRUE);
1141 SET(data->instc_options_main->opt_copycore, MUIA_Disabled, TRUE);
1142 SET(data->instc_options_main->opt_copyextra, MUIA_Disabled, TRUE);
1143 SET(data->instc_options_main->opt_developer, MUIA_Disabled, TRUE);
1144 SET(data->instc_options_main->opt_bootloader, MUIA_Disabled, TRUE);
1145 SET(data->instc_options_main->opt_reboot, MUIA_Disabled, TRUE);
1146 goto donecancel;
1148 case EDestOptionsStage:
1149 SET(dest_volume, MUIA_Disabled, TRUE);
1150 SET(work_volume, MUIA_Disabled, TRUE);
1151 SET(check_copytowork, MUIA_Disabled, TRUE);
1152 SET(check_work, MUIA_Disabled, TRUE);
1153 goto donecancel;
1155 case EPartitionOptionsStage:
1156 SET(data->instc_options_main->opt_partmethod, MUIA_Disabled, TRUE);
1157 goto donecancel;
1159 case EGrubOptionsStage:
1160 goto donecancel;
1162 default:
1163 donecancel:
1164 cancelmessage = KMsgCancelOK;
1165 break;
1168 SET(data->back, MUIA_Selected, FALSE);
1169 SET(data->back, MUIA_Disabled, TRUE);
1171 SET(data->proceed, MUIA_Selected, FALSE);
1172 SET(data->proceed, MUIA_Disabled, TRUE);
1174 SET(data->cancel, MUIA_Selected, FALSE);
1175 SET(data->cancel, MUIA_Disabled, TRUE);
1177 if (!MUI_RequestA(data->installer, data->window, 0,
1178 "Cancel Installation...", "*Continue Install|Cancel Install",
1179 cancelmessage, NULL))
1181 DoMethod(self, MUIM_IC_QuitInstall);
1183 else
1184 DoMethod(self, MUIM_IC_ContinueInstall);
1186 return 0;
1189 IPTR Install__MUIM_IC_ContinueInstall
1190 (Class * CLASS, Object * self, Msg message)
1192 struct Install_DATA *data = INST_DATA(CLASS, self);
1193 struct optionstmp *backupOptions = NULL;
1194 IPTR this_page = 0;
1196 backupOptions = data->instc_options_backup;
1198 GET(data->page, MUIA_Group_ActivePage, &this_page);
1200 if (!(BOOL) data->disable_back)
1201 SET(data->back, MUIA_Disabled, data->status_back);
1202 else
1203 SET(data->back, MUIA_Disabled, TRUE);
1204 SET(data->back, MUIA_Selected, FALSE);
1206 SET(data->proceed, MUIA_Disabled, data->status_proceed);
1207 SET(data->proceed, MUIA_Selected, FALSE);
1209 SET(data->cancel, MUIA_Disabled, data->status_cancel);
1210 SET(data->cancel, MUIA_Selected, FALSE);
1212 switch (this_page)
1214 case EInstallOptionsStage:
1215 SET(data->instc_options_main->opt_format, MUIA_Disabled,
1216 (BOOL) backupOptions->opt_format);
1217 SET(data->instc_options_main->opt_locale, MUIA_Disabled,
1218 (BOOL) backupOptions->opt_locale);
1219 SET(data->instc_options_main->opt_copycore, MUIA_Disabled,
1220 (BOOL) backupOptions->opt_copycore);
1221 SET(data->instc_options_main->opt_copyextra, MUIA_Disabled,
1222 (BOOL) backupOptions->opt_copyextra);
1223 SET(data->instc_options_main->opt_developer, MUIA_Disabled,
1224 (BOOL) backupOptions->opt_developer);
1225 SET(data->instc_options_main->opt_bootloader, MUIA_Disabled,
1226 (BOOL) backupOptions->opt_bootloader);
1227 SET(data->instc_options_main->opt_reboot, MUIA_Disabled,
1228 (BOOL) backupOptions->opt_reboot);
1229 break;
1231 case EDestOptionsStage:
1232 SET(dest_volume, MUIA_Disabled, FALSE);
1233 SET(check_work, MUIA_Disabled, FALSE);
1235 IPTR reenable = 0;
1236 GET(check_work, MUIA_Selected, &reenable);
1238 if (reenable)
1240 SET(check_copytowork, MUIA_Disabled, FALSE);
1241 SET(work_volume, MUIA_Disabled, FALSE);
1243 break;
1245 case EPartitionOptionsStage:
1246 SET(data->instc_options_main->opt_partmethod, MUIA_Disabled, FALSE);
1247 break;
1249 case EGrubOptionsStage:
1250 break;
1252 default:
1253 break;
1256 return 0;
1259 IPTR Install__MUIM_IC_QuitInstall(Class * CLASS, Object * self, Msg message)
1261 struct Install_DATA *data = INST_DATA(CLASS, self);
1263 if (data->inst_success == MUIV_Inst_InProgress)
1265 data->inst_success = MUIV_Inst_Cancelled;
1267 DoMethod(self, MUIM_Reboot);
1270 return 0;
1273 /* ****** FUNCTION IS CALLED BY THE PROCEDURE PROCESSOR
1275 IT LAUNCHES THE NECESSARY FUNCTION TO PERFORM WHATEVER IS BEING ASKED TO DO
1278 IPTR Install__MUIM_DispatchInstallProcedure
1279 (Class * CLASS, Object * self, Msg message)
1281 // struct Install_DATA* data = INST_DATA(CLASS, self);
1283 return 0;
1287 static LONG GetPartitionSize(BOOL get_work)
1289 LONG size = -1;
1290 IPTR tmp = 0;
1292 if (!get_work)
1294 if ((BOOL) XGET(check_sizesys, MUIA_Selected))
1296 GET(sys_size, MUIA_String_Integer, &tmp);
1297 size = (LONG) tmp;
1298 if (XGET(cycle_sysunits, MUIA_Cycle_Active) == 1)
1299 size *= 1024;
1302 else
1304 if ((BOOL) XGET(check_sizework, MUIA_Selected))
1306 GET(work_size, MUIA_String_Integer, &tmp);
1307 size = (LONG) tmp;
1308 if (XGET(cycle_workunits, MUIA_Cycle_Active) == 1)
1309 size *= 1024;
1313 return size;
1316 IPTR Install__MUIM_Partition(Class * CLASS, Object * self, Msg message)
1318 struct Install_DATA *data = INST_DATA(CLASS, self);
1319 IPTR option = FALSE;
1320 IPTR tmp = 0;
1322 if (data->inst_success == MUIV_Inst_InProgress)
1324 SET(data->back, MUIA_Disabled, TRUE);
1325 SET(data->proceed, MUIA_Disabled, TRUE);
1327 char tmpcmd[150], tmparg[100];
1328 GET(dest_device, MUIA_String_Contents, &tmp);
1329 GET(dest_unit, MUIA_String_Integer, &option);
1330 sprintf(tmpcmd, "C:Partition DEVICE=%s UNIT=%ld FORCE QUIET",
1331 (char *)tmp, option);
1333 /* Specify SYS size */
1334 GET(check_sizesys, MUIA_Selected, &option);
1335 if (option)
1337 tmp = GetPartitionSize(FALSE);
1338 sprintf(tmparg, " SYSSIZE=%ld", tmp);
1339 strcat(tmpcmd, tmparg);
1342 /* Specify SYS name */
1343 GET(sys_devname, MUIA_String_Contents, &tmp);
1344 sprintf(tmparg, " SYSNAME=\"%s\"", (char *)tmp);
1345 strcat(tmpcmd, tmparg);
1347 /* Specify SYS filesystem (defaults to FFSIntl) */
1348 get(cycle_fstypesys, MUIA_Cycle_Active, &tmp);
1349 if ((int)tmp == 1)
1350 strcat(tmpcmd, " SYSTYPE=SFS");
1351 else
1352 strcat(tmpcmd, " SYSTYPE=FFSIntl");
1354 /* Specify Work size */
1355 GET(check_creatework, MUIA_Selected, &option);
1356 if (option)
1358 GET(check_sizework, MUIA_Selected, &option);
1359 if (option)
1361 tmp = GetPartitionSize(TRUE);
1362 sprintf(tmparg, " WORKSIZE=%ld", tmp);
1363 strcat(tmpcmd, tmparg);
1365 else
1367 strcat(tmpcmd, " MAXWORK");
1370 /* Specify WORK filesystem (defaults to SFS) */
1371 get(cycle_fstypework, MUIA_Cycle_Active, &tmp);
1372 if ((int)tmp == 0)
1373 strcat(tmpcmd, " WORKTYPE=FFSIntl");
1374 else
1375 strcat(tmpcmd, " WORKTYPE=SFS");
1377 /* Specify WORK name */
1378 GET(work_devname, MUIA_String_Contents, &tmp);
1379 sprintf(tmparg, " WORKNAME=\"%s\"", (char *)tmp);
1380 strcat(tmpcmd, tmparg);
1383 /* Specify whether to wipe disk or not */
1384 GET(data->instc_options_main->opt_partmethod, MUIA_Radio_Active,
1385 &option);
1386 if (option == 1)
1388 D(bug("[INSTALLER] Partitioning EVERYTHING! MUAHAHAHA...\n"));
1389 strcat(tmpcmd, " WIPE");
1391 else
1392 D(bug("[INSTALLER] Partitioning Free Space...\n"));
1394 D(bug("[INSTALLER] ### Executing '%s'\n", &tmpcmd));
1395 tmp = SystemTagList(tmpcmd, NULL);
1397 SET(data->proceed, MUIA_Disabled, FALSE);
1400 return tmp;
1403 void create_environment_variable(CONST_STRPTR envarchiveDisk,
1404 CONST_STRPTR name, CONST_STRPTR value)
1406 BPTR env_variable_fh = NULL;
1407 TEXT env_variable_path[100];
1409 if ((envarchiveDisk == NULL) || (name == NULL) || (value == NULL))
1410 return;
1413 sprintf(env_variable_path, "%s:", envarchiveDisk);
1414 AddPart(env_variable_path, "Prefs/Env-Archive/", 100);
1415 AddPart(env_variable_path, name, 100);
1417 D(bug
1418 ("[INSTALLER] create_environment_variable: Setting Var '%s' to '%s'\n",
1419 env_variable_path, value));
1421 if ((env_variable_fh = Open(env_variable_path, MODE_NEWFILE)) != NULL)
1423 FPuts(env_variable_fh, value);
1424 Close(env_variable_fh);
1428 static BOOL read_environment_variable(CONST_STRPTR envarchiveDisk,
1429 CONST_STRPTR name, STRPTR buffer, ULONG size)
1431 BPTR env_variable_fh = NULL;
1432 TEXT env_variable_path[100];
1434 if ((envarchiveDisk == NULL) || (name == NULL) || (buffer == NULL))
1435 return FALSE;
1437 sprintf(env_variable_path, "%s:", envarchiveDisk);
1438 AddPart(env_variable_path, "Prefs/Env-Archive/", 100);
1439 AddPart(env_variable_path, name, 100);
1441 D(bug("[INSTALLER] read_environment_variable: Getting Var '%s'\n",
1442 env_variable_path));
1444 if ((env_variable_fh = Open(env_variable_path, MODE_OLDFILE)) != NULL)
1446 FGets(env_variable_fh, buffer, size);
1447 Close(env_variable_fh);
1448 return TRUE;
1450 return FALSE;
1453 LONG CountFiles(CONST_STRPTR directory, CONST_STRPTR fileMask,
1454 BOOL recursive)
1456 UBYTE *buffer = NULL;
1457 TEXT matchString[3 * strlen(fileMask)];
1458 BPTR dirLock = NULL;
1459 LONG fileCount = 0;
1461 D(bug("[INSTALLER.Count] Entry, directory: %s, mask: %s\n", directory,
1462 fileMask));
1464 /* Check if directory exists */
1465 dirLock = Lock(directory, SHARED_LOCK);
1467 if (dirLock == NULL)
1469 return -1;
1472 buffer = AllocVec(kExallBufSize, MEMF_CLEAR | MEMF_PUBLIC);
1474 if (buffer == NULL)
1476 UnLock(dirLock);
1477 return -1;
1480 if (ParsePatternNoCase(fileMask, matchString, 3 * strlen(fileMask)) < 0)
1482 UnLock(dirLock);
1483 FreeVec(buffer);
1484 return -1;
1487 struct ExAllData *ead = (struct ExAllData *)buffer;
1488 struct ExAllControl *eac = AllocDosObject(DOS_EXALLCONTROL, NULL);
1489 eac->eac_LastKey = 0;
1491 BOOL loop;
1492 struct ExAllData *oldEad = ead;
1496 ead = oldEad;
1497 loop = ExAll(dirLock, ead, kExallBufSize, ED_COMMENT, eac);
1499 if (!loop && IoErr() != ERROR_NO_MORE_ENTRIES)
1500 break;
1502 if (eac->eac_Entries != 0)
1506 if (ead->ed_Type == ST_FILE
1507 && MatchPatternNoCase(matchString, ead->ed_Name))
1508 fileCount++;
1510 if (ead->ed_Type == ST_USERDIR && recursive)
1512 LONG subFileCount = 0;
1513 ULONG subDirNameLen =
1514 strlen(directory) + strlen(ead->ed_Name) + 2;
1515 TEXT subDirName[subDirNameLen];
1517 sprintf(subDirName, "%s", directory);
1518 AddPart(subDirName, ead->ed_Name, subDirNameLen);
1520 subFileCount =
1521 CountFiles(subDirName, fileMask, recursive);
1523 if (subFileCount >= 0)
1524 fileCount += subFileCount;
1525 else
1527 /* Error at lower level */
1528 FreeDosObject(DOS_EXALLCONTROL, eac);
1529 UnLock(dirLock);
1530 FreeVec(buffer);
1531 return -1;
1534 ead = ead->ed_Next;
1536 while (ead != NULL);
1539 while (loop);
1541 FreeDosObject(DOS_EXALLCONTROL, eac);
1542 UnLock(dirLock);
1543 FreeVec(buffer);
1545 return fileCount;
1548 LONG InternalCopyFiles(Class * CLASS, Object * self, CONST_STRPTR srcDir,
1549 CONST_STRPTR dstDir, CONST_STRPTR fileMask, BOOL recursive,
1550 LONG totalFiles, LONG totalFilesCopied)
1552 struct Install_DATA *data = INST_DATA(CLASS, self);
1553 UBYTE *buffer = NULL;
1554 TEXT matchString[3 * strlen(fileMask)];
1555 BPTR srcDirLock = NULL, dstDirLock = NULL;
1556 LONG totalFilesCopiedThis = 0;
1558 /* Check entry condition */
1559 if (data->inst_success != MUIV_Inst_InProgress)
1560 return totalFilesCopied;
1562 /* Check if source directory exists */
1565 srcDirLock = Lock(srcDir, SHARED_LOCK);
1567 if (srcDirLock == NULL)
1569 ULONG retry =
1570 AskRetry(CLASS, self, "Could not find %s\nRetry?", srcDir,
1571 "Yes", "Skip", "Quit");
1572 switch (retry)
1574 case 0: /*retry */
1575 break;
1576 case 1: /* skip */
1577 return -1;
1578 default: /* quit */
1579 DoMethod(self, MUIM_IC_QuitInstall);
1580 return -1;
1584 while (srcDirLock == NULL);
1586 /* Check if destination directory exists and create it */
1587 dstDirLock = Lock(dstDir, SHARED_LOCK);
1589 if (dstDirLock != NULL)
1590 UnLock(dstDirLock);
1591 else
1593 dstDirLock = CreateDir(dstDir);
1594 if (dstDirLock != NULL)
1595 UnLock(dstDirLock);
1596 else
1598 UnLock(srcDirLock);
1599 return -1;
1603 /* Allocate buffer for ExAll */
1604 buffer = AllocVec(kExallBufSize, MEMF_CLEAR | MEMF_PUBLIC);
1606 if (buffer == NULL)
1608 UnLock(srcDirLock);
1609 return -1;
1612 if (ParsePatternNoCase(fileMask, matchString, 3 * strlen(fileMask)) < 0)
1614 UnLock(srcDirLock);
1615 FreeVec(buffer);
1616 return -1;
1619 struct ExAllData *ead = (struct ExAllData *)buffer;
1620 struct ExAllControl *eac = AllocDosObject(DOS_EXALLCONTROL, NULL);
1621 eac->eac_LastKey = 0;
1623 BOOL loop;
1624 struct ExAllData *oldEad = ead;
1627 /* Main copy file loop */
1630 ead = oldEad;
1631 loop = ExAll(srcDirLock, ead, kExallBufSize, ED_COMMENT, eac);
1633 if (!loop && IoErr() != ERROR_NO_MORE_ENTRIES)
1634 break;
1636 if (eac->eac_Entries != 0)
1640 if (((ead->ed_Type == ST_FILE)
1641 && MatchPatternNoCase(matchString, ead->ed_Name))
1642 || ((ead->ed_Type == ST_USERDIR) && recursive))
1644 ULONG srcLen = strlen(srcDir);
1645 ULONG dstLen = strlen(dstDir);
1646 ULONG newSrcLen = srcLen + strlen(ead->ed_Name) + 2;
1647 ULONG newDstLen = dstLen + strlen(ead->ed_Name) + 2;
1649 TEXT srcFile[newSrcLen];
1650 TEXT dstFile[newDstLen];
1652 sprintf(srcFile, "%s", srcDir);
1653 sprintf(dstFile, "%s", dstDir);
1655 AddPart(srcFile, ead->ed_Name, newSrcLen);
1656 AddPart(dstFile, ead->ed_Name, newDstLen);
1658 if (ead->ed_Type == ST_FILE)
1660 totalFilesCopiedThis +=
1661 (ULONG) DoMethod(self, MUIM_IC_CopyFile,
1662 srcFile, dstFile);
1664 if (totalFiles > 0)
1666 SET(data->gauge2, MUIA_Gauge_Current,
1667 (LONG) ((100.0 / totalFiles) *
1668 (totalFilesCopied +
1669 totalFilesCopiedThis)));
1673 if (ead->ed_Type == ST_USERDIR)
1676 LONG totalFilesCopiedSub =
1677 InternalCopyFiles(CLASS, self, srcFile, dstFile,
1678 fileMask,
1679 recursive, totalFiles,
1680 totalFilesCopied + totalFilesCopiedThis);
1681 if (totalFilesCopiedSub >= 0)
1682 totalFilesCopiedThis += totalFilesCopiedSub;
1683 else
1685 /* Do nothing. It will be caught at level of Install__MUIM_IC_CopyFiles */
1690 ead = ead->ed_Next;
1692 while ((ead != NULL)
1693 && (data->inst_success == MUIV_Inst_InProgress));
1696 while ((loop) && (data->inst_success == MUIV_Inst_InProgress));
1698 FreeDosObject(DOS_EXALLCONTROL, eac);
1699 UnLock(srcDirLock);
1700 FreeVec(buffer);
1702 return totalFilesCopiedThis;
1705 IPTR Install__MUIM_IC_CopyFiles
1706 (Class * CLASS, Object * self, struct MUIP_CopyFiles * message)
1708 struct Install_DATA *data = INST_DATA(CLASS, self);
1709 LONG totalFiles = -1, totalFilesCopied = 0;
1712 D(bug("[INSTALLER.CFs] Entry, src: %s, dst: %s, mask: %s\n",
1713 message->srcDir, message->dstDir, message->fileMask));
1715 /* Check entry condition */
1716 if (data->inst_success != MUIV_Inst_InProgress)
1718 D(bug("[INSTALLER.CFs] Installation failed\n"));
1719 return totalFilesCopied;
1722 SET(data->gauge2, MUIA_Gauge_Current, 0);
1724 /* Get file count */
1727 totalFiles =
1728 CountFiles(message->srcDir, message->fileMask,
1729 message->recursive);
1730 D(bug("[INSTALLER.CFs] Found %ld files in %s\n", totalFiles,
1731 message->srcDir));
1733 if (totalFiles < 0)
1735 ULONG retry =
1736 AskRetry(CLASS, self, "Error scanning %s\nRetry?",
1737 message->srcDir, "Yes", "Skip", "Quit");
1738 switch (retry)
1740 case 0: /* retry */
1741 break;
1742 case 1: /* skip */
1743 totalFiles = 0;
1744 break;
1745 default: /* quit */
1746 DoMethod(self, MUIM_IC_QuitInstall);
1747 return totalFilesCopied;
1751 while (totalFiles < 0);
1753 /* Copy files */
1754 totalFilesCopied =
1755 InternalCopyFiles(CLASS, self, message->srcDir, message->dstDir,
1756 message->fileMask, message->recursive, totalFiles,
1757 totalFilesCopied);
1759 /* Check final condition */
1760 if ((data->inst_success == MUIV_Inst_InProgress)
1761 && (totalFiles != totalFilesCopied))
1763 TEXT msg[strlen(KMsgNotAllFilesCopied) + strlen(message->srcDir) +
1765 sprintf(msg, KMsgNotAllFilesCopied, message->srcDir);
1767 if (MUI_RequestA(data->installer, data->window, 0, "Error",
1768 "Continue|*Quit", msg, NULL) != 1)
1769 DoMethod(self, MUIM_IC_QuitInstall);
1771 return totalFilesCopied;
1774 return totalFilesCopied;
1777 IPTR Install__MUIM_IC_Install(Class * CLASS, Object * self, Msg message)
1779 struct Install_DATA *data = INST_DATA(CLASS, self);
1780 BPTR lock = NULL;
1781 IPTR option = FALSE;
1783 GET(dest_volume, MUIA_String_Contents, &option);
1784 strcpy(dest_Path, (STRPTR) option);
1785 GET(work_volume, MUIA_String_Contents, &option);
1786 strcpy(work_Path, (STRPTR) option);
1788 SET(data->back, MUIA_Disabled, TRUE);
1789 SET(data->proceed, MUIA_Disabled, TRUE);
1791 SET(data->pagetitle, MUIA_Text_Contents, "Installing AROS...");
1793 /* set up destination Work name to use */
1795 GET(check_copytowork, MUIA_Selected, &option);
1796 if (option && (data->inst_success == MUIV_Inst_InProgress))
1797 extras_path = work_Path;
1798 else
1799 extras_path = dest_Path;
1801 /* STEP : FORMAT */
1803 GET(data->instc_options_main->opt_format, MUIA_Selected, &option);
1804 if (option && data->inst_success == MUIV_Inst_InProgress)
1806 GET(data->instc_options_main->opt_partmethod, MUIA_Radio_Active,
1807 &option);
1809 DoMethod(self, MUIM_Format);
1812 /* MAKE SURE THE WORK PART EXISTS TO PREVENT CRASHING! */
1814 if ((BOOL) XGET(check_work, MUIA_Selected))
1816 char tmp[100];
1817 sprintf(tmp, "%s:", work_Path);
1818 D(bug
1819 ("[INSTALLER] Install : Using a Work partition - checking validity..."));
1820 if ((lock = Lock(tmp, SHARED_LOCK))) /* check the dest dir exists */
1822 D(bug("OK!\n"));
1823 UnLock(lock);
1825 else
1827 D(bug
1828 ("FAILED!\n[INSTALLER] (Warning) INSTALL - Failed to locate chosen work partition '%s' : defaulting to sys only\n",
1829 work_Path));
1830 extras_path = dest_Path;
1832 lock = 0;
1834 else
1836 D(bug("[INSTALLER] Install: Using SYS partition only (%s)\n",
1837 dest_Path));
1840 DoMethod(data->installer, MUIM_Application_InputBuffered);
1842 /* STEP : LOCALE */
1844 GET(data->instc_options_main->opt_locale, MUIA_Selected, &option);
1845 if (option && (data->inst_success == MUIV_Inst_InProgress))
1847 D(bug("[INSTALLER] Launching Locale Prefs...\n"));
1849 ULONG srcLen = strlen(source_Path), dstLen =
1850 (strlen(dest_Path) + 1);
1851 ULONG envsrcLen = strlen(prefssrc_path), envdstLen =
1852 strlen(prefs_path);
1854 ULONG localeFileLen = srcLen + strlen(localeFile_path) + 3;
1855 ULONG inputFileLen = srcLen + strlen(inputFile_path) + 3;
1857 ULONG localePFileLen =
1858 dstLen + envdstLen + strlen(locale_prfs_file) + 4;
1860 ULONG inputPFileLen =
1861 dstLen + envdstLen + strlen(input_prfs_file) + 4;
1863 ULONG envdstdirLen = 1024;
1864 TEXT envDstDir[envdstdirLen]; /* "DH0:Prefs/Env-Archive/SYS" */
1866 TEXT localeFile[localeFileLen]; /* "CD0:Prefs/Locale" */
1867 TEXT localesrcPFile[localePFileLen]; /* "ENV:SYS/locale.prefs" */
1868 TEXT localePFile[localePFileLen]; /* "DH0:Prefs/Env-Archive/SYS/locale.prefs" */
1869 TEXT inputFile[inputFileLen]; /* "CD0:Prefs/Input" */
1870 TEXT inputsrcPFile[inputPFileLen]; /* "ENV:SYS/input.prefs" */
1871 TEXT inputPFile[inputPFileLen]; /* "DH0:Prefs/Env-Archive/SYS/input.prefs" */
1873 sprintf(envDstDir, "%s:", dest_Path);
1874 sprintf(localeFile, "\"%s", source_Path);
1875 CopyMem(prefssrc_path, localesrcPFile, envsrcLen + 1);
1876 sprintf(localePFile, "%s:", dest_Path);
1877 sprintf(inputFile, "\"%s", source_Path);
1878 CopyMem(prefssrc_path, inputsrcPFile, envsrcLen + 1);
1879 sprintf(inputPFile, "%s:", dest_Path);
1881 AddPart(localeFile, inputFile_path, localeFileLen);
1883 AddPart(localesrcPFile, locale_prfs_file, localePFileLen);
1885 AddPart(localePFile, prefs_path, localePFileLen);
1886 AddPart(localePFile, locale_prfs_file, localePFileLen);
1888 AddPart(inputFile, localeFile_path, inputFileLen);
1890 AddPart(inputsrcPFile, input_prfs_file, inputPFileLen);
1892 AddPart(inputPFile, prefs_path, inputPFileLen);
1893 AddPart(inputPFile, input_prfs_file, inputPFileLen);
1895 D(bug("[INSTALLER] Excecuting '%s'...\n", localeFile));
1897 Execute(localeFile, NULL, NULL);
1899 DoMethod(data->installer, MUIM_Application_InputBuffered);
1901 D(bug("[INSTALLER] Excecuting '%s'...\n", inputFile));
1903 Execute(inputFile, NULL, NULL);
1905 DoMethod(data->installer, MUIM_Application_InputBuffered);
1907 D(bug("[INSTALLER] Copying Locale Settings...\n"));
1909 //create the dirs "Prefs","Prefs/Env-Archive" and "Prefs/Env-Archive/SYS"
1910 AddPart(envDstDir, "Prefs", dstLen + envdstLen);
1911 D(bug("[INSTALLER] Create Dir '%s' \n", envDstDir));
1913 BPTR bootDirLock = NULL;
1915 if ((lock = Lock(envDstDir, ACCESS_READ)) != NULL)
1917 D(bug("[INSTALLER] Dir '%s' Exists - no nead to create\n",
1918 envDstDir));
1919 UnLock(lock);
1921 else
1923 bootDirLock = CreateDir(envDstDir);
1924 if (bootDirLock != NULL)
1925 UnLock(bootDirLock);
1926 else
1928 createdirfaild:
1929 D(bug("[INSTALLER] Failed to create %s dir!!\n",
1930 envDstDir));
1931 /* TODO: Should prompt on failure to try again/continue anyhow/exit */
1932 goto localecopydone;
1933 //data->inst_success = MUIV_Inst_Failed;
1934 //return 0;
1938 bootDirLock = NULL;
1939 lock = 0;
1941 AddPart(envDstDir, "Env-Archive", envdstdirLen);
1942 D(bug("[INSTALLER] Create Dir '%s' \n", envDstDir));
1943 if ((lock = Lock(envDstDir, ACCESS_READ)) != NULL)
1945 D(bug("[INSTALLER] Dir '%s' Exists - no nead to create\n",
1946 envDstDir));
1947 UnLock(lock);
1949 else
1951 bootDirLock = CreateDir(envDstDir);
1952 if (bootDirLock != NULL)
1953 UnLock(bootDirLock);
1954 else
1955 goto createdirfaild;
1958 bootDirLock = NULL;
1959 lock = 0;
1961 AddPart(envDstDir, "SYS", envdstdirLen);
1962 D(bug("[INSTALLER] Create Dir '%s' \n", envDstDir));
1963 if ((lock = Lock(envDstDir, ACCESS_READ)) != NULL)
1965 D(bug("[INSTALLER] Dir '%s' Exists - no nead to create\n",
1966 envDstDir));
1967 UnLock(lock);
1969 else
1971 bootDirLock = CreateDir(envDstDir);
1972 if (bootDirLock != NULL)
1973 UnLock(bootDirLock);
1974 else
1975 goto createdirfaild;
1978 bootDirLock = NULL;
1979 lock = 0;
1981 D(bug("[INSTALLER] Copying files\n"));
1983 if ((lock = Lock(localesrcPFile, ACCESS_READ)) != NULL)
1985 UnLock(lock);
1986 DoMethod(self, MUIM_IC_CopyFile, localesrcPFile, localePFile);
1989 bootDirLock = NULL;
1990 lock = 0;
1992 if ((lock = Lock(inputsrcPFile, ACCESS_READ)) != NULL)
1994 UnLock(lock);
1995 DoMethod(self, MUIM_IC_CopyFile, inputsrcPFile, inputPFile);
1997 localecopydone:
2001 DoMethod(data->installer, MUIM_Application_InputBuffered);
2003 /* STEP : COPY CORE */
2005 GET(data->instc_options_main->opt_copycore, MUIA_Selected, &option);
2006 if (option && (data->inst_success == MUIV_Inst_InProgress))
2008 TEXT tmp[100];
2009 BOOL success = FALSE;
2010 CONST_STRPTR core_dirs[] = {
2011 "boot", "boot",
2012 "C", "C",
2013 "Classes", "Classes",
2014 "Devs", "Devs",
2015 "Fonts", "Fonts",
2016 "L", "L",
2017 "Libs", "Libs",
2018 "Locale", "Locale",
2019 "Prefs", "Prefs",
2020 "Rexxc", "Rexxc",
2021 "S", "S",
2022 "Storage", "Storage",
2023 "System", "System",
2024 "Tools", "Tools",
2025 "Utilities", "Utilities",
2026 "WBStartup", "WBStartup",
2027 NULL
2029 ULONG dstLen = strlen(dest_Path) + strlen(AROS_BOOT_FILE) + 2;
2030 TEXT destinationPath[dstLen];
2032 /* Copying Core system Files */
2033 D(bug("[INSTALLER] Copying Core files...\n"));
2034 SET(data->label, MUIA_Text_Contents,
2035 "Copying Core System files...");
2036 sprintf(destinationPath, "%s:", dest_Path);
2037 CopyDirArray(CLASS, self, source_Path, destinationPath, core_dirs);
2039 /* Copy AROS.boot file */
2040 sprintf(tmp, "%s", source_Path);
2041 sprintf(destinationPath, "%s:" AROS_BOOT_FILE, dest_Path);
2042 AddPart(tmp, AROS_BOOT_FILE, 100);
2043 DoMethod(self, MUIM_IC_CopyFile, tmp, destinationPath);
2045 /* Make Env-Archive Writeable */
2046 sprintf(tmp, "Protect ADD FLAGS=W ALL QUIET %s:Prefs/Env-Archive",
2047 dest_Path);
2048 D(bug
2049 ("[INSTALLER] Changing Protection on Env Files (command='%s')\n",
2050 tmp));
2051 success = (BOOL) Execute(tmp, NULL, NULL);
2053 if (!success)
2055 D(bug
2056 ("[INSTALLER] Changing Protection on Env Files failed: %d\n",
2057 IoErr()));
2061 DoMethod(data->installer, MUIM_Application_InputBuffered);
2063 /* STEP : COPY EXTRAS */
2065 GET(data->instc_options_main->opt_copyextra, MUIA_Selected, &option);
2066 if (option && data->inst_success == MUIV_Inst_InProgress)
2068 CONST_STRPTR extras_dirs[] = {
2069 "Demos", "Demos",
2070 "Extras", "Extras",
2071 NULL
2074 TEXT extraspath[100];
2075 BOOL undoenabled = data->instc_copt_undoenabled;
2077 /* Explicitly disable undo. Some users might not have RAM for backup */
2078 data->instc_copt_undoenabled = FALSE;
2080 /* Copying Extras */
2081 D(bug("[INSTALLER] Copying Extras to '%s'...\n", extras_path));
2082 SET(data->label, MUIA_Text_Contents, "Copying Extra Software...");
2083 sprintf(extraspath, "%s:", extras_path);
2084 CopyDirArray(CLASS, self, extras_source, extraspath, extras_dirs);
2086 /* Set EXTRASPATH environment variable */
2087 AddPart(extraspath, "Extras", 100);
2088 create_environment_variable(dest_Path, "EXTRASPATH", extraspath);
2090 /* Restore undo state */
2091 data->instc_copt_undoenabled = undoenabled;
2094 DoMethod(data->installer, MUIM_Application_InputBuffered);
2096 /* STEP : COPY DEVELOPER FILES */
2098 GET(data->instc_options_main->opt_developer, MUIA_Selected, &option);
2099 if (option && (data->inst_success == MUIV_Inst_InProgress))
2101 ULONG srcLen = strlen(source_Path);
2102 ULONG developerDirLen = srcLen + strlen("Developer") + 2;
2103 TEXT developerDir[srcLen + developerDirLen];
2105 CopyMem(source_Path, &developerDir, srcLen + 1);
2106 AddPart(developerDir, "Developer", srcLen + developerDirLen);
2108 if ((lock = Lock(developerDir, SHARED_LOCK)) != NULL)
2110 CONST_STRPTR developer_dirs[] = {
2111 "Developer", "Developer",
2112 NULL
2114 TEXT developmentpath[100];
2115 BOOL undoenabled = data->instc_copt_undoenabled;
2117 /* Explicitly disable undo. Some users might not have RAM for backup */
2118 data->instc_copt_undoenabled = FALSE;
2120 UnLock(lock);
2122 /* Copying Developer stuff */
2123 D(bug("[INSTALLER] Copying Developer Files...\n"));
2124 SET(data->label, MUIA_Text_Contents,
2125 "Copying Developer Files...");
2126 sprintf(developmentpath, "%s:", extras_path);
2127 CopyDirArray(CLASS, self, source_Path, developmentpath,
2128 developer_dirs);
2130 /* Set DEVELPATH environment variable */
2131 AddPart(developmentpath, "Developer", 100);
2132 create_environment_variable(dest_Path, "DEVELPATH",
2133 developmentpath);
2135 /* Restore undo state */
2136 data->instc_copt_undoenabled = undoenabled;
2138 else
2139 D(bug("[INSTALLER] Couldn't locate Developer Files...\n"));
2142 if (!option && (data->inst_success == MUIV_Inst_InProgress))
2144 /* If not installing Development, delete the package file */
2145 TEXT packagePath[100];
2146 sprintf(packagePath, "%s:Prefs/Env-Archive/SYS/Packages/Developer",
2147 dest_Path);
2148 D(bug("[INSTALLER] Deleting Developer Package...\n"));
2149 DeleteFile(packagePath);
2152 DoMethod(data->installer, MUIM_Application_InputBuffered);
2154 /* STEP : INSTALL BOOTLOADER */
2156 GET(data->instc_options_main->opt_bootloader, MUIA_Selected, &option);
2157 if (option && (data->inst_success == MUIV_Inst_InProgress))
2159 int numgrubfiles = 0, file_count = 0;
2160 LONG part_no;
2161 ULONG srcLen =
2162 strlen(source_Path) + strlen(ARCH_PATH) + strlen(GRUB_PATH) + 4;
2163 ULONG dstLen =
2164 strlen(dest_Path) + strlen(ARCH_PATH) + strlen(GRUB_PATH) + 4;
2165 TEXT srcPath[srcLen];
2166 TEXT dstPath[dstLen];
2167 TEXT tmp[256];
2169 /* Installing GRUB */
2170 D(bug("[INSTALLER] Installing Grub...\n"));
2171 SET(data->label, MUIA_Text_Contents, "Installing Grub...");
2172 SET(data->pageheader, MUIA_Text_Contents, KMsgBootLoader);
2173 SET(data->label, MUIA_Text_Contents, "Copying BOOT files...");
2175 strcpy(srcPath, source_Path);
2176 AddPart(srcPath, ARCH_PATH, srcLen);
2177 sprintf(dstPath, "%s:%s", dest_Path, ARCH_PATH);
2179 /* Get drive chosen to install GRUB bootblock to */
2180 GET(grub_device, MUIA_String_Contents, &option);
2181 strcpy(boot_Device, (STRPTR) option);
2182 boot_Unit = XGET(grub_unit, MUIA_String_Integer);
2184 switch (BootLoaderType)
2186 case BOOTLOADER_GRUB2:
2187 AddPart(srcPath, GRUB_PATH, srcLen);
2188 AddPart(dstPath, GRUB_PATH, dstLen);
2190 /* Warning: do not modify srcPath or dstPath beyond this point */
2192 /* Grub 2 text/gfx mode */
2193 GET(data->instc_options_grub->gopt_grub2mode, MUIA_Cycle_Active,
2194 &option);
2196 /* Rename _unicode.pf2 <-> unicode.pf2 if necessary */
2198 ULONG newDstLen =
2199 strlen(dstPath) + strlen("_unicode.pf2") + 2;
2200 TEXT srcFile[newDstLen];
2201 TEXT dstFile[newDstLen];
2203 sprintf(srcFile, "%s", dstPath);
2204 sprintf(dstFile, "%s", dstPath);
2205 AddPart(srcFile, "_unicode.pf2", newDstLen);
2206 AddPart(dstFile, "unicode.pf2", newDstLen);
2208 if (option == 1 && !gfx_font_exists)
2209 Rename(srcFile, dstFile);
2210 else if (option == 0 && gfx_font_exists)
2211 Rename(dstFile, srcFile);
2214 /* Add entry to boot MS Windows if present */
2215 if ((part_no =
2216 FindWindowsPartition(boot_Device, boot_Unit)) != -1
2217 && XGET(cycle_drivetype, MUIA_Cycle_Active) != 2)
2219 sprintf(tmp, "%s", dstPath);
2220 AddPart(tmp, "grub.cfg", 256);
2222 BPTR menu_file = Open(tmp, MODE_READWRITE);
2224 if (menu_file != NULL)
2226 Seek(menu_file, 0, OFFSET_END);
2227 FPrintf(menu_file, "\nmenuentry \"Microsoft Windows\" {\n chainloader (hd%ld,%ld)+1\n}\n\n", 0, part_no + 1); /* GRUB2 counts partitions from 1 */
2228 Close(menu_file);
2230 D(bug
2231 ("[INSTALLER] Windows partition found. Adding Windows option to GRUB2 menu.\n"));
2234 sprintf(tmp,
2235 "C:Install-grub2 DEVICE \"%s\" UNIT %d GRUB \"%s\"",
2236 boot_Device, boot_Unit, dstPath);
2238 break;
2239 case BOOTLOADER_GRUB1:
2241 CreateDir(dstPath);
2243 numgrubfiles = 3;
2245 TEXT *grub_files[] = {
2246 "stage1", "stage1",
2247 "stage2_hdisk", "stage2",
2248 "menu.lst.DH0", "menu.lst",
2249 NULL
2252 GRUB_COPY_FILE_LOOP(grub_files);
2254 /* Add entry to boot MS Windows if present */
2255 if ((part_no =
2256 FindWindowsPartition(boot_Device, boot_Unit)) != -1)
2258 sprintf(tmp, "%s", dstPath);
2259 AddPart(tmp, "menu.lst", 256);
2261 BPTR menu_file = Open(tmp, MODE_READWRITE);
2262 if (menu_file != NULL)
2264 Seek(menu_file, 0, OFFSET_END);
2265 FPrintf(menu_file,
2266 "\ntitle Microsoft Windows\nrootnoverify (hd%ld,%ld)\nchainloader +1\n",
2267 0, part_no);
2268 Close(menu_file);
2270 D(bug
2271 ("[INSTALLER] Windows partition found. Adding Windows option to GRUB menu.\n"));
2274 sprintf(tmp,
2275 "C:Install-grub DEVICE \"%s\" UNIT %d GRUB \"%s\" FORCELBA",
2276 boot_Device, boot_Unit, dstPath);
2278 break;
2279 /* TODO: support more bootloaders */
2282 D(bug("[INSTALLER] execute: %s\n", tmp));
2283 Execute(tmp, NULL, NULL);
2284 SET(data->gauge2, MUIA_Gauge_Current, 100);
2287 SET(data->proceed, MUIA_Disabled, FALSE);
2289 /* STEP : PACKAGE CLEANUP */
2290 /* REMOVED - handled by DEVELPATH and EXTRASPATH variables */
2292 /* STEP : CREATE ENVIRONMENT VARIABLES THAT POINT TO INSTALLATION LOCATIONS */
2294 TEXT varval[255];
2295 IPTR optcheck = 0;
2297 /* Volume name of installed SYS */
2298 sprintf(varval, "%s:", dest_Path);
2299 SetVar("INSTALLEDSYS", varval, strlen(varval), GVF_GLOBAL_ONLY);
2301 /* Volume name of installed WORK */
2302 GET(check_work, MUIA_Selected, &optcheck);
2303 if (optcheck)
2305 sprintf(varval, "%s:", work_Path);
2306 SetVar("INSTALLEDWORK", varval, strlen(varval),
2307 GVF_GLOBAL_ONLY);
2309 else
2310 SetVar("INSTALLEDWORK", "", 0, GVF_GLOBAL_ONLY);
2312 /* Path to Extras */
2313 sprintf(varval, "%s:", extras_path);
2314 AddPart(varval, "Extras", 255);
2315 SetVar("INSTALLEDEXTRAS", varval, strlen(varval), GVF_GLOBAL_ONLY);
2319 /* STEP : EXECUTE EXTERNAL POST-INSTALL SCRIPT */
2320 if ((BOOL) XGET(data->instc_options_main->opt_copycore, MUIA_Selected))
2322 BPTR scriptfile = Open(POST_INSTALL_SCRIPT, MODE_OLDFILE);
2323 if (scriptfile)
2326 D(bug("[INSTALLER] Running post-install script...\n"));
2327 SET(data->label, MUIA_Text_Contents,
2328 "Running post-install script...");
2329 SET(data->pageheader, MUIA_Text_Contents, KMsgPostInstall);
2330 SET(data->gauge2, MUIA_Gauge_Current, 0);
2331 SET(data->actioncurrent, MUIA_Text_Contents,
2332 POST_INSTALL_SCRIPT);
2335 /* Post install script (at this momement) does not allow user interaction.
2336 Set SYS_Input to opened console and SYS_Background to FALSE to allow it. */
2338 struct TagItem tags[] = {
2339 {SYS_Input, (IPTR) NULL},
2340 {SYS_Output, (IPTR) NULL},
2341 {SYS_Error, (IPTR) NULL},
2342 {SYS_ScriptInput, (IPTR) scriptfile},
2343 {SYS_UserShell, TRUE},
2344 {TAG_DONE, 0}
2347 D(bug("[INSTALLER] execute: %s\n", POST_INSTALL_SCRIPT));
2349 SystemTagList("", tags);
2351 /* Do not close scriptfile. It was closed by SystemTagList */
2353 SET(data->gauge2, MUIA_Gauge_Current, 100);
2356 else
2357 bug("[INSTALLER] no post-install script\n"));
2360 /* STEP : UNDORECORD CLEANUP */
2362 D(bug
2363 ("[INSTALLER] Reached end of Install Function - cleaning up undo logs @ %p...\n",
2364 &data->instc_undorecord));
2366 struct InstallC_UndoRecord *CurUndoNode = NULL;
2367 struct Node *undonode_tmp = NULL;
2369 ForeachNodeSafe(&data->instc_undorecord, CurUndoNode, undonode_tmp)
2371 D(bug("[INSTALLER] Removing undo record @ %p\n", CurUndoNode));
2372 Remove((struct Node *)CurUndoNode);
2374 switch (CurUndoNode->undo_method)
2376 case MUIM_IC_CopyFile:
2377 D(bug("[INSTALLER] Deleting undo file '%s'\n",
2378 CurUndoNode->undo_src));
2379 DeleteFile(CurUndoNode->undo_src);
2381 FreeVec(CurUndoNode->undo_dst);
2382 FreeVec(CurUndoNode->undo_src);
2383 break;
2384 default:
2385 continue;
2387 FreeMem(CurUndoNode, sizeof(struct InstallC_UndoRecord));
2390 return 0;
2393 IPTR Install__MUIM_RefreshWindow(Class * CLASS, Object * self, Msg message)
2395 struct Install_DATA *data = INST_DATA(CLASS, self);
2396 ULONG cur_width = 0, cur_height = 0;
2398 GET(data->window, MUIA_Window_Width, &cur_width);
2399 GET(data->window, MUIA_Window_Height, &cur_height);
2401 if ((data->cur_width != cur_width) || (data->cur_height != cur_height))
2403 DoMethod(data->contents, MUIM_Hide);
2404 DoMethod(data->contents, MUIM_Layout);
2405 DoMethod(data->contents, MUIM_Show);
2407 else
2408 MUI_Redraw(data->contents, MADF_DRAWOBJECT);
2410 return 0;
2413 static LONG FindWindowsPartition(STRPTR device, LONG unit)
2415 IPTR active, id;
2416 struct PartitionType type;
2417 struct PartitionHandle *root, *partition;
2418 LONG partition_no = -1, i = 0;
2420 if ((root = OpenRootPartition(device, unit)) != NULL)
2422 if (OpenPartitionTable(root) == 0)
2424 /* Look for an active partition with a Windows FS */
2425 ForeachNode(&root->table->list, partition)
2427 GetPartitionAttrsTags
2428 (partition,
2429 PT_ACTIVE, (IPTR) & active,
2430 PT_TYPE, (IPTR) & type, TAG_DONE);
2431 id = type.id[0];
2432 if (active && (id == 0x7 || id == 0xb || id == 0xc))
2433 partition_no = i;
2434 i++;
2436 ClosePartitionTable(root);
2438 CloseRootPartition(root);
2441 return partition_no;
2445 LONG CopyDirArray(Class * CLASS, Object * self, CONST_STRPTR sourcePath,
2446 CONST_STRPTR destinationPath, CONST_STRPTR directories[])
2448 struct Install_DATA *data = INST_DATA(CLASS, self);
2449 LONG numdirs = 0, dir_count = 0;
2450 BPTR lock = 0;
2452 while (directories[numdirs] != NULL)
2453 numdirs++;
2455 numdirs = (numdirs - 1) / 2;
2457 D(bug("[INSTALLER.CDA] Copying %d Dirs...\n", numdirs));
2459 while ((directories[dir_count] != NULL)
2460 && (data->inst_success == MUIV_Inst_InProgress))
2462 ULONG newSrcLen =
2463 strlen(sourcePath) + strlen(directories[dir_count]) + 2;
2464 ULONG newDstLen =
2465 strlen(destinationPath) + strlen(directories[dir_count + 1]) +
2468 TEXT srcDirs[newSrcLen + strlen(".info")];
2469 TEXT dstDirs[newDstLen + strlen(".info")];
2471 sprintf(srcDirs, "%s", sourcePath);
2472 sprintf(dstDirs, "%s", destinationPath);
2473 AddPart(srcDirs, directories[dir_count], newSrcLen);
2474 AddPart(dstDirs, directories[dir_count + 1], newDstLen);
2476 SET(data->actioncurrent, MUIA_Text_Contents, strchr(srcDirs,
2477 ':') + 1);
2479 /* OK Now copy the contents */
2480 DoMethod(self, MUIM_IC_CopyFiles, srcDirs, dstDirs, "#?", TRUE);
2482 if (data->inst_success == MUIV_Inst_InProgress)
2484 /* Check if folder has an icon */
2485 CopyMem(".info", srcDirs + strlen(srcDirs),
2486 strlen(".info") + 1);
2487 CopyMem(".info", dstDirs + strlen(dstDirs),
2488 strlen(".info") + 1);
2489 /* If the icon already exists in the destination, don't overwrite it.
2490 It may contain snapshotted position and/or edited tooltypes.
2491 TODO: may be consider replacing icon's image here using icon.library ? */
2492 lock = Lock(dstDirs, SHARED_LOCK);
2493 if (!lock)
2495 UnLock(lock);
2496 if ((lock = Lock(srcDirs, SHARED_LOCK)) != NULL)
2498 UnLock(lock);
2499 DoMethod(self, MUIM_IC_CopyFile, srcDirs, dstDirs);
2504 /* Folder copied */
2505 dir_count += 2;
2508 return dir_count / 2; /* Return no. of copied dirs */
2511 BOOL FormatPartition(CONST_STRPTR device, CONST_STRPTR name, ULONG dostype)
2513 BOOL success = FALSE;
2515 if (Inhibit(device, DOSTRUE))
2517 success = Format(device, name, dostype);
2518 Inhibit(device, DOSFALSE);
2521 return success;
2524 IPTR Install__MUIM_Format(Class * CLASS, Object * self, Msg message)
2526 struct Install_DATA *data = INST_DATA(CLASS, self);
2527 char dev_nametmp[100];
2528 char vol_nametmp[100] = SYS_VOL_NAME;
2529 char fmt_nametmp[100];
2530 BOOL success = FALSE;
2531 IPTR option = FALSE;
2532 BPTR lock = NULL;
2533 char tmp[100];
2535 if ((BOOL) XGET(check_formatsys, MUIA_Selected))
2537 /* Format Vol0 */
2538 sprintf(fmt_nametmp, "Formatting '%s'...", dest_Path);
2539 D(bug("[INSTALLER] %s\n", fmt_nametmp));
2540 SET(data->label, MUIA_Text_Contents, fmt_nametmp);
2541 SET(data->gauge2, MUIA_Gauge_Current, 0);
2543 /* Change volume name if installing to a USB drive */
2544 GET(grub_device, MUIA_String_Contents, &option);
2545 if (strcmp((char *)option, "usbscsi.device") == 0)
2546 strcpy(vol_nametmp, USB_SYS_VOL_NAME);
2548 sprintf(dev_nametmp, "%s:", dest_Path);
2550 /* XXX HACK
2551 * If partition is FFS -> it will format it for FFS
2552 * If partition is SFS -> it will format it for SFS
2553 * Correct way of doing things: read type for DH0 and DH1, apply correct
2554 * type when formatting
2556 D(bug("[INSTALLER] (info) Using FormatPartition\n"));
2557 success =
2558 FormatPartition(dev_nametmp, vol_nametmp, ID_INTER_FFS_DISK);
2560 if (success)
2561 set(data->gauge2, MUIA_Gauge_Current, 100);
2564 GET(check_work, MUIA_Selected, &option);
2565 if (option && XGET(check_formatwork, MUIA_Selected))
2567 /* Format Vol1 */
2568 sprintf(fmt_nametmp, "Formatting '%s'...", work_Path);
2569 D(bug("[INSTALLER] %s\n", fmt_nametmp));
2570 SET(data->label, MUIA_Text_Contents, fmt_nametmp);
2572 SET(data->gauge2, MUIA_Gauge_Current, 0);
2574 /* Change volume name if installing to a USB drive */
2575 GET(grub_device, MUIA_String_Contents, &option);
2576 if (strcmp((char *)option, "usbscsi.device") == 0)
2577 strcpy(vol_nametmp, USB_WORK_VOL_NAME);
2578 else
2579 strcpy(vol_nametmp, WORK_VOL_NAME);
2581 sprintf(dev_nametmp, "%s:", work_Path);
2583 /* XXX HACK
2584 * If partition is FFS -> it will format it for FFS
2585 * If partition is SFS -> it will format it for SFS
2586 * Correct way of doing things: read type for DH0 and DH1, apply
2587 * correct type when formatting (ID_INTER_FFS_DISK or ID_SFS_BE_DISK)
2589 D(bug("[INSTALLER] (info) Using FormatPartition\n"));
2590 success =
2591 FormatPartition(dev_nametmp, vol_nametmp, ID_INTER_FFS_DISK);
2593 if (success)
2595 sprintf(tmp, "%s:", work_Path);
2596 SET(data->gauge2, MUIA_Gauge_Current, 100);
2597 lock = Lock(tmp, SHARED_LOCK); /* check the dest dir exists */
2598 if (lock == 0)
2600 D(bug
2601 ("[INSTALLER] (Warning) FORMAT: Failed for chosen work partition '%s' : defaulting to sys only\n",
2602 tmp));
2603 extras_path = dest_Path;
2605 else
2607 UnLock(lock);
2608 lock = 0;
2612 if (success)
2613 SET(data->gauge2, MUIA_Gauge_Current, 100);
2615 return success;
2618 BPTR RecursiveCreateDir(CONST_STRPTR dirpath)
2620 /* Will create directory even if top level directory does not exist */
2622 BPTR lock = NULL;
2623 ULONG lastdirseparator = 0;
2624 ULONG dirpathlen = strlen(dirpath);
2625 STRPTR tmpdirpath = AllocVec(dirpathlen + 2, MEMF_CLEAR | MEMF_PUBLIC);
2627 CopyMem(dirpath, tmpdirpath, dirpathlen);
2629 /* Recurvice directory creation */
2630 while (TRUE)
2632 if (lastdirseparator >= dirpathlen)
2633 break;
2635 for (; lastdirseparator < dirpathlen; lastdirseparator++)
2636 if (tmpdirpath[lastdirseparator] == '/')
2637 break;
2639 tmpdirpath[lastdirseparator] = '\0'; /* cut */
2641 /* Unlock any lock from previous interation. Last iteration lock will be returned. */
2642 if (lock != NULL)
2644 UnLock(lock);
2645 lock = NULL;
2648 /* Check if directory exists */
2649 lock = Lock(tmpdirpath, SHARED_LOCK);
2650 if (lock == NULL)
2652 lock = CreateDir(tmpdirpath);
2653 if (lock == NULL)
2654 break; /* Error with creation */
2657 tmpdirpath[lastdirseparator] = '/'; /* restore */
2658 lastdirseparator++;
2661 FreeVec(tmpdirpath);
2662 return lock;
2665 BOOL BackUpFile(CONST_STRPTR filepath, CONST_STRPTR backuppath,
2666 struct InstallC_UndoRecord * undorecord)
2668 ULONG filepathlen = strlen(filepath);
2669 ULONG backuppathlen = strlen(backuppath);
2670 ULONG i = 0;
2671 STRPTR tmp = NULL;
2672 STRPTR pathpart = NULL;
2673 BPTR lock = NULL, from = NULL, to = NULL;
2674 static TEXT buffer[kBufSize];
2675 BOOL err = FALSE;
2677 if (undorecord == NULL)
2678 return FALSE;
2680 undorecord->undo_src =
2681 AllocVec(filepathlen + backuppathlen + 3, MEMF_CLEAR | MEMF_PUBLIC);
2682 undorecord->undo_dst =
2683 AllocVec(filepathlen + 2, MEMF_CLEAR | MEMF_PUBLIC);
2685 /* Create backup file name */
2686 tmp = AllocVec(filepathlen + 2, MEMF_CLEAR | MEMF_PUBLIC);
2687 CopyMem(filepath, tmp, filepathlen);
2688 for (i = 0; i < filepathlen; i++)
2689 if (tmp[i] == ':')
2690 tmp[i] = '/'; /* Substitute : with / */
2691 sprintf(undorecord->undo_src, "%s/%s", backuppath, tmp);
2692 FreeVec(tmp);
2694 /* Create source file name */
2695 CopyMem(filepath, undorecord->undo_dst, filepathlen);
2697 /* Create backup file path */
2698 tmp =
2699 AllocVec(strlen(undorecord->undo_src) + 2,
2700 MEMF_CLEAR | MEMF_PUBLIC);
2701 CopyMem(undorecord->undo_src, tmp, strlen(undorecord->undo_src));
2702 pathpart = PathPart(tmp);
2703 if (pathpart == NULL)
2705 FreeVec(tmp);
2706 return FALSE;
2708 *pathpart = '\0'; /* 'cut' string at end of path */
2710 D(bug("[INSTALLER.CF] Backup '%s' @ '%s'\n", undorecord->undo_dst,
2711 undorecord->undo_src));
2713 undorecord->undo_method = MUIM_IC_CopyFile;
2715 /* Create backup directory */
2716 if ((lock = Lock(tmp, SHARED_LOCK)) != NULL)
2718 D(bug("[INSTALLER.CF] Dir '%s' Exists - no need to create\n", tmp));
2719 UnLock(lock);
2721 else
2723 lock = RecursiveCreateDir(tmp);
2724 if (lock != NULL)
2725 UnLock(lock);
2726 else
2728 D(bug("[INSTALLER.CF] Failed to create %s dir!!\n", tmp));
2729 FreeVec(tmp);
2730 return FALSE;
2734 FreeVec(tmp);
2736 /* Copy file */
2737 if ((from = Open(undorecord->undo_dst, MODE_OLDFILE)))
2739 if ((to = Open(undorecord->undo_src, MODE_NEWFILE)))
2741 LONG s = 0;
2745 if ((s = Read(from, buffer, kBufSize)) == -1)
2747 err = TRUE;
2748 break;
2751 if (Write(to, buffer, s) == -1)
2753 err = TRUE;
2754 break;
2758 while (s == kBufSize && !err);
2760 Close(to);
2763 Close(from);
2766 return !err;
2769 IPTR Install__MUIM_IC_CopyFile
2770 (Class * CLASS, Object * self, struct MUIP_CopyFile * message)
2772 struct Install_DATA *data = INST_DATA(CLASS, self);
2773 static TEXT buffer[kBufSize];
2774 struct InstallC_UndoRecord *undorecord = NULL;
2775 ULONG retry = 0;
2776 ULONG filescopied = 0;
2777 BPTR from = NULL, to = NULL;
2779 /* Display copied file name */
2780 SET(data->actioncurrent, MUIA_Text_Contents, strchr(message->srcFile,
2781 ':') + 1);
2783 DoMethod(data->installer, MUIM_Application_InputBuffered);
2785 /* Check if destination file exists */
2786 if ((to = Open(message->dstFile, MODE_OLDFILE)))
2788 /* File exists */
2789 ULONG l;
2791 Close(to);
2793 /* Do not overwrite existing icons and preferences.
2794 TODO: May be ask about it too? */
2795 l = strlen(message->dstFile);
2796 if ((l > 4) && (!stricmp(&message->dstFile[l - 5], ".info")))
2798 /* Count the file as copied because otherwise installer will warn that
2799 not everything was copied. */
2800 filescopied = 1;
2801 goto copy_skip;
2803 else if ((l > 5) && (!stricmp(&message->dstFile[l - 6], ".prefs")))
2805 filescopied = 1;
2806 goto copy_skip;
2808 else
2810 switch (data->IO_Always_overwrite)
2812 case IIO_Overwrite_Ask:
2813 retry =
2814 AskRetry(CLASS, self,
2815 "File Already Exists\nReplace %s?", message->dstFile,
2816 "Yes", "Yes [Always]", "No");
2817 switch (retry)
2819 case 0: /* Yes */
2820 goto copy_backup;
2821 case 1: /* Always */
2822 data->IO_Always_overwrite = IIO_Overwrite_Always;
2823 goto copy_backup;
2824 default: /* NO! */
2825 goto copy_skip;
2827 case IIO_Overwrite_Always:
2828 goto copy_backup;
2829 case IIO_Overwrite_Never:
2830 goto copy_skip;
2834 else
2835 goto copy_retry;
2837 copy_backup:
2839 /* if the user has requested - backup all replaced files */
2841 if (data->instc_copt_undoenabled)
2843 if ((undorecord =
2844 AllocMem(sizeof(struct InstallC_UndoRecord),
2845 MEMF_CLEAR | MEMF_PUBLIC)) == NULL)
2846 DoMethod(self, MUIM_IC_QuitInstall);
2848 if (!BackUpFile(message->dstFile, INSTALLAROS_TMP_PATH, undorecord))
2850 data->inst_success = MUIV_Inst_Failed;
2851 return 0;
2855 /* Main copy code */
2856 copy_retry:
2858 if ((from = Open(message->srcFile, MODE_OLDFILE)))
2860 if ((to = Open(message->dstFile, MODE_NEWFILE)))
2862 LONG s = 0;
2866 if ((s = Read(from, buffer, kBufSize)) == -1)
2868 D(bug("[INSTALLER.CF] Failed to read: %s [ioerr=%d]\n",
2869 message->srcFile, IoErr()));
2871 Close(to);
2872 Close(from);
2874 retry =
2875 AskRetry(CLASS, self, "Couldn't Open %s",
2876 message->srcFile, "Retry", "Skip", "Cancel");
2877 switch (retry)
2879 case 0: /* Retry */
2880 goto copy_retry;
2881 case 1: /*Skip */
2882 goto copy_skip;
2883 default:
2884 DoMethod(self, MUIM_IC_QuitInstall);
2885 goto copy_skip;
2889 DoMethod(data->installer, MUIM_Application_InputBuffered);
2891 if (Write(to, buffer, s) == -1)
2893 D(bug
2894 ("[INSTALLER.CF] Failed to write: %s [%d bytes, ioerr=%d]\n",
2895 message->dstFile, s, IoErr()));
2897 if (IoErr() == 103)
2898 retry =
2899 AskRetry(CLASS, self,
2900 "Couldn't Write to %s\nDisk Full!",
2901 message->dstFile, "Retry", "Skip", "Cancel");
2902 else
2903 retry =
2904 AskRetry(CLASS, self, "Couldn't Write to %s",
2905 message->dstFile, "Retry", "Skip", "Cancel");
2907 Close(to);
2908 Close(from);
2910 switch (retry)
2912 case 0: /* Retry */
2913 goto copy_retry;
2914 case 1: /*Skip */
2915 goto copy_skip;
2916 default:
2917 DoMethod(self, MUIM_IC_QuitInstall);
2918 goto copy_skip;
2922 while ((s == kBufSize)
2923 && (data->inst_success == MUIV_Inst_InProgress));
2925 if (data->inst_success == MUIV_Inst_InProgress)
2926 filescopied = 1;
2928 Close(to);
2930 else
2932 D(bug
2933 ("[INSTALLER.CF] Failed to open '%s' for writing [ioerr=%d]\n",
2934 message->dstFile, IoErr()));
2935 data->inst_success = MUIV_Inst_Failed;
2937 Close(from);
2939 copy_skip:
2940 /* Add the undo record */
2941 if (undorecord != NULL)
2943 if (filescopied > 0)
2945 D(bug
2946 ("[INSTALLER.CF] Adding undo record @ %x to undo list @ %x \n",
2947 undorecord, &data->instc_undorecord));
2948 AddHead(&data->instc_undorecord, (struct Node *)undorecord);
2950 else
2952 D(bug("[INSTALLER.CF] Freeing undo record\n"));
2953 /* remove the backup file */
2955 DeleteFile(undorecord->undo_src);
2957 /* remove the undo record */
2958 FreeVec(undorecord->undo_dst);
2959 FreeVec(undorecord->undo_src);
2960 FreeMem(undorecord, sizeof(struct InstallC_UndoRecord));
2964 else
2966 D(bug("[INSTALLER.CF] Failed to open: %s [ioerr=%d]\n",
2967 message->srcFile, IoErr()));
2968 data->inst_success = MUIV_Inst_Failed;
2971 return filescopied;
2974 IPTR Install__MUIM_IC_UndoSteps(Class * CLASS, Object * self, Msg message)
2976 struct Install_DATA *data = INST_DATA(CLASS, self);
2977 struct InstallC_UndoRecord *CurUndoNode = NULL;
2979 D(bug("[INSTALLER.US] Performing UNDO steps...\n"));
2981 /* Disbale "UNDO" mode to prevent new records */
2982 data->instc_copt_undoenabled = FALSE;
2984 ForeachNode(&data->instc_undorecord, CurUndoNode)
2986 D(bug("[INSTALLER.US] Removing undo record @ %x\n", CurUndoNode));
2987 Remove((struct Node *)CurUndoNode);
2989 switch (CurUndoNode->undo_method)
2991 case MUIM_IC_CopyFile:
2992 D(bug("[INSTALLER.US] Reverting file '%s'\n",
2993 CurUndoNode->undo_dst));
2995 DoMethod(self, CurUndoNode->undo_method, CurUndoNode->undo_src,
2996 CurUndoNode->undo_dst);
2998 D(bug("[INSTALLER.US] Deleting undo file '%s'\n",
2999 CurUndoNode->undo_src));
3000 DeleteFile(CurUndoNode->undo_src);
3002 FreeVec(CurUndoNode->undo_dst);
3003 FreeVec(CurUndoNode->undo_src);
3004 break;
3005 default:
3006 continue;
3008 FreeMem(CurUndoNode, sizeof(struct InstallC_UndoRecord));
3011 D(bug("[INSTALLER.US] UNDO complete\n"));
3013 return 0;
3016 IPTR Install__MUIM_Reboot(Class * CLASS, Object * self, Msg message)
3018 struct Install_DATA *data = INST_DATA(CLASS, self);
3020 IPTR option = FALSE;
3022 /* Make sure the user wants to reboot */
3023 GET(data->instc_options_main->opt_reboot, MUIA_Selected, &option);
3024 if (option && (data->inst_success == MUIV_Inst_InProgress))
3026 D(bug("[INSTALLER] Cold rebooting...\n"));
3027 ShutdownA(SD_ACTION_COLDREBOOT);
3029 else
3031 D(bug("[INSTALLER] Install Finished [no reboot]...\n"));
3032 if (data->inst_success == MUIV_Inst_InProgress)
3033 data->inst_success = MUIV_Inst_Completed;
3034 SET(data->window, MUIA_Window_CloseRequest, TRUE);
3037 return TRUE; /* Keep the compiler happy... */
3040 IPTR Install__OM_SET(Class * CLASS, Object * self, struct opSet * message)
3042 return DoSuperMethodA(CLASS, self, (Msg) message);
3045 BOOPSI_DISPATCHER(IPTR, Install_Dispatcher, CLASS, self, message)
3047 switch (message->MethodID)
3049 case OM_NEW:
3050 return Install__OM_NEW(CLASS, self, (struct opSet *)message);
3052 case OM_SET:
3053 return Install__OM_SET(CLASS, self, (struct opSet *)message);
3055 case MUIM_FindDrives:
3056 return Install__MUIM_FindDrives(CLASS, self, message);
3058 case MUIM_IC_NextStep:
3059 return Install__MUIM_IC_NextStep(CLASS, self, message);
3061 case MUIM_IC_PrevStep:
3062 return Install__MUIM_IC_PrevStep(CLASS, self, message);
3063 //cancel control methods
3064 case MUIM_IC_CancelInstall:
3065 return Install__MUIM_IC_CancelInstall(CLASS, self, message);
3067 case MUIM_IC_ContinueInstall:
3068 return Install__MUIM_IC_ContinueInstall(CLASS, self, message);
3070 case MUIM_IC_QuitInstall:
3071 return Install__MUIM_IC_QuitInstall(CLASS, self, message);
3073 case MUIM_Reboot:
3074 return Install__MUIM_Reboot(CLASS, self, message);
3076 //This should disappear
3077 case MUIM_RefreshWindow:
3078 return Install__MUIM_RefreshWindow(CLASS, self, message);
3080 case MUIM_IC_Install:
3081 return Install__MUIM_IC_Install(CLASS, self, message);
3083 //These will be consumed by the io task
3084 case MUIM_Partition:
3085 return Install__MUIM_Partition(CLASS, self, message);
3087 case MUIM_Format:
3088 return Install__MUIM_Format(CLASS, self, message);
3090 case MUIM_IC_CopyFiles:
3091 return Install__MUIM_IC_CopyFiles(CLASS, self,
3092 (struct MUIP_CopyFiles *)message);
3094 case MUIM_IC_CopyFile:
3095 return Install__MUIM_IC_CopyFile(CLASS, self,
3096 (struct MUIP_CopyFile *)message);
3098 case MUIM_IC_UndoSteps:
3099 return Install__MUIM_IC_UndoSteps(CLASS, self, message);
3101 default:
3102 return DoSuperMethodA(CLASS, self, message);
3105 return 0;
3107 BOOPSI_DISPATCHER_END
3109 void FindBootLoader(void)
3111 ULONG newSrcLen = strlen(source_Path) + BOOTLOADER_PATH_LEN;
3112 TEXT srcFile[newSrcLen];
3113 LONG i;
3114 BPTR lock;
3116 for (i = 0; BootLoaderFiles[i]; i++)
3118 strcpy(srcFile, source_Path);
3119 AddPart(srcFile, BootLoaderFiles[i], newSrcLen);
3120 lock = Lock(srcFile, ACCESS_READ);
3121 if (lock)
3123 UnLock(lock);
3124 BootLoaderType = i;
3125 return;
3128 BootLoaderType = BOOTLOADER_NONE;
3131 #define BUTTONCOMMON \
3132 ImageButtonFrame, \
3133 MUIA_CycleChain, 1, \
3134 MUIA_InputMode, MUIV_InputMode_Toggle, \
3135 MUIA_Image_Spec, MUII_CheckMark, \
3136 MUIA_Image_FreeVert, TRUE, \
3137 MUIA_Background, MUII_ButtonBack, \
3138 MUIA_ShowSelState, FALSE,
3140 int main(int argc, char *argv[])
3142 Object *wnd = NULL; /* installer window objects - will get swallowed into the class eventually */
3143 Object *wndcontents = NULL;
3144 Object *page = NULL;
3146 Object *welcomeMsg = NULL;
3147 Object *LicenseMsg = NULL;
3148 Object *doneMsg = NULL;
3150 Object *pagetitle = NULL;
3151 Object *pageheader = NULL;
3152 Object *currentaction = NULL;
3154 Object *radio_part = NULL;
3156 Object *gad_back = SimpleButton("<< _Back...");
3157 Object *gad_proceed = SimpleButton(KMsgProceed);
3158 Object *gad_cancel = SimpleButton("_Cancel");
3160 Object *grub_drive = NULL;
3161 Object *grub_grub = NULL;
3163 Object *LicenseMandGrp = NULL;
3164 Object *check_license = ImageObject, BUTTONCOMMON
3165 MUIA_Selected, FALSE,
3166 End;
3168 Object *check_format = ImageObject, BUTTONCOMMON
3169 MUIA_Selected, TRUE,
3170 End;
3172 Object *check_locale = ImageObject, BUTTONCOMMON
3173 MUIA_Selected, FALSE,
3174 End;
3176 Object *check_core = ImageObject, BUTTONCOMMON
3177 MUIA_Selected, TRUE,
3178 End;
3180 Object *check_dev = ImageObject, BUTTONCOMMON
3181 MUIA_Selected, FALSE,
3182 End;
3184 Object *check_extras = ImageObject, BUTTONCOMMON
3185 MUIA_Selected, TRUE,
3186 End;
3188 Object *check_bootloader;
3190 Object *check_reboot = ImageObject, BUTTONCOMMON
3191 End;
3193 Object *gauge1 =
3194 (GaugeObject, MUIA_Gauge_InfoText, "%ld %%", MUIA_Gauge_Horiz, TRUE,
3195 MUIA_Gauge_Current, 0, End);
3197 Object *gauge2 =
3198 (GaugeObject, MUIA_Gauge_InfoText, "%ld %%", MUIA_Gauge_Horiz, TRUE,
3199 MUIA_Gauge_Current, 0, End);
3201 Object *gauge3 =
3202 (GaugeObject, MUIA_Gauge_InfoText, "%ld %%", MUIA_Gauge_Horiz, TRUE,
3203 MUIA_Gauge_Current, 0, End);
3205 static char *opt_drivetypes[] = {
3206 "AHCI/SATA",
3207 "IDE",
3208 "USB",
3209 NULL
3212 Object *label = NULL;
3213 static char *opt_partentries[] = {
3214 "Only use free space",
3215 "Wipe disk",
3216 "Use existing AROS partitions (on any drive)",
3217 NULL
3219 struct Install_Options *install_opts = NULL;
3220 struct Grub_Options *grub_opts = NULL;
3221 char *source_path = NULL;
3222 char *dest_path = NULL;
3223 char *work_path = NULL;
3225 IPTR pathend = 0;
3227 check_copytowork = ImageObject, BUTTONCOMMON
3228 MUIA_Disabled, TRUE,
3229 End;
3231 check_work = ImageObject, BUTTONCOMMON
3232 MUIA_Selected, FALSE,
3233 End;
3235 check_formatsys = ImageObject, BUTTONCOMMON
3236 MUIA_Selected, TRUE,
3237 End;
3239 check_formatwork = ImageObject, BUTTONCOMMON
3240 MUIA_Disabled, TRUE,
3241 End;
3243 check_sizesys = ImageObject, BUTTONCOMMON
3244 MUIA_Selected, FALSE,
3245 End;
3247 check_sizework = ImageObject, BUTTONCOMMON
3248 MUIA_Selected, FALSE,
3249 MUIA_Disabled, TRUE,
3250 End;
3252 check_creatework = ImageObject, BUTTONCOMMON
3253 MUIA_Selected, FALSE,
3254 MUIA_Disabled, TRUE,
3255 End;
3257 static char *opt_fstypes[] = {
3258 "FFS-Intl",
3259 "SFS",
3260 NULL
3263 cycle_fstypework = CycleObject,
3264 MUIA_CycleChain, 1,
3265 MUIA_Cycle_Entries, opt_fstypes,
3266 MUIA_Disabled, TRUE,
3267 MUIA_Cycle_Active, 1,
3268 End;
3270 static char *opt_sizeunits[] = {
3271 "MB",
3272 "GB",
3273 NULL
3276 cycle_sysunits = CycleObject,
3277 MUIA_CycleChain, 1,
3278 MUIA_Cycle_Entries, opt_sizeunits,
3279 MUIA_Disabled, TRUE,
3280 MUIA_Cycle_Active, 1,
3281 End;
3283 cycle_workunits = CycleObject,
3284 MUIA_CycleChain, 1,
3285 MUIA_Cycle_Entries, opt_sizeunits,
3286 MUIA_Disabled, TRUE,
3287 MUIA_Cycle_Active, 1,
3288 End;
3290 static char *opt_grub2mode[] = {
3291 "Text",
3292 "Graphics",
3293 NULL
3296 Object *cycle_grub2mode = CycleObject,
3297 MUIA_CycleChain, 1,
3298 MUIA_Cycle_Entries, opt_grub2mode,
3299 MUIA_Disabled, FALSE,
3300 MUIA_Cycle_Active, 0,
3301 End;
3303 install_opts =
3304 AllocMem(sizeof(struct Install_Options), MEMF_CLEAR | MEMF_PUBLIC);
3306 grub_opts =
3307 AllocMem(sizeof(struct Grub_Options), MEMF_CLEAR | MEMF_PUBLIC);
3309 source_path = AllocVec(256, MEMF_CLEAR | MEMF_PUBLIC);
3310 extras_source = AllocVec(256, MEMF_CLEAR | MEMF_PUBLIC);
3312 dest_path = AllocVec(256, MEMF_CLEAR | MEMF_PUBLIC);
3313 work_path = AllocVec(256, MEMF_CLEAR | MEMF_PUBLIC);
3315 BPTR lock = 0;
3317 if (!(ExpansionBase =
3318 (struct ExpansionBase *)OpenLibrary("expansion.library", 0)))
3319 goto main_error;
3321 if (!NameFromLock(GetProgramDir(), source_path, 255))
3323 D(bug("[INST-APP] Couldn't get progdir\n"));
3324 goto main_error;
3326 pathend = (IPTR) FilePart(source_path);
3327 pathend = pathend - (IPTR) source_path;
3329 D(bug("[INST-APP] Path length = %d bytes\n", pathend));
3331 source_Path = AllocVec(pathend + 1, MEMF_CLEAR | MEMF_PUBLIC);
3332 CopyMem(source_path, source_Path, pathend);
3333 D(bug("[INST-APP] Launched from '%s'\n", source_Path));
3335 /* Let GRUB text/graphics choice default to same as on boot media */
3336 source_path[pathend] = '\0';
3337 AddPart(source_path, ARCH_PATH"/"GRUB_PATH"/unicode.pf2", 256);
3338 if ((lock = Lock(source_path, SHARED_LOCK)) != BNULL)
3340 gfx_font_exists = TRUE;
3341 SET(cycle_grub2mode, MUIA_Cycle_Active, 1);
3342 UnLock(lock);
3344 else
3345 gfx_font_exists = FALSE;
3347 FreeVec(source_path);
3349 /* Get source location for Extras dir */
3350 if (read_environment_variable(source_Path, "EXTRASPATH", extras_source,
3351 256))
3352 *PathPart(extras_source) = '\0';
3353 else
3354 strcpy(extras_source, source_Path);
3356 dest_Path = dest_path;
3357 sprintf(dest_Path, "" SYS_PART_NAME);
3359 work_Path = work_path;
3360 sprintf(work_Path, "" WORK_PART_NAME);
3362 FindBootLoader();
3363 cycle_fstypesys = CycleObject,
3364 MUIA_CycleChain, 1,
3365 MUIA_Cycle_Entries, opt_fstypes,
3366 MUIA_Disabled, FALSE,
3367 MUIA_Cycle_Active, BootLoaderType == BOOTLOADER_GRUB1 ? 0 : 1,
3368 End;
3370 check_bootloader = ImageObject, BUTTONCOMMON
3371 MUIA_Selected, BootLoaderType == BOOTLOADER_NONE ? FALSE : TRUE,
3372 MUIA_Disabled, BootLoaderType == BOOTLOADER_NONE ? TRUE : FALSE,
3373 End;
3375 lock = Lock(DEF_INSTALL_IMAGE, ACCESS_READ);
3376 UnLock(lock);
3378 LicenseMsg = MUI_NewObject(MUIC_TextEditor,
3379 MUIA_CycleChain, 1,
3380 MUIA_Background, MUII_SHINE,
3381 MUIA_TextEditor_ReadOnly, TRUE, TAG_DONE);
3383 if (!LicenseMsg)
3385 D(bug("[INST-APP] Failed to create LicenseMsg Object\n"));
3386 exit(5);
3389 Object *app = ApplicationObject,
3390 MUIA_Application_Title, (IPTR) "AROS Installer",
3391 MUIA_Application_Version, (IPTR) "$VER: InstallAROS 1.17 (05.12.2014)",
3392 MUIA_Application_Copyright, (IPTR) "Copyright © 2003-2014, The AROS Development Team. All rights reserved.",
3393 MUIA_Application_Author, (IPTR) "John \"Forgoil\" Gustafsson, Nick Andrews & Neil Cafferkey",
3394 MUIA_Application_Description, (IPTR) "Installs AROS on to a PC.",
3395 MUIA_Application_Base, (IPTR) "INSTALLER",
3397 SubWindow, (IPTR) (wnd = WindowObject,
3398 MUIA_Window_Title, (IPTR) "AROS Installer",
3399 MUIA_Window_ID, MAKE_ID('f','o','r','g'),
3400 MUIA_Window_SizeGadget, TRUE,
3401 WindowContents, (IPTR) (wndcontents = VGroup,
3403 Child, (IPTR) VGroup,
3404 Child, (IPTR) HGroup,
3405 Child, (IPTR) VGroup,
3406 MUIA_Background, MUII_SHADOW,
3408 Child, (IPTR) ImageObject,
3409 MUIA_Frame, MUIV_Frame_None,
3410 MUIA_Image_Spec, (IPTR) "3:"DEF_INSTALL_IMAGE,
3411 End,
3412 Child, (IPTR) HVSpace,
3413 End,
3415 Child, (IPTR) ScrollgroupObject,
3416 MUIA_Scrollgroup_FreeHoriz, FALSE,
3417 MUIA_Scrollgroup_FreeVert, TRUE,
3418 MUIA_Scrollgroup_Contents, (IPTR) (page = VGroup,
3419 MUIA_Group_PageMode, TRUE,
3420 ReadListFrame,
3422 /* each page represents an install time page... you must have one for each enumerated install progress page */
3424 Child, (IPTR) VGroup,
3425 Child, (IPTR) VGroup,
3426 Child, (IPTR) (welcomeMsg = FreeCLabel("")),
3427 Child, (IPTR) HVSpace,
3428 End,
3429 End,
3431 Child, (IPTR) VGroup,
3432 Child, (IPTR) VGroup,
3433 Child, (IPTR) LicenseMsg,
3434 Child, (IPTR) (LicenseMandGrp = HGroup,
3435 Child, (IPTR) HVSpace,
3436 Child, (IPTR) check_license,
3437 Child, (IPTR) LLabel("Accept License Agreement?"),
3438 Child, (IPTR) HVSpace,
3439 End),
3440 End,
3441 End,
3443 /* Partitioning options */
3444 Child, (IPTR) VGroup,
3445 Child, (IPTR) VGroup,
3446 Child, (IPTR) CLabel(KMsgPartitionOptions),
3447 Child, (IPTR) HVSpace,
3449 Child, (IPTR) HVSpace,
3450 Child, (IPTR) (radio_part = RadioObject,
3451 GroupFrame,
3452 MUIA_CycleChain, 1,
3453 MUIA_Radio_Entries, (IPTR) opt_partentries,
3454 End),
3456 Child, (IPTR) HVSpace,
3458 Child, (IPTR) LLabel(MUIX_B "Drive:" MUIX_N),
3459 Child, (IPTR) ColGroup(6),
3460 Child, (IPTR) LLabel("Type:"),
3461 Child, (IPTR) (cycle_drivetype =
3462 CycleObject,
3463 MUIA_CycleChain, 1,
3464 MUIA_Cycle_Entries, (IPTR) opt_drivetypes,
3465 MUIA_Cycle_Active, 0,
3466 End),
3467 Child, (IPTR) HVSpace,
3468 Child, (IPTR) LLabel("Device:"),
3469 Child, (IPTR) (dest_device =
3470 StringObject,
3471 MUIA_CycleChain, 1,
3472 MUIA_String_Contents, (IPTR) boot_Device,
3473 MUIA_String_Reject, " \"\'*",
3474 MUIA_Frame, MUIV_Frame_String,
3475 MUIA_HorizWeight, 300,
3476 End),
3477 Child, (IPTR) LLabel("Unit:"),
3478 Child, (IPTR) (dest_unit =
3479 StringObject,
3480 MUIA_CycleChain, 1,
3481 MUIA_String_Integer, 0,
3482 MUIA_String_Accept, "0123456789",
3483 MUIA_Frame, MUIV_Frame_String,
3484 MUIA_HorizWeight, 20,
3485 End),
3486 End,
3488 Child, (IPTR) HVSpace,
3490 Child, (IPTR) LLabel(KMsgDestPartition),
3491 Child, (IPTR) ColGroup(7),
3492 Child, (IPTR) LLabel("Name:"),
3493 Child, (IPTR) (sys_devname = StringObject,
3494 MUIA_CycleChain, 1,
3495 MUIA_String_Contents, SYS_PART_NAME,
3496 MUIA_Disabled, TRUE,
3497 MUIA_Frame, MUIV_Frame_String,
3498 End),
3499 Child, (IPTR) HVSpace,
3500 Child, (IPTR) HVSpace,
3501 Child, (IPTR) HVSpace,
3502 Child, (IPTR) HVSpace,
3503 Child, (IPTR) HVSpace,
3504 Child, (IPTR) LLabel("Filesystem:"),
3505 Child, (IPTR) cycle_fstypesys,
3506 Child, (IPTR) LLabel("Size:"),
3507 Child, (IPTR) (sys_size = StringObject,
3508 MUIA_CycleChain, 1,
3509 MUIA_String_Accept, "0123456789",
3510 MUIA_String_Integer, 0,
3511 MUIA_Disabled, TRUE,
3512 MUIA_Frame, MUIV_Frame_String,
3513 End),
3514 Child, (IPTR) cycle_sysunits,
3515 Child, (IPTR) check_sizesys,
3516 Child, (IPTR) LLabel("Specify Size"),
3517 End,
3519 Child, (IPTR) HVSpace,
3521 Child, (IPTR) LLabel(KMsgWorkPartition),
3522 Child, (IPTR) ColGroup(7),
3523 Child, (IPTR) LLabel("Name:"),
3524 Child, (IPTR) (work_devname = StringObject,
3525 MUIA_CycleChain, 1,
3526 MUIA_String_Contents, WORK_PART_NAME,
3527 MUIA_Disabled, TRUE,
3528 MUIA_Frame, MUIV_Frame_String,
3529 End),
3530 Child, (IPTR) HVSpace,
3531 Child, (IPTR) HVSpace,
3532 Child, (IPTR) HVSpace,
3533 Child, (IPTR) check_creatework,
3534 Child, (IPTR) LLabel("Create"),
3535 Child, (IPTR) LLabel("Filesystem:"),
3536 Child, (IPTR) cycle_fstypework,
3537 Child, (IPTR) LLabel("Size:"),
3538 Child, (IPTR) (work_size = StringObject,
3539 MUIA_CycleChain, 1,
3540 MUIA_String_Accept, "0123456789",
3541 MUIA_String_Integer, 0,
3542 MUIA_Disabled, TRUE,
3543 MUIA_Frame, MUIV_Frame_String,
3544 End),
3545 Child, (IPTR) cycle_workunits,
3546 Child, (IPTR) check_sizework,
3547 Child, (IPTR) LLabel("Specify Size"),
3548 End,
3549 End,
3550 End,
3552 Child, (IPTR) VGroup,
3553 Child, (IPTR) VGroup,
3554 Child, (IPTR) CLabel(KMsgInstallOptions),
3555 Child, (IPTR) HVSpace,
3556 Child, (IPTR) ColGroup(2),
3557 Child, (IPTR) check_locale,
3558 Child, (IPTR) LLabel("Choose Language Options"),
3559 Child, (IPTR) check_core,
3560 Child, (IPTR) LLabel("Install AROS Core System"),
3561 Child, (IPTR) check_extras,
3562 Child, (IPTR) LLabel("Install Extra Software"),
3563 Child, (IPTR) check_dev,
3564 Child, (IPTR) LLabel("Install Debugging tools and Developer Software"),
3565 Child, (IPTR) check_bootloader,
3566 Child, (IPTR) LLabel("Install Bootloader"),
3567 End,
3568 Child, (IPTR) HVSpace,
3569 End,
3570 End,
3572 Child, (IPTR) VGroup,
3573 Child, (IPTR) VGroup,
3574 Child, (IPTR) CLabel(KMsgDestOptions),
3575 Child, (IPTR) HVSpace,
3576 Child, (IPTR) ColGroup(2),
3577 Child, (IPTR) ColGroup(2),
3578 Child, (IPTR) LLabel(KMsgDestVolume),
3579 Child, (IPTR) HVSpace,
3580 End,
3581 Child, (IPTR) (show_formatsys = ColGroup(2),
3582 Child, (IPTR) check_formatsys,
3583 Child, (IPTR) LLabel("Format Partition"),
3584 End),
3585 End,
3586 Child, (IPTR) HVSpace,
3587 Child, (IPTR) (dest_volume = StringObject,
3588 MUIA_CycleChain, 1,
3589 MUIA_String_Contents, (IPTR) dest_Path,
3590 MUIA_Frame, MUIV_Frame_String,
3591 End),
3592 Child, (IPTR) HVSpace,
3593 Child, (IPTR) ColGroup(2),
3594 Child, (IPTR) check_work,
3595 Child, (IPTR) LLabel("Use 'Work' Partition"),
3596 Child, (IPTR) check_copytowork,
3597 Child, (IPTR) LLabel("Use 'Work' Partition for Extras and Developer Files"),
3598 End,
3599 Child, (IPTR) HVSpace,
3601 Child, (IPTR) ColGroup(2),
3602 Child, (IPTR) ColGroup(2),
3603 Child, (IPTR) LLabel(KMsgWorkVolume),
3604 Child, (IPTR) HVSpace,
3605 End,
3606 Child, (IPTR) (show_formatwork = ColGroup(2),
3607 Child, (IPTR) check_formatwork,
3608 Child, (IPTR) LLabel("Format Partition"),
3609 End),
3610 End,
3611 Child, (IPTR) HVSpace,
3612 Child, (IPTR) (work_volume = StringObject,
3613 MUIA_CycleChain, 1,
3614 MUIA_String_Contents,
3615 (IPTR) work_Path,
3616 MUIA_Disabled, TRUE,
3617 MUIA_Frame, MUIV_Frame_String,
3618 End),
3619 Child, (IPTR) HVSpace,
3620 End,
3621 End,
3623 /* Bootloader options */
3624 Child, (IPTR) VGroup,
3625 Child, (IPTR) VGroup,
3626 Child, (IPTR) CLabel(KMsgGrubOptions),
3627 Child, (IPTR) HVSpace,
3628 Child, (IPTR) LLabel(KMsgGrubGOptions),
3629 Child, (IPTR) LLabel(KMsgGrubDrive),
3630 Child, (IPTR) HVSpace,
3632 Child, (IPTR) ColGroup(5),
3633 Child, (IPTR) HVSpace,
3634 Child, (IPTR) LLabel("Device:"),
3635 Child, (IPTR) (grub_device = StringObject,
3636 MUIA_CycleChain, 1,
3637 MUIA_String_Reject, " \"\'*",
3638 MUIA_Frame, MUIV_Frame_String,
3639 MUIA_HorizWeight, 200,
3640 End),
3641 Child, (IPTR) HVSpace,
3642 Child, (IPTR) LLabel("Unit:"),
3643 Child, (IPTR) (grub_unit = StringObject,
3644 MUIA_CycleChain, 1,
3645 MUIA_String_Integer, 0,
3646 MUIA_String_Accept, "0123456789",
3647 MUIA_Frame, MUIV_Frame_String,
3648 MUIA_HorizWeight, 20,
3649 End),
3650 End,
3652 Child, (IPTR) (grub_drive = TextObject,
3653 MUIA_Text_PreParse, (IPTR) "" MUIX_C,
3654 MUIA_Text_Contents, (IPTR)" ",
3655 End),
3656 Child, (IPTR) HVSpace,
3657 Child, (IPTR) LLabel(KMsgGrubGrub),
3658 Child, (IPTR) HVSpace,
3659 Child, (IPTR) (grub_grub = TextObject,
3660 MUIA_Text_PreParse, (IPTR) "" MUIX_C,
3661 MUIA_Text_Contents, (IPTR)" ",
3662 End),
3663 Child, (IPTR) HVSpace,
3664 Child, (IPTR) ColGroup(4),
3665 Child, (IPTR) LLabel("Menu Mode:"),
3666 Child, (IPTR) cycle_grub2mode,
3667 Child, (IPTR) HVSpace,
3668 End,
3669 Child, (IPTR) HVSpace,
3670 End,
3671 End,
3673 Child, (IPTR) VGroup,
3674 Child, (IPTR) VGroup,
3675 Child, (IPTR) CLabel(KMsgPartitioning),
3676 Child, (IPTR) HVSpace,
3677 Child, (IPTR) VGroup,
3678 GaugeFrame,
3679 MUIA_Background, MUII_HSHINEBACK,
3680 Child, gauge1,
3681 End,
3682 Child, (IPTR) ScaleObject, End,
3683 Child, (IPTR) HVSpace,
3684 End,
3685 End,
3687 Child, (IPTR) VGroup,
3688 Child, (IPTR) VGroup,
3689 Child, (IPTR) CLabel(KMsgPartitioning),
3690 Child, (IPTR) HVSpace,
3691 Child, (IPTR) VGroup,
3692 GaugeFrame,
3693 MUIA_Background, MUII_HSHINEBACK,
3694 Child, (IPTR) gauge3,
3695 End,
3696 Child, (IPTR) ScaleObject, End,
3697 Child, (IPTR) HVSpace,
3698 End,
3699 End,
3701 Child, (IPTR) VGroup,
3702 Child, (IPTR) VGroup,
3703 Child, (IPTR) (pagetitle = CLabel(" ")),
3704 Child, (IPTR) HVSpace,
3705 Child, (IPTR) (pageheader = FreeCLabel(KMsgInstall)),
3706 Child, (IPTR) HVSpace,
3707 Child, (IPTR) (label = FreeLLabel("YOU SHOULD NOT SEE THIS")),
3708 Child, (IPTR) HVSpace,
3709 Child, (IPTR) (currentaction = TextObject,
3710 MUIA_Text_Contents,(IPTR)" ",
3711 End),
3712 Child, (IPTR) VGroup,
3713 GaugeFrame,
3714 MUIA_Background, MUII_HSHINEBACK,
3715 Child, gauge2,
3716 End,
3717 Child, (IPTR) HVSpace,
3718 End,
3719 End,
3721 /* Completed page */
3722 Child, (IPTR) VGroup,
3723 Child, (IPTR) VGroup,
3724 MUIA_Group_SameHeight, FALSE,
3725 Child, (IPTR) (doneMsg = FreeCLabel(KMsgDone)),
3726 Child, (IPTR) HVSpace,
3727 Child, (IPTR) (reboot_group = ColGroup(2),
3728 MUIA_Weight,0,
3729 MUIA_ShowMe, FALSE,
3730 Child, (IPTR) check_reboot,
3731 Child, (IPTR) LLabel("Reboot AROS now"),
3732 End),
3733 End,
3734 End,
3735 End),
3736 End,
3737 End,
3738 End,
3740 Child, (IPTR) HGroup,
3741 Child, (IPTR) HVSpace,
3742 Child, (IPTR) gad_back,
3743 Child, (IPTR) gad_proceed,
3744 Child, (IPTR) gad_cancel,
3745 End,
3746 End),
3747 End),
3749 End;
3751 if (!app)
3753 D(bug("[INST-APP] Failed to create Installer GUI\n"));
3754 exit(5);
3757 /* Update GUI in response to certain user actions */
3759 /* Notifications on partitioning action */
3760 DoMethod(radio_part, MUIM_Notify, (IPTR) MUIA_Radio_Active, 0,
3761 (IPTR) check_sizesys, 3, MUIM_Set, MUIA_Disabled, FALSE);
3762 DoMethod(radio_part, MUIM_Notify, (IPTR) MUIA_Radio_Active, 1,
3763 (IPTR) check_sizesys, 3, MUIM_Set, MUIA_Disabled, FALSE);
3764 DoMethod(radio_part, MUIM_Notify, (IPTR) MUIA_Radio_Active, 2,
3765 (IPTR) check_sizesys, 3, MUIM_Set, MUIA_Disabled, TRUE);
3766 DoMethod(radio_part, MUIM_Notify, (IPTR) MUIA_Radio_Active, 2,
3767 (IPTR) check_sizesys, 3, MUIM_Set, MUIA_Selected, FALSE);
3769 /* Notifications upon selection of drive type */
3770 DoMethod(cycle_drivetype, MUIM_Notify, (IPTR) MUIA_Cycle_Active, 0,
3771 (IPTR) dest_device, 3, MUIM_Set,
3772 MUIA_String_Contents, "ahci.device");
3773 DoMethod(cycle_drivetype, MUIM_Notify, (IPTR) MUIA_Cycle_Active, 1,
3774 (IPTR) dest_device, 3, MUIM_Set,
3775 MUIA_String_Contents, "ata.device");
3776 DoMethod(cycle_drivetype, MUIM_Notify, (IPTR) MUIA_Cycle_Active, 2,
3777 (IPTR) dest_device, 3, MUIM_Set,
3778 MUIA_String_Contents, "usbscsi.device");
3779 DoMethod(cycle_drivetype, MUIM_Notify, MUIA_Cycle_Active,
3780 MUIV_EveryTime, (IPTR) dest_unit, 3, MUIM_Set, MUIA_String_Integer,
3782 DoMethod(cycle_drivetype, MUIM_Notify, (IPTR) MUIA_Cycle_Active, 0,
3783 (IPTR) sys_devname, 3, MUIM_Set, MUIA_String_Contents,
3784 SYS_PART_NAME);
3785 DoMethod(cycle_drivetype, MUIM_Notify, (IPTR) MUIA_Cycle_Active, 1,
3786 (IPTR) sys_devname, 3, MUIM_Set, MUIA_String_Contents,
3787 SYS_PART_NAME);
3788 DoMethod(cycle_drivetype, MUIM_Notify, (IPTR) MUIA_Cycle_Active, 2,
3789 (IPTR) sys_devname, 3, MUIM_Set, MUIA_String_Contents,
3790 USB_SYS_PART_NAME);
3791 DoMethod(cycle_drivetype, MUIM_Notify, (IPTR) MUIA_Cycle_Active, 0,
3792 (IPTR) work_devname, 3, MUIM_Set, MUIA_String_Contents,
3793 WORK_PART_NAME);
3794 DoMethod(cycle_drivetype, MUIM_Notify, (IPTR) MUIA_Cycle_Active, 1,
3795 (IPTR) work_devname, 3, MUIM_Set, MUIA_String_Contents,
3796 WORK_PART_NAME);
3797 DoMethod(cycle_drivetype, MUIM_Notify, (IPTR) MUIA_Cycle_Active, 2,
3798 (IPTR) work_devname, 3, MUIM_Set, MUIA_String_Contents,
3799 USB_WORK_PART_NAME);
3801 /* Notifications on change of enable status of 'enter size of sys volume'
3802 * (this tells us if we are using existing partitions) */
3803 DoMethod(check_sizesys, MUIM_Notify, MUIA_Disabled, MUIV_EveryTime,
3804 (IPTR) sys_devname, 3, MUIM_Set, MUIA_Disabled, MUIV_TriggerValue);
3805 DoMethod(check_sizesys, MUIM_Notify, MUIA_Disabled, MUIV_EveryTime,
3806 (IPTR) cycle_drivetype, 3, MUIM_Set,
3807 MUIA_Disabled, MUIV_TriggerValue);
3808 DoMethod(check_sizesys, MUIM_Notify, MUIA_Disabled, MUIV_EveryTime,
3809 (IPTR) dest_device, 3, MUIM_Set, MUIA_Disabled, MUIV_TriggerValue);
3810 DoMethod(check_sizesys, MUIM_Notify, MUIA_Disabled, MUIV_EveryTime,
3811 (IPTR) dest_unit, 3, MUIM_Set, MUIA_Disabled, MUIV_TriggerValue);
3812 DoMethod(check_sizesys, MUIM_Notify, MUIA_Disabled, MUIV_EveryTime,
3813 (IPTR) cycle_fstypesys, 3, MUIM_Set,
3814 MUIA_Disabled, MUIV_TriggerValue);
3816 /* Notifications on change of selected status of 'enter size of sys volume' */
3817 DoMethod(check_sizesys, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
3818 (IPTR) check_creatework, 3, MUIM_Set,
3819 MUIA_Disabled, MUIV_NotTriggerValue);
3820 DoMethod(check_sizesys, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
3821 (IPTR) sys_size, 3, MUIM_Set, MUIA_Disabled, MUIV_NotTriggerValue);
3822 DoMethod(check_sizesys, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
3823 (IPTR) cycle_sysunits, 3, MUIM_Set,
3824 MUIA_Disabled, MUIV_NotTriggerValue);
3825 DoMethod(check_sizesys, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
3826 (IPTR) check_creatework, 3, MUIM_Set, MUIA_Selected, FALSE);
3828 /* Notifications on change of selected status of 'create work volume' */
3829 DoMethod(check_creatework, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
3830 (IPTR) work_devname, 3, MUIM_Set,
3831 MUIA_Disabled, MUIV_NotTriggerValue);
3832 DoMethod(check_creatework, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
3833 (IPTR) check_sizework, 3, MUIM_Set,
3834 MUIA_Disabled, MUIV_NotTriggerValue);
3835 DoMethod(check_creatework, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
3836 (IPTR) cycle_fstypework, 3, MUIM_Set,
3837 MUIA_Disabled, MUIV_NotTriggerValue);
3838 DoMethod(check_creatework, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
3839 (IPTR) check_sizework, 3, MUIM_Set, MUIA_Selected, FALSE);
3841 /* Notifications on change of selected status of 'enter size of work volume' */
3842 DoMethod(check_sizework, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
3843 (IPTR) work_size, 3, MUIM_Set, MUIA_Disabled, MUIV_NotTriggerValue);
3844 DoMethod(check_sizework, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
3845 (IPTR) cycle_workunits, 3, MUIM_Set,
3846 MUIA_Disabled, MUIV_NotTriggerValue);
3848 #if 0 /* Notification doesn't seem to work on String gadgets */
3849 DoMethod(dest_volume, MUIM_Notify, MUIA_String_Contents, MUIV_EveryTime,
3850 (IPTR) dest_volume, 3, MUIM_WriteString,
3851 MUIV_TriggerValue, dest_Path);
3852 #endif
3853 /* Notifications on installing bootloader */
3854 DoMethod(check_bootloader, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
3855 (IPTR) cycle_grub2mode, 3, MUIM_Set,
3856 MUIA_Disabled, MUIV_NotTriggerValue);
3858 DoMethod(check_core, MUIM_Notify, MUIA_Selected, FALSE,
3859 (IPTR) check_formatsys, 3, MUIM_Set, MUIA_Selected, FALSE);
3860 DoMethod(check_work, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
3861 (IPTR) check_copytowork, 3, MUIM_Set,
3862 MUIA_Disabled, MUIV_NotTriggerValue);
3863 DoMethod(check_work, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
3864 (IPTR) check_copytowork, 3, MUIM_Set, MUIA_Selected, FALSE);
3865 DoMethod(check_work, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
3866 (IPTR) check_formatwork, 3, MUIM_Set,
3867 MUIA_Disabled, MUIV_NotTriggerValue);
3868 DoMethod(check_work, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
3869 (IPTR) check_formatwork, 3, MUIM_Set, MUIA_Selected, FALSE);
3870 DoMethod(check_work, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
3871 (IPTR) work_volume, 3, MUIM_Set,
3872 MUIA_Disabled, MUIV_NotTriggerValue);
3874 install_opts->opt_license = check_license;
3875 install_opts->opt_lic_box = LicenseMsg;
3876 install_opts->opt_lic_mgrp = LicenseMandGrp;
3878 install_opts->opt_partmethod = radio_part;
3880 install_opts->opt_format = check_format;
3881 install_opts->opt_locale = check_locale;
3882 install_opts->opt_copycore = check_core;
3883 install_opts->opt_copyextra = check_extras;
3884 install_opts->opt_developer = check_dev;
3885 install_opts->opt_bootloader = check_bootloader;
3887 install_opts->opt_reboot = check_reboot;
3889 grub_opts->gopt_drive = grub_drive;
3890 grub_opts->gopt_grub = grub_grub;
3891 grub_opts->gopt_grub2mode = cycle_grub2mode;
3893 struct MUI_CustomClass *mcc =
3894 MUI_CreateCustomClass(NULL, MUIC_Notify, NULL,
3895 sizeof(struct Install_DATA), Install_Dispatcher);
3896 Object *installer = NewObject(mcc->mcc_Class, NULL,
3898 MUIA_Page, (IPTR) page,
3899 MUIA_Gauge1, (IPTR) gauge1,
3900 MUIA_Gauge2, (IPTR) gauge2,
3901 MUIA_Install, (IPTR) label,
3903 MUIA_OBJ_Installer, (IPTR) app,
3905 MUIA_WelcomeMsg, (IPTR) welcomeMsg,
3906 MUIA_FinishedMsg, (IPTR) doneMsg,
3908 MUIA_List_Options, (IPTR) install_opts,
3909 MUIA_Grub_Options, (IPTR) grub_opts,
3911 MUIA_OBJ_WindowContent, (IPTR) wndcontents,
3912 MUIA_OBJ_Window, (IPTR) wnd,
3914 MUIA_OBJ_PageTitle, (IPTR) pagetitle,
3915 MUIA_OBJ_PageHeader, (IPTR) pageheader,
3916 MUIA_OBJ_CActionStrng, (IPTR) currentaction,
3917 MUIA_OBJ_Back, (IPTR) gad_back,
3918 MUIA_OBJ_Proceed, (IPTR) gad_proceed,
3919 MUIA_OBJ_Cancel, (IPTR) gad_cancel,
3921 MUIA_IC_EnableUndo, TRUE,
3923 // MUIA_IC_License_File,"HELP:English/license", /* License can only be viewed by highlighting text and dragging */
3924 MUIA_IC_License_Mandatory, TRUE,
3926 TAG_DONE);
3928 DoMethod(wnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, app, 2,
3929 MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
3931 SET(wnd, MUIA_Window_Open, TRUE);
3933 ULONG sigs = 0;
3935 while (DoMethod(app, MUIM_Application_NewInput,
3936 &sigs) != MUIV_Application_ReturnID_Quit)
3938 if (sigs)
3940 sigs = Wait(sigs | SIGBREAKF_CTRL_C);
3941 if (sigs & SIGBREAKF_CTRL_C)
3942 break;
3947 D(bug("[INST-APP] Closing Window\n"));
3949 SET(wnd, MUIA_Window_Open, FALSE);
3951 D(bug("[INST-APP] Disposing of Installer Object\n"));
3953 DisposeObject(installer);
3955 D(bug("[INST-APP] Removing Custom Class\n"));
3957 MUI_DeleteCustomClass(mcc);
3959 D(bug("[INST-APP] Removing App Object\n"));
3961 MUI_DisposeObject(app);
3963 FreeVec(extras_source);
3964 FreeVec(source_Path);
3966 main_error:
3967 return 0;