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
15 #include <afs/param.h>
19 #include "submounts_dlg.h"
20 #include "add_submount_dlg.h"
22 #include "submount_info.h"
23 #include "hourglass.h"
24 #include <WINNT\afsreg.h>
29 static char THIS_FILE[] = __FILE__;
32 #define PCCHAR(str) ((char *)(const char *)(str))
35 /////////////////////////////////////////////////////////////////////////////
36 // CSubmountsDlg property page
38 IMPLEMENT_DYNCREATE(CSubmountsDlg, CDialog)
40 static CSubmountInfo *ReadSubmtInfo(const CString& strShareName)
44 CSubmountInfo *pInfo = 0;
51 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
52 AFSREG_CLT_OPENAFS_SUBKEY "\\Submounts",
55 REG_OPTION_NON_VOLATILE,
56 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_READ,
63 len = sizeof(pathName);
64 status = RegQueryValueEx( hkSubmounts, (LPCSTR)PCCHAR(strShareName), 0,
65 &dwType, (LPBYTE)pathName, &len);
66 RegCloseKey( hkSubmounts );
68 if (status || len == 0)
71 pInfo = new CSubmountInfo();
72 pInfo->SetShareName(strShareName);
73 pInfo->SetPathName(pathName);
78 CSubmountsDlg::CSubmountsDlg() : CDialog()
80 InitModalIndirect (TaLocale_GetDialogResource (CSubmountsDlg::IDD));
82 //{{AFX_DATA_INIT(CSubmountsDlg)
83 // NOTE: the ClassWizard will add member initialization here
86 m_bAddOnlyMode = FALSE;
89 CSubmountsDlg::~CSubmountsDlg()
91 for (int i = 0; i < m_ToDo.GetSize(); i++)
97 void CSubmountsDlg::DoDataExchange(CDataExchange* pDX)
99 CDialog::DoDataExchange(pDX);
100 //{{AFX_DATA_MAP(CSubmountsDlg)
101 DDX_Control(pDX, IDC_DELETE, m_Delete);
102 DDX_Control(pDX, IDC_CHANGE, m_Change);
103 DDX_Control(pDX, IDC_LIST, m_SubmtList);
108 BEGIN_MESSAGE_MAP(CSubmountsDlg, CDialog)
109 //{{AFX_MSG_MAP(CSubmountsDlg)
110 ON_BN_CLICKED(IDC_ADD, OnAdd)
111 ON_BN_CLICKED(IDC_CHANGE, OnChange)
112 ON_BN_CLICKED(IDC_DELETE, OnDelete)
113 ON_LBN_SELCHANGE(IDC_LIST, OnSelChangeList)
114 ON_BN_CLICKED(IDOK, OnOk)
118 /////////////////////////////////////////////////////////////////////////////
119 // CSubmountsDlg message handlers
121 BOOL CSubmountsDlg::OnInitDialog()
123 CDialog::OnInitDialog();
125 if (m_bAddOnlyMode) {
126 TCHAR szRemoteName[MAX_PATH];
127 ULONG nBufSize = sizeof(szRemoteName);
129 if (WNetGetConnection(m_strAddOnlyPath.Left(2), szRemoteName, &nBufSize) == ERROR_SUCCESS) {
130 CString strAfsShare(szRemoteName);
131 int nSlashPos = strAfsShare.ReverseFind('\\');
132 if (nSlashPos > -1) {
133 strAfsShare = strAfsShare.Mid(nSlashPos + 1);
135 // Get the submount info for this share name
136 CSubmountInfo *pInfo = ReadSubmtInfo(strAfsShare);
137 CString strSharePath;
140 strSharePath = pInfo->GetPathName();
143 m_strAddOnlyPath = strSharePath + m_strAddOnlyPath.Mid(2);
153 if (!FillSubmtList()) {
154 // ShowMessageBox(IDS_GET_CELL_LIST_ERROR);
159 return TRUE; // return TRUE unless you set the focus to a control
160 // EXCEPTION: OCX Property Pages should return FALSE
163 BOOL CSubmountsDlg::FillSubmtList()
172 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
173 AFSREG_CLT_OPENAFS_SUBKEY "\\Submounts",
176 REG_OPTION_NON_VOLATILE,
177 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_READ|KEY_WRITE|KEY_QUERY_VALUE,
182 RegQueryInfoKey( hkSubmounts,
185 NULL, /* lpReserved */
186 NULL, /* lpcSubKeys */
187 NULL, /* lpcMaxSubKeyLen */
188 NULL, /* lpcMaxClassLen */
189 &dwSubmounts, /* lpcValues */
190 NULL, /* lpcMaxValueNameLen */
191 NULL, /* lpcMaxValueLen */
192 NULL, /* lpcbSecurityDescriptor */
193 NULL /* lpftLastWriteTime */
197 for ( dwIndex = 0; dwIndex < dwSubmounts; dwIndex ++ ) {
198 char submountName[256];
199 DWORD submountNameLen = sizeof(submountName);
201 RegEnumValue( hkSubmounts, dwIndex, submountName, &submountNameLen, NULL,
202 &dwType, NULL, NULL);
204 m_SubmtList.AddString(submountName);
207 RegCloseKey( hkSubmounts );
212 void CSubmountsDlg::OnDelete()
216 int nIndex = m_SubmtList.GetCurSel();
220 CString strShareName;
221 m_SubmtList.GetText(nIndex, strSubmt);
223 ASSERT(!strSubmt.IsEmpty());
225 strShareName = strSubmt.SpanExcluding("=");
227 if (ShowMessageBox(IDS_REALLY_DELETE_SUBMT, MB_YESNO | MB_ICONQUESTION, IDS_REALLY_DELETE_SUBMT, strShareName) != IDYES)
230 m_SubmtList.DeleteString(nIndex);
232 if (m_SubmtList.GetCount() == 0) {
233 m_Delete.EnableWindow(FALSE);
234 m_Change.EnableWindow(FALSE);
237 CSubmountInfo *pInfo = new CSubmountInfo();
238 pInfo->SetShareName(strShareName);
239 pInfo->SetStatus(SIS_DELETED);
243 void CSubmountsDlg::OnSelChangeList()
245 m_Delete.EnableWindow(TRUE);
246 m_Change.EnableWindow(TRUE);
249 static BOOL AddSubmt(CSubmountInfo *pInfo)
254 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
255 AFSREG_CLT_OPENAFS_SUBKEY "\\Submounts",
258 REG_OPTION_NON_VOLATILE,
259 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE,
264 DWORD status = RegSetValueEx( hkSubmounts, PCCHAR(pInfo->GetShareName()), 0, REG_SZ,
265 (const BYTE *)PCCHAR(pInfo->GetPathName()), strlen(PCCHAR(pInfo->GetPathName())) + 1);
267 RegCloseKey(hkSubmounts);
268 return (status == ERROR_SUCCESS);
271 static BOOL DeleteSubmt(CSubmountInfo *pInfo)
276 RegCreateKeyEx( HKEY_LOCAL_MACHINE,
277 AFSREG_CLT_OPENAFS_SUBKEY "\\Submounts",
280 REG_OPTION_NON_VOLATILE,
281 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE,
286 DWORD status = RegDeleteValue( hkSubmounts, PCCHAR(pInfo->GetShareName()));
288 RegCloseKey(hkSubmounts);
289 return (status == ERROR_SUCCESS);
292 void CSubmountsDlg::OnAdd()
296 if (m_bAddOnlyMode) {
297 CSubmountInfo info("", m_strAddOnlyPath, SIS_ADDED);
298 dlg.SetSubmtInfo(&info);
303 CSubmountInfo *pInfo = dlg.GetSubmtInfo();
307 m_SubmtList.AddString(pInfo->GetShareName() + "=" + pInfo->GetPathName());
311 void CSubmountsDlg::OnChange()
317 dlg.SetAddMode(FALSE);
319 int nIndex = m_SubmtList.GetCurSel();
323 CString strShareName;
324 m_SubmtList.GetText(nIndex, strSubmt);
326 ASSERT(!strSubmt.IsEmpty());
328 strShareName = strSubmt.SpanExcluding("=");
330 CSubmountInfo *pInfo = FindWork(strShareName);
332 // Make a copy we can free below
333 pInfo = new CSubmountInfo(*pInfo);
335 pInfo = ReadSubmtInfo(strShareName);
338 ShowMessageBox(IDS_GET_SUBMT_INFO_ERROR, MB_ICONEXCLAMATION, IDS_GET_SUBMT_INFO_ERROR, strShareName);
342 dlg.SetSubmtInfo(pInfo);
346 if (dlg.DoModal() != IDOK)
349 pInfo = dlg.GetSubmtInfo();
351 m_SubmtList.DeleteString(nIndex);
352 m_SubmtList.InsertString(nIndex,
353 pInfo->GetShareName() + "=" + pInfo->GetPathName());
358 void CSubmountsDlg::AddWork(CSubmountInfo *pInfo)
366 for (int i = 0; i < m_ToDo.GetSize(); i++) {
367 if (m_ToDo[i]->GetShareName() == pInfo->GetShareName()) {
368 if ((pInfo->GetStatus() == SIS_DELETED) && (m_ToDo[i]->GetStatus() == SIS_ADDED))
380 BOOL CSubmountsDlg::FixSubmts()
382 for (int i = 0; i < m_ToDo.GetSize(); i++) {
383 SUBMT_INFO_STATUS status = m_ToDo[i]->GetStatus();
384 if ((status == SIS_ADDED) || (status == SIS_CHANGED))
385 if (!AddSubmt(m_ToDo[i]))
387 if (status == SIS_DELETED)
388 if (!DeleteSubmt(m_ToDo[i]))
395 CSubmountInfo *CSubmountsDlg::FindWork(const CString& strShareName)
397 for (int i = 0; i < m_ToDo.GetSize(); i++)
398 if (m_ToDo[i]->GetShareName() == strShareName)
404 void CSubmountsDlg::WinHelp(DWORD dwData, UINT nCmd)
406 CDialog::WinHelp(dwData, nCmd);
409 void CSubmountsDlg::OnOk()
412 ShowMessageBox(IDS_SUBMT_SAVE_FAILED);
417 void CSubmountsDlg::SetAddOnlyMode(const CString& strAddOnlyPath)
419 m_bAddOnlyMode = TRUE;
420 m_strAddOnlyPath = strAddOnlyPath;