libroken: Build on windows
[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 #include <winsock2.h>
15 #include <ws2tcpip.h>
16
17 extern "C" {
18 #include <afsconfig.h>
19 #include <afs/param.h>
20 #include <afs/stds.h>
21 #include <roken.h>
22 }
23
24 #include "afscfg.h"
25 #include "resource.h"
26 #include "cfg_utils.h"
27
28
29 /*
30  * EXPORTED FUNCTIONS _________________________________________________________
31  *
32  */
33 BOOL IsStepEnabled(const CONFIG_STATE& step)
34 {
35     return ((step & CS_DISABLED) == 0);
36 }
37
38 void EnableStep(CONFIG_STATE& step, BOOL bEnable)
39 {       
40     if (bEnable)
41         step &= ~CS_DISABLED;
42     else
43         step |= CS_DISABLED;            
44 }       
45
46 BOOL ShouldConfig(const CONFIG_STATE& state)            
47 {
48     return (state == CS_CONFIGURE);
49 }
50
51 BOOL DontConfig(const CONFIG_STATE& state)
52 {
53     return (state == CS_DONT_CONFIGURE);
54 }
55
56 BOOL ShouldUnconfig(const CONFIG_STATE& state)
57 {
58     return (state == CS_UNCONFIGURE);
59 }
60
61 BOOL ConfiguredOrConfiguring(const CONFIG_STATE& step)
62 {
63     return (step == CS_CONFIGURE) || (step == CS_ALREADY_CONFIGURED);
64 }
65
66 BOOL Configured(const CONFIG_STATE& step)
67 {
68     return (step == CS_ALREADY_CONFIGURED);
69 }
70
71 void ToggleConfig(CONFIG_STATE& state)
72 {
73     if (ShouldConfig(state))
74         state = CS_DONT_CONFIGURE;
75     else if (DontConfig(state))
76         state = CS_CONFIGURE;
77 }       
78
79 void RedrawGraphic()
80 {
81     HWND hWiz = g_pWiz->GetWindow();
82
83     HWND hBg = GetDlgItem(hWiz, IDC_WIZARD_LEFTPANE);
84
85     RECT rect;
86     GetClientRect(hBg, &rect);
87
88     InvalidateRect(hBg, &rect, FALSE);
89     UpdateWindow(hBg);
90 }       
91
92 UINT GetAppTitleID()
93 {
94     if (g_CfgData.bWizard)
95         return IDS_WIZARD_APP_TITLE;
96
97     return IDS_CFG_TOOL_APP_TITLE;
98 }
99
100 const char *GetAdminLibErrorCodeMessage(afs_status_t nErrorCode)
101 {
102     afs_status_t nStatus;
103     const char *pszMsg = 0;
104
105     int nResult = util_AdminErrorCodeTranslate(nErrorCode, 0, &pszMsg, &nStatus);
106     if (!nResult)
107         return 0;
108
109     return pszMsg;
110 }
111
112 void LogError(afs_status_t nErrorCode)
113 {
114     const char *pszMsg = GetAdminLibErrorCodeMessage(nErrorCode);
115     
116     if (pszMsg)
117         g_LogFile.Write("Error 0x%0x has occurred: %s.\r\n", (UINT)nErrorCode, pszMsg);
118     else
119         g_LogFile.Write("Error 0x%0x has occurred.\r\n", (UINT)nErrorCode);
120 }
121
122 void ShowError(HWND hDlg, afs_status_t nErrorCode, UINT uiErrorMsgID)
123 {
124     TCHAR szMsg[cchRESOURCE];
125
126     LogError(nErrorCode);
127
128     GetString(szMsg, uiErrorMsgID);
129
130     ErrorDialog(nErrorCode, szMsg);
131
132     SetWndText(hDlg, IDC_STATUS_MSG, IDS_CONFIG_FAILED);
133 }
134
135 int ShowWarning(HWND hDlg, UINT uiMsgID)
136 {
137     TCHAR szMsg[cchRESOURCE];
138     TCHAR szTitle[cchRESOURCE];
139
140     GetString(szTitle, GetAppTitleID());
141     GetString(szMsg, uiMsgID);
142
143     return MessageBox(hDlg, szMsg, szTitle, MB_OKCANCEL | MB_ICONWARNING);
144 }
145