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 ULONG OperatingSystemCount
;
46 PUCHAR
*OperatingSystemSectionNames
;
47 PUCHAR
*OperatingSystemDisplayNames
;
48 ULONG DefaultOperatingSystem
;
50 ULONG SelectedOperatingSystem
;
52 if (!FsOpenBootVolume())
54 printf("Error opening boot partition for file access.\n");
59 if (!IniFileInitialize())
61 printf("Press any key to reboot.\n");
66 if (!IniOpenSection("FreeLoader", &SectionId
))
68 printf("Section [FreeLoader] not found in freeldr.ini.\n");
72 TimeOut
= GetTimeOut();
74 if (!UiInitialize(TimeOut
))
76 printf("Press any key to reboot.\n");
82 if (!InitOperatingSystemList(&OperatingSystemSectionNames
, &OperatingSystemDisplayNames
, &OperatingSystemCount
))
84 UiMessageBox("Press ENTER to reboot.\n");
88 if (OperatingSystemCount
== 0)
90 UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
94 DefaultOperatingSystem
= GetDefaultOperatingSystem(OperatingSystemSectionNames
, OperatingSystemCount
);
97 // Find all the message box settings and run them
99 UiShowMessageBoxesInSection("FreeLoader");
104 /* If Timeout is 0, don't even bother loading any gui */
105 if (!UserInterfaceUp
) {
106 SelectedOperatingSystem
= DefaultOperatingSystem
;
110 // Redraw the backdrop
113 // Show the operating system list menu
114 if (!UiDisplayMenu(OperatingSystemDisplayNames
, OperatingSystemCount
, DefaultOperatingSystem
, TimeOut
, &SelectedOperatingSystem
, FALSE
, MainBootMenuKeyPressFilter
))
116 UiMessageBox("Press ENTER to reboot.\n");
123 // Try to open the operating system section in the .ini file
124 if (!IniOpenSection(OperatingSystemSectionNames
[SelectedOperatingSystem
], &SectionId
))
126 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemSectionNames
[SelectedOperatingSystem
]);
127 UiMessageBox(SettingName
);
131 // Try to read the boot type
132 if (!IniReadSettingByName(SectionId
, "BootType", SettingValue
, 80))
134 sprintf(SettingName
, "BootType= line not found in section [%s] in freeldr.ini.\n", OperatingSystemSectionNames
[SelectedOperatingSystem
]);
135 UiMessageBox(SettingName
);
139 // Install the drive mapper according to this sections drive mappings
140 DriveMapMapDrivesInSection(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
141 if (stricmp(SettingValue
, "ReactOS") == 0)
143 LoadAndBootReactOS(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
145 else if (stricmp(SettingValue
, "Linux") == 0)
147 LoadAndBootLinux(OperatingSystemSectionNames
[SelectedOperatingSystem
], OperatingSystemDisplayNames
[SelectedOperatingSystem
]);
149 else if (stricmp(SettingValue
, "BootSector") == 0)
151 LoadAndBootBootSector(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
153 else if (stricmp(SettingValue
, "Partition") == 0)
155 LoadAndBootPartition(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
157 else if (stricmp(SettingValue
, "Drive") == 0)
159 LoadAndBootDrive(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
165 UiUnInitialize("Rebooting...");
169 ULONG
GetDefaultOperatingSystem(PUCHAR OperatingSystemList
[], ULONG OperatingSystemCount
)
171 UCHAR DefaultOSText
[80];
177 if (!IniOpenSection("FreeLoader", &SectionId
))
182 DefaultOSName
= CmdLineGetDefaultOS();
183 if (NULL
== DefaultOSName
)
185 if (IniReadSettingByName(SectionId
, "DefaultOS", DefaultOSText
, 80))
187 DefaultOSName
= DefaultOSText
;
191 if (NULL
!= DefaultOSName
)
193 for (Idx
=0; Idx
<OperatingSystemCount
; Idx
++)
195 if (stricmp(DefaultOSName
, OperatingSystemList
[Idx
]) == 0)
206 LONG
GetTimeOut(VOID
)
208 UCHAR TimeOutText
[20];
212 TimeOut
= CmdLineGetTimeOut();
218 if (!IniOpenSection("FreeLoader", &SectionId
))
223 if (IniReadSettingByName(SectionId
, "TimeOut", TimeOutText
, 20))
225 TimeOut
= atoi(TimeOutText
);
235 BOOL
MainBootMenuKeyPressFilter(ULONG KeyPress
)
237 if (KeyPress
== KEY_F8
)
244 // We didn't handle the key