Leaked source code of windows server 2003
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.

215 lines
4.0 KiB

  1. #include "stdafx.h"
  2. #include "common.h"
  3. #include "balloon.h"
  4. #include "strfn.h"
  5. #ifdef _DEBUG
  6. #undef THIS_FILE
  7. static char BASED_CODE THIS_FILE[] = __FILE__;
  8. #endif
  9. #define new DEBUG_NEW
  10. void _EXPORT
  11. EditShowBalloon(HWND hwnd, LPCTSTR txt)
  12. {
  13. Edit_ShowBalloonTipHandler(hwnd, (LPCTSTR) txt);
  14. }
  15. void _EXPORT
  16. EditShowBalloon(HWND hwnd, HINSTANCE hInst, UINT ids)
  17. {
  18. if (ids != 0)
  19. {
  20. CString txt;
  21. if (txt.LoadString(hInst,ids))
  22. {
  23. EditShowBalloon(hwnd, (LPCTSTR) txt);
  24. }
  25. }
  26. }
  27. void _EXPORT EditHideBalloon(void)
  28. {
  29. Edit_HideBalloonTipHandler();
  30. }
  31. BOOL _EXPORT IsValidFolderPath(
  32. HWND hwnd,
  33. LPCTSTR value,
  34. BOOL local
  35. )
  36. {
  37. BOOL bReturn = TRUE;
  38. TCHAR expanded[_MAX_PATH];
  39. ExpandEnvironmentStrings(value, expanded, _MAX_PATH);
  40. int ids = 0;
  41. do
  42. {
  43. if (!PathIsValid(expanded))
  44. {
  45. ids = IDS_ERR_INVALID_PATH;
  46. break;
  47. }
  48. if (!IsDevicePath(expanded))
  49. {
  50. if (PathIsUNCServerShare(expanded) || PathIsUNCServer(expanded))
  51. {
  52. ids = IDS_ERR_BAD_PATH;
  53. break;
  54. }
  55. if (PathIsRelative(expanded))
  56. {
  57. ids = IDS_ERR_BAD_PATH;
  58. break;
  59. }
  60. if (local)
  61. {
  62. if (!PathIsDirectory(expanded))
  63. {
  64. ids = IDS_ERR_PATH_NOT_FOUND;
  65. break;
  66. }
  67. }
  68. }
  69. }
  70. while (FALSE);
  71. if (ids != 0)
  72. {
  73. bReturn = FALSE;
  74. EditShowBalloon(hwnd,_Module.GetResourceInstance(),ids);
  75. }
  76. return bReturn;
  77. }
  78. BOOL _EXPORT IsValidFilePath(
  79. HWND hwnd,
  80. LPCTSTR value,
  81. BOOL local
  82. )
  83. {
  84. BOOL bReturn = TRUE;
  85. TCHAR expanded[_MAX_PATH];
  86. ExpandEnvironmentStrings(value, expanded, _MAX_PATH);
  87. int ids = 0;
  88. do
  89. {
  90. if (!PathIsValid(expanded))
  91. {
  92. ids = IDS_ERR_INVALID_PATH;
  93. break;
  94. }
  95. if (!IsDevicePath(expanded))
  96. {
  97. if (PathIsUNCServerShare(expanded) || PathIsUNCServer(expanded))
  98. {
  99. ids = IDS_ERR_BAD_PATH;
  100. break;
  101. }
  102. if (PathIsRelative(expanded))
  103. {
  104. ids = IDS_ERR_BAD_PATH;
  105. break;
  106. }
  107. if (local)
  108. {
  109. if (PathIsDirectory(expanded))
  110. {
  111. ids = IDS_ERR_FILE_NOT_FOUND;
  112. break;
  113. }
  114. if (!PathFileExists(expanded))
  115. {
  116. ids = IDS_ERR_FILE_NOT_FOUND;
  117. break;
  118. }
  119. }
  120. }
  121. }
  122. while (FALSE);
  123. if (ids != 0)
  124. {
  125. bReturn = FALSE;
  126. EditShowBalloon(hwnd,_Module.GetResourceInstance(),ids);
  127. }
  128. return bReturn;
  129. }
  130. BOOL _EXPORT IsValidUNCFolderPath(
  131. HWND hwnd,
  132. LPCTSTR value
  133. )
  134. {
  135. BOOL bReturn = TRUE;
  136. int ids = 0;
  137. do
  138. {
  139. if (!PathIsValid(value))
  140. {
  141. ids = IDS_ERR_INVALID_PATH;
  142. break;
  143. }
  144. // PathIsUNCServer doesn't catch "\\". We are expecting share here.
  145. if (!PathIsUNC(value) || PathIsUNCServer(value) || lstrlen(value) == 2)
  146. {
  147. ids = IDS_BAD_UNC_PATH;
  148. break;
  149. }
  150. }
  151. while (FALSE);
  152. if (ids != 0)
  153. {
  154. bReturn = FALSE;
  155. EditShowBalloon(hwnd,_Module.GetResourceInstance(),ids);
  156. }
  157. return bReturn;
  158. }
  159. BOOL _EXPORT IsValidPath(LPCTSTR lpFileName)
  160. {
  161. while ((*lpFileName != _T('?'))
  162. && (*lpFileName != _T('*'))
  163. && (*lpFileName != _T('"'))
  164. && (*lpFileName != _T('<'))
  165. && (*lpFileName != _T('>'))
  166. && (*lpFileName != _T('|'))
  167. && (*lpFileName != _T('/'))
  168. && (*lpFileName != _T(','))
  169. && (*lpFileName != _T('\0')))
  170. {
  171. lpFileName++;
  172. }
  173. if (*lpFileName != '\0')
  174. return FALSE;
  175. return TRUE;
  176. }
  177. BOOL _EXPORT IsValidName(LPCTSTR lpFileName)
  178. {
  179. while ((*lpFileName != _T('?'))
  180. && (*lpFileName != _T('\\'))
  181. && (*lpFileName != _T('*'))
  182. && (*lpFileName != _T('"'))
  183. && (*lpFileName != _T('<'))
  184. && (*lpFileName != _T('>'))
  185. && (*lpFileName != _T('|'))
  186. && (*lpFileName != _T('/'))
  187. && (*lpFileName != _T(':'))
  188. && (*lpFileName != _T('\0')))
  189. {
  190. lpFileName++;
  191. }
  192. if (*lpFileName != '\0')
  193. return FALSE;
  194. return TRUE;
  195. }