2006-04-09 12:15:43 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Applications
|
2007-01-05 20:15:07 +00:00
|
|
|
* LICENSE: LGPL - See COPYING in the top level directory
|
2011-05-17 18:32:51 +00:00
|
|
|
* FILE: base/applications/msconfig/freeldrpage.c
|
2006-04-09 12:15:43 +00:00
|
|
|
* PURPOSE: Freeloader configuration page message handler
|
|
|
|
* COPYRIGHT: Copyright 2005-2006 Christoph von Wittich <Christoph@ApiViewer.de>
|
2011-05-17 18:32:51 +00:00
|
|
|
* 2011 Gregor Schneider <Gregor.Schneider@reactos.org>
|
2006-04-09 12:15:43 +00:00
|
|
|
*/
|
|
|
|
|
2013-01-24 23:00:42 +00:00
|
|
|
#include "precomp.h"
|
2006-02-16 23:18:11 +00:00
|
|
|
|
|
|
|
HWND hFreeLdrPage;
|
|
|
|
HWND hFreeLdrDialog;
|
|
|
|
|
2008-03-07 16:48:07 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
ULONG TimeOut;
|
|
|
|
WCHAR szDefaultOS[512];
|
|
|
|
ULONG szDefaultPos;
|
|
|
|
ULONG OSConfigurationCount;
|
|
|
|
BOOL UseBootIni;
|
2008-12-03 17:34:49 +00:00
|
|
|
} FREELDR_SETTINGS;
|
2008-03-07 16:48:07 +00:00
|
|
|
|
2008-12-03 17:34:49 +00:00
|
|
|
static FREELDR_SETTINGS Settings = { 0, { 0, }, 0, 0, FALSE };
|
2008-03-07 16:48:07 +00:00
|
|
|
|
2011-05-17 18:32:51 +00:00
|
|
|
#define BUFFER_SIZE 512
|
2008-03-07 16:48:07 +00:00
|
|
|
|
2011-05-17 18:32:51 +00:00
|
|
|
static BOOL
|
|
|
|
LoadBootIni(WCHAR *szDrive, HWND hDlg)
|
2008-03-07 16:48:07 +00:00
|
|
|
{
|
2011-05-17 18:32:51 +00:00
|
|
|
WCHAR szBuffer[BUFFER_SIZE];
|
|
|
|
HWND hDlgCtrl;
|
|
|
|
FILE * file;
|
|
|
|
UINT length;
|
|
|
|
LRESULT pos;
|
2014-01-19 08:20:45 +00:00
|
|
|
HRESULT hr;
|
2008-03-07 16:48:07 +00:00
|
|
|
|
2014-01-19 08:20:45 +00:00
|
|
|
hr = StringCbCopyW(szBuffer, sizeof(szBuffer), szDrive);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
hr = StringCbCatW(szBuffer, sizeof(szBuffer), L"freeldr.ini");
|
|
|
|
if (FAILED(hr))
|
|
|
|
return FALSE;
|
2008-03-07 16:48:07 +00:00
|
|
|
|
2011-05-17 18:32:51 +00:00
|
|
|
file = _wfopen(szBuffer, L"rt");
|
|
|
|
if (!file)
|
|
|
|
{
|
2014-01-19 08:20:45 +00:00
|
|
|
hr = StringCbCopyW(szBuffer, sizeof(szBuffer), szDrive);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
hr = StringCbCatW(szBuffer, sizeof(szBuffer), L"boot.ini");
|
|
|
|
if (FAILED(hr))
|
|
|
|
return FALSE;
|
|
|
|
|
2011-05-17 18:32:51 +00:00
|
|
|
file = _wfopen(szBuffer, L"rt");
|
|
|
|
if (!file)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-03-07 16:48:07 +00:00
|
|
|
|
2011-05-17 18:32:51 +00:00
|
|
|
hDlgCtrl = GetDlgItem(hDlg, IDC_LIST_BOX);
|
2008-03-07 16:48:07 +00:00
|
|
|
|
2011-05-17 18:32:51 +00:00
|
|
|
while(!feof(file))
|
|
|
|
{
|
|
|
|
if (fgetws(szBuffer, BUFFER_SIZE, file))
|
|
|
|
{
|
|
|
|
length = wcslen(szBuffer);
|
|
|
|
if (length > 1)
|
2008-03-07 16:48:07 +00:00
|
|
|
{
|
2011-05-17 18:32:51 +00:00
|
|
|
szBuffer[length] = L'\0';
|
|
|
|
szBuffer[length - 1] = L'\0';
|
2008-03-07 16:48:07 +00:00
|
|
|
|
2011-05-17 18:32:51 +00:00
|
|
|
pos = SendMessageW(hDlgCtrl, LB_ADDSTRING, 0, (LPARAM)szBuffer);
|
|
|
|
|
|
|
|
if (szBuffer[0] == L'[')
|
|
|
|
continue;
|
|
|
|
|
2012-04-21 10:41:16 +00:00
|
|
|
if (!_wcsnicmp(szBuffer, L"timeout=", 8))
|
2011-05-17 18:32:51 +00:00
|
|
|
{
|
|
|
|
Settings.TimeOut = _wtoi(&szBuffer[8]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-04-21 10:41:16 +00:00
|
|
|
if (!_wcsnicmp(szBuffer, L"default=", 8))
|
2011-05-17 18:32:51 +00:00
|
|
|
{
|
|
|
|
wcscpy(Settings.szDefaultOS, &szBuffer[8]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (pos != LB_ERR)
|
|
|
|
SendMessage(hDlgCtrl, LB_SETITEMDATA, pos, 1); // indicate that this item is an boot entry
|
|
|
|
Settings.OSConfigurationCount++;
|
2008-03-07 16:48:07 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-17 18:32:51 +00:00
|
|
|
}
|
2008-03-07 16:48:07 +00:00
|
|
|
|
2011-05-17 18:32:51 +00:00
|
|
|
fclose(file);
|
|
|
|
Settings.UseBootIni = TRUE;
|
2008-03-07 16:48:07 +00:00
|
|
|
|
2011-05-17 18:32:51 +00:00
|
|
|
pos = SendMessageW(hDlgCtrl, LB_FINDSTRING, 3, (LPARAM)Settings.szDefaultOS);
|
|
|
|
if (pos != LB_ERR)
|
|
|
|
{
|
2008-03-07 16:48:07 +00:00
|
|
|
Settings.szDefaultPos = pos;
|
|
|
|
SendMessage(hDlgCtrl, LB_SETCURSEL, pos, 0);
|
2011-05-17 18:32:51 +00:00
|
|
|
}
|
2008-03-07 16:48:07 +00:00
|
|
|
|
2011-05-17 18:32:51 +00:00
|
|
|
SetDlgItemInt(hDlg, IDC_TXT_BOOT_TIMEOUT, Settings.TimeOut, FALSE);
|
|
|
|
if (Settings.OSConfigurationCount < 2)
|
|
|
|
{
|
2008-03-07 16:48:07 +00:00
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_BTN_SET_DEFAULT_BOOT), FALSE);
|
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_BTN_MOVE_UP_BOOT_OPTION), FALSE);
|
|
|
|
EnableWindow(GetDlgItem(hDlg, IDC_BTN_MOVE_DOWN_BOOT_OPTION), FALSE);
|
2011-05-17 18:32:51 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
2008-03-07 16:48:07 +00:00
|
|
|
}
|
|
|
|
|
2011-05-17 18:32:51 +00:00
|
|
|
static BOOL
|
|
|
|
InitializeFreeLDRDialog(HWND hDlg)
|
2008-03-07 16:48:07 +00:00
|
|
|
{
|
2011-05-17 18:32:51 +00:00
|
|
|
WCHAR winDir[PATH_MAX];
|
|
|
|
WCHAR* ptr = NULL;
|
|
|
|
|
|
|
|
GetWindowsDirectoryW(winDir, PATH_MAX);
|
|
|
|
ptr = wcschr(winDir, L'\\');
|
|
|
|
if (ptr == NULL)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ptr[1] = L'\0';
|
|
|
|
return LoadBootIni(winDir, hDlg);
|
2008-03-07 16:48:07 +00:00
|
|
|
}
|
|
|
|
|
2006-02-16 23:18:11 +00:00
|
|
|
INT_PTR CALLBACK
|
|
|
|
FreeLdrPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2008-03-07 16:48:07 +00:00
|
|
|
LRESULT pos;
|
|
|
|
|
2006-02-16 23:18:11 +00:00
|
|
|
switch (message) {
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
hFreeLdrDialog = hDlg;
|
2006-08-29 13:01:47 +00:00
|
|
|
SetWindowPos(hDlg, NULL, 10, 32, 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
|
2011-05-17 18:32:51 +00:00
|
|
|
InitializeFreeLDRDialog(hDlg);
|
2006-08-29 13:01:47 +00:00
|
|
|
return TRUE;
|
2008-03-07 16:48:07 +00:00
|
|
|
case WM_COMMAND:
|
|
|
|
switch(HIWORD(wParam))
|
|
|
|
{
|
|
|
|
case LBN_SELCHANGE:
|
|
|
|
pos = SendMessage((HWND)lParam, LB_GETCURSEL, 0, 0);
|
|
|
|
if (pos != LB_ERR)
|
|
|
|
{
|
|
|
|
LPARAM res = SendMessage((HWND)lParam, LB_GETITEMDATA, pos, 0);
|
2014-01-19 08:20:45 +00:00
|
|
|
if (!res) /* line is not a default one */
|
2008-03-07 16:48:07 +00:00
|
|
|
SendMessage((HWND)lParam, LB_SETCURSEL, Settings.szDefaultPos, 0);
|
|
|
|
else
|
|
|
|
Settings.szDefaultPos = pos;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-08-29 13:01:47 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2006-02-16 23:18:11 +00:00
|
|
|
}
|