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 ARC_DISK_SIGNATURE reactos_arc_disk_info
[32]; // ARC Disk Information
23 unsigned long reactos_disk_count
= 0;
24 char reactos_arc_hardware_data
[HW_MAX_ARC_HEAP_SIZE
] = {0};
25 char reactos_arc_strings
[32][256];
27 ULONG
GetDefaultOperatingSystem(OperatingSystemItem
* OperatingSystemList
, ULONG OperatingSystemCount
)
29 CHAR DefaultOSText
[80];
35 if (!IniOpenSection("FreeLoader", &SectionId
))
40 DefaultOSName
= CmdLineGetDefaultOS();
41 if (NULL
== DefaultOSName
)
43 if (IniReadSettingByName(SectionId
, "DefaultOS", DefaultOSText
, sizeof(DefaultOSText
)))
45 DefaultOSName
= DefaultOSText
;
49 if (NULL
!= DefaultOSName
)
51 for (Idx
=0; Idx
<OperatingSystemCount
; Idx
++)
53 if (_stricmp(DefaultOSName
, OperatingSystemList
[Idx
].SystemPartition
) == 0)
70 TimeOut
= CmdLineGetTimeOut();
76 if (!IniOpenSection("FreeLoader", &SectionId
))
81 if (IniReadSettingByName(SectionId
, "TimeOut", TimeOutText
, sizeof(TimeOutText
)))
83 TimeOut
= atoi(TimeOutText
);
93 BOOLEAN
MainBootMenuKeyPressFilter(ULONG KeyPress
)
95 if (KeyPress
== KEY_F8
)
102 // We didn't handle the key
108 CHAR SettingValue
[80];
111 ULONG OperatingSystemCount
;
112 OperatingSystemItem
* OperatingSystemList
;
113 PCSTR
*OperatingSystemDisplayNames
;
116 ULONG DefaultOperatingSystem
;
118 ULONG SelectedOperatingSystem
;
120 // FIXME: if possible, only detect and register ARC devices...
123 UiMessageBoxCritical("Error when detecting hardware");
128 // Load additional SCSI driver (if any)
129 if (LoadBootDeviceDriver() != ESUCCESS
)
131 UiMessageBoxCritical("Unable to load additional boot device driver");
135 if (!IniFileInitialize())
137 UiMessageBoxCritical("Error initializing .ini file");
141 if (!IniOpenSection("FreeLoader", &SectionId
))
143 UiMessageBoxCritical("Section [FreeLoader] not found in freeldr.ini.");
146 TimeOut
= GetTimeOut();
148 if (!UiInitialize(TRUE
))
150 UiMessageBoxCritical("Unable to initialize UI.");
154 OperatingSystemList
= InitOperatingSystemList(&OperatingSystemCount
);
155 if (!OperatingSystemList
)
157 UiMessageBox("Unable to read operating systems section in freeldr.ini.\nPress ENTER to reboot.");
161 if (OperatingSystemCount
== 0)
163 UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
167 DefaultOperatingSystem
= GetDefaultOperatingSystem(OperatingSystemList
, OperatingSystemCount
);
170 // Create list of display names
172 OperatingSystemDisplayNames
= MmHeapAlloc(sizeof(PCSTR
) * OperatingSystemCount
);
173 if (!OperatingSystemDisplayNames
)
177 for (i
= 0; i
< OperatingSystemCount
; i
++)
179 OperatingSystemDisplayNames
[i
] = OperatingSystemList
[i
].LoadIdentifier
;
183 // Find all the message box settings and run them
185 UiShowMessageBoxesInSection("FreeLoader");
190 // Redraw the backdrop
193 // Show the operating system list menu
194 if (!UiDisplayMenu(OperatingSystemDisplayNames
, OperatingSystemCount
, DefaultOperatingSystem
, TimeOut
, &SelectedOperatingSystem
, FALSE
, MainBootMenuKeyPressFilter
))
196 UiMessageBox("Press ENTER to reboot.");
202 // Try to open the operating system section in the .ini file
203 SettingValue
[0] = ANSI_NULL
;
204 SectionName
= OperatingSystemList
[SelectedOperatingSystem
].SystemPartition
;
205 if (IniOpenSection(SectionName
, &SectionId
))
207 // Try to read the boot type
208 IniReadSettingByName(SectionId
, "BootType", BootType
, sizeof(BootType
));
211 BootType
[0] = ANSI_NULL
;
213 if (BootType
[0] == ANSI_NULL
&& SectionName
[0] != ANSI_NULL
)
215 // Try to infere boot type value
218 if (ArcOpen((CHAR
*)SectionName
, OpenReadOnly
, &FileId
) == ESUCCESS
)
221 strcpy(BootType
, "BootSector");
226 strcpy(BootType
, "Windows");
230 // Get OS setting value
231 IniOpenSection("Operating Systems", &SectionId
);
232 IniReadSettingByName(SectionId
, SectionName
, SettingValue
, sizeof(SettingValue
));
234 // Install the drive mapper according to this sections drive mappings
235 #if defined(_M_IX86) && !defined(_MSC_VER)
236 DriveMapMapDrivesInSection(SectionName
);
239 #ifdef FREELDR_REACTOS_SETUP
242 #elif defined(_M_IX86)
243 if (_stricmp(BootType
, "Windows") == 0)
245 LoadAndBootWindows(SectionName
, SettingValue
, 0);
247 else if (_stricmp(BootType
, "WindowsNT40") == 0)
249 LoadAndBootWindows(SectionName
, SettingValue
, _WIN32_WINNT_NT4
);
251 else if (_stricmp(BootType
, "Windows2003") == 0)
253 LoadAndBootWindows(SectionName
, SettingValue
, _WIN32_WINNT_WS03
);
255 else if (_stricmp(BootType
, "Linux") == 0)
257 LoadAndBootLinux(SectionName
, OperatingSystemDisplayNames
[SelectedOperatingSystem
]);
259 else if (_stricmp(BootType
, "BootSector") == 0)
261 LoadAndBootBootSector(SectionName
);
263 else if (_stricmp(BootType
, "Partition") == 0)
265 LoadAndBootPartition(SectionName
);
267 else if (_stricmp(BootType
, "Drive") == 0)
269 LoadAndBootDrive(SectionName
);
272 LoadAndBootWindows(SectionName
, SettingValue
, _WIN32_WINNT_WS03
);
277 UiUnInitialize("Rebooting...");