- Create KD branch. All debugging support is removed in this branch (no symbols,...
[reactos.git] / reactos / dll / cpl / sysdm / startrec.c
1
2 /*
3 * PROJECT: ReactOS System Control Panel Applet
4 * LICENSE: GPL - See COPYING in the top level directory
5 * FILE: dll/cpl/sysdm/startrec.c
6 * PURPOSE: Computer settings for startup and recovery
7 * COPYRIGHT: Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
8 * Copyright 2006 Christoph von Wittich <Christoph@ApiViewer.de>
9 *
10 */
11
12 #include "precomp.h"
13
14 static TCHAR m_szFreeldrIni[MAX_PATH + 15];
15
16 void SetTimeout(HWND hwndDlg, int Timeout)
17 {
18 if (Timeout == 0)
19 {
20 EnableWindow(GetDlgItem(hwndDlg, IDC_STRRECLISTUPDWN), FALSE);
21 }
22 else
23 {
24 EnableWindow(GetDlgItem(hwndDlg, IDC_STRRECLISTUPDWN), TRUE);
25 }
26 SendDlgItemMessage(hwndDlg, IDC_STRRECLISTUPDWN, UDM_SETPOS, (WPARAM) 0, (LPARAM) MAKELONG((short) Timeout, 0));
27 }
28
29 /* Property page dialog callback */
30 INT_PTR CALLBACK
31 StartRecDlgProc(HWND hwndDlg,
32 UINT uMsg,
33 WPARAM wParam,
34 LPARAM lParam)
35 {
36 TCHAR *szSystemDrive;
37 TCHAR szDefaultOS[MAX_PATH];
38 TCHAR szDefaultOSName[MAX_PATH];
39 TCHAR szTimeout[10];
40 int iTimeout;
41
42 UNREFERENCED_PARAMETER(lParam);
43
44 switch(uMsg)
45 {
46 case WM_INITDIALOG:
47 {
48 DWORD dwBufSize;
49
50 /* get Path to freeldr.ini or boot.ini */
51 szSystemDrive = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(TCHAR));
52 if (szSystemDrive != NULL)
53 {
54 dwBufSize = GetEnvironmentVariable(_T("SystemDrive"), szSystemDrive, MAX_PATH);
55 if (dwBufSize > MAX_PATH)
56 {
57 TCHAR *szTmp;
58 DWORD dwBufSize2;
59
60 szTmp = HeapReAlloc(GetProcessHeap(), 0, szSystemDrive, dwBufSize * sizeof(TCHAR));
61 if (szTmp == NULL)
62 goto FailGetSysDrive;
63
64 szSystemDrive = szTmp;
65
66 dwBufSize2 = GetEnvironmentVariable(_T("SystemDrive"), szSystemDrive, dwBufSize);
67 if (dwBufSize2 > dwBufSize || dwBufSize2 == 0)
68 goto FailGetSysDrive;
69 }
70 else if (dwBufSize == 0)
71 {
72 FailGetSysDrive:
73 HeapFree(GetProcessHeap(), 0, szSystemDrive);
74 szSystemDrive = NULL;
75 }
76
77 if (szSystemDrive != NULL)
78 {
79 if (m_szFreeldrIni != NULL)
80 {
81 _tcscpy(m_szFreeldrIni, szSystemDrive);
82 _tcscat(m_szFreeldrIni, _T("\\freeldr.ini"));
83 if (!PathFileExists(m_szFreeldrIni))
84 {
85 _tcscpy(m_szFreeldrIni, szSystemDrive);
86 _tcscat(m_szFreeldrIni, _T("\\boot.ini"));
87 }
88 }
89 HeapFree(GetProcessHeap(), 0, szSystemDrive);
90 }
91 }
92
93 SetDlgItemText(hwndDlg, IDC_STRRECDUMPFILE, _T("%SystemRoot%\\MiniDump"));
94
95 /* load settings from freeldr.ini */
96 GetPrivateProfileString(_T("boot loader"), _T("default"), NULL, szDefaultOS, MAX_PATH, m_szFreeldrIni);
97 GetPrivateProfileString(_T("operating systems"), szDefaultOS, NULL, szDefaultOSName, MAX_PATH, m_szFreeldrIni);
98 SendDlgItemMessage(hwndDlg, IDC_STRECOSCOMBO, CB_ADDSTRING, (WPARAM)0, (LPARAM)szDefaultOSName);
99 SendDlgItemMessage(hwndDlg, IDC_STRECOSCOMBO, CB_SETCURSEL, (WPARAM)0, (LPARAM)0);
100
101 /* timeout */
102 iTimeout = GetPrivateProfileInt(_T("boot loader"), _T("timeout"), 0, m_szFreeldrIni);
103 SetTimeout(hwndDlg, iTimeout);
104 if (iTimeout != 0)
105 SendDlgItemMessage(hwndDlg, IDC_STRECLIST, BM_SETCHECK, (WPARAM)BST_CHECKED, (LPARAM)0);
106
107 }
108 break;
109
110 case WM_COMMAND:
111 {
112 switch(LOWORD(wParam))
113 {
114 case IDC_STRRECEDIT:
115 {
116 ShellExecute(0, _T("open"), _T("notepad"), m_szFreeldrIni, NULL, SW_SHOWNORMAL);
117 break;
118 }
119 case IDOK:
120 {
121 /* save timeout */
122 if (SendDlgItemMessage(hwndDlg, IDC_STRECLIST, BM_GETCHECK, (WPARAM)0, (LPARAM)0) == BST_CHECKED)
123 iTimeout = SendDlgItemMessage(hwndDlg, IDC_STRRECLISTUPDWN, UDM_GETPOS, (WPARAM)0, (LPARAM)0);
124 else
125 iTimeout = 0;
126 _stprintf(szTimeout, _T("%i"), iTimeout);
127 WritePrivateProfileString(_T("boot loader"), _T("timeout"), szTimeout, m_szFreeldrIni);
128 }
129 case IDCANCEL:
130 {
131 EndDialog(hwndDlg,
132 LOWORD(wParam));
133 return TRUE;
134 break;
135 }
136 case IDC_STRECLIST:
137 {
138 if (SendDlgItemMessage(hwndDlg, IDC_STRECLIST, BM_GETCHECK, (WPARAM)0, (LPARAM)0) == BST_CHECKED)
139 SetTimeout(hwndDlg, 30);
140 else
141 SetTimeout(hwndDlg, 0);
142 }
143 }
144 }
145 break;
146 }
147 return FALSE;
148 }