windows-shell-add-symlink-20080206
[openafs.git] / src / WINNT / client_exp / make_symbolic_link_dlg.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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  */
9
10 #include "stdafx.h"
11 #include <winsock2.h>
12 #include <ws2tcpip.h>
13
14 extern "C" {
15 #include <afs/param.h>
16 #include <afs/stds.h>
17 }
18
19 #include "afs_shl_ext.h"
20 #include "make_symbolic_link_dlg.h"
21 #include "gui2fs.h"
22 #include "msgs.h"
23 #define MAXSIZE 2048 /* most I'll get back from PIOCTL */
24
25 #ifdef _DEBUG
26 #define new DEBUG_NEW
27 #undef THIS_FILE
28 static char THIS_FILE[] = __FILE__;
29 #endif
30
31 /////////////////////////////////////////////////////////////////////////////
32 // CMakeMountPointDlg dialog
33
34
35 CMakeSymbolicLinkDlg::CMakeSymbolicLinkDlg(CWnd* pParent /*=NULL*/)
36         : CDialog()
37 {
38         InitModalIndirect (TaLocale_GetDialogResource (CMakeSymbolicLinkDlg::IDD), pParent);
39
40         //{{AFX_DATA_INIT(CMakeSymbolicLinkDlg)
41         m_strName = _T("");
42         m_strDir = _T("");
43         //}}AFX_DATA_INIT
44 }
45
46
47 void CMakeSymbolicLinkDlg::DoDataExchange(CDataExchange* pDX)
48 {
49         CDialog::DoDataExchange(pDX);
50         //{{AFX_DATA_MAP(CMakeSymbolicLinkDlg)
51         DDX_Control(pDX, IDOK, m_OK);
52         DDX_Control(pDX, IDC_NAME, m_Name);
53         DDX_Control(pDX, IDC_DIR, m_Dir);
54         DDX_Text(pDX, IDC_NAME, m_strName);
55         DDV_MaxChars(pDX, m_strName, 63);
56         DDX_Text(pDX, IDC_DIR, m_strDir);
57         DDV_MaxChars(pDX, m_strDir, 255);
58         //}}AFX_DATA_MAP
59 }
60
61
62 BEGIN_MESSAGE_MAP(CMakeSymbolicLinkDlg, CDialog)
63         //{{AFX_MSG_MAP(CMakeSymbolicLinkDlg)
64         //}}AFX_MSG_MAP
65 END_MESSAGE_MAP()
66
67 /////////////////////////////////////////////////////////////////////////////
68 // CMakeSymbolicLinkDlg message handlers
69
70 void CMakeSymbolicLinkDlg::OnOK() 
71 {
72     char space[64];
73     UINT code;
74     int i;
75     UpdateData(TRUE);
76     CString strName;
77     CString strTarget;
78     m_Name.GetWindowText(strName);
79     m_Dir.GetWindowText(strTarget);
80     if (!IsPathInAfs(m_sBase)) {
81         MessageBeep((UINT)-1);
82         strTarget+=" - Path is not in AFS directory";
83         AfxMessageBox(strTarget,MB_OK);
84         return;
85     } 
86     if (m_sBase.GetLength()>MAX_PATH-2)
87     {
88         MessageBeep((UINT)-1);
89         ShowMessageBox(IDS_CURRENT_DIRECTORY_PATH_TOO_LONG,MB_OK,IDS_CURRENT_DIRECTORY_PATH_TOO_LONG);
90     }
91     if (!SetCurrentDirectory(m_sBase))
92     {
93         MessageBeep((UINT)-1);
94         ShowMessageBox(IDS_UNABLE_TO_SET_CURRENT_DIRECTORY,MB_OK,IDS_UNABLE_TO_SET_CURRENT_DIRECTORY);
95         return;
96     }
97     if ((code=MakeSymbolicLink(strName,strTarget))!=0){
98         MessageBeep((UINT)-1);
99         ShowMessageBox(IDS_UNABLE_TO_CREATE_SYMBOLIC_LINK,MB_OK,IDS_UNABLE_TO_CREATE_SYMBOLIC_LINK,code);
100         return;
101     }
102     CDialog::OnOK();
103 }
104 /*
105 void CMakeSymbolicLinkDlg::OnChangeName() 
106 {
107         CString strName;
108         m_Name.GetWindowText(strName);
109         if (strName.GetLength() > 63) {
110                 MessageBeep((UINT)-1);
111                 m_Name.SetWindowText(m_strName);
112         } else
113                 m_strName = strName;
114         CheckEnableOk();
115 }
116
117 void CMakeSymbolicLinkDlg::OnChangeDir() 
118 {
119         m_Dir.GetWindowText(m_strDir);
120     if (!IsPathInAfs(m_strDir)) {
121                 MessageBeep((UINT)-1);
122                 m_Dir.SetWindowText(m_strDir);
123         }
124         CheckEnableOk();
125 }
126 */
127 void CMakeSymbolicLinkDlg::CheckEnableOk()
128 {
129         BOOL bEnable = FALSE;
130         
131         if ((m_strName.GetLength() > 0) && (m_strDir.GetLength() > 0))
132                 bEnable = TRUE;
133
134         m_OK.EnableWindow(bEnable);
135 }
136
137 BOOL CMakeSymbolicLinkDlg::OnInitDialog() 
138 {
139         CDialog::OnInitDialog();
140         
141 //      m_Dir.SetWindowText(m_strDir);
142 //      m_Name.SetWindowText(m_strName);
143         UpdateData(FALSE);
144
145         return TRUE;  // return TRUE unless you set the focus to a control
146                       // EXCEPTION: OCX Property Pages should return FALSE
147 }