Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afssvrmgr / svr_install.cpp
blob228a25e48b8501249e17eee7940b73bff3938a30
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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 */
10 #include <winsock2.h>
11 #include <ws2tcpip.h>
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
18 #include "svrmgr.h"
19 #include "svr_install.h"
20 #include "propcache.h"
23 * PROTOTYPES _________________________________________________________________
27 BOOL WINAPI Server_Install_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
29 void Server_Install_OnInitDialog (HWND hDlg, LPSVR_INSTALL_PARAMS lpp);
30 void Server_Install_OnEndTask_InitDialog (HWND hDlg, LPTASKPACKET ptp, LPSVR_INSTALL_PARAMS lpp);
31 void Server_Install_OnBrowse (HWND hDlg);
32 void Server_Install_EnableOK (HWND hDlg);
33 void Server_Install_OnOK (HWND hDlg);
37 * ROUTINES ___________________________________________________________________
41 void Server_Install (LPIDENT lpiServer)
43 HWND hCurrent;
45 if ((hCurrent = PropCache_Search (pcSVR_INSTALL, NULL)) != NULL)
47 SetFocus (hCurrent);
49 else
51 LPSVR_INSTALL_PARAMS lpp = New (SVR_INSTALL_PARAMS);
52 lpp->lpiServer = lpiServer;
53 lpp->szSource[0] = TEXT('\0');
54 lpp->szTarget[0] = TEXT('\0');
56 HWND hDlg = ModelessDialogParam (IDD_SVR_INSTALL, NULL, (DLGPROC)Server_Install_DlgProc, (LPARAM)lpp);
57 ShowWindow (hDlg, SW_SHOW);
62 BOOL WINAPI Server_Install_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
64 if (AfsAppLib_HandleHelp (IDD_SVR_INSTALL, hDlg, msg, wp, lp))
65 return TRUE;
67 LPSVR_INSTALL_PARAMS lpp;
69 if (msg == WM_INITDIALOG)
70 SetWindowLongPtr (hDlg, DWLP_USER, lp);
72 if ((lpp = (LPSVR_INSTALL_PARAMS)GetWindowLongPtr(hDlg,DWLP_USER)) != NULL)
74 switch (msg)
76 case WM_INITDIALOG:
77 PropCache_Add (pcSVR_INSTALL, NULL, hDlg);
78 Server_Install_OnInitDialog (hDlg, lpp);
79 break;
81 case WM_ENDTASK:
82 LPTASKPACKET ptp;
83 if ((ptp = (LPTASKPACKET)lp) != NULL)
85 if (ptp->idTask == taskSVR_ENUM_TO_COMBOBOX)
86 Server_Install_OnEndTask_InitDialog (hDlg, ptp, lpp);
87 FreeTaskPacket (ptp);
89 break;
91 case WM_COMMAND:
92 switch (LOWORD(wp))
94 case IDOK:
95 Server_Install_OnOK (hDlg);
96 // fall through
98 case IDCANCEL:
99 DestroyWindow (hDlg);
100 break;
102 case IDC_BROWSE:
103 Server_Install_OnBrowse (hDlg);
104 break;
106 case IDC_FILENAME:
107 case IDC_DIRECTORY:
108 case IDC_SERVER:
109 Server_Install_EnableOK (hDlg);
110 break;
112 break;
114 case WM_DESTROY:
115 SetWindowLongPtr (hDlg, DWLP_USER, 0);
116 PropCache_Delete (pcSVR_INSTALL, NULL);
117 Delete (lpp);
118 break;
122 return FALSE;
126 void Server_Install_OnInitDialog (HWND hDlg, LPSVR_INSTALL_PARAMS lpp)
128 LPTSTR pszText = FormatString (IDS_INSTALL_DESC1);
129 SetDlgItemText (hDlg, IDC_INSTALL_DESC, pszText);
130 FreeString (pszText);
132 LPSVR_ENUM_TO_COMBOBOX_PACKET lppEnum = New (SVR_ENUM_TO_COMBOBOX_PACKET);
133 lppEnum->hCombo = GetDlgItem (hDlg, IDC_SERVER);
134 lppEnum->lpiSelect = lpp->lpiServer;
135 StartTask (taskSVR_ENUM_TO_COMBOBOX, hDlg, lppEnum);
137 EnableWindow (GetDlgItem (hDlg, IDC_SERVER), FALSE);
138 EnableWindow (GetDlgItem (hDlg, IDOK), FALSE);
142 void Server_Install_OnEndTask_InitDialog (HWND hDlg, LPTASKPACKET ptp, LPSVR_INSTALL_PARAMS lpp)
144 EnableWindow (GetDlgItem (hDlg, IDC_SERVER), TRUE);
145 Server_Install_EnableOK (hDlg);
149 void Server_Install_EnableOK (HWND hDlg)
151 LPIDENT lpiServer = NULL;
153 if (IsWindowEnabled (GetDlgItem (hDlg, IDC_SERVER)))
154 lpiServer = (LPIDENT)CB_GetSelectedData (GetDlgItem (hDlg, IDC_SERVER));
156 BOOL fEnable = (lpiServer != NULL) ? TRUE : FALSE;
158 if (fEnable)
160 TCHAR szName[ MAX_PATH ];
161 GetDlgItemText (hDlg, IDC_FILENAME, szName, MAX_PATH);
162 if (szName[0] == TEXT('\0'))
163 fEnable = FALSE;
166 if (fEnable)
168 TCHAR szName[ MAX_PATH ];
169 GetDlgItemText (hDlg, IDC_DIRECTORY, szName, MAX_PATH);
170 if (szName[0] == TEXT('\0'))
171 fEnable = FALSE;
174 EnableWindow (GetDlgItem (hDlg, IDOK), fEnable);
178 void Server_Install_OnOK (HWND hDlg)
180 LPSVR_INSTALL_PARAMS lpp = New (SVR_INSTALL_PARAMS);
181 lpp->lpiServer = (LPIDENT)CB_GetSelectedData (GetDlgItem (hDlg, IDC_SERVER));
182 GetDlgItemText (hDlg, IDC_FILENAME, lpp->szSource, MAX_PATH);
183 GetDlgItemText (hDlg, IDC_DIRECTORY, lpp->szTarget, MAX_PATH);
185 StartTask (taskSVR_INSTALL, NULL, lpp);
189 void Server_Install_OnBrowse (HWND hDlg)
191 TCHAR szFilter[ cchRESOURCE ];
192 GetString (szFilter, IDS_FILTER_ALLFILES);
193 TCHAR chFilter = szFilter[ lstrlen(szFilter)-1 ];
194 for (LPTSTR pszFilter = szFilter;
195 (*pszFilter) && ((pszFilter = (LPTSTR)lstrchr (pszFilter, chFilter)) != NULL);
196 ++pszFilter)
198 *pszFilter = TEXT('\0');
201 TCHAR szFilename[ MAX_PATH ];
202 GetDlgItemText (hDlg, IDC_FILENAME, szFilename, MAX_PATH);
204 OPENFILENAME ofn;
205 memset (&ofn, 0x00, sizeof(ofn));
206 ofn.lStructSize = sizeof(ofn);
207 ofn.hwndOwner = hDlg;
208 ofn.hInstance = THIS_HINST;
209 ofn.lpstrFilter = szFilter;
210 ofn.nFilterIndex = 1;
211 ofn.lpstrFile = szFilename;
212 ofn.nMaxFile = MAX_PATH;
213 ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
215 TCHAR szPath[ MAX_PATH ];
216 GetCurrentDirectory (MAX_PATH, szPath);
218 BOOL rc = GetOpenFileName (&ofn);
220 SetCurrentDirectory (szPath);
222 if (rc)
223 SetDlgItemText (hDlg, IDC_FILENAME, szFilename);