ReactOS  0.4.12-dev-43-g63b00d8
freeldrpage.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Applications
3  * LICENSE: LGPL - See COPYING in the top level directory
4  * FILE: base/applications/msconfig/freeldrpage.c
5  * PURPOSE: Freeloader configuration page message handler
6  * COPYRIGHT: Copyright 2005-2006 Christoph von Wittich <Christoph@ApiViewer.de>
7  * 2011 Gregor Schneider <Gregor.Schneider@reactos.org>
8  */
9 
10 #include "precomp.h"
11 
14 
15 typedef struct
16 {
18  WCHAR szDefaultOS[512];
23 
24 static FREELDR_SETTINGS Settings = { 0, { 0, }, 0, 0, FALSE };
25 
26 #define BUFFER_SIZE 512
27 
28 static BOOL
29 LoadBootIni(WCHAR *szDrive, HWND hDlg)
30 {
31  WCHAR szBuffer[BUFFER_SIZE];
32  HWND hDlgCtrl;
33  FILE * file;
34  UINT length;
35  LRESULT pos;
36  HRESULT hr;
37 
38  hr = StringCbCopyW(szBuffer, sizeof(szBuffer), szDrive);
39  if (FAILED(hr))
40  return FALSE;
41 
42  hr = StringCbCatW(szBuffer, sizeof(szBuffer), L"freeldr.ini");
43  if (FAILED(hr))
44  return FALSE;
45 
46  file = _wfopen(szBuffer, L"rt");
47  if (!file)
48  {
49  hr = StringCbCopyW(szBuffer, sizeof(szBuffer), szDrive);
50  if (FAILED(hr))
51  return FALSE;
52 
53  hr = StringCbCatW(szBuffer, sizeof(szBuffer), L"boot.ini");
54  if (FAILED(hr))
55  return FALSE;
56 
57  file = _wfopen(szBuffer, L"rt");
58  if (!file)
59  return FALSE;
60  }
61 
62  hDlgCtrl = GetDlgItem(hDlg, IDC_LIST_BOX);
63 
64  while(!feof(file))
65  {
66  if (fgetws(szBuffer, BUFFER_SIZE, file))
67  {
68  length = wcslen(szBuffer);
69  if (length > 1)
70  {
71  szBuffer[length] = L'\0';
72  szBuffer[length - 1] = L'\0';
73 
74  pos = SendMessageW(hDlgCtrl, LB_ADDSTRING, 0, (LPARAM)szBuffer);
75 
76  if (szBuffer[0] == L'[')
77  continue;
78 
79  if (!_wcsnicmp(szBuffer, L"timeout=", 8))
80  {
81  Settings.TimeOut = _wtoi(&szBuffer[8]);
82  continue;
83  }
84 
85  if (!_wcsnicmp(szBuffer, L"default=", 8))
86  {
87  wcscpy(Settings.szDefaultOS, &szBuffer[8]);
88  continue;
89  }
90  if (pos != LB_ERR)
91  SendMessage(hDlgCtrl, LB_SETITEMDATA, pos, 1); // indicate that this item is an boot entry
92  Settings.OSConfigurationCount++;
93  }
94  }
95  }
96 
97  fclose(file);
98  Settings.UseBootIni = TRUE;
99 
100  pos = SendMessageW(hDlgCtrl, LB_FINDSTRING, 3, (LPARAM)Settings.szDefaultOS);
101  if (pos != LB_ERR)
102  {
103  Settings.szDefaultPos = pos;
104  SendMessage(hDlgCtrl, LB_SETCURSEL, pos, 0);
105  }
106 
108  if (Settings.OSConfigurationCount < 2)
109  {
113  }
114  return TRUE;
115 }
116 
117 static BOOL
119 {
120  WCHAR winDir[PATH_MAX];
121  WCHAR* ptr = NULL;
122 
124  ptr = wcschr(winDir, L'\\');
125  if (ptr == NULL)
126  {
127  return FALSE;
128  }
129  ptr[1] = L'\0';
130  return LoadBootIni(winDir, hDlg);
131 }
132 
135 {
136  LRESULT pos;
137 
138  switch (message) {
139  case WM_INITDIALOG:
140  hFreeLdrDialog = hDlg;
143  return TRUE;
144  case WM_COMMAND:
145  switch(HIWORD(wParam))
146  {
147  case LBN_SELCHANGE:
148  pos = SendMessage((HWND)lParam, LB_GETCURSEL, 0, 0);
149  if (pos != LB_ERR)
150  {
151  LPARAM res = SendMessage((HWND)lParam, LB_GETITEMDATA, pos, 0);
152  if (!res) /* line is not a default one */
153  SendMessage((HWND)lParam, LB_SETCURSEL, Settings.szDefaultPos, 0);
154  else
155  Settings.szDefaultPos = pos;
156 
157 
158  }
159  break;
160  }
161  }
162  return 0;
163 }
#define LB_SETCURSEL
Definition: winuser.h:2024
WCHAR szDefaultOS[512]
Definition: freeldrpage.c:18
Definition: tftpd.h:59
#define TRUE
Definition: types.h:120
#define IDC_TXT_BOOT_TIMEOUT
Definition: resource.h:41
#define LB_ADDSTRING
Definition: winuser.h:1992
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define LB_GETITEMDATA
Definition: winuser.h:2002
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
#define CALLBACK
Definition: compat.h:27
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
#define SWP_NOZORDER
Definition: winuser.h:1232
int32_t INT_PTR
Definition: typedefs.h:62
#define BUFFER_SIZE
Definition: freeldrpage.c:26
#define IDC_LIST_BOX
Definition: resource.h:30
#define LBN_SELCHANGE
Definition: winuser.h:2036
WPARAM wParam
Definition: combotst.c:138
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2351
UINT_PTR WPARAM
Definition: windef.h:207
#define IDC_BTN_MOVE_UP_BOOT_OPTION
Definition: resource.h:33
struct _FREELDR_SETTINGS FREELDR_SETTINGS
#define LB_ERR
Definition: winuser.h:2386
LONG_PTR LPARAM
Definition: windef.h:208
static BOOL InitializeFreeLDRDialog(HWND hDlg)
Definition: freeldrpage.c:118
#define IDC_BTN_MOVE_DOWN_BOOT_OPTION
Definition: resource.h:34
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
_Check_return_ _CRTIMP int __cdecl feof(_In_ FILE *_File)
unsigned int BOOL
Definition: ntddk_ex.h:94
INT_PTR CALLBACK FreeLdrPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: freeldrpage.c:134
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
LONG HRESULT
Definition: typedefs.h:77
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
#define SWP_NOACTIVATE
Definition: winuser.h:1227
const char file[]
Definition: icontest.c:11
unsigned int UINT
Definition: ndis.h:50
#define PATH_MAX
Definition: types.h:280
#define LB_SETITEMDATA
Definition: winuser.h:2026
ULONG OSConfigurationCount
Definition: freeldrpage.c:20
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
BOOL WINAPI SetDlgItemInt(_In_ HWND, _In_ int, _In_ UINT, _In_ BOOL)
static BOOL LoadBootIni(WCHAR *szDrive, HWND hDlg)
Definition: freeldrpage.c:29
static const WCHAR L[]
Definition: oid.c:1087
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define WM_COMMAND
Definition: winuser.h:1716
HWND hFreeLdrPage
Definition: freeldrpage.c:12
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define SWP_NOSIZE
Definition: winuser.h:1230
#define LB_FINDSTRING
Definition: winuser.h:1995
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define LB_GETCURSEL
Definition: winuser.h:2000
static FREELDR_SETTINGS Settings
Definition: freeldrpage.c:24
#define SendMessage
Definition: winuser.h:5709
GLuint res
Definition: glext.h:9613
#define HIWORD(l)
Definition: typedefs.h:246
wchar_t * fgetws(wchar_t *buf, int bufsize, FILE *file)
Definition: wmain.c:22
unsigned int ULONG
Definition: retypes.h:1
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
LONG_PTR LRESULT
Definition: windef.h:209
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
HWND hFreeLdrDialog
Definition: freeldrpage.c:13
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define IDC_BTN_SET_DEFAULT_BOOT
Definition: resource.h:32
#define SWP_NOOWNERZORDER
Definition: winuser.h:1234