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
TEXT("\\Submounts"),
55 REG_OPTION_NON_VOLATILE
,
56 (IsWow64()?KEY_WOW64_64KEY
:0)|KEY_READ
,
63 len
= sizeof(pathName
);
64 status
= RegQueryValueEx( hkSubmounts
, 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
TEXT("\\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 TCHAR 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(_T("="));
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
TEXT("\\Submounts"),
258 REG_OPTION_NON_VOLATILE
,
259 (IsWow64()?KEY_WOW64_64KEY
:0)|KEY_WRITE
,
264 DWORD status
= RegSetValueEx( hkSubmounts
, pInfo
->GetShareName(), 0, REG_SZ
,
265 (const BYTE
*)(const TCHAR
*) pInfo
->GetPathName(),
266 pInfo
->GetPathName().GetLength() + 1);
268 RegCloseKey(hkSubmounts
);
269 return (status
== ERROR_SUCCESS
);
272 static BOOL
DeleteSubmt(CSubmountInfo
*pInfo
)
277 RegCreateKeyEx( HKEY_LOCAL_MACHINE
,
278 AFSREG_CLT_OPENAFS_SUBKEY
TEXT("\\Submounts"),
281 REG_OPTION_NON_VOLATILE
,
282 (IsWow64()?KEY_WOW64_64KEY
:0)|KEY_WRITE
,
287 DWORD status
= RegDeleteValue( hkSubmounts
, pInfo
->GetShareName());
289 RegCloseKey(hkSubmounts
);
290 return (status
== ERROR_SUCCESS
);
293 void CSubmountsDlg::OnAdd()
297 if (m_bAddOnlyMode
) {
298 CSubmountInfo
info("", m_strAddOnlyPath
, SIS_ADDED
);
299 dlg
.SetSubmtInfo(&info
);
304 CSubmountInfo
*pInfo
= dlg
.GetSubmtInfo();
308 m_SubmtList
.AddString(pInfo
->GetShareName() + "=" + pInfo
->GetPathName());
312 void CSubmountsDlg::OnChange()
318 dlg
.SetAddMode(FALSE
);
320 int nIndex
= m_SubmtList
.GetCurSel();
324 CString strShareName
;
325 m_SubmtList
.GetText(nIndex
, strSubmt
);
327 ASSERT(!strSubmt
.IsEmpty());
329 strShareName
= strSubmt
.SpanExcluding(_T("="));
331 CSubmountInfo
*pInfo
= FindWork(strShareName
);
333 // Make a copy we can free below
334 pInfo
= new CSubmountInfo(*pInfo
);
336 pInfo
= ReadSubmtInfo(strShareName
);
339 ShowMessageBox(IDS_GET_SUBMT_INFO_ERROR
, MB_ICONEXCLAMATION
, IDS_GET_SUBMT_INFO_ERROR
, strShareName
);
343 dlg
.SetSubmtInfo(pInfo
);
347 if (dlg
.DoModal() != IDOK
)
350 pInfo
= dlg
.GetSubmtInfo();
352 m_SubmtList
.DeleteString(nIndex
);
353 m_SubmtList
.InsertString(nIndex
,
354 pInfo
->GetShareName() + "=" + pInfo
->GetPathName());
359 void CSubmountsDlg::AddWork(CSubmountInfo
*pInfo
)
367 for (int i
= 0; i
< m_ToDo
.GetSize(); i
++) {
368 if (m_ToDo
[i
]->GetShareName() == pInfo
->GetShareName()) {
369 if ((pInfo
->GetStatus() == SIS_DELETED
) && (m_ToDo
[i
]->GetStatus() == SIS_ADDED
))
381 BOOL
CSubmountsDlg::FixSubmts()
383 for (int i
= 0; i
< m_ToDo
.GetSize(); i
++) {
384 SUBMT_INFO_STATUS status
= m_ToDo
[i
]->GetStatus();
385 if ((status
== SIS_ADDED
) || (status
== SIS_CHANGED
))
386 if (!AddSubmt(m_ToDo
[i
]))
388 if (status
== SIS_DELETED
)
389 if (!DeleteSubmt(m_ToDo
[i
]))
396 CSubmountInfo
*CSubmountsDlg::FindWork(const CString
& strShareName
)
398 for (int i
= 0; i
< m_ToDo
.GetSize(); i
++)
399 if (m_ToDo
[i
]->GetShareName() == strShareName
)
405 void CSubmountsDlg::WinHelp(DWORD dwData
, UINT nCmd
)
407 CDialog::WinHelp(dwData
, nCmd
);
410 void CSubmountsDlg::OnOk()
413 ShowMessageBox(IDS_SUBMT_SAVE_FAILED
);
418 void CSubmountsDlg::SetAddOnlyMode(const CString
& strAddOnlyPath
)
420 m_bAddOnlyMode
= TRUE
;
421 m_strAddOnlyPath
= strAddOnlyPath
;