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