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.

95 lines
2.6 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. /* File: dir.c */
  4. /*************************************************************************
  5. ** Install: Directory commands.
  6. **************************************************************************/
  7. extern HWND hwndFrame;
  8. /*
  9. ** Purpose:
  10. ** Creates a new directory at the given path.
  11. ** Arguments:
  12. ** szDir: non-NULL dir path pointer.
  13. ** Valid command options:
  14. ** cmoVital
  15. ** cmoNone
  16. ** Returns:
  17. ** Returns fTrue if the directory is successfully created, or if
  18. ** it already exists. Returns fFalse otherwise.
  19. **
  20. **************************************************************************/
  21. BOOL APIENTRY FCreateDir(SZ szDir,CMO cmo)
  22. {
  23. CB cb;
  24. SZ szDirPlus;
  25. EERC eerc;
  26. DWORD Attr;
  27. BOOL fRet = fTrue;
  28. ChkArg(szDir != (SZ)NULL && *szDir != '\0', 1, fFalse);
  29. ChkArg(cmo == cmoNone || cmo == cmoVital, 2, fFalse);
  30. //
  31. // Create directory
  32. //
  33. while ( !((( Attr = GetFileAttributes(szDir) ) != 0xFFFFFFFF && (Attr & FILE_ATTRIBUTE_DIRECTORY ))
  34. || CreateDirectory( szDir, NULL )) ) {
  35. if ((eerc = EercErrorHandler(hwndFrame, grcCreateDirErr, cmo == cmoVital,
  36. szDir, 0, 0)) != eercRetry) {
  37. fRet = (eerc == eercIgnore) ? fTrue : fFalse;
  38. break;
  39. }
  40. }
  41. return(fRet);
  42. }
  43. /*
  44. ** Purpose:
  45. ** Removes the existing directory at the given path.
  46. ** Arguments:
  47. ** szDir: non-NULL dir path pointer.
  48. ** Valid command options:
  49. ** cmoVital
  50. ** cmoNone
  51. ** Returns:
  52. ** Returns fTrue if the directory is successfuly removed,
  53. ** or if did not exist. Returns fFalse otherwise.
  54. **
  55. **************************************************************************/
  56. BOOL APIENTRY FRemoveDir(SZ szDir,CMO cmo)
  57. {
  58. SZ szLast;
  59. EERC eerc;
  60. DWORD Attr;
  61. ChkArg(szDir != (SZ)NULL, 1, fFalse);
  62. ChkArg(cmo == cmoNone || cmo == cmoVital, 2, fFalse);
  63. if (!FValidDir(szDir) ||
  64. (szLast = SzLastChar(szDir)) == (SZ)NULL)
  65. return(fFalse);
  66. Assert(*szLast != '\0');
  67. if (*szLast == '\\')
  68. *szLast = '\0';
  69. while (!RemoveDirectory(szDir) && (( Attr = GetFileAttributes(szDir) ) != 0xFFFFFFFF) && (Attr & FILE_ATTRIBUTE_DIRECTORY )) {
  70. if ((eerc = EercErrorHandler(hwndFrame, grcRemoveDirErr, cmo & cmoVital,
  71. szDir, 0, 0)) != eercRetry) {
  72. if (*szLast == '\0')
  73. *szLast = '\\';
  74. return(eerc == eercIgnore);
  75. }
  76. }
  77. if (*szLast == '\0')
  78. *szLast = '\\';
  79. return(fTrue);
  80. }