bool CPathUtils::PathIsChild(const std::wstring& parent, const std::wstring& child) { std::wstring sParent = GetLongPathname(parent); std::wstring sChild = GetLongPathname(child); if (sParent.size() >= sChild.size()) return false; NormalizeFolderSeparators(sParent); NormalizeFolderSeparators(sChild); std::wstring sChildAsParent = sChild.substr(0, sParent.size()); if (sChildAsParent.empty()) return false; if (PathCompare(sParent, sChildAsParent) != 0) return false; if (IsFolderSeparator(*sParent.rbegin())) { if (!IsFolderSeparator(*sChildAsParent.rbegin())) return false; } else { if (!IsFolderSeparator(sChild[sParent.size()])) return false; } return true; }
CString CPathUtils::GetAppPath(HMODULE hMod /*= NULL*/) { CString path; DWORD len = 0; DWORD bufferlen = MAX_PATH; // MAX_PATH is not the limit here! path.GetBuffer(bufferlen); do { bufferlen += MAX_PATH; // MAX_PATH is not the limit here! path.ReleaseBuffer(0); len = GetModuleFileName(hMod, path.GetBuffer(bufferlen + 1), bufferlen); } while (len == bufferlen); path.ReleaseBuffer(); return GetLongPathname(path); }
CString CPathUtils::GetAppDirectory(HMODULE hMod /* = nullptr */) { CString path; DWORD len = 0; DWORD bufferlen = MAX_PATH; // MAX_PATH is not the limit here! path.GetBuffer(bufferlen); do { bufferlen += MAX_PATH; // MAX_PATH is not the limit here! path.ReleaseBuffer(0); len = GetModuleFileName(hMod, path.GetBuffer(bufferlen+1), bufferlen); } while(len == bufferlen); path.ReleaseBuffer(); path = path.Left(path.ReverseFind('\\')+1); return GetLongPathname(path); }
CString CPathUtils::GetAppDirectory(HMODULE hMod /* = NULL */) { CString path = GetAppPath(hMod); path = path.Left(path.ReverseFind('\\')+1); return GetLongPathname(path); }