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 printf("Error opening boot partition for file access.\n");
41 if (!IniFileInitialize())
43 printf("Press any key to reboot.\n");
48 if (!IniOpenSection("FreeLoader", &SectionId
))
50 printf("Section [FreeLoader] not found in freeldr.ini.\n");
54 TimeOut
= GetTimeOut();
56 if (!UiInitialize(TimeOut
))
58 printf("Press any key to reboot.\n");
64 if (!InitOperatingSystemList(&OperatingSystemSectionNames
, &OperatingSystemDisplayNames
, &OperatingSystemCount
))
66 UiMessageBox("Press ENTER to reboot.\n");
70 if (OperatingSystemCount
== 0)
72 UiMessageBox("There were no operating systems listed in freeldr.ini.\nPress ENTER to reboot.");
76 DefaultOperatingSystem
= GetDefaultOperatingSystem(OperatingSystemSectionNames
, OperatingSystemCount
);
79 // Find all the message box settings and run them
81 UiShowMessageBoxesInSection("FreeLoader");
86 /* If Timeout is 0, don't even bother loading any gui */
87 if (!UserInterfaceUp
) {
88 SelectedOperatingSystem
= DefaultOperatingSystem
;
92 // Redraw the backdrop
95 // Show the operating system list menu
96 if (!UiDisplayMenu(OperatingSystemDisplayNames
, OperatingSystemCount
, DefaultOperatingSystem
, TimeOut
, &SelectedOperatingSystem
, FALSE
, MainBootMenuKeyPressFilter
))
98 UiMessageBox("Press ENTER to reboot.\n");
105 // Try to open the operating system section in the .ini file
106 if (!IniOpenSection(OperatingSystemSectionNames
[SelectedOperatingSystem
], &SectionId
))
108 sprintf(SettingName
, "Section [%s] not found in freeldr.ini.\n", OperatingSystemSectionNames
[SelectedOperatingSystem
]);
109 UiMessageBox(SettingName
);
113 // Try to read the boot type
114 if (!IniReadSettingByName(SectionId
, "BootType", SettingValue
, 80))
116 sprintf(SettingName
, "BootType= line not found in section [%s] in freeldr.ini.\n", OperatingSystemSectionNames
[SelectedOperatingSystem
]);
117 UiMessageBox(SettingName
);
121 // Install the drive mapper according to this sections drive mappings
122 DriveMapMapDrivesInSection(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
123 if (_stricmp(SettingValue
, "ReactOS") == 0)
125 LoadAndBootReactOS(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
127 else if (_stricmp(SettingValue
, "Linux") == 0)
129 LoadAndBootLinux(OperatingSystemSectionNames
[SelectedOperatingSystem
], OperatingSystemDisplayNames
[SelectedOperatingSystem
]);
131 else if (_stricmp(SettingValue
, "BootSector") == 0)
133 LoadAndBootBootSector(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
135 else if (_stricmp(SettingValue
, "Partition") == 0)
137 LoadAndBootPartition(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
139 else if (_stricmp(SettingValue
, "Drive") == 0)
141 LoadAndBootDrive(OperatingSystemSectionNames
[SelectedOperatingSystem
]);
147 UiUnInitialize("Rebooting...");
151 ULONG
GetDefaultOperatingSystem(PCSTR OperatingSystemList
[], ULONG OperatingSystemCount
)
153 CHAR DefaultOSText
[80];
159 if (!IniOpenSection("FreeLoader", &SectionId
))
164 DefaultOSName
= CmdLineGetDefaultOS();
165 if (NULL
== DefaultOSName
)
167 if (IniReadSettingByName(SectionId
, "DefaultOS", DefaultOSText
, 80))
169 DefaultOSName
= DefaultOSText
;
173 if (NULL
!= DefaultOSName
)
175 for (Idx
=0; Idx
<OperatingSystemCount
; Idx
++)
177 if (_stricmp(DefaultOSName
, OperatingSystemList
[Idx
]) == 0)
188 LONG
GetTimeOut(VOID
)
190 CHAR TimeOutText
[20];
194 TimeOut
= CmdLineGetTimeOut();
200 if (!IniOpenSection("FreeLoader", &SectionId
))
205 if (IniReadSettingByName(SectionId
, "TimeOut", TimeOutText
, 20))
207 TimeOut
= atoi(TimeOutText
);
217 BOOL
MainBootMenuKeyPressFilter(ULONG KeyPress
)
219 if (KeyPress
== KEY_F8
)
226 // We didn't handle the key