nt-makefile-clean-targets-20010917
[openafs.git] / src / WINNT / afssvrcfg / cfg_utils.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * INCLUDES ___________________________________________________________________
12  *
13  */
14 extern "C" {
15 #include <afs/param.h>
16 #include <afs/stds.h>
17 }
18
19 #include "afscfg.h"
20 #include "resource.h"
21 #include "cfg_utils.h"
22
23
24 /*
25  * EXPORTED FUNCTIONS _________________________________________________________
26  *
27  */
28 BOOL IsStepEnabled(const CONFIG_STATE& step)
29 {
30         return ((step & CS_DISABLED) == 0);
31 }
32
33 void EnableStep(CONFIG_STATE& step, BOOL bEnable)
34 {
35         if (bEnable)
36                 step &= ~CS_DISABLED;
37         else
38                 step |= CS_DISABLED;            
39 }
40
41 BOOL ShouldConfig(const CONFIG_STATE& state)            
42 {
43         return (state == CS_CONFIGURE);
44 }
45
46 BOOL DontConfig(const CONFIG_STATE& state)
47 {
48         return (state == CS_DONT_CONFIGURE);
49 }
50
51 BOOL ShouldUnconfig(const CONFIG_STATE& state)
52 {
53         return (state == CS_UNCONFIGURE);
54 }
55
56 BOOL ConfiguredOrConfiguring(const CONFIG_STATE& step)
57 {
58         return (step == CS_CONFIGURE) || (step == CS_ALREADY_CONFIGURED);
59 }
60
61 BOOL Configured(const CONFIG_STATE& step)
62 {
63         return (step == CS_ALREADY_CONFIGURED);
64 }
65
66 void ToggleConfig(CONFIG_STATE& state)
67 {
68         if (ShouldConfig(state))
69                 state = CS_DONT_CONFIGURE;
70         else if (DontConfig(state))
71                 state = CS_CONFIGURE;
72 }
73
74 void RedrawGraphic()
75 {
76         HWND hWiz = g_pWiz->GetWindow();
77
78         HWND hBg = GetDlgItem(hWiz, IDC_WIZARD_LEFTPANE);
79
80         RECT rect;
81         GetClientRect(hBg, &rect);
82
83         InvalidateRect(hBg, &rect, FALSE);
84         UpdateWindow(hBg);
85 }
86
87 UINT GetAppTitleID()
88 {
89         if (g_CfgData.bWizard)
90                 return IDS_WIZARD_APP_TITLE;
91
92         return IDS_CFG_TOOL_APP_TITLE;
93 }
94
95 const char *GetAdminLibErrorCodeMessage(afs_status_t nErrorCode)
96 {
97     afs_status_t nStatus;
98     const char *pszMsg = 0;
99
100     int nResult = util_AdminErrorCodeTranslate(nErrorCode, 0, &pszMsg, &nStatus);
101     if (!nResult)
102         return 0;
103
104     return pszMsg;
105 }
106
107 void LogError(afs_status_t nErrorCode)
108 {
109     const char *pszMsg = GetAdminLibErrorCodeMessage(nErrorCode);
110     
111     if (pszMsg)
112         g_LogFile.Write("Error %0xd has occurred:  %s.\r\n", (UINT)nErrorCode, pszMsg);
113     else
114         g_LogFile.Write("Error %0xd has occurred.\r\n", (UINT)nErrorCode);
115 }
116
117 void ShowError(HWND hDlg, afs_status_t nErrorCode, UINT uiErrorMsgID)
118 {
119         TCHAR szMsg[cchRESOURCE];
120
121     LogError(nErrorCode);
122
123         GetString(szMsg, uiErrorMsgID);
124         
125         ErrorDialog(nErrorCode, szMsg);
126
127     SetWndText(hDlg, IDC_STATUS_MSG, IDS_CONFIG_FAILED);
128 }
129
130 int ShowWarning(HWND hDlg, UINT uiMsgID)
131 {
132         TCHAR szMsg[cchRESOURCE];
133         TCHAR szTitle[cchRESOURCE];
134
135         GetString(szTitle, GetAppTitleID());
136         GetString(szMsg, uiMsgID);
137
138         return MessageBox(hDlg, szMsg, szTitle, MB_OKCANCEL | MB_ICONWARNING);
139 }
140