size_t CMimAPI::pathToRelative(const TCHAR *pSrc, TCHAR *pOut, const TCHAR *szBase) const { const TCHAR *tszBase = szBase ? szBase : m_szProfilePath; pOut[0] = 0; if (!pSrc || !lstrlen(pSrc) || lstrlen(pSrc) > MAX_PATH) return 0; if (!pathIsAbsolute(pSrc)) { mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc); return lstrlen(pOut); } else { TCHAR szTmp[MAX_PATH]; mir_sntprintf(szTmp, SIZEOF(szTmp), _T("%s"), pSrc); if (StriStr(szTmp, tszBase)) { if(tszBase[lstrlen(tszBase) - 1] == '\\') mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc + lstrlen(tszBase)); else { mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc + lstrlen(tszBase) + 1 ); //pOut[0]='.'; } return(lstrlen(pOut)); } else { mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc); return(lstrlen(pOut)); } } }
/** * Translate a relativ path to an absolute, using the current profile * data directory. * * @param pSrc TCHAR *: input path + filename (relative) * @param pOut TCHAR *: the result * @param szBase TCHAR *: (OPTIONAL) base path for the translation. Can be 0 in which case * the function will use m_szProfilePath (usually \tabSRMM below %miranda_userdata% * * @return */ size_t CMimAPI::pathToAbsolute(const TCHAR *pSrc, TCHAR *pOut, const TCHAR *szBase) const { const TCHAR *tszBase = szBase ? szBase : m_szProfilePath; pOut[0] = 0; if (!pSrc || !lstrlen(pSrc) || lstrlen(pSrc) > MAX_PATH) return 0; if (pathIsAbsolute(pSrc) && pSrc[0]!='.') mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc); else if (pSrc[0]=='.') mir_sntprintf(pOut, MAX_PATH, _T("%s\\%s"), tszBase, pSrc + 1); else mir_sntprintf(pOut, MAX_PATH, _T("%s\\%s"), tszBase, pSrc); return lstrlen(pOut); }
void pathRemoveSlash(char_t *path) { char_t *end; //Skip the leading slash character if(pathIsAbsolute(path)) path++; //Search for the first slash character to be removed for(end = NULL; *path != '\0'; path++) { if(*path != '/' && *path != '\\') end = NULL; else if(!end) end = path; } //Remove the trailing slash characters if(end) *end = '\0'; }