Create the AHCI branch for Aman's work
[reactos.git] / base / applications / msconfig_new / systempage.c
1 /*
2 * PROJECT: ReactOS Applications
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: base/applications/msconfig_new/systempage.c
5 * PURPOSE: System 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
12 HWND hSystemPage;
13 HWND hSystemDialog;
14
15 #define BUFFER_SIZE 512
16
17 static BOOL
18 LoadSystemIni(WCHAR * szPath, HWND hDlg)
19 {
20 WCHAR szBuffer[BUFFER_SIZE];
21 HWND hDlgCtrl;
22 HTREEITEM parent = NULL;
23 FILE* file;
24 UINT length;
25 TVINSERTSTRUCT insert;
26 HRESULT hr;
27
28 hr = StringCbCopyW(szBuffer, sizeof(szBuffer), szPath);
29 if (FAILED(hr))
30 return FALSE;
31
32 hr = StringCbCatW(szBuffer, sizeof(szBuffer), L"\\system.ini");
33 if (FAILED(hr))
34 return FALSE;
35
36 file = _wfopen(szBuffer, L"rt");
37 if (!file)
38 return FALSE;
39
40 hDlgCtrl = GetDlgItem(hDlg, IDC_SYSTEM_TREE);
41
42 while(!feof(file))
43 {
44 if (fgetws(szBuffer, BUFFER_SIZE, file))
45 {
46 length = wcslen(szBuffer);
47 if (length > 1)
48 {
49 szBuffer[length] = L'\0';
50 szBuffer[length - 1] = L'\0';
51 insert.hInsertAfter = TVI_LAST;
52 insert.item.mask = TVIF_TEXT;
53 insert.item.pszText = szBuffer;
54
55 if (szBuffer[0] == L';' || szBuffer[0] == L'[')
56 {
57 /* Parent */
58 insert.hParent = NULL;
59 parent = TreeView_InsertItem(hDlgCtrl, &insert);
60 }
61 else
62 {
63 /* Child */
64 insert.hParent = parent;
65 TreeView_InsertItem(hDlgCtrl, &insert);
66 }
67 }
68 }
69 }
70
71 fclose(file);
72
73 return TRUE;
74 }
75
76 static BOOL
77 InitializeSystemDialog(HWND hDlg)
78 {
79 WCHAR winDir[PATH_MAX];
80
81 GetWindowsDirectoryW(winDir, PATH_MAX);
82 return LoadSystemIni(winDir, hDlg);
83 }
84
85
86 INT_PTR CALLBACK
87 SystemPageWndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
88 {
89 UNREFERENCED_PARAMETER(lParam);
90 UNREFERENCED_PARAMETER(wParam);
91 switch (message) {
92 case WM_INITDIALOG:
93 {
94 hSystemDialog = hDlg;
95 SetWindowPos(hDlg, NULL, 10, 32, 0, 0, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER);
96 InitializeSystemDialog(hDlg);
97 return TRUE;
98 }
99 }
100
101 return 0;
102 }