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
, sizeof(SettingValue
)))
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
, "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
]);
163 UiUnInitialize("Rebooting...");
167 ULONG
GetDefaultOperatingSystem(PCSTR OperatingSystemList
[], ULONG OperatingSystemCount
)
169 CHAR DefaultOSText
[80];
175 if (!IniOpenSection("FreeLoader", &SectionId
))
180 DefaultOSName
= CmdLineGetDefaultOS();
181 if (NULL
== DefaultOSName
)
183 if (IniReadSettingByName(SectionId
, "DefaultOS", DefaultOSText
, sizeof(DefaultOSText
)))
185 DefaultOSName
= DefaultOSText
;
189 if (NULL
!= DefaultOSName
)
191 for (Idx
=0; Idx
<OperatingSystemCount
; Idx
++)
193 if (_stricmp(DefaultOSName
, OperatingSystemList
[Idx
]) == 0)
204 LONG
GetTimeOut(VOID
)
206 CHAR TimeOutText
[20];
210 TimeOut
= CmdLineGetTimeOut();
216 if (!IniOpenSection("FreeLoader", &SectionId
))
221 if (IniReadSettingByName(SectionId
, "TimeOut", TimeOutText
, sizeof(TimeOutText
)))
223 TimeOut
= atoi(TimeOutText
);
233 BOOLEAN
MainBootMenuKeyPressFilter(ULONG KeyPress
)
235 if (KeyPress
== KEY_F8
)
242 // We didn't handle the key