ReactOS 0.4.15-dev-6047-gb29e82d
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
15typedef struct
16{
18 WCHAR szDefaultOS[512];
23
24static FREELDR_SETTINGS Settings = { 0, { 0, }, 0, 0, FALSE };
25
26#define BUFFER_SIZE 512
27
28static BOOL
29LoadBootIni(WCHAR *szDrive, HWND hDlg)
30{
31 WCHAR szBuffer[BUFFER_SIZE];
32 HWND hDlgCtrl;
33 FILE * file;
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
117static 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:
149 if (pos != LB_ERR)
150 {
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 IDC_LIST_BOX
Definition: resource.h:30
#define IDC_BTN_SET_DEFAULT_BOOT
Definition: resource.h:32
#define IDC_BTN_MOVE_DOWN_BOOT_OPTION
Definition: resource.h:34
#define IDC_BTN_MOVE_UP_BOOT_OPTION
Definition: resource.h:33
#define IDC_TXT_BOOT_TIMEOUT
Definition: resource.h:41
#define PATH_MAX
Definition: types.h:280
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define wcschr
Definition: compat.h:17
#define CALLBACK
Definition: compat.h:35
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2352
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint res
Definition: glext.h:9613
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
_Check_return_ _CRTIMP int __cdecl feof(_In_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define FAILED(hr)
Definition: intsafe.h:51
static PVOID ptr
Definition: dispmode.c:27
HWND hFreeLdrPage
Definition: freeldrpage.c:12
INT_PTR CALLBACK FreeLdrPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: freeldrpage.c:134
#define BUFFER_SIZE
Definition: freeldrpage.c:26
static BOOL InitializeFreeLDRDialog(HWND hDlg)
Definition: freeldrpage.c:118
HWND hFreeLdrDialog
Definition: freeldrpage.c:13
static BOOL LoadBootIni(WCHAR *szDrive, HWND hDlg)
Definition: freeldrpage.c:29
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_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)
HRESULT hr
Definition: shlfolder.c:183
STRSAFEAPI StringCbCopyW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:166
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
ULONG OSConfigurationCount
Definition: freeldrpage.c:20
Definition: fci.c:127
Definition: tftpd.h:60
int32_t INT_PTR
Definition: typedefs.h:64
uint32_t ULONG
Definition: typedefs.h:59
#define HIWORD(l)
Definition: typedefs.h:247
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_POWER_POLICY_IDLE_SETTINGS Settings
Definition: wdfdevice.h:2595
LONG_PTR LPARAM
Definition: windef.h:208
LONG_PTR LRESULT
Definition: windef.h:209
UINT_PTR WPARAM
Definition: windef.h:207
#define LB_ERR
Definition: winuser.h:2422
#define SWP_NOACTIVATE
Definition: winuser.h:1232
#define LB_GETITEMDATA
Definition: winuser.h:2031
BOOL WINAPI SetWindowPos(_In_ HWND, _In_opt_ HWND, _In_ int, _In_ int, _In_ int, _In_ int, _In_ UINT)
#define WM_COMMAND
Definition: winuser.h:1730
#define SWP_NOSIZE
Definition: winuser.h:1235
#define WM_INITDIALOG
Definition: winuser.h:1729
#define LB_ADDSTRING
Definition: winuser.h:2021
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
BOOL WINAPI SetDlgItemInt(_In_ HWND, _In_ int, _In_ UINT, _In_ BOOL)
#define LB_FINDSTRING
Definition: winuser.h:2024
#define SendMessage
Definition: winuser.h:5833
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define LB_SETITEMDATA
Definition: winuser.h:2055
#define LBN_SELCHANGE
Definition: winuser.h:2065
#define SWP_NOOWNERZORDER
Definition: winuser.h:1239
#define LB_SETCURSEL
Definition: winuser.h:2053
#define SWP_NOZORDER
Definition: winuser.h:1237
#define LB_GETCURSEL
Definition: winuser.h:2029
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
wchar_t * fgetws(wchar_t *buf, int bufsize, FILE *file)
Definition: wmain.c:22
__wchar_t WCHAR
Definition: xmlstorage.h:180