avoid crash
[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 /* get Path to freeldr.ini or boot.ini */
49 szSystemDrive = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, MAX_PATH);
50 if (szSystemDrive != NULL && szSystemDrive != NULL)
51 {
52 szSystemDrive = _tgetenv(_T("SystemDrive"));
53 if (m_szFreeldrIni != NULL)
54 {
55 _tcscpy(m_szFreeldrIni, szSystemDrive);
56 _tcscat(m_szFreeldrIni, _T("\\freeldr.ini"));
57 if (!PathFileExists(m_szFreeldrIni))
58 {
59 _tcscpy(m_szFreeldrIni, szSystemDrive);
60 _tcscat(m_szFreeldrIni, _T("\\boot.ini"));
61 }
62 }
63 HeapFree(GetProcessHeap(), 0, szSystemDrive);
64 }
65
66 SetDlgItemText(hwndDlg, IDC_STRRECDUMPFILE, _T("%SystemRoot%\\MiniDump"));
67
68 /* load settings from freeldr.ini */
69 GetPrivateProfileString(_T("boot loader"), _T("default"), NULL, szDefaultOS, MAX_PATH, m_szFreeldrIni);
70 GetPrivateProfileString(_T("operating systems"), szDefaultOS, NULL, szDefaultOSName, MAX_PATH, m_szFreeldrIni);
71 SendDlgItemMessage(hwndDlg, IDC_STRECOSCOMBO, CB_ADDSTRING, (WPARAM)0, (LPARAM)szDefaultOSName);
72 SendDlgItemMessage(hwndDlg, IDC_STRECOSCOMBO, CB_SETCURSEL, (WPARAM)0, (LPARAM)0);
73
74 /* timeout */
75 iTimeout = GetPrivateProfileInt(_T("boot loader"), _T("timeout"), 0, m_szFreeldrIni);
76 SetTimeout(hwndDlg, iTimeout);
77 if (iTimeout != 0)
78 SendDlgItemMessage(hwndDlg, IDC_STRECLIST, BM_SETCHECK, (WPARAM)BST_CHECKED, (LPARAM)0);
79
80 }
81 break;
82
83 case WM_COMMAND:
84 {
85 switch(LOWORD(wParam))
86 {
87 case IDC_STRRECEDIT:
88 {
89 ShellExecute(0, _T("open"), _T("notepad"), m_szFreeldrIni, NULL, SW_SHOWNORMAL);
90 break;
91 }
92 case IDOK:
93 {
94 /* save timeout */
95 if (SendDlgItemMessage(hwndDlg, IDC_STRECLIST, BM_GETCHECK, (WPARAM)0, (LPARAM)0) == BST_CHECKED)
96 iTimeout = SendDlgItemMessage(hwndDlg, IDC_STRRECLISTUPDWN, UDM_GETPOS, (WPARAM)0, (LPARAM)0);
97 else
98 iTimeout = 0;
99 _stprintf(szTimeout, _T("%i"), iTimeout);
100 WritePrivateProfileString(_T("boot loader"), _T("timeout"), szTimeout, m_szFreeldrIni);
101 }
102 case IDCANCEL:
103 {
104 EndDialog(hwndDlg,
105 LOWORD(wParam));
106 return TRUE;
107 break;
108 }
109 case IDC_STRECLIST:
110 {
111 if (SendDlgItemMessage(hwndDlg, IDC_STRECLIST, BM_GETCHECK, (WPARAM)0, (LPARAM)0) == BST_CHECKED)
112 SetTimeout(hwndDlg, 30);
113 else
114 SetTimeout(hwndDlg, 0);
115 }
116 }
117 }
118 break;
119 }
120 return FALSE;
121 }