📄 bootsup.c
字号:
/*
* ReactOS kernel
* Copyright (C) 2002 ReactOS Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS text-mode setup
* FILE: subsys/system/usetup/bootsup.c
* PURPOSE: Bootloader support functions
* PROGRAMMER: Eric Kohl
*/
#include "usetup.h"
#define NDEBUG
#include <debug.h>
#define SECTORSIZE 512
/* FUNCTIONS ****************************************************************/
static VOID
CreateCommonFreeLoaderSections(PINICACHE IniCache)
{
PINICACHESECTION IniSection;
/* Create "FREELOADER" section */
IniSection = IniCacheAppendSection(IniCache,
L"FREELOADER");
#ifdef DBG
if (IsUnattendedSetup)
{
/* DefaultOS=ReactOS */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"DefaultOS",
L"ReactOS_Debug");
}
else
#endif
{
/* DefaultOS=ReactOS */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"DefaultOS",
L"ReactOS");
}
#ifdef DBG
if (IsUnattendedSetup)
#endif
{
/* Timeout=0 for unattended or non debug*/
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"TimeOut",
L"0");
}
#ifdef DBG
else
{
/* Timeout=0 or 10 */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"TimeOut",
L"10");
}
#endif
/* Create "Display" section */
IniSection = IniCacheAppendSection(IniCache,
L"Display");
/* TitleText=ReactOS Boot Manager */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"TitleText",
L"ReactOS Boot Manager");
/* StatusBarColor=Cyan */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"StatusBarColor",
L"Cyan");
/* StatusBarTextColor=Black */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"StatusBarTextColor",
L"Black");
/* BackdropTextColor=White */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"BackdropTextColor",
L"White");
/* BackdropColor=Blue */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"BackdropColor",
L"Blue");
/* BackdropFillStyle=Medium */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"BackdropFillStyle",
L"Medium");
/* TitleBoxTextColor=White */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"TitleBoxTextColor",
L"White");
/* TitleBoxColor=Red */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"TitleBoxColor",
L"Red");
/* MessageBoxTextColor=White */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"MessageBoxTextColor",
L"White");
/* MessageBoxColor=Blue */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"MessageBoxColor",
L"Blue");
/* MenuTextColor=White */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"MenuTextColor",
L"Gray");
/* MenuColor=Blue */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"MenuColor",
L"Black");
/* TextColor=Yellow */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"TextColor",
L"Gray");
/* SelectedTextColor=Black */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"SelectedTextColor",
L"Black");
/* SelectedColor=Gray */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"SelectedColor",
L"Gray");
/* SelectedColor=Gray */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"ShowTime",
L"No");
/* SelectedColor=Gray */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"MenuBox",
L"No");
/* SelectedColor=Gray */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"CenterMenu",
L"No");
/* SelectedColor=Gray */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"MinimalUI",
L"Yes");
/* SelectedColor=Gray */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"TimeText",
L"Seconds until highlighted choice will be started automatically: ");
}
NTSTATUS
CreateFreeLoaderIniForDos(PWCHAR IniPath,
PWCHAR ArcPath)
{
PINICACHE IniCache;
PINICACHESECTION IniSection;
IniCache = IniCacheCreate();
CreateCommonFreeLoaderSections(IniCache);
/* Create "Operating Systems" section */
IniSection = IniCacheAppendSection(IniCache,
L"Operating Systems");
/* REACTOS=ReactOS */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"ReactOS",
L"\"ReactOS\"");
/* ReactOS_Debug="ReactOS (Debug)" */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"ReactOS_Debug",
L"\"ReactOS (Debug)\"");
/* DOS=Dos/Windows */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"DOS",
L"\"DOS/Windows\"");
/* Create "ReactOS" section */
IniSection = IniCacheAppendSection(IniCache,
L"ReactOS");
/* BootType=ReactOS */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"BootType",
L"ReactOS");
/* SystemPath=<ArcPath> */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"SystemPath",
ArcPath);
/* Create "ReactOS_Debug" section */
IniSection = IniCacheAppendSection(IniCache,
L"ReactOS_Debug");
/* BootType=ReactOS */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"BootType",
L"ReactOS");
/* SystemPath=<ArcPath> */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"SystemPath",
ArcPath);
/* Options=/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS*/
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"Options",
L"/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS");
/* Create "DOS" section */
IniSection = IniCacheAppendSection(IniCache,
L"DOS");
/* BootType=BootSector */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"BootType",
L"BootSector");
/* BootDrive=hd0 */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"BootDrive",
L"hd0");
/* BootPartition=1 */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"BootPartition",
L"1");
/* BootSector=BOOTSECT.DOS */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"BootSectorFile",
L"BOOTSECT.DOS");
IniCacheSave(IniCache, IniPath);
IniCacheDestroy(IniCache);
return(STATUS_SUCCESS);
}
NTSTATUS
CreateFreeLoaderIniForReactos(PWCHAR IniPath,
PWCHAR ArcPath)
{
PINICACHE IniCache;
PINICACHESECTION IniSection;
IniCache = IniCacheCreate();
CreateCommonFreeLoaderSections(IniCache);
/* Create "Operating Systems" section */
IniSection = IniCacheAppendSection(IniCache,
L"Operating Systems");
/* ReactOS="ReactOS" */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"ReactOS",
L"\"ReactOS\"");
/* ReactOS_Debug="ReactOS (Debug)" */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"ReactOS_Debug",
L"\"ReactOS (Debug)\"");
/* Create "ReactOS" section */
IniSection = IniCacheAppendSection(IniCache,
L"ReactOS");
/* BootType=ReactOS */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"BootType",
L"ReactOS");
/* SystemPath=<ArcPath> */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"SystemPath",
ArcPath);
/* Options=/SOS*/
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"Options",
L"/SOS");
/* Create "ReactOS_Debug" section */
IniSection = IniCacheAppendSection(IniCache,
L"ReactOS_Debug");
/* BootType=ReactOS */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"BootType",
L"ReactOS");
/* SystemPath=<ArcPath> */
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"SystemPath",
ArcPath);
/* Options=/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS*/
IniCacheInsertKey(IniSection,
NULL,
INSERT_LAST,
L"Options",
L"/DEBUG /DEBUGPORT=COM1 /BAUDRATE=115200 /SOS");
/* Save the ini file */
IniCacheSave(IniCache, IniPath);
IniCacheDestroy(IniCache);
return(STATUS_SUCCESS);
}
NTSTATUS
UpdateFreeLoaderIni(PWCHAR IniPath,
PWCHAR ArcPath)
{
UNICODE_STRING Name;
PINICACHE IniCache;
PINICACHESECTION IniSection;
PINICACHESECTION OsIniSection;
WCHAR SectionName[80];
WCHAR OsName[80];
WCHAR SystemPath[200];
WCHAR SectionName2[200];
PWCHAR KeyData;
ULONG i,j;
NTSTATUS Status;
RtlInitUnicodeString(&Name,
IniPath);
Status = IniCacheLoad(&IniCache,
&Name,
FALSE);
if (!NT_SUCCESS(Status))
return(Status);
/* Get "Operating Systems" section */
IniSection = IniCacheGetSection(IniCache,
L"Operating Systems");
if (IniSection == NULL)
{
IniCacheDestroy(IniCache);
return(STATUS_UNSUCCESSFUL);
}
/* Find an existing usable or an unused section name */
i = 1;
wcscpy(SectionName, L"ReactOS");
wcscpy(OsName, L"\"ReactOS\"");
while(TRUE)
{
Status = IniCacheGetKey(IniSection,
SectionName,
&KeyData);
if (!NT_SUCCESS(Status))
break;
/* Get operation system section */
if (KeyData[0] == '"')
{
wcscpy(SectionName2, &KeyData[1]);
j = wcslen(SectionName2);
if (j > 0)
{
SectionName2[j-1] = 0;
}
}
else
{
wcscpy(SectionName2, KeyData);
}
OsIniSection = IniCacheGetSection(IniCache,
SectionName2);
if (OsIniSection != NULL)
{
BOOLEAN UseExistingEntry = TRUE;
/* Check BootType */
Status = IniCacheGetKey(OsIniSection,
L"BootType",
&KeyData);
if (NT_SUCCESS(Status))
{
if (KeyData == NULL
|| (_wcsicmp(KeyData, L"ReactOS") != 0
&& _wcsicmp(KeyData, L"\"ReactOS\"") != 0))
{
/* This is not a ReactOS entry */
UseExistingEntry = FALSE;
}
}
else
{
UseExistingEntry = FALSE;
}
if (UseExistingEntry)
{
/* BootType is ReactOS. Now check SystemPath */
Status = IniCacheGetKey(OsIniSection,
L"SystemPath",
&KeyData);
if (NT_SUCCESS(Status))
{
swprintf(SystemPath, L"\"%S\"", ArcPath);
if (KeyData == NULL
|| (_wcsicmp(KeyData, ArcPath) != 0
&& _wcsicmp(KeyData, SystemPath) != 0))
{
/* This entry is a ReactOS entry, but the SystemRoot does not
match the one we are looking for */
UseExistingEntry = FALSE;
}
}
else
{
UseExistingEntry = FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -