Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

286 lines
8.6 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. * thunk.cxx
  7. * Contains dialogs called by the wfw thunk DLL.
  8. * For deleting and creating shares.
  9. *
  10. * FILE HISTORY:
  11. * ChuckC 3/25/93 Created
  12. *
  13. */
  14. #define INCL_WINDOWS
  15. #define INCL_NETERRORS
  16. #define INCL_NETSHARE
  17. #define INCL_NETSERVER
  18. #include <lmui.hxx>
  19. extern "C"
  20. {
  21. #include <helpnums.h>
  22. #include <sharedlg.h>
  23. }
  24. #define INCL_BLT_MSGPOPUP
  25. #define INCL_BLT_SPIN_GROUP
  26. #include <blt.hxx>
  27. #include <lmoshare.hxx>
  28. #include <lmoesh.hxx>
  29. #include <lmoeconn.hxx>
  30. #include <wnetdev.hxx>
  31. #include "sharestp.hxx"
  32. #include "sharecrt.hxx"
  33. /*******************************************************************
  34. NAME: ShareAsDialogA0
  35. SYNOPSIS: dialog for creating shares
  36. ENTRY: hwnd - hwnd of the parent window
  37. nType - type of share (currently must be disk)
  38. pszPath - directory to share
  39. EXIT:
  40. RETURNS:
  41. NOTES: CODEWORK: the help context here is relative to our
  42. normal winfile stuff. at this late stage,
  43. it is too late to add new help for something
  44. that most likely is never used. as it is, any
  45. app that calls this internal API will still
  46. get help, just that it piggybacks on top of winfile.
  47. HISTORY:
  48. ChuckC 3/25/93 Stole from sharefmx
  49. ********************************************************************/
  50. DWORD ShareAsDialogA0( HWND hwnd,
  51. DWORD nType,
  52. CHAR *pszPath)
  53. {
  54. APIERR err = NERR_Success;
  55. if (nType != RESOURCETYPE_DISK)
  56. return ERROR_NOT_SUPPORTED ;
  57. if ( err = ::InitShellUI() )
  58. return err;
  59. ULONG ulOldHelpContextBase = POPUP::SetHelpContextBase( HC_UI_SHELL_BASE );
  60. //
  61. // Get the selected item passed in
  62. //
  63. NLS_STR nlsSelItem;
  64. SERVER_WITH_PASSWORD_PROMPT *psvr = NULL;
  65. if ((err = nlsSelItem.MapCopyFrom(pszPath)) == NERR_Success )
  66. {
  67. BOOL fShared = FALSE;
  68. //
  69. // If a file/directory is selected, check to see if the directory
  70. // (the directory the file is in if a file is selected)
  71. // is shared or not. If we select a file/directory on a LM2.1
  72. // share level server, a dialog will prompt for password to the
  73. // ADMIN$ share if we don't already have a connection to it.
  74. //
  75. if ( nlsSelItem.QueryTextLength() != 0 )
  76. {
  77. AUTO_CURSOR autocur;
  78. NET_NAME netname( nlsSelItem, TYPE_PATH_ABS );
  79. NLS_STR nlsLocalPath;
  80. NLS_STR nlsServer;
  81. if ( ((err = netname.QueryError()) == NERR_Success )
  82. && ((err = nlsLocalPath.QueryError()) == NERR_Success )
  83. && ((err = nlsServer.QueryError()) == NERR_Success )
  84. )
  85. {
  86. BOOL fLocal = netname.IsLocal( &err );
  87. if ( ( err == NERR_Success )
  88. && ( fLocal
  89. || ((err = netname.QueryComputerName(&nlsServer))
  90. == NERR_Success)
  91. )
  92. )
  93. {
  94. psvr = new SERVER_WITH_PASSWORD_PROMPT( nlsServer,
  95. hwnd,
  96. HC_UI_SHELL_BASE );
  97. if ( ( psvr != NULL )
  98. && ((err = psvr->QueryError()) == NERR_Success )
  99. && ((err = psvr->GetInfo()) == NERR_Success )
  100. && ((err = netname.QueryLocalPath(&nlsLocalPath))
  101. ==NERR_Success)
  102. )
  103. {
  104. //
  105. // Check to see if the directory is shared
  106. //
  107. SHARE2_ENUM sh2Enum( nlsServer );
  108. if ( ((err = sh2Enum.QueryError()) == NERR_Success )
  109. && ((err = sh2Enum.GetInfo()) == NERR_Success )
  110. )
  111. {
  112. SHARE_NAME_WITH_PATH_ENUM_ITER shPathEnum(sh2Enum,
  113. nlsLocalPath);
  114. if ((err = shPathEnum.QueryError()) == NERR_Success)
  115. {
  116. const TCHAR *pszShare;
  117. while ((pszShare = shPathEnum()) != NULL )
  118. {
  119. fShared = TRUE;
  120. break;
  121. }
  122. }
  123. }
  124. }
  125. else
  126. {
  127. if ( psvr == NULL )
  128. err = ERROR_NOT_ENOUGH_MEMORY;
  129. }
  130. }
  131. }
  132. }
  133. if ( err == NERR_Success )
  134. {
  135. //
  136. // If the directory is shared, popup the share properties
  137. // dialog. If not, popup the new share dialog.
  138. //
  139. SHARE_DIALOG_BASE *pdlg;
  140. if ( !fShared )
  141. pdlg = new FILEMGR_NEW_SHARE_DIALOG( hwnd,
  142. nlsSelItem,
  143. HC_UI_SHELL_BASE );
  144. else
  145. pdlg = new FILEMGR_SHARE_PROP_DIALOG( hwnd,
  146. nlsSelItem,
  147. HC_UI_SHELL_BASE );
  148. err = (APIERR) ( pdlg == NULL? ERROR_NOT_ENOUGH_MEMORY
  149. : pdlg->QueryError());
  150. if ( err == NERR_Success)
  151. {
  152. BOOL fSucceeded;
  153. err = pdlg->Process( &fSucceeded );
  154. //
  155. // Refresh the file manager if successfully created a share
  156. //
  157. if (( err == NERR_Success ) && fSucceeded )
  158. {
  159. delete psvr;
  160. psvr = NULL;
  161. }
  162. }
  163. delete pdlg;
  164. }
  165. }
  166. delete psvr;
  167. psvr = NULL;
  168. if ( err != NERR_Success )
  169. {
  170. if ( err == ERROR_INVALID_LEVEL )
  171. err = ERROR_NOT_SUPPORTED;
  172. else if ( err == IERR_USER_CLICKED_CANCEL )
  173. err = NERR_Success;
  174. if ( err != NERR_Success )
  175. ::MsgPopup( hwnd, err );
  176. }
  177. POPUP::SetHelpContextBase( ulOldHelpContextBase );
  178. return NERR_Success;
  179. }
  180. /*******************************************************************
  181. NAME: StopShareDialogA0
  182. SYNOPSIS: dialog for deleting shares
  183. ENTRY: hwnd - hwnd of the parent window
  184. nType - type of share (currently must be disk)
  185. pszPath - directory to stop share
  186. EXIT:
  187. RETURNS:
  188. NOTES:
  189. HISTORY:
  190. ChuckC 3/25/93 Stole from sharefmx.cxx
  191. ********************************************************************/
  192. DWORD StopShareDialogA0( HWND hwnd,
  193. DWORD nType,
  194. CHAR *pszPath)
  195. {
  196. APIERR err = NERR_Success;
  197. if (nType != RESOURCETYPE_DISK)
  198. return ERROR_NOT_SUPPORTED ;
  199. if ( err = ::InitShellUI() )
  200. return err;
  201. ULONG ulOldHelpContextBase = POPUP::SetHelpContextBase( HC_UI_SHELL_BASE );
  202. //
  203. // use the item passed in
  204. //
  205. NLS_STR nlsSelItem;
  206. if ( (err = nlsSelItem.MapCopyFrom(pszPath)) == NERR_Success )
  207. {
  208. //
  209. // Show the stop sharing dialog
  210. //
  211. STOP_SHARING_DIALOG *pdlg = new STOP_SHARING_DIALOG( hwnd,
  212. nlsSelItem,
  213. HC_UI_SHELL_BASE );
  214. err = (APIERR) ( pdlg == NULL? ERROR_NOT_ENOUGH_MEMORY
  215. : pdlg->QueryError() );
  216. BOOL fSucceeded;
  217. if ( err == NERR_Success )
  218. err = pdlg->Process( &fSucceeded );
  219. delete pdlg;
  220. }
  221. if ( err != NERR_Success )
  222. {
  223. if (err == IERR_USER_CLICKED_CANCEL)
  224. err = NERR_Success;
  225. else
  226. ::MsgPopup( hwnd, err );
  227. }
  228. POPUP::SetHelpContextBase( ulOldHelpContextBase );
  229. return NERR_Success;
  230. }