2 * Copyright 2000, International Business Machines Corporation and others.
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
11 #include <afs/param.h>
16 #include "submounts_dlg.h"
17 #include "add_submount_dlg.h"
19 #include "submount_info.h"
20 #include "hourglass.h"
21 #include <WINNT\afsreg.h>
26 static char THIS_FILE[] = __FILE__;
29 #define PCCHAR(str) ((char *)(const char *)(str))
32 /////////////////////////////////////////////////////////////////////////////
33 // CSubmountsDlg property page
35 IMPLEMENT_DYNCREATE(CSubmountsDlg, CDialog)
37 static CSubmountInfo *ReadSubmtInfo(const CString& strShareName)
41 CSubmountInfo *pInfo = 0;
48 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
49 AFSREG_CLT_OPENAFS_SUBKEY "\\Submounts",
52 REG_OPTION_NON_VOLATILE,
53 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_READ,
60 len = sizeof(pathName);
61 status = RegQueryValueEx( hkSubmounts, (LPCSTR)PCCHAR(strShareName), 0,
62 &dwType, (LPBYTE)pathName, &len);
63 RegCloseKey( hkSubmounts );
65 if (status || len == 0)
68 pInfo = new CSubmountInfo();
69 pInfo->SetShareName(strShareName);
70 pInfo->SetPathName(pathName);
75 CSubmountsDlg::CSubmountsDlg() : CDialog()
77 InitModalIndirect (TaLocale_GetDialogResource (CSubmountsDlg::IDD));
79 //{{AFX_DATA_INIT(CSubmountsDlg)
80 // NOTE: the ClassWizard will add member initialization here
83 m_bAddOnlyMode = FALSE;
86 CSubmountsDlg::~CSubmountsDlg()
88 for (int i = 0; i < m_ToDo.GetSize(); i++)
94 void CSubmountsDlg::DoDataExchange(CDataExchange* pDX)
96 CDialog::DoDataExchange(pDX);
97 //{{AFX_DATA_MAP(CSubmountsDlg)
98 DDX_Control(pDX, IDC_DELETE, m_Delete);
99 DDX_Control(pDX, IDC_CHANGE, m_Change);
100 DDX_Control(pDX, IDC_LIST, m_SubmtList);
105 BEGIN_MESSAGE_MAP(CSubmountsDlg, CDialog)
106 //{{AFX_MSG_MAP(CSubmountsDlg)
107 ON_BN_CLICKED(IDC_ADD, OnAdd)
108 ON_BN_CLICKED(IDC_CHANGE, OnChange)
109 ON_BN_CLICKED(IDC_DELETE, OnDelete)
110 ON_LBN_SELCHANGE(IDC_LIST, OnSelChangeList)
111 ON_BN_CLICKED(IDOK, OnOk)
115 /////////////////////////////////////////////////////////////////////////////
116 // CSubmountsDlg message handlers
118 BOOL CSubmountsDlg::OnInitDialog()
120 CDialog::OnInitDialog();
122 if (m_bAddOnlyMode) {
123 TCHAR szRemoteName[MAX_PATH];
124 ULONG nBufSize = sizeof(szRemoteName);
126 if (WNetGetConnection(m_strAddOnlyPath.Left(2), szRemoteName, &nBufSize) == ERROR_SUCCESS) {
127 CString strAfsShare(szRemoteName);
128 int nSlashPos = strAfsShare.ReverseFind('\\');
129 if (nSlashPos > -1) {
130 strAfsShare = strAfsShare.Mid(nSlashPos + 1);
132 // Get the submount info for this share name
133 CSubmountInfo *pInfo = ReadSubmtInfo(strAfsShare);
134 CString strSharePath;
137 strSharePath = pInfo->GetPathName();
140 m_strAddOnlyPath = strSharePath + m_strAddOnlyPath.Mid(2);
150 if (!FillSubmtList()) {
151 // ShowMessageBox(IDS_GET_CELL_LIST_ERROR);
156 return TRUE; // return TRUE unless you set the focus to a control
157 // EXCEPTION: OCX Property Pages should return FALSE
160 BOOL CSubmountsDlg::FillSubmtList()
169 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
170 AFSREG_CLT_OPENAFS_SUBKEY "\\Submounts",
173 REG_OPTION_NON_VOLATILE,
174 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
179 RegQueryInfoKey( hkSubmounts,
182 NULL, /* lpReserved */
183 NULL, /* lpcSubKeys */
184 NULL, /* lpcMaxSubKeyLen */
185 NULL, /* lpcMaxClassLen */
186 &dwSubmounts, /* lpcValues */
187 NULL, /* lpcMaxValueNameLen */
188 NULL, /* lpcMaxValueLen */
189 NULL, /* lpcbSecurityDescriptor */
190 NULL /* lpftLastWriteTime */
194 for ( dwIndex = 0; dwIndex < dwSubmounts; dwIndex ++ ) {
195 char submountName[256];
196 DWORD submountNameLen = sizeof(submountName);
198 RegEnumValue( hkSubmounts, dwIndex, submountName, &submountNameLen, NULL,
199 &dwType, NULL, NULL);
201 m_SubmtList.AddString(submountName);
204 RegCloseKey( hkSubmounts );
209 void CSubmountsDlg::OnDelete()
213 int nIndex = m_SubmtList.GetCurSel();
217 CString strShareName;
218 m_SubmtList.GetText(nIndex, strSubmt);
220 ASSERT(!strSubmt.IsEmpty());
222 strShareName = strSubmt.SpanExcluding("=");
224 if (ShowMessageBox(IDS_REALLY_DELETE_SUBMT, MB_YESNO | MB_ICONQUESTION, IDS_REALLY_DELETE_SUBMT, strShareName) != IDYES)
227 m_SubmtList.DeleteString(nIndex);
229 if (m_SubmtList.GetCount() == 0) {
230 m_Delete.EnableWindow(FALSE);
231 m_Change.EnableWindow(FALSE);
234 CSubmountInfo *pInfo = new CSubmountInfo();
235 pInfo->SetShareName(strShareName);
236 pInfo->SetStatus(SIS_DELETED);
240 void CSubmountsDlg::OnSelChangeList()
242 m_Delete.EnableWindow(TRUE);
243 m_Change.EnableWindow(TRUE);
246 static BOOL AddSubmt(CSubmountInfo *pInfo)
251 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
252 AFSREG_CLT_OPENAFS_SUBKEY "\\Submounts",
255 REG_OPTION_NON_VOLATILE,
256 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE,
261 DWORD status = RegSetValueEx( hkSubmounts, PCCHAR(pInfo->GetShareName()), 0, REG_SZ,
262 (const BYTE *)PCCHAR(pInfo->GetPathName()), strlen(PCCHAR(pInfo->GetPathName())) + 1);
264 RegCloseKey(hkSubmounts);
265 return (status == ERROR_SUCCESS);
268 static BOOL DeleteSubmt(CSubmountInfo *pInfo)
273 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
274 AFSREG_CLT_OPENAFS_SUBKEY "\\Submounts",
277 REG_OPTION_NON_VOLATILE,
278 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE,
283 DWORD status = RegDeleteValue( hkSubmounts, PCCHAR(pInfo->GetShareName()));
285 RegCloseKey(hkSubmounts);
286 return (status == ERROR_SUCCESS);
289 void CSubmountsDlg::OnAdd()
293 if (m_bAddOnlyMode) {
294 CSubmountInfo info("", m_strAddOnlyPath, SIS_ADDED);
295 dlg.SetSubmtInfo(&info);
300 CSubmountInfo *pInfo = dlg.GetSubmtInfo();
304 m_SubmtList.AddString(pInfo->GetShareName() + "=" + pInfo->GetPathName());
308 void CSubmountsDlg::OnChange()
314 dlg.SetAddMode(FALSE);
316 int nIndex = m_SubmtList.GetCurSel();
320 CString strShareName;
321 m_SubmtList.GetText(nIndex, strSubmt);
323 ASSERT(!strSubmt.IsEmpty());
325 strShareName = strSubmt.SpanExcluding("=");
327 CSubmountInfo *pInfo = FindWork(strShareName);
329 // Make a copy we can free below
330 pInfo = new CSubmountInfo(*pInfo);
332 pInfo = ReadSubmtInfo(strShareName);
335 ShowMessageBox(IDS_GET_SUBMT_INFO_ERROR, MB_ICONEXCLAMATION, IDS_GET_SUBMT_INFO_ERROR, strShareName);
339 dlg.SetSubmtInfo(pInfo);
343 if (dlg.DoModal() != IDOK)
346 pInfo = dlg.GetSubmtInfo();
348 m_SubmtList.DeleteString(nIndex);
349 m_SubmtList.InsertString(nIndex,
350 pInfo->GetShareName() + "=" + pInfo->GetPathName());
355 void CSubmountsDlg::AddWork(CSubmountInfo *pInfo)
363 for (int i = 0; i < m_ToDo.GetSize(); i++) {
364 if (m_ToDo[i]->GetShareName() == pInfo->GetShareName()) {
365 if ((pInfo->GetStatus() == SIS_DELETED) && (m_ToDo[i]->GetStatus() == SIS_ADDED))
377 BOOL CSubmountsDlg::FixSubmts()
379 for (int i = 0; i < m_ToDo.GetSize(); i++) {
380 SUBMT_INFO_STATUS status = m_ToDo[i]->GetStatus();
381 if ((status == SIS_ADDED) || (status == SIS_CHANGED))
382 if (!AddSubmt(m_ToDo[i]))
384 if (status == SIS_DELETED)
385 if (!DeleteSubmt(m_ToDo[i]))
392 CSubmountInfo *CSubmountsDlg::FindWork(const CString& strShareName)
394 for (int i = 0; i < m_ToDo.GetSize(); i++)
395 if (m_ToDo[i]->GetShareName() == strShareName)
401 void CSubmountsDlg::WinHelp(DWORD dwData, UINT nCmd)
403 CDialog::WinHelp(dwData, nCmd);
406 void CSubmountsDlg::OnOk()
409 ShowMessageBox(IDS_SUBMT_SAVE_FAILED);
414 void CSubmountsDlg::SetAddOnlyMode(const CString& strAddOnlyPath)
416 m_bAddOnlyMode = TRUE;
417 m_strAddOnlyPath = strAddOnlyPath;