rx: Remove RX_CALL_BUSY
[openafs.git] / src / WINNT / afssvrmgr / svr_uninstall.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 #include <winsock2.h>
11 #include <ws2tcpip.h>
12
13 extern "C" {
14 #include <afsconfig.h>
15 #include <afs/param.h>
16 #include <roken.h>
17 }
18
19 #include "svrmgr.h"
20 #include "svr_uninstall.h"
21 #include "propcache.h"
22
23 /*
24  * PROTOTYPES _________________________________________________________________
25  *
26  */
27
28 BOOL WINAPI Server_Uninstall_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
29
30 void Server_Uninstall_OnInitDialog (HWND hDlg, LPSVR_UNINSTALL_PARAMS lpp);
31 void Server_Uninstall_OnEndTask_InitDialog (HWND hDlg, LPTASKPACKET ptp, LPSVR_UNINSTALL_PARAMS lpp);
32 void Server_Uninstall_EnableOK (HWND hDlg);
33 void Server_Uninstall_OnOK (HWND hDlg);
34
35
36 /*
37  * ROUTINES ___________________________________________________________________
38  *
39  */
40
41 void Server_Uninstall (LPIDENT lpiServer)
42 {
43    HWND hCurrent;
44
45    if ((hCurrent = PropCache_Search (pcSVR_UNINSTALL, NULL)) != NULL)
46       {
47       SetFocus (hCurrent);
48       }
49    else
50       {
51       LPSVR_UNINSTALL_PARAMS lpp = New (SVR_UNINSTALL_PARAMS);
52       lpp->lpiServer = lpiServer;
53       lpp->szUninstall[0] = TEXT('\0');
54
55       HWND hDlg = ModelessDialogParam (IDD_SVR_UNINSTALL, NULL, (DLGPROC)Server_Uninstall_DlgProc, (LPARAM)lpp);
56       ShowWindow (hDlg, SW_SHOW);
57       }
58 }
59
60
61 BOOL WINAPI Server_Uninstall_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
62 {
63    if (AfsAppLib_HandleHelp (IDD_SVR_UNINSTALL, hDlg, msg, wp, lp))
64       return TRUE;
65
66    LPSVR_UNINSTALL_PARAMS lpp;
67
68    if (msg == WM_INITDIALOG)
69       SetWindowLongPtr (hDlg, DWLP_USER, lp);
70
71    if ((lpp = (LPSVR_UNINSTALL_PARAMS)GetWindowLongPtr(hDlg,DWLP_USER)) != NULL)
72       {
73       switch (msg)
74          {
75          case WM_INITDIALOG:
76             PropCache_Add (pcSVR_UNINSTALL, NULL, hDlg);
77             Server_Uninstall_OnInitDialog (hDlg, lpp);
78             break;
79
80          case WM_ENDTASK:
81             LPTASKPACKET ptp;
82             if ((ptp = (LPTASKPACKET)lp) != NULL)
83                {
84                if (ptp->idTask == taskSVR_ENUM_TO_COMBOBOX)
85                   Server_Uninstall_OnEndTask_InitDialog (hDlg, ptp, lpp);
86                FreeTaskPacket (ptp);
87                }
88             break;
89
90          case WM_COMMAND:
91             switch (LOWORD(wp))
92                {
93                case IDOK:
94                   Server_Uninstall_OnOK (hDlg);
95                   DestroyWindow (hDlg);
96                   break;
97
98                case IDCANCEL:
99                   DestroyWindow (hDlg);
100                   break;
101
102                case IDC_SERVER:
103                case IDC_FILENAME:
104                   Server_Uninstall_EnableOK (hDlg);
105                   break;
106                }
107             break;
108
109          case WM_DESTROY:
110             SetWindowLongPtr (hDlg, DWLP_USER, 0);
111             PropCache_Delete (pcSVR_UNINSTALL, NULL);
112             Delete (lpp);
113             break;
114          }
115       }
116
117    return FALSE;
118 }
119
120
121 void Server_Uninstall_OnInitDialog (HWND hDlg, LPSVR_UNINSTALL_PARAMS lpp)
122 {
123    LPSVR_ENUM_TO_COMBOBOX_PACKET lppEnum = New (SVR_ENUM_TO_COMBOBOX_PACKET);
124    lppEnum->hCombo = GetDlgItem (hDlg, IDC_SERVER);
125    lppEnum->lpiSelect = lpp->lpiServer;
126    StartTask (taskSVR_ENUM_TO_COMBOBOX, hDlg, lppEnum);
127
128    EnableWindow (GetDlgItem (hDlg, IDC_SERVER), FALSE);
129    EnableWindow (GetDlgItem (hDlg, IDOK),       FALSE);
130 }
131
132
133 void Server_Uninstall_OnEndTask_InitDialog (HWND hDlg, LPTASKPACKET ptp, LPSVR_UNINSTALL_PARAMS lpp)
134 {
135    EnableWindow (GetDlgItem (hDlg, IDC_SERVER), TRUE);
136    Server_Uninstall_EnableOK (hDlg);
137 }
138
139
140 void Server_Uninstall_EnableOK (HWND hDlg)
141 {
142    LPIDENT lpiServer = NULL;
143
144    if (IsWindowEnabled (GetDlgItem (hDlg, IDC_SERVER)))
145       lpiServer = (LPIDENT)CB_GetSelectedData (GetDlgItem (hDlg, IDC_SERVER));
146
147    BOOL fEnable = (lpiServer != NULL) ? TRUE : FALSE;
148
149    if (fEnable)
150       {
151       TCHAR szName[ MAX_PATH ];
152       GetDlgItemText (hDlg, IDC_FILENAME, szName, MAX_PATH);
153       if (szName[0] == TEXT('\0'))
154          fEnable = FALSE;
155       }
156
157    EnableWindow (GetDlgItem (hDlg, IDOK), fEnable);
158 }
159
160
161 void Server_Uninstall_OnOK (HWND hDlg)
162 {
163    LPSVR_UNINSTALL_PARAMS lpp = New (SVR_UNINSTALL_PARAMS);
164    lpp->lpiServer = (LPIDENT)CB_GetSelectedData (GetDlgItem (hDlg, IDC_SERVER));
165    GetDlgItemText (hDlg, IDC_FILENAME, lpp->szUninstall, MAX_PATH);
166
167    StartTask (taskSVR_UNINSTALL, NULL, lpp);
168 }
169