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.

146 lines
3.9 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: createld.cpp
  4. //
  5. // Module: CMSETUP.LIB
  6. //
  7. // Synopsis: Implementation of the CreateLayerDirectory function.
  8. //
  9. // Copyright (c) 1997-1998 Microsoft Corporation
  10. //
  11. // Author: quintinb Created Header 08/19/99
  12. //
  13. //+----------------------------------------------------------------------------
  14. #include <windows.h>
  15. #include <tchar.h>
  16. #include <cmsetup.h>
  17. //+----------------------------------------------------------------------------
  18. //
  19. // Function: CreateLayerDirectory
  20. //
  21. // Synopsis: Given a path to a directory, this function creates the path (if necessary)
  22. // layer by layer.
  23. //
  24. // Arguments: LPCTSTR str - path to be created
  25. //
  26. // Returns: TRUE if the directory was created (or exists), FALSE otherwise.
  27. //
  28. // Note: This function was taken from cmocm.cpp.
  29. //
  30. // History: quintinb Created Header 12/15/97
  31. //
  32. //
  33. //+----------------------------------------------------------------------------
  34. BOOL CreateLayerDirectory( LPCTSTR str )
  35. {
  36. BOOL fReturn = TRUE;
  37. do
  38. {
  39. INT index=0;
  40. INT iLength = _tcslen(str);
  41. // first find the index for the first directory
  42. if ( iLength > 2 )
  43. {
  44. if ( str[1] == _T(':'))
  45. {
  46. // assume the first character is driver letter
  47. if ( str[2] == _T('\\'))
  48. {
  49. index = 2;
  50. } else
  51. {
  52. index = 1;
  53. }
  54. } else if ( str[0] == _T('\\'))
  55. {
  56. if ( str[1] == _T('\\'))
  57. {
  58. BOOL fFound = FALSE;
  59. INT i;
  60. INT nNum = 0;
  61. // unc name
  62. for (i = 2; i < iLength; i++ )
  63. {
  64. if ( str[i]==_T('\\'))
  65. {
  66. // find it
  67. nNum ++;
  68. if ( nNum == 2 )
  69. {
  70. fFound = TRUE;
  71. break;
  72. }
  73. }
  74. }
  75. if ( fFound )
  76. {
  77. index = i;
  78. } else
  79. {
  80. // bad name
  81. break;
  82. }
  83. } else
  84. {
  85. index = 1;
  86. }
  87. }
  88. } else if ( str[0] == _T('\\'))
  89. {
  90. index = 0;
  91. }
  92. // okay ... build directory
  93. do
  94. {
  95. // find next one
  96. do
  97. {
  98. if ( index < ( iLength - 1))
  99. {
  100. index ++;
  101. } else
  102. {
  103. break;
  104. }
  105. } while ( str[index] != _T('\\'));
  106. TCHAR szCurrentDir[MAX_PATH+1];
  107. if (GetCurrentDirectory(MAX_PATH+1, szCurrentDir))
  108. {
  109. TCHAR szNewDir[MAX_PATH+1];
  110. _tcscpy(szNewDir, str);
  111. szNewDir[index+1]=0;
  112. if ( !SetCurrentDirectory(szNewDir))
  113. {
  114. if (( fReturn = CreateDirectory(szNewDir, NULL )) != TRUE )
  115. {
  116. break;
  117. }
  118. }
  119. SetCurrentDirectory( szCurrentDir );
  120. if ( index >= ( iLength - 1 ))
  121. {
  122. fReturn = TRUE;
  123. break;
  124. }
  125. }
  126. else
  127. {
  128. fReturn = FALSE;
  129. break;
  130. }
  131. } while ( TRUE );
  132. } while (FALSE);
  133. return(fReturn);
  134. }