MCPcopy Create free account
hub / github.com/Scobalula/Greyhound / ForcePathExist

Function ForcePathExist

src/External/CascLib/src/CascFiles.cpp:1009–1067  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1007}
1008
1009static DWORD ForcePathExist(LPCTSTR szFileName, bool bIsFileName)
1010{
1011 DWORD dwErrCode = ERROR_NOT_ENOUGH_MEMORY;
1012 bool bFirstSeparator = false;
1013
1014 // Sanity checks
1015 if(szFileName && szFileName[0])
1016 {
1017 CASC_PATH<TCHAR> LocalPath(szFileName, NULL);
1018
1019 // Get the end of search
1020 if(bIsFileName)
1021 LocalPath.CutLastPart();
1022
1023 // Check whether the path exists
1024 if(_taccess(LocalPath, 0) != 0)
1025 {
1026 LPTSTR szLocalPath = (LPTSTR)(LPCTSTR)LocalPath;
1027
1028 // Search the entire path
1029 for(size_t nIndex = 0; nIndex < LocalPath.Length(); nIndex++)
1030 {
1031 if(szLocalPath[nIndex] == '\\' || szLocalPath[nIndex] == '/')
1032 {
1033 // Cut the path and verify whether the folder/file exists
1034 szLocalPath[nIndex] = 0;
1035
1036 // Skip the very first separator
1037 if(bFirstSeparator == true)
1038 {
1039 // Is it there?
1040 if(DirectoryExists(szLocalPath) == false && MakeDirectory(szLocalPath) == false)
1041 {
1042 dwErrCode = ERROR_PATH_NOT_FOUND;
1043 break;
1044 }
1045 }
1046
1047 // Restore the character
1048 szLocalPath[nIndex] = PATH_SEP_CHAR;
1049 bFirstSeparator = true;
1050 dwErrCode = ERROR_SUCCESS;
1051 }
1052 }
1053
1054 // Now check the final path
1055 if(DirectoryExists(szLocalPath) || MakeDirectory(szLocalPath))
1056 {
1057 dwErrCode = ERROR_SUCCESS;
1058 }
1059 }
1060 else
1061 {
1062 dwErrCode = ERROR_SUCCESS;
1063 }
1064 }
1065
1066 return dwErrCode;

Callers 2

SaveLocalFileFunction · 0.85
FetchCascFileFunction · 0.85

Calls 4

DirectoryExistsFunction · 0.85
MakeDirectoryFunction · 0.85
CutLastPartMethod · 0.80
LengthMethod · 0.45

Tested by

no test coverage detected