3 * Copyright (C) 2001 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.
28 PUCHAR FreeLoaderIniFileData
= NULL
;
29 ULONG FreeLoaderIniFileSize
= 0;
31 BOOL
ParseIniFile(VOID
)
36 PFILE Freeldr_Ini
; // File handle for freeldr.ini
38 // Open the boot drive for file access
39 if (!OpenDiskDrive(BootDrive
, 0))
41 printf("Error opening boot drive for file access.\n");
45 // Try to open freeldr.ini or fail
46 Freeldr_Ini
= OpenFile("freeldr.ini");
47 if (Freeldr_Ini
== NULL
)
49 printf("FREELDR.INI not found.\nYou need to re-install FreeLoader.\n");
53 // Get the file size & allocate enough memory for it
54 FreeLoaderIniFileSize
= GetFileSize(Freeldr_Ini
);
55 FreeLoaderIniFileData
= AllocateMemory(FreeLoaderIniFileSize
);
57 // If we are out of memory then return FALSE
58 if (FreeLoaderIniFileData
== NULL
)
60 printf("Out of memory while loading FREELDR.INI.\n");
61 CloseFile(Freeldr_Ini
);
65 // Read freeldr.ini off the disk
66 ReadFile(Freeldr_Ini
, FreeLoaderIniFileSize
, NULL
, FreeLoaderIniFileData
);
67 CloseFile(Freeldr_Ini
);
69 // Make sure the [FREELOADER] section exists
70 /*if (OpenSection("FREELOADER", NULL))
72 printf("Section [FREELOADER] not found in FREELDR.INI.\nYou need to re-install FreeLoader.\n");
76 // Validate the settings in the [FREELOADER] section
77 for (i=1; i<=GetNumSectionItems("FREELOADER"); i++)
79 ReadSectionSettingByNumber("FREELOADER", i, name, value);
80 if (!IsValidSetting(name, value))
82 printf("Invalid setting in freeldr.ini.\nName: \"%s\", Value: \"%s\"\n", name, value);
83 printf("Press any key to continue.\n");
87 SetSetting(name, value);
93 ULONG
GetNextLineOfFileData(PUCHAR Buffer
, ULONG BufferSize
, ULONG CurrentOffset
)
97 // Loop through grabbing chars until we hit the end of the
98 // file or we encounter a new line char
99 for (Idx
=0; (CurrentOffset
< FreeLoaderIniFileSize
); CurrentOffset
++)
101 // If we haven't exceeded our buffer size yet
102 // then store another char
103 if (Idx
< (BufferSize
- 1))
105 Buffer
[Idx
++] = FreeLoaderIniFileData
[CurrentOffset
];
108 // Check for new line char
109 if (FreeLoaderIniFileData
[CurrentOffset
] == '\n')
116 // Terminate the string
119 // Get rid of newline & linefeed characters (if any)
120 if((Buffer
[strlen(Buffer
)-1] == '\n') || (Buffer
[strlen(Buffer
)-1] == '\r'))
121 Buffer
[strlen(Buffer
)-1] = '\0';
122 if((Buffer
[strlen(Buffer
)-1] == '\n') || (Buffer
[strlen(Buffer
)-1] == '\r'))
123 Buffer
[strlen(Buffer
)-1] = '\0';
125 // Send back new offset
126 return CurrentOffset
;
129 BOOL
OpenSection(PUCHAR SectionName
, PULONG SectionId
)
131 UCHAR TempString
[80];
132 UCHAR RealSectionName
[80];
134 BOOL SectionFound
= FALSE
;
137 // Get the real section name
139 strcpy(RealSectionName
, "[");
140 strcat(RealSectionName
, SectionName
);
141 strcat(RealSectionName
, "]");
144 // Get to the beginning of the file
151 while (FileOffset
< FreeLoaderIniFileSize
)
156 FileOffset
= GetNextLineOfFileData(TempString
, 80, FileOffset
);
159 // If it isn't a section header then continue on
161 if (TempString
[0] != '[')
165 // Check and see if we found it
167 if (stricmp(TempString
, RealSectionName
) == 0)
176 *SectionId
= FileOffset
;
182 ULONG
GetNumSectionItems(ULONG SectionId
)
184 UCHAR TempString
[80];
185 ULONG SectionItemCount
= 0;
187 // Now count how many settings are in this section
188 while (SectionId
< FreeLoaderIniFileSize
)
191 SectionId
= GetNextLineOfFileData(TempString
, 80, SectionId
);
193 // If we hit a new section then we're done
194 if (TempString
[0] == '[')
198 if (TempString
[0] == '#')
202 if (!strlen(TempString
))
208 return SectionItemCount
;
211 BOOL
ReadSectionSettingByNumber(ULONG SectionId
, ULONG SettingNumber
, PUCHAR SettingName
, ULONG NameSize
, PUCHAR SettingValue
, ULONG ValueSize
)
213 UCHAR TempString
[1024];
214 ULONG SectionItemCount
= 0;
219 // Get to the beginning of the section
221 FileOffset
= SectionId
;
224 // Now find the setting we are looking for
229 FileOffset
= GetNextLineOfFileData(TempString
, 1024, FileOffset
);
232 if (TempString
[0] == '#')
236 if (!strlen(TempString
))
239 // If we hit a new section then we're done
240 if (TempString
[0] == '[')
243 // Check and see if we found the setting
244 if (SectionItemCount
== SettingNumber
)
246 for (Idx
=0; Idx
<strlen(TempString
); Idx
++)
248 // Check and see if this character is the separator
249 if (TempString
[Idx
] == '=')
251 SettingName
[Idx
] = '\0';
253 strncpy(SettingValue
, TempString
+ Idx
+ 1, ValueSize
);
257 else if (Idx
< NameSize
)
259 SettingName
[Idx
] = TempString
[Idx
];
264 // Increment setting number
267 while (FileOffset
< FreeLoaderIniFileSize
);
272 BOOL
ReadSectionSettingByName(ULONG SectionId
, PUCHAR SettingName
, PUCHAR Buffer
, ULONG BufferSize
)
274 UCHAR TempString
[1024];
275 UCHAR TempBuffer
[80];
280 // Get to the beginning of the section
282 FileOffset
= SectionId
;
285 // Now find the setting we are looking for
287 while (FileOffset
< FreeLoaderIniFileSize
)
290 FileOffset
= GetNextLineOfFileData(TempString
, 1024, FileOffset
);
293 if (TempString
[0] == '#')
297 if (!strlen(TempString
))
300 // If we hit a new section then we're done
301 if (TempString
[0] == '[')
304 // Extract the setting name
305 for (Idx
=0; Idx
<strlen(TempString
); Idx
++)
307 if (TempString
[Idx
] != '=')
308 TempBuffer
[Idx
] = TempString
[Idx
];
311 TempBuffer
[Idx
] = '\0';
316 // Check and see if we found the setting
317 if (stricmp(TempBuffer
, SettingName
) == 0)
319 for (Idx
=0; Idx
<strlen(TempString
); Idx
++)
321 // Check and see if this character is the separator
322 if (TempString
[Idx
] == '=')
324 strcpy(Buffer
, TempString
+ Idx
+ 1);
335 BOOL
IsValidSetting(char *setting
, char *value
)
337 if(stricmp(setting
, "MessageBox") == 0)
339 else if(stricmp(setting
, "MessageLine") == 0)
341 else if(stricmp(setting
, "TitleText") == 0)
343 else if(stricmp(setting
, "StatusBarColor") == 0)
345 if(IsValidColor(value
))
348 else if(stricmp(setting
, "StatusBarTextColor") == 0)
350 if(IsValidColor(value
))
353 else if(stricmp(setting
, "BackdropTextColor") == 0)
355 if(IsValidColor(value
))
358 else if(stricmp(setting
, "BackdropColor") == 0)
360 if(IsValidColor(value
))
363 else if(stricmp(setting
, "BackdropFillStyle") == 0)
365 if(IsValidFillStyle(value
))
368 else if(stricmp(setting
, "TitleBoxTextColor") == 0)
370 if(IsValidColor(value
))
373 else if(stricmp(setting
, "TitleBoxColor") == 0)
375 if(IsValidColor(value
))
378 else if(stricmp(setting
, "MessageBoxTextColor") == 0)
380 if(IsValidColor(value
))
383 else if(stricmp(setting
, "MessageBoxColor") == 0)
385 if(IsValidColor(value
))
388 else if(stricmp(setting
, "MenuTextColor") == 0)
390 if(IsValidColor(value
))
393 else if(stricmp(setting
, "MenuColor") == 0)
395 if(IsValidColor(value
))
398 else if(stricmp(setting
, "TextColor") == 0)
400 if(IsValidColor(value
))
403 else if(stricmp(setting
, "SelectedTextColor") == 0)
405 if(IsValidColor(value
))
408 else if(stricmp(setting
, "SelectedColor") == 0)
410 if(IsValidColor(value
))
413 else if(stricmp(setting
, "OS") == 0)
415 else if(stricmp(setting
, "TimeOut") == 0)
417 /*else if(stricmp(setting, "") == 0)
419 else if(stricmp(setting, "") == 0)
421 else if(stricmp(setting, "") == 0)
423 else if(stricmp(setting, "") == 0)
425 else if(stricmp(setting, "") == 0)
427 else if(stricmp(setting, "") == 0)
429 else if(stricmp(setting, "") == 0)
435 /*void SetSetting(char *setting, char *value)
439 if(stricmp(setting, "TitleText") == 0)
440 strcpy(szTitleBoxTitleText, value);
441 else if(stricmp(setting, "StatusBarColor") == 0)
442 cStatusBarBgColor = TextToColor(value);
443 else if(stricmp(setting, "StatusBarTextColor") == 0)
444 cStatusBarFgColor = TextToColor(value);
445 else if(stricmp(setting, "BackdropTextColor") == 0)
446 cBackdropFgColor = TextToColor(value);
447 else if(stricmp(setting, "BackdropColor") == 0)
448 cBackdropBgColor = TextToColor(value);
449 else if(stricmp(setting, "BackdropFillStyle") == 0)
450 cBackdropFillStyle = TextToFillStyle(value);
451 else if(stricmp(setting, "TitleBoxTextColor") == 0)
452 cTitleBoxFgColor = TextToColor(value);
453 else if(stricmp(setting, "TitleBoxColor") == 0)
454 cTitleBoxBgColor = TextToColor(value);
455 else if(stricmp(setting, "MessageBoxTextColor") == 0)
456 cMessageBoxFgColor = TextToColor(value);
457 else if(stricmp(setting, "MessageBoxColor") == 0)
458 cMessageBoxBgColor = TextToColor(value);
459 else if(stricmp(setting, "MenuTextColor") == 0)
460 cMenuFgColor = TextToColor(value);
461 else if(stricmp(setting, "MenuColor") == 0)
462 cMenuBgColor = TextToColor(value);
463 else if(stricmp(setting, "TextColor") == 0)
464 cTextColor = TextToColor(value);
465 else if(stricmp(setting, "SelectedTextColor") == 0)
466 cSelectedTextColor = TextToColor(value);
467 else if(stricmp(setting, "SelectedColor") == 0)
468 cSelectedTextBgColor = TextToColor(value);
469 else if(stricmp(setting, "OS") == 0)
473 printf("Error: you can only boot to at most 16 different operating systems.\n");
474 printf("Press any key to continue\n");
479 if(!GetNumSectionItems(value))
481 printf("Error: OS \"%s\" listed.\n", value);
482 printf("It does not have it's own [section], or it is empty.\n");
483 printf("Press any key to continue\n");
488 strcpy(OSList[nNumOS].name, value);
490 if (!ReadSectionSettingByName(value, "BootType", v))
492 printf("Unknown BootType for OS \"%s\"\n", value);
493 printf("Press any key to continue\n");
498 if (stricmp(v, "ReactOS") == 0)
499 OSList[nNumOS].nOSType = OSTYPE_REACTOS;
500 else if (stricmp(v, "Linux") == 0)
501 OSList[nNumOS].nOSType = OSTYPE_LINUX;
502 else if (stricmp(v, "BootSector") == 0)
503 OSList[nNumOS].nOSType = OSTYPE_BOOTSECTOR;
504 else if (stricmp(v, "Partition") == 0)
505 OSList[nNumOS].nOSType = OSTYPE_PARTITION;
506 else if (stricmp(v, "Drive") == 0)
507 OSList[nNumOS].nOSType = OSTYPE_DRIVE;
510 printf("Unknown BootType for OS \"%s\"\n", value);
511 printf("Press any key to continue\n");
518 else if(stricmp(setting, "TimeOut") == 0)
519 nTimeOut = atoi(value);