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"
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;
47 len = GetPrivateProfileString("AFS Submounts",
49 "", pathName, sizeof(pathName),
52 if (len == 0 || len == sizeof(pathName) - 1)
55 pInfo = new CSubmountInfo();
56 pInfo->SetShareName(strShareName);
57 pInfo->SetPathName(pathName);
62 CSubmountsDlg::CSubmountsDlg() : CDialog()
64 InitModalIndirect (TaLocale_GetDialogResource (CSubmountsDlg::IDD));
66 //{{AFX_DATA_INIT(CSubmountsDlg)
67 // NOTE: the ClassWizard will add member initialization here
70 m_bAddOnlyMode = FALSE;
73 CSubmountsDlg::~CSubmountsDlg()
75 for (int i = 0; i < m_ToDo.GetSize(); i++)
81 void CSubmountsDlg::DoDataExchange(CDataExchange* pDX)
83 CDialog::DoDataExchange(pDX);
84 //{{AFX_DATA_MAP(CSubmountsDlg)
85 DDX_Control(pDX, IDC_DELETE, m_Delete);
86 DDX_Control(pDX, IDC_CHANGE, m_Change);
87 DDX_Control(pDX, IDC_LIST, m_SubmtList);
92 BEGIN_MESSAGE_MAP(CSubmountsDlg, CDialog)
93 //{{AFX_MSG_MAP(CSubmountsDlg)
94 ON_BN_CLICKED(IDC_ADD, OnAdd)
95 ON_BN_CLICKED(IDC_CHANGE, OnChange)
96 ON_BN_CLICKED(IDC_DELETE, OnDelete)
97 ON_LBN_SELCHANGE(IDC_LIST, OnSelChangeList)
98 ON_BN_CLICKED(IDOK, OnOk)
102 /////////////////////////////////////////////////////////////////////////////
103 // CSubmountsDlg message handlers
105 BOOL CSubmountsDlg::OnInitDialog()
107 CDialog::OnInitDialog();
109 if (m_bAddOnlyMode) {
110 TCHAR szRemoteName[MAX_PATH];
111 ULONG nBufSize = sizeof(szRemoteName);
113 if (WNetGetConnection(m_strAddOnlyPath.Left(2), szRemoteName, &nBufSize) == ERROR_SUCCESS) {
114 CString strAfsShare(szRemoteName);
115 int nSlashPos = strAfsShare.ReverseFind('\\');
116 if (nSlashPos > -1) {
117 strAfsShare = strAfsShare.Mid(nSlashPos + 1);
119 // Get the submount info for this share name
120 CSubmountInfo *pInfo = ReadSubmtInfo(strAfsShare);
121 CString strSharePath;
124 strSharePath = pInfo->GetPathName();
127 m_strAddOnlyPath = strSharePath + m_strAddOnlyPath.Mid(2);
137 if (!FillSubmtList()) {
138 // ShowMessageBox(IDS_GET_CELL_LIST_ERROR);
143 return TRUE; // return TRUE unless you set the focus to a control
144 // EXCEPTION: OCX Property Pages should return FALSE
147 BOOL CSubmountsDlg::FillSubmtList()
151 DWORD lsize, size = 500;
152 char *buf = NULL, *next;
155 * We don't know how large a buffer we need. Keep doubling it until
156 * we're sure we have enough.
160 if (buf != NULL) free(buf);
161 buf = (char *)malloc(size);
162 lsize = GetPrivateProfileSection("AFS Submounts", buf, size,
165 while (lsize >= size - 2);
170 m_SubmtList.AddString(next);
171 next += (strlen(next) + 1);
181 void CSubmountsDlg::OnDelete()
185 int nIndex = m_SubmtList.GetCurSel();
189 CString strShareName;
190 m_SubmtList.GetText(nIndex, strSubmt);
192 ASSERT(!strSubmt.IsEmpty());
194 strShareName = strSubmt.SpanExcluding("=");
196 if (ShowMessageBox(IDS_REALLY_DELETE_SUBMT, MB_YESNO | MB_ICONQUESTION, IDS_REALLY_DELETE_SUBMT, strShareName) != IDYES)
199 m_SubmtList.DeleteString(nIndex);
201 if (m_SubmtList.GetCount() == 0) {
202 m_Delete.EnableWindow(FALSE);
203 m_Change.EnableWindow(FALSE);
206 CSubmountInfo *pInfo = new CSubmountInfo();
207 pInfo->SetShareName(strShareName);
208 pInfo->SetStatus(SIS_DELETED);
212 void CSubmountsDlg::OnSelChangeList()
214 m_Delete.EnableWindow(TRUE);
215 m_Change.EnableWindow(TRUE);
218 static BOOL AddSubmt(CSubmountInfo *pInfo)
223 WritePrivateProfileString("AFS Submounts",
224 PCCHAR(pInfo->GetShareName()),
225 PCCHAR(pInfo->GetPathName()),
231 static BOOL DeleteSubmt(CSubmountInfo *pInfo)
236 WritePrivateProfileString("AFS Submounts",
237 PCCHAR(pInfo->GetShareName()),
243 void CSubmountsDlg::OnAdd()
247 if (m_bAddOnlyMode) {
248 CSubmountInfo info("", m_strAddOnlyPath, SIS_ADDED);
249 dlg.SetSubmtInfo(&info);
254 CSubmountInfo *pInfo = dlg.GetSubmtInfo();
258 m_SubmtList.AddString(pInfo->GetShareName() + "=" + pInfo->GetPathName());
262 void CSubmountsDlg::OnChange()
268 dlg.SetAddMode(FALSE);
270 int nIndex = m_SubmtList.GetCurSel();
274 CString strShareName;
275 m_SubmtList.GetText(nIndex, strSubmt);
277 ASSERT(!strSubmt.IsEmpty());
279 strShareName = strSubmt.SpanExcluding("=");
281 CSubmountInfo *pInfo = FindWork(strShareName);
283 // Make a copy we can free below
284 pInfo = new CSubmountInfo(*pInfo);
286 pInfo = ReadSubmtInfo(strShareName);
289 ShowMessageBox(IDS_GET_SUBMT_INFO_ERROR, MB_ICONEXCLAMATION, IDS_GET_SUBMT_INFO_ERROR, strShareName);
293 dlg.SetSubmtInfo(pInfo);
297 if (dlg.DoModal() != IDOK)
300 pInfo = dlg.GetSubmtInfo();
302 m_SubmtList.DeleteString(nIndex);
303 m_SubmtList.InsertString(nIndex,
304 pInfo->GetShareName() + "=" + pInfo->GetPathName());
309 void CSubmountsDlg::AddWork(CSubmountInfo *pInfo)
317 for (int i = 0; i < m_ToDo.GetSize(); i++) {
318 if (m_ToDo[i]->GetShareName() == pInfo->GetShareName()) {
319 if ((pInfo->GetStatus() == SIS_DELETED) && (m_ToDo[i]->GetStatus() == SIS_ADDED))
331 BOOL CSubmountsDlg::FixSubmts()
333 for (int i = 0; i < m_ToDo.GetSize(); i++) {
334 SUBMT_INFO_STATUS status = m_ToDo[i]->GetStatus();
335 if ((status == SIS_ADDED) || (status == SIS_CHANGED))
336 if (!AddSubmt(m_ToDo[i]))
338 if (status == SIS_DELETED)
339 if (!DeleteSubmt(m_ToDo[i]))
346 CSubmountInfo *CSubmountsDlg::FindWork(const CString& strShareName)
348 for (int i = 0; i < m_ToDo.GetSize(); i++)
349 if (m_ToDo[i]->GetShareName() == strShareName)
355 void CSubmountsDlg::WinHelp(DWORD dwData, UINT nCmd)
357 CDialog::WinHelp(dwData, nCmd);
360 void CSubmountsDlg::OnOk()
363 ShowMessageBox(IDS_SUBMT_SAVE_FAILED);
368 void CSubmountsDlg::SetAddOnlyMode(const CString& strAddOnlyPath)
370 m_bAddOnlyMode = TRUE;
371 m_strAddOnlyPath = strAddOnlyPath;