Create a branch for header work.
[reactos.git] / base / applications / msconfig / freeldrpage.c
1 /*
2 * PROJECT: ReactOS Applications
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: base/applications/freeldrpage.c
5 * PURPOSE: Freeloader configuration page message handler
6 * COPYRIGHT: Copyright 2005-2006 Christoph von Wittich <Christoph@ApiViewer.de>
7 *
8 */
9
10 #include <precomp.h>
11
12 HWND hFreeLdrPage;
13 HWND hFreeLdrDialog;
14
15 typedef struct
16 {
17 ULONG TimeOut;
18 WCHAR szDefaultOS[512];
19 ULONG szDefaultPos;
20 ULONG OSConfigurationCount;
21 BOOL UseBootIni;
22 } FREELDR_SETTINGS;
23
24 static FREELDR_SETTINGS Settings = { 0, { 0, }, 0, 0, FALSE };
25
26
27 BOOL
28 LoadBootIni(WCHAR * szDrive, HWND hDlg)
29 {
30 WCHAR szBuffer[512];
31 HWND hDlgCtrl;
32 FILE * file;
33 UINT length;
34 LRESULT pos;
35
36 wcscpy(szBuffer, szDrive);
37 wcscat(szBuffer, L"boot.ini");
38
39 file = _wfopen(szBuffer, L"rt");
40 if (!file)
41 return FALSE;
42
43 hDlgCtrl = GetDlgItem(hDlg, IDC_LIST_BOX);
44
45 while(!feof(file))
46 {
47 if (fgetws(szBuffer, sizeof(szBuffer) / sizeof(WCHAR), file))
48 {
49 length = wcslen(szBuffer);
50 while(szBuffer[length] < 14) //FIXME remove line feeds
51 szBuffer[length--] = 0;
52
53 pos = SendMessageW(hDlgCtrl, LB_ADDSTRING, 0, (LPARAM)szBuffer);
54
55
56 if (szBuffer[0] == L'[')
57 continue;
58
59 if (!wcsncmp(szBuffer, L"timeout=", 8))
60 {
61 Settings.TimeOut = _wtoi(&szBuffer[8]);
62 continue;
63 }
64
65 if (!wcsncmp(szBuffer, L"default=", 8))
66 {
67 wcscpy(Settings.szDefaultOS, &szBuffer[8]);
68 continue;
69 }
70 if (pos != LB_ERR)
71 SendMessage(hDlgCtrl, LB_SETITEMDATA, pos, 1); // indicate that this item is an boot entry
72 Settings.OSConfigurationCount++;
73 }
74 }
75
76 fclose(file);
77 Settings.UseBootIni = TRUE;
78
79 pos = SendMessageW(hDlgCtrl, LB_FINDSTRING, 3, (LPARAM)Settings.szDefaultOS);
80 if (pos != LB_ERR)
81 {
82 Settings.szDefaultPos = pos;
83 SendMessage(hDlgCtrl, LB_SETCURSEL, pos, 0);
84 }
85
86 SetDlgItemInt(hDlg, IDC_TXT_BOOT_TIMEOUT, Settings.TimeOut, FALSE);
87 if (Settings.OSConfigurationCount < 2)
88 {
89 EnableWindow(GetDlgItem(hDlg, IDC_BTN_SET_DEFAULT_BOOT), FALSE);
90 EnableWindow(GetDlgItem(hDlg, IDC_BTN_MOVE_UP_BOOT_OPTION), FALSE);
91 EnableWindow(GetDlgItem(hDlg, IDC_BTN_MOVE_DOWN_BOOT_OPTION), FALSE);
92 }
93 return TRUE;
94 }
95
96
97 BOOL
98 InitializeDialog(HWND hDlg)
99 {
100 // FIXME
101 // find real boot drive and handle freeldr configuration ini
102 return LoadBootIni(L"C:\\", hDlg);
103 }
104
105
106
107 INT_PTR CALLBACK
108 FreeLdrPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
109 {
110 LRESULT pos;
111
112 UNREFERENCED_PARAMETER(lParam);
113 UNREFERENCED_PARAMETER(wParam);
114
115 switch (message) {
116 case WM_INITDIALOG:
117 hFreeLdrDialog = hDlg;
118 SetWindowPos(hDlg, NULL, 10, 32, 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
119 InitializeDialog(hDlg);
120 return TRUE;
121 case WM_COMMAND:
122 switch(HIWORD(wParam))
123 {
124 case LBN_SELCHANGE:
125 pos = SendMessage((HWND)lParam, LB_GETCURSEL, 0, 0);
126 if (pos != LB_ERR)
127 {
128 LPARAM res = SendMessage((HWND)lParam, LB_GETITEMDATA, pos, 0);
129 if (!res) //line is not a default one
130 SendMessage((HWND)lParam, LB_SETCURSEL, Settings.szDefaultPos, 0);
131 else
132 Settings.szDefaultPos = pos;
133
134
135 }
136 break;
137 }
138 }
139 return 0;
140 }