| 1007 | } |
| 1008 | |
| 1009 | static 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; |
no test coverage detected