diff options
Diffstat (limited to 'src/mir_core')
-rw-r--r-- | src/mir_core/mir_core.def | 1 | ||||
-rw-r--r-- | src/mir_core/path.cpp | 81 |
2 files changed, 41 insertions, 41 deletions
diff --git a/src/mir_core/mir_core.def b/src/mir_core/mir_core.def index 4fd9df1b85..651e71ee90 100644 --- a/src/mir_core/mir_core.def +++ b/src/mir_core/mir_core.def @@ -264,3 +264,4 @@ db_mc_isEnabled @261 LoadLangPackDescr @262
PathIsAbsolute @263
PathIsAbsoluteW @264
+db_mc_notifyDefChange @265
diff --git a/src/mir_core/path.cpp b/src/mir_core/path.cpp index fd57404195..e3d6093bb2 100644 --- a/src/mir_core/path.cpp +++ b/src/mir_core/path.cpp @@ -21,12 +21,13 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+
#include "commonheaders.h"
static char szMirandaPath[MAX_PATH];
-static char szMirandaPathLower[MAX_PATH];
static TCHAR szMirandaPathW[MAX_PATH];
-static TCHAR szMirandaPathWLower[MAX_PATH];
+
+/////////////////////////////////////////////////////////////////////////////////////////
MIR_CORE_DLL(int) PathIsAbsolute(const char *path)
{
@@ -37,30 +38,30 @@ MIR_CORE_DLL(int) PathIsAbsolute(const char *path) return 0;
}
-MIR_CORE_DLL(int) PathToRelative(const char *pSrc, char *pOut)
+MIR_CORE_DLL(int) PathToRelative(const char *pSrc, char *pOut, const char *pBase)
{
- if ( !pSrc || !strlen(pSrc) || strlen(pSrc)>MAX_PATH) return 0;
- if ( !PathIsAbsolute(pSrc)) {
- mir_snprintf(pOut, MAX_PATH, "%s", pSrc);
- return (int)strlen(pOut);
- }
+ if (!pSrc || !strlen(pSrc) || strlen(pSrc) > MAX_PATH) return 0;
- char szTmp[MAX_PATH];
- mir_snprintf(szTmp, SIZEOF(szTmp), "%s", pSrc);
- _strlwr(szTmp);
- if (strstr(szTmp, szMirandaPathLower)) {
- mir_snprintf(pOut, MAX_PATH, "%s", pSrc+strlen(szMirandaPathLower));
- return (int)strlen(pOut);
- }
+ if (!PathIsAbsolute(pSrc))
+ strncpy_s(pOut, MAX_PATH, pSrc, _TRUNCATE);
else {
- mir_snprintf(pOut, MAX_PATH, "%s", pSrc);
- return (int)strlen(pOut);
+ if (pBase == NULL)
+ pBase = szMirandaPath;
+ char *szTmp = NEWSTR_ALLOCA(pSrc); strlwr(szTmp);
+ char *szBase = NEWSTR_ALLOCA(pBase); strlwr(szBase);
+
+ if (strstr(szTmp, szBase))
+ strncpy_s(pOut, MAX_PATH, pSrc + lstrlenA(szBase), _TRUNCATE);
+ else
+ strncpy_s(pOut, MAX_PATH, pSrc, _TRUNCATE);
}
+
+ return (int)strlen(pOut);
}
-MIR_CORE_DLL(int) PathToAbsolute(const char *pSrc, char *pOut, char* base)
+MIR_CORE_DLL(int) PathToAbsolute(const char *pSrc, char *pOut, const char *base)
{
- if ( !pSrc || !strlen(pSrc) || strlen(pSrc) > MAX_PATH) {
+ if (!pSrc || !strlen(pSrc) || strlen(pSrc) > MAX_PATH) {
*pOut = 0;
return 0;
}
@@ -78,14 +79,14 @@ MIR_CORE_DLL(int) PathToAbsolute(const char *pSrc, char *pOut, char* base) if (pSrc[0] != '\\')
mir_snprintf(buf, MAX_PATH, "%s%s", base, pSrc);
else
- mir_snprintf(buf, MAX_PATH, "%s%s", base, pSrc+1);
+ mir_snprintf(buf, MAX_PATH, "%s%s", base, pSrc + 1);
return GetFullPathNameA(buf, MAX_PATH, pOut, NULL);
}
-MIR_CORE_DLL(void) CreatePathToFile(char* szFilePath)
+MIR_CORE_DLL(void) CreatePathToFile(char *szFilePath)
{
- char* pszLastBackslash = strrchr(szFilePath, '\\');
+ char *pszLastBackslash = strrchr(szFilePath, '\\');
if (pszLastBackslash == NULL)
return;
@@ -97,7 +98,7 @@ MIR_CORE_DLL(void) CreatePathToFile(char* szFilePath) MIR_CORE_DLL(int) CreateDirectoryTree(const char *szDir)
{
DWORD dwAttributes;
- char *pszLastBackslash, szTestDir[ MAX_PATH ];
+ char *pszLastBackslash, szTestDir[MAX_PATH];
lstrcpynA(szTestDir, szDir, SIZEOF(szTestDir));
if ((dwAttributes = GetFileAttributesA(szTestDir)) != INVALID_FILE_ATTRIBUTES && (dwAttributes & FILE_ATTRIBUTE_DIRECTORY))
@@ -113,7 +114,7 @@ MIR_CORE_DLL(int) CreateDirectoryTree(const char *szDir) return (CreateDirectoryA(szTestDir, NULL) == 0) ? GetLastError() : 0;
}
-///////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////////////////
MIR_CORE_DLL(int) PathIsAbsoluteW(const TCHAR *path)
{
@@ -124,27 +125,29 @@ MIR_CORE_DLL(int) PathIsAbsoluteW(const TCHAR *path) return 0;
}
-MIR_CORE_DLL(int) PathToRelativeW(const WCHAR *pSrc, WCHAR *pOut)
+MIR_CORE_DLL(int) PathToRelativeW(const WCHAR *pSrc, WCHAR *pOut, const WCHAR *pBase)
{
if (!pSrc || !lstrlen(pSrc) || lstrlen(pSrc) > MAX_PATH)
return 0;
if (!PathIsAbsoluteW(pSrc))
- mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc);
+ wcsncpy_s(pOut, MAX_PATH, pSrc, _TRUNCATE);
else {
- TCHAR szTmp[MAX_PATH];
+ if (pBase == NULL)
+ pBase = szMirandaPathW;
+
+ WCHAR *wszTmp = NEWWSTR_ALLOCA(pSrc); wcslwr(wszTmp);
+ WCHAR *wszBase = NEWWSTR_ALLOCA(pBase); wcslwr(wszBase);
- mir_sntprintf(szTmp, SIZEOF(szTmp), _T("%s"), pSrc);
- _tcslwr(szTmp);
- if (_tcsstr(szTmp, szMirandaPathWLower))
- mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc + lstrlen(szMirandaPathWLower));
+ if (wcsstr(wszTmp, wszBase))
+ wcsncpy_s(pOut, MAX_PATH, pSrc + lstrlen(wszBase), _TRUNCATE);
else
- mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc);
+ wcsncpy_s(pOut, MAX_PATH, pSrc, _TRUNCATE);
}
return lstrlen(pOut);
}
-MIR_CORE_DLL(int) PathToAbsoluteW(const TCHAR *pSrc, TCHAR *pOut, TCHAR* base)
+MIR_CORE_DLL(int) PathToAbsoluteW(const TCHAR *pSrc, TCHAR *pOut, const TCHAR *base)
{
if (!pSrc || !wcslen(pSrc) || wcslen(pSrc) > MAX_PATH) {
*pOut = 0;
@@ -168,7 +171,7 @@ MIR_CORE_DLL(int) PathToAbsoluteW(const TCHAR *pSrc, TCHAR *pOut, TCHAR* base) return GetFullPathName(buf, MAX_PATH, pOut, NULL);
}
-MIR_CORE_DLL(void) CreatePathToFileW(WCHAR* wszFilePath)
+MIR_CORE_DLL(void) CreatePathToFileW(WCHAR *wszFilePath)
{
WCHAR *pszLastBackslash = wcsrchr(wszFilePath, '\\');
if (pszLastBackslash == NULL)
@@ -179,7 +182,7 @@ MIR_CORE_DLL(void) CreatePathToFileW(WCHAR* wszFilePath) *pszLastBackslash = '\\';
}
-MIR_CORE_DLL(int) CreateDirectoryTreeW(const WCHAR* szDir)
+MIR_CORE_DLL(int) CreateDirectoryTreeW(const WCHAR *szDir)
{
DWORD dwAttributes;
WCHAR *pszLastBackslash, szTestDir[MAX_PATH];
@@ -205,14 +208,10 @@ int InitPathUtils(void) p = strrchr(szMirandaPath, '\\');
if (p)
p[1] = 0;
- mir_snprintf(szMirandaPathLower, MAX_PATH, "%s", szMirandaPath);
- _strlwr(szMirandaPathLower);
- GetModuleFileName(hInst, szMirandaPathW, SIZEOF(szMirandaPathW));
- TCHAR *tp = _tcsrchr(szMirandaPathW, '\\');
+ GetModuleFileNameW(hInst, szMirandaPathW, SIZEOF(szMirandaPathW));
+ WCHAR *tp = wcsrchr(szMirandaPathW, '\\');
if (tp)
tp[1] = 0;
- mir_sntprintf(szMirandaPathWLower, SIZEOF(szMirandaPathWLower), _T("%s"), szMirandaPathW);
- _tcslwr(szMirandaPathWLower);
return 0;
}
|