📄 startrec.c
字号:
/*
* PROJECT: ReactOS System Control Panel Applet
* LICENSE: GPL - See COPYING in the top level directory
* FILE: dll/cpl/sysdm/startrec.c
* PURPOSE: Computer settings for startup and recovery
* COPYRIGHT: Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
* Copyright 2006 Christoph von Wittich <Christoph@ApiViewer.de>
*
*/
#include "precomp.h"
static TCHAR m_szFreeldrIni[MAX_PATH + 15];
static int m_FreeLdrIni = 0;
void SetTimeout(HWND hwndDlg, int Timeout)
{
if (Timeout == 0)
{
EnableWindow(GetDlgItem(hwndDlg, IDC_STRRECLISTUPDWN), FALSE);
}
else
{
EnableWindow(GetDlgItem(hwndDlg, IDC_STRRECLISTUPDWN), TRUE);
}
SendDlgItemMessage(hwndDlg, IDC_STRRECLISTUPDWN, UDM_SETPOS, (WPARAM) 0, (LPARAM) MAKELONG((short) Timeout, 0));
}
DWORD GetSystemDrive(TCHAR ** szSystemDrive)
{
DWORD dwBufSize;
/* get Path to freeldr.ini or boot.ini */
*szSystemDrive = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(TCHAR));
if (szSystemDrive != NULL)
{
dwBufSize = GetEnvironmentVariable(_T("SystemDrive"), *szSystemDrive, MAX_PATH);
if (dwBufSize > MAX_PATH)
{
TCHAR *szTmp;
DWORD dwBufSize2;
szTmp = HeapReAlloc(GetProcessHeap(), 0, *szSystemDrive, dwBufSize * sizeof(TCHAR));
if (szTmp == NULL)
goto FailGetSysDrive;
*szSystemDrive = szTmp;
dwBufSize2 = GetEnvironmentVariable(_T("SystemDrive"), *szSystemDrive, dwBufSize);
if (dwBufSize2 > dwBufSize || dwBufSize2 == 0)
goto FailGetSysDrive;
}
else if (dwBufSize == 0)
{
FailGetSysDrive:
HeapFree(GetProcessHeap(), 0, szSystemDrive);
*szSystemDrive = NULL;
return FALSE;
}
return dwBufSize;
}
return FALSE;
}
PBOOTRECORD ReadFreeldrSection(HINF hInf, TCHAR * szSectionName)
{
PBOOTRECORD pRecord;
INFCONTEXT InfContext;
TCHAR szName[MAX_PATH];
TCHAR szValue[MAX_PATH];
DWORD LineLength;
if (!SetupFindFirstLine(hInf,
szSectionName,
NULL,
&InfContext))
{
/* failed to find section */
return NULL;
}
pRecord = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BOOTRECORD));
if (pRecord == NULL)
{
return NULL;
}
_tcscpy(pRecord->szSectionName, szSectionName);
do
{
if (!SetupGetStringField(&InfContext,
0,
szName,
sizeof(szName) / sizeof(TCHAR),
&LineLength))
{
break;
}
if (!SetupGetStringField(&InfContext,
1,
szValue,
sizeof(szValue) / sizeof(TCHAR),
&LineLength))
{
break;
}
if (!_tcsnicmp(szName, _T("BootType"), 8))
{
if (!_tcsnicmp(szValue, _T("ReactOS"), 7))
{
//FIXME store as enum
pRecord->BootType = 1;
}
else
{
pRecord->BootType = 0;
}
}
else if (!_tcsnicmp(szName, _T("SystemPath"), 10))
{
_tcscpy(pRecord->szBootPath, szValue);
}
else if (!_tcsnicmp(szName, _T("Options"), 7))
{
//FIXME store flags as values
_tcscpy(pRecord->szOptions, szValue);
}
}while(SetupFindNextLine(&InfContext, &InfContext));
return pRecord;
}
int LoadFreeldrSettings(HINF hInf, HWND hwndDlg)
{
INFCONTEXT InfContext;
PBOOTRECORD pRecord;
TCHAR szDefaultOs[MAX_PATH];
TCHAR szName[MAX_PATH];
TCHAR szValue[MAX_PATH];
DWORD LineLength;
DWORD TimeOut;
LRESULT lResult;
if (!SetupFindFirstLine(hInf,
_T("FREELOADER"),
_T("DefaultOS"),
&InfContext))
{
/* failed to find default os */
return FALSE;
}
if (!SetupGetStringField(&InfContext,
1,
szDefaultOs,
sizeof(szDefaultOs) / sizeof(TCHAR),
&LineLength))
{
/* no key */
return FALSE;
}
if (!SetupFindFirstLine(hInf,
_T("FREELOADER"),
_T("TimeOut"),
&InfContext))
{
/* expected to find timeout value */
return FALSE;
}
if (!SetupGetIntField(&InfContext,
1,
(PINT)&TimeOut))
{
/* failed to retrieve timeout */
return FALSE;
}
if (!SetupFindFirstLine(hInf,
_T("Operating Systems"),
NULL,
&InfContext))
{
/* expected list of operating systems */
return FALSE;
}
do
{
if (!SetupGetStringField(&InfContext,
0,
szName,
sizeof(szName) / sizeof(TCHAR),
&LineLength))
{
/* the ini file is messed up */
return FALSE;
}
if (!SetupGetStringField(&InfContext,
1,
szValue,
sizeof(szValue) / sizeof(TCHAR),
&LineLength))
{
/* the ini file is messed up */
return FALSE;
}
pRecord = ReadFreeldrSection(hInf, szName);
if (pRecord)
{
lResult = SendDlgItemMessage(hwndDlg, IDC_STRECOSCOMBO, CB_ADDSTRING, (WPARAM)0, (LPARAM)szValue);
if (lResult != CB_ERR)
{
SendDlgItemMessage(hwndDlg, IDC_STRECOSCOMBO, CB_SETITEMDATA, (WPARAM)lResult, (LPARAM)pRecord);
if (!_tcscmp(szDefaultOs, szName))
{
/* we store the friendly name as key */
_tcscpy(szDefaultOs, szValue);
}
}
else
{
HeapFree(GetProcessHeap(), 0, pRecord);
}
}
}while(SetupFindNextLine(&InfContext, &InfContext));
/* find default os in list */
lResult = SendDlgItemMessage(hwndDlg, IDC_STRECOSCOMBO, CB_FINDSTRING, (WPARAM)-1, (LPARAM)szDefaultOs);
if (lResult != CB_ERR)
{
/* set cur sel */
SendDlgItemMessage(hwndDlg, IDC_STRECOSCOMBO, CB_SETCURSEL, (WPARAM)lResult, (LPARAM)0);
}
SetTimeout(hwndDlg, TimeOut);
return TRUE;
}
int LoadBootSettings(HINF hInf, HWND hwndDlg)
{
INFCONTEXT InfContext;
TCHAR szName[MAX_PATH];
TCHAR szValue[MAX_PATH];
DWORD LineLength;
DWORD TimeOut = 0;
TCHAR szDefaultOS[MAX_PATH];
TCHAR szOptions[MAX_PATH];
PBOOTRECORD pRecord;
LRESULT lResult;
if(!SetupFindFirstLine(hInf,
_T("boot loader"),
NULL,
&InfContext))
{
return FALSE;
}
do
{
if (!SetupGetStringField(&InfContext,
0,
szName,
sizeof(szName) / sizeof(TCHAR),
&LineLength))
{
return FALSE;
}
if (!SetupGetStringField(&InfContext,
1,
szValue,
sizeof(szValue) / sizeof(TCHAR),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -