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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 ULONG
GetDefaultOperatingSystem(OperatingSystemItem
* OperatingSystemList
, ULONG OperatingSystemCount
)
24 CHAR DefaultOSText
[80];
30 if (!IniOpenSection("FreeLoader", &SectionId
))
35 DefaultOSName
= CmdLineGetDefaultOS();
36 if (NULL
== DefaultOSName
)
38 if (IniReadSettingByName(SectionId
, "DefaultOS", DefaultOSText
, sizeof(DefaultOSText
)))
40 DefaultOSName
= DefaultOSText
;
44 if (NULL
!= DefaultOSName
)
46 for (Idx
=0; Idx
<OperatingSystemCount
; Idx
++)
48 if (_stricmp(DefaultOSName
, OperatingSystemList
[Idx
].SystemPartition
) == 0)
65 TimeOut
= CmdLineGetTimeOut();
71 if (!IniOpenSection("FreeLoader", &SectionId
))
76 if (IniReadSettingByName(SectionId
, "TimeOut", TimeOutText
, sizeof(TimeOutText
)))
78 TimeOut
= atoi(TimeOutText
);
88 BOOLEAN
MainBootMenuKeyPressFilter(ULONG KeyPress
)
90 if (KeyPress
== KEY_F8
)
97 // We didn't handle the key
103 CHAR SettingValue
[80];
106 ULONG OperatingSystemCount
;
107 OperatingSystemItem
* OperatingSystemList
;
108 PCSTR
*OperatingSystemDisplayNames
;
111 ULONG DefaultOperatingSystem
;
113 ULONG SelectedOperatingSystem
;
115 // FIXME: if possible, only detect and register ARC devices...
118 UiMessageBoxCritical("Error when detecting hardware");
122 // Load additional SCSI driver (if any)
123 if (LoadBootDeviceDriver() != ESUCCESS
)
125 UiMessageBoxCritical("Unable to load additional boot device driver");
128 if (!IniFileInitialize())
130 UiMessageBoxCritical("Error initializing .ini file");
134 if (!IniOpenSection("FreeLoader", &SectionId
))
136 UiMessageBoxCritical("Section [FreeLoader] not found in freeldr.ini.");
139 TimeOut
= GetTimeOut();
141 if (!UiInitialize(TimeOut
))
143 UiMessageBoxCritical("Unable to initialize UI.");
147 OperatingSystemList
= InitOperatingSystemList(&OperatingSystemCount
);
148 if (!OperatingSystemList
)
150 UiMessageBox("Unable to read operating systems section in freeldr.ini.\nPress ENTER to reboot.");
154 if (OperatingSystemCount
== 0)
156 UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
160 DefaultOperatingSystem
= GetDefaultOperatingSystem(OperatingSystemList
, OperatingSystemCount
);
163 // Create list of display names
165 OperatingSystemDisplayNames
= MmHeapAlloc(sizeof(PCSTR
) * OperatingSystemCount
);
166 if (!OperatingSystemDisplayNames
)
170 for (i
= 0; i
< OperatingSystemCount
; i
++)
172 OperatingSystemDisplayNames
[i
] = OperatingSystemList
[i
].LoadIdentifier
;
176 // Find all the message box settings and run them
178 UiShowMessageBoxesInSection("FreeLoader");
183 // Redraw the backdrop
186 // Show the operating system list menu
187 if (!UiDisplayMenu(OperatingSystemDisplayNames
, OperatingSystemCount
, DefaultOperatingSystem
, TimeOut
, &SelectedOperatingSystem
, FALSE
, MainBootMenuKeyPressFilter
))
189 UiMessageBox("Press ENTER to reboot.");
195 // Try to open the operating system section in the .ini file
196 SettingValue
[0] = ANSI_NULL
;
197 SectionName
= OperatingSystemList
[SelectedOperatingSystem
].SystemPartition
;
198 if (IniOpenSection(SectionName
, &SectionId
))
200 // Try to read the boot type
201 IniReadSettingByName(SectionId
, "BootType", BootType
, sizeof(BootType
));
204 BootType
[0] = ANSI_NULL
;
206 if (BootType
[0] == ANSI_NULL
&& SectionName
[0] != ANSI_NULL
)
208 // Try to infere boot type value
211 if (ArcOpen((CHAR
*)SectionName
, OpenReadOnly
, &FileId
) == ESUCCESS
)
214 strcpy(BootType
, "BootSector");
219 strcpy(BootType
, "Windows");
223 // Get OS setting value
224 IniOpenSection("Operating Systems", &SectionId
);
225 IniReadSettingByName(SectionId
, SectionName
, SettingValue
, sizeof(SettingValue
));
228 // Install the drive mapper according to this sections drive mappings
230 DriveMapMapDrivesInSection(SectionName
);
232 if (_stricmp(BootType
, "ReactOS") == 0)
234 LoadAndBootReactOS(SectionName
);
236 #ifdef FREELDR_REACTOS_SETUP
237 else if (_stricmp(BootType
, "ReactOSSetup") == 0)
239 // In future we could pass the selected OS details through this
240 // to have different install methods, etc.
243 #if defined(__i386__) || defined(__x86_64__)
244 else if (_stricmp(BootType
, "ReactOSSetup2") == 0)
252 else if (_stricmp(BootType
, "Windows") == 0)
254 LoadAndBootWindows(SectionName
, SettingValue
, 0);
256 else if (_stricmp(BootType
, "WindowsNT40") == 0)
258 LoadAndBootWindows(SectionName
, SettingValue
, _WIN32_WINNT_NT4
);
260 else if (_stricmp(BootType
, "Windows2003") == 0)
262 LoadAndBootWindows(SectionName
, SettingValue
, _WIN32_WINNT_WS03
);
264 else if (_stricmp(BootType
, "Linux") == 0)
266 LoadAndBootLinux(SectionName
, OperatingSystemDisplayNames
[SelectedOperatingSystem
]);
268 else if (_stricmp(BootType
, "BootSector") == 0)
270 LoadAndBootBootSector(SectionName
);
272 else if (_stricmp(BootType
, "Partition") == 0)
274 LoadAndBootPartition(SectionName
);
276 else if (_stricmp(BootType
, "Drive") == 0)
278 LoadAndBootDrive(SectionName
);
282 LoadAndBootWindows(SectionName
, SettingValue
, _WIN32_WINNT_WS03
);
288 UiUnInitialize("Rebooting...");