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.
25 CHAR SettingValue
[80];
27 ULONG OperatingSystemCount
;
28 PCSTR
*OperatingSystemSectionNames
;
29 PCSTR
*OperatingSystemDisplayNames
;
30 ULONG DefaultOperatingSystem
;
32 ULONG SelectedOperatingSystem
;
34 if (!FsOpenBootVolume())
36 UiMessageBoxCritical("Error opening boot partition for file access.");
41 // Check if we have a virtual RAM disk
42 // This is for x86 emulation -- on real hardware, the RAM disk will be
43 // located in one of the hardware memory descriptors as well as on the
44 // freeldr command-line
46 RamDiskCheckForVirtualFile();
48 if (!IniFileInitialize())
50 UiMessageBoxCritical("Error initializing .ini file");
54 if (!IniOpenSection("FreeLoader", &SectionId
))
56 UiMessageBoxCritical("Section [FreeLoader] not found in freeldr.ini.");
59 TimeOut
= GetTimeOut();
61 if (!UiInitialize(TimeOut
))
63 UiMessageBoxCritical("Unable to initialize UI.");
68 if (!InitOperatingSystemList(&OperatingSystemSectionNames
, &OperatingSystemDisplayNames
, &OperatingSystemCount
))
70 UiMessageBox("Press ENTER to reboot.");
74 if (OperatingSystemCount
== 0)
76 UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
80 DefaultOperatingSystem
= GetDefaultOperatingSystem(OperatingSystemSectionNames
, OperatingSystemCount
);
83 // Find all the message box settings and run them
85 UiShowMessageBoxesInSection("FreeLoader");
90 // Redraw the backdrop
93 // Show the operating system list menu
94 if (!UiDisplayMenu(OperatingSystemDisplayNames
, OperatingSystemCount
, DefaultOperatingSystem
, TimeOut
, &SelectedOperatingSystem
, FALSE
, MainBootMenuKeyPressFilter
))
96 UiMessageBox("Press ENTER to reboot.");
102 // Try to open the operating system section in the .ini file
103 if (!IniOpenSection(OperatingSystemSectionNames
[SelectedOperatingSystem
], &SectionId
))
105 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.", OperatingSystemSectionNames
[SelectedOperatingSystem
]);
106 UiMessageBox(SettingName
);
110 // Try to read the boot type
111 if (!IniReadSettingByName(SectionId
, "BootType", SettingValue
, sizeof(SettingValue
)))
113 sprintf(SettingName
, "BootType= line not found in section [%s] in freeldr.ini.", OperatingSystemSectionNames
[SelectedOperatingSystem
]);
114 UiMessageBox(SettingName
);
118 // Install the drive mapper according to this sections drive mappings
120 DriveMapMapDrivesInSection(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
122 if (_stricmp(SettingValue
, "ReactOS") == 0)
124 LoadAndBootReactOS(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
127 else if (_stricmp(SettingValue
, "WindowsNT40") == 0)
129 LoadAndBootWindows(OperatingSystemSectionNames
[SelectedOperatingSystem
], _WIN32_WINNT_NT4
);
131 else if (_stricmp(SettingValue
, "Windows2000") == 0)
133 LoadAndBootWindows(OperatingSystemSectionNames
[SelectedOperatingSystem
], _WIN32_WINNT_WIN2K
);
135 else if (_stricmp(SettingValue
, "WindowsXP") == 0)
137 LoadAndBootWindows(OperatingSystemSectionNames
[SelectedOperatingSystem
], _WIN32_WINNT_WINXP
);
139 else if (_stricmp(SettingValue
, "Windows2003") == 0)
141 LoadAndBootWindows(OperatingSystemSectionNames
[SelectedOperatingSystem
], _WIN32_WINNT_WS03
);
143 else if (_stricmp(SettingValue
, "Linux") == 0)
145 LoadAndBootLinux(OperatingSystemSectionNames
[SelectedOperatingSystem
], OperatingSystemDisplayNames
[SelectedOperatingSystem
]);
147 else if (_stricmp(SettingValue
, "BootSector") == 0)
149 LoadAndBootBootSector(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
151 else if (_stricmp(SettingValue
, "Partition") == 0)
153 LoadAndBootPartition(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
155 else if (_stricmp(SettingValue
, "Drive") == 0)
157 LoadAndBootDrive(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
164 UiUnInitialize("Rebooting...");
168 ULONG
GetDefaultOperatingSystem(PCSTR OperatingSystemList
[], ULONG OperatingSystemCount
)
170 CHAR DefaultOSText
[80];
176 if (!IniOpenSection("FreeLoader", &SectionId
))
181 DefaultOSName
= CmdLineGetDefaultOS();
182 if (NULL
== DefaultOSName
)
184 if (IniReadSettingByName(SectionId
, "DefaultOS", DefaultOSText
, sizeof(DefaultOSText
)))
186 DefaultOSName
= DefaultOSText
;
190 if (NULL
!= DefaultOSName
)
192 for (Idx
=0; Idx
<OperatingSystemCount
; Idx
++)
194 if (_stricmp(DefaultOSName
, OperatingSystemList
[Idx
]) == 0)
205 LONG
GetTimeOut(VOID
)
207 CHAR TimeOutText
[20];
211 TimeOut
= CmdLineGetTimeOut();
217 if (!IniOpenSection("FreeLoader", &SectionId
))
222 if (IniReadSettingByName(SectionId
, "TimeOut", TimeOutText
, sizeof(TimeOutText
)))
224 TimeOut
= atoi(TimeOutText
);
234 BOOLEAN
MainBootMenuKeyPressFilter(ULONG KeyPress
)
236 if (KeyPress
== KEY_F8
)
243 // We didn't handle the key