3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
42 UCHAR SettingName
[80];
43 UCHAR SettingValue
[80];
45 U32 OperatingSystemCount
;
46 PUCHAR
*OperatingSystemSectionNames
;
47 PUCHAR
*OperatingSystemDisplayNames
;
48 U32 DefaultOperatingSystem
;
50 U32 SelectedOperatingSystem
;
52 if (!IniFileInitialize())
54 printf("Press any key to reboot.\n");
59 if (!IniOpenSection("FreeLoader", &SectionId
))
61 printf("Section [FreeLoader] not found in freeldr.ini.\n");
65 TimeOut
= GetTimeOut();
67 if (!UiInitialize(TimeOut
))
69 printf("Press any key to reboot.\n");
75 if (!InitOperatingSystemList(&OperatingSystemSectionNames
, &OperatingSystemDisplayNames
, &OperatingSystemCount
))
77 UiMessageBox("Press ENTER to reboot.\n");
81 if (OperatingSystemCount
== 0)
83 UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
87 DefaultOperatingSystem
= GetDefaultOperatingSystem(OperatingSystemSectionNames
, OperatingSystemCount
);
90 // Find all the message box settings and run them
92 UiShowMessageBoxesInSection("FreeLoader");
97 /* If Timeout is 0, don't even bother loading any gui */
98 if (!UserInterfaceUp
) {
102 // Redraw the backdrop
105 // Show the operating system list menu
106 if (!UiDisplayMenu(OperatingSystemDisplayNames
, OperatingSystemCount
, DefaultOperatingSystem
, TimeOut
, &SelectedOperatingSystem
, FALSE
, MainBootMenuKeyPressFilter
))
108 UiMessageBox("Press ENTER to reboot.\n");
114 DefaultOperatingSystem
= SelectedOperatingSystem
;
116 // Try to open the operating system section in the .ini file
117 if (!IniOpenSection(OperatingSystemSectionNames
[SelectedOperatingSystem
], &SectionId
))
119 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemSectionNames
[SelectedOperatingSystem
]);
120 UiMessageBox(SettingName
);
124 // Try to read the boot type
125 if (!IniReadSettingByName(SectionId
, "BootType", SettingValue
, 80))
127 sprintf(SettingName
, "BootType= line not found in section [%s] in freeldr.ini.\n", OperatingSystemSectionNames
[SelectedOperatingSystem
]);
128 UiMessageBox(SettingName
);
132 // Install the drive mapper according to this sections drive mappings
133 DriveMapMapDrivesInSection(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
134 if (stricmp(SettingValue
, "ReactOS") == 0)
136 LoadAndBootReactOS(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
138 else if (stricmp(SettingValue
, "Linux") == 0)
140 LoadAndBootLinux(OperatingSystemSectionNames
[SelectedOperatingSystem
], OperatingSystemDisplayNames
[SelectedOperatingSystem
]);
142 else if (stricmp(SettingValue
, "BootSector") == 0)
144 LoadAndBootBootSector(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
146 else if (stricmp(SettingValue
, "Partition") == 0)
148 LoadAndBootPartition(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
150 else if (stricmp(SettingValue
, "Drive") == 0)
152 LoadAndBootDrive(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
158 UiUnInitialize("Rebooting...");
162 U32
GetDefaultOperatingSystem(PUCHAR OperatingSystemList
[], U32 OperatingSystemCount
)
164 UCHAR DefaultOSText
[80];
170 if (!IniOpenSection("FreeLoader", &SectionId
))
175 DefaultOSName
= CmdLineGetDefaultOS();
176 if (NULL
== DefaultOSName
)
178 if (IniReadSettingByName(SectionId
, "DefaultOS", DefaultOSText
, 80))
180 DefaultOSName
= DefaultOSText
;
184 if (NULL
!= DefaultOSName
)
186 for (Idx
=0; Idx
<OperatingSystemCount
; Idx
++)
188 if (stricmp(DefaultOSName
, OperatingSystemList
[Idx
]) == 0)
201 UCHAR TimeOutText
[20];
205 TimeOut
= CmdLineGetTimeOut();
211 if (!IniOpenSection("FreeLoader", &SectionId
))
216 if (IniReadSettingByName(SectionId
, "TimeOut", TimeOutText
, 20))
218 TimeOut
= atoi(TimeOutText
);
228 BOOL
MainBootMenuKeyPressFilter(U32 KeyPress
)
230 if (KeyPress
== KEY_F8
)
237 // We didn't handle the key