filex.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #include "stdafx.h"
  11. #include <SysUtils.hpp>
  12. #include <StrUtils.hpp>
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CFileException
  15. void CFileException::ThrowOsError(LONG lOsError,
  16. const wchar_t * lpszFileName /* = NULL */)
  17. {
  18. if (lOsError != 0)
  19. AfxThrowFileException(CFileException::OsErrorToException(lOsError),
  20. lOsError, lpszFileName);
  21. }
  22. UnicodeString CFileException::GetErrorMessage()
  23. {
  24. UnicodeString strFileName = m_strFileName;
  25. if (strFileName.IsEmpty())
  26. strFileName = LoadStr(AFX_IDS_UNNAMED_FILE);
  27. UnicodeString strMessage = LoadStr(m_cause + AFX_IDP_FILE_NONE);
  28. strMessage = ReplaceStr(strMessage, L"%1", strFileName.c_str());
  29. return strMessage;
  30. }
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CFileException helpers
  33. void AfxThrowFileException(int cause, LONG lOsError,
  34. const wchar_t * lpszFileName /* == NULL */)
  35. {
  36. throw new CFileException(cause, lOsError, lpszFileName);
  37. }
  38. int CFileException::OsErrorToException(LONG lOsErr)
  39. {
  40. // NT Error codes
  41. switch ((UINT)lOsErr)
  42. {
  43. case NO_ERROR:
  44. return CFileException::none;
  45. case ERROR_FILE_NOT_FOUND:
  46. return CFileException::fileNotFound;
  47. case ERROR_PATH_NOT_FOUND:
  48. return CFileException::badPath;
  49. case ERROR_TOO_MANY_OPEN_FILES:
  50. return CFileException::tooManyOpenFiles;
  51. case ERROR_ACCESS_DENIED:
  52. return CFileException::accessDenied;
  53. case ERROR_INVALID_HANDLE:
  54. return CFileException::fileNotFound;
  55. case ERROR_BAD_FORMAT:
  56. return CFileException::invalidFile;
  57. case ERROR_INVALID_ACCESS:
  58. return CFileException::accessDenied;
  59. case ERROR_INVALID_DRIVE:
  60. return CFileException::badPath;
  61. case ERROR_CURRENT_DIRECTORY:
  62. return CFileException::removeCurrentDir;
  63. case ERROR_NOT_SAME_DEVICE:
  64. return CFileException::badPath;
  65. case ERROR_NO_MORE_FILES:
  66. return CFileException::fileNotFound;
  67. case ERROR_WRITE_PROTECT:
  68. return CFileException::accessDenied;
  69. case ERROR_BAD_UNIT:
  70. return CFileException::hardIO;
  71. case ERROR_NOT_READY:
  72. return CFileException::hardIO;
  73. case ERROR_BAD_COMMAND:
  74. return CFileException::hardIO;
  75. case ERROR_CRC:
  76. return CFileException::hardIO;
  77. case ERROR_BAD_LENGTH:
  78. return CFileException::badSeek;
  79. case ERROR_SEEK:
  80. return CFileException::badSeek;
  81. case ERROR_NOT_DOS_DISK:
  82. return CFileException::invalidFile;
  83. case ERROR_SECTOR_NOT_FOUND:
  84. return CFileException::badSeek;
  85. case ERROR_WRITE_FAULT:
  86. return CFileException::accessDenied;
  87. case ERROR_READ_FAULT:
  88. return CFileException::badSeek;
  89. case ERROR_SHARING_VIOLATION:
  90. return CFileException::sharingViolation;
  91. case ERROR_LOCK_VIOLATION:
  92. return CFileException::lockViolation;
  93. case ERROR_WRONG_DISK:
  94. return CFileException::badPath;
  95. case ERROR_SHARING_BUFFER_EXCEEDED:
  96. return CFileException::tooManyOpenFiles;
  97. case ERROR_HANDLE_EOF:
  98. return CFileException::endOfFile;
  99. case ERROR_HANDLE_DISK_FULL:
  100. return CFileException::diskFull;
  101. case ERROR_DUP_NAME:
  102. return CFileException::badPath;
  103. case ERROR_BAD_NETPATH:
  104. return CFileException::badPath;
  105. case ERROR_NETWORK_BUSY:
  106. return CFileException::accessDenied;
  107. case ERROR_DEV_NOT_EXIST:
  108. return CFileException::badPath;
  109. case ERROR_ADAP_HDW_ERR:
  110. return CFileException::hardIO;
  111. case ERROR_BAD_NET_RESP:
  112. return CFileException::accessDenied;
  113. case ERROR_UNEXP_NET_ERR:
  114. return CFileException::hardIO;
  115. case ERROR_BAD_REM_ADAP:
  116. return CFileException::invalidFile;
  117. case ERROR_NO_SPOOL_SPACE:
  118. return CFileException::directoryFull;
  119. case ERROR_NETNAME_DELETED:
  120. return CFileException::accessDenied;
  121. case ERROR_NETWORK_ACCESS_DENIED:
  122. return CFileException::accessDenied;
  123. case ERROR_BAD_DEV_TYPE:
  124. return CFileException::invalidFile;
  125. case ERROR_BAD_NET_NAME:
  126. return CFileException::badPath;
  127. case ERROR_TOO_MANY_NAMES:
  128. return CFileException::tooManyOpenFiles;
  129. case ERROR_SHARING_PAUSED:
  130. return CFileException::badPath;
  131. case ERROR_REQ_NOT_ACCEP:
  132. return CFileException::accessDenied;
  133. case ERROR_FILE_EXISTS:
  134. return CFileException::accessDenied;
  135. case ERROR_CANNOT_MAKE:
  136. return CFileException::accessDenied;
  137. case ERROR_ALREADY_ASSIGNED:
  138. return CFileException::badPath;
  139. case ERROR_INVALID_PASSWORD:
  140. return CFileException::accessDenied;
  141. case ERROR_NET_WRITE_FAULT:
  142. return CFileException::hardIO;
  143. case ERROR_DISK_CHANGE:
  144. return CFileException::fileNotFound;
  145. case ERROR_DRIVE_LOCKED:
  146. return CFileException::lockViolation;
  147. case ERROR_BUFFER_OVERFLOW:
  148. return CFileException::badPath;
  149. case ERROR_DISK_FULL:
  150. return CFileException::diskFull;
  151. case ERROR_NO_MORE_SEARCH_HANDLES:
  152. return CFileException::tooManyOpenFiles;
  153. case ERROR_INVALID_TARGET_HANDLE:
  154. return CFileException::invalidFile;
  155. case ERROR_INVALID_CATEGORY:
  156. return CFileException::hardIO;
  157. case ERROR_INVALID_NAME:
  158. return CFileException::badPath;
  159. case ERROR_INVALID_LEVEL:
  160. return CFileException::badPath;
  161. case ERROR_NO_VOLUME_LABEL:
  162. return CFileException::badPath;
  163. case ERROR_NEGATIVE_SEEK:
  164. return CFileException::badSeek;
  165. case ERROR_SEEK_ON_DEVICE:
  166. return CFileException::badSeek;
  167. case ERROR_DIR_NOT_ROOT:
  168. return CFileException::badPath;
  169. case ERROR_DIR_NOT_EMPTY:
  170. return CFileException::removeCurrentDir;
  171. case ERROR_LABEL_TOO_LONG:
  172. return CFileException::badPath;
  173. case ERROR_BAD_PATHNAME:
  174. return CFileException::badPath;
  175. case ERROR_LOCK_FAILED:
  176. return CFileException::lockViolation;
  177. case ERROR_BUSY:
  178. return CFileException::accessDenied;
  179. case ERROR_INVALID_ORDINAL:
  180. return CFileException::invalidFile;
  181. case ERROR_ALREADY_EXISTS:
  182. return CFileException::accessDenied;
  183. case ERROR_INVALID_EXE_SIGNATURE:
  184. return CFileException::invalidFile;
  185. case ERROR_BAD_EXE_FORMAT:
  186. return CFileException::invalidFile;
  187. case ERROR_FILENAME_EXCED_RANGE:
  188. return CFileException::badPath;
  189. case ERROR_META_EXPANSION_TOO_LONG:
  190. return CFileException::badPath;
  191. case ERROR_DIRECTORY:
  192. return CFileException::badPath;
  193. case ERROR_OPERATION_ABORTED:
  194. return CFileException::hardIO;
  195. case ERROR_IO_INCOMPLETE:
  196. return CFileException::hardIO;
  197. case ERROR_IO_PENDING:
  198. return CFileException::hardIO;
  199. case ERROR_SWAPERROR:
  200. return CFileException::accessDenied;
  201. default:
  202. return CFileException::generic;
  203. }
  204. }
  205. /////////////////////////////////////////////////////////////////////////////