diff options
author | George Hazan <george.hazan@gmail.com> | 2013-10-09 12:07:26 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2013-10-09 12:07:26 +0000 |
commit | f4aa7e3b87abf75249e35b6bcb1c37ce9f7b648b (patch) | |
tree | c4de493e697bac261ef23ddbea7631c0867f010d /src/modules/utils | |
parent | 2ff607d58d8889248484d3bcd4eb123a13c0a164 (diff) |
fix for recursion in Folders
git-svn-id: http://svn.miranda-ng.org/main/trunk@6414 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/modules/utils')
-rw-r--r-- | src/modules/utils/path.cpp | 67 |
1 files changed, 39 insertions, 28 deletions
diff --git a/src/modules/utils/path.cpp b/src/modules/utils/path.cpp index 74d12bd3ba..8887699f5c 100644 --- a/src/modules/utils/path.cpp +++ b/src/modules/utils/path.cpp @@ -26,9 +26,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "..\..\..\plugins\ExternalAPI\m_folders.h"
-extern TCHAR g_profileDir[MAX_PATH], g_profileRoot[MAX_PATH];
+extern TCHAR g_profileDir[MAX_PATH], g_shortProfileName[MAX_PATH];
static HANDLE hAvatarFolder;
+static TCHAR tszAvatarRoot[MAX_PATH];
static INT_PTR pathToRelative(WPARAM wParam, LPARAM lParam)
{
@@ -155,12 +156,7 @@ static __forceinline char *GetUserNameX(char *) }
static __forceinline char *GetProfileNameX(char *)
{
- TCHAR szProfileName[MAX_PATH];
- _tcscpy(szProfileName, g_profileName);
- TCHAR *pos = _tcsrchr(szProfileName, '.');
- if (lstrcmp(pos, _T(".dat")) == 0)
- *pos = 0;
- return mir_t2a(szProfileName);
+ return mir_t2a(g_shortProfileName);
}
static __forceinline char *GetPathVarX(char *, int code)
{
@@ -168,14 +164,16 @@ static __forceinline char *GetPathVarX(char *, int code) switch(code) {
case 1:
- if (hAvatarFolder == NULL || FoldersGetCustomPathT(hAvatarFolder, szFullPath, SIZEOF(szFullPath), _T("")))
- mir_sntprintf(szFullPath, SIZEOF(szFullPath), _T("%s\\AvatarCache"), g_profileRoot);
+ if (hAvatarFolder != NULL)
+ _tcsncpy_s(szFullPath, SIZEOF(szFullPath), tszAvatarRoot, _TRUNCATE);
+ else
+ mir_sntprintf(szFullPath, SIZEOF(szFullPath), _T("%s\\%s\\AvatarCache"), g_profileDir, g_shortProfileName);
break;
case 2:
- mir_sntprintf(szFullPath, SIZEOF(szFullPath), _T("%s\\Logs"), g_profileRoot);
+ mir_sntprintf(szFullPath, SIZEOF(szFullPath), _T("%s\\%s\\Logs"), g_profileDir, g_shortProfileName);
break;
case 3:
- _tcsncpy_s(szFullPath, SIZEOF(szFullPath), g_profileRoot, _TRUNCATE);
+ mir_sntprintf(szFullPath, SIZEOF(szFullPath), _T("%s\\%s"), g_profileDir, g_shortProfileName);
break;
}
return makeFileName(szFullPath);
@@ -233,12 +231,7 @@ static __forceinline TCHAR *GetUserNameX(TCHAR *) }
static __forceinline TCHAR *GetProfileNameX(TCHAR *)
{
- TCHAR szProfileName[MAX_PATH];
- _tcscpy(szProfileName, g_profileName);
- TCHAR *pos = _tcsrchr(szProfileName, '.');
- if (lstrcmp(pos, _T(".dat")) == 0)
- *pos = 0;
- return mir_tstrdup(szProfileName);
+ return mir_tstrdup(g_shortProfileName);
}
static __forceinline TCHAR *GetPathVarX(TCHAR *, int code)
{
@@ -246,14 +239,16 @@ static __forceinline TCHAR *GetPathVarX(TCHAR *, int code) switch(code) {
case 1:
- if (hAvatarFolder == NULL || FoldersGetCustomPathT(hAvatarFolder, szFullPath, SIZEOF(szFullPath), _T("")))
- mir_sntprintf(szFullPath, SIZEOF(szFullPath), _T("%s\\AvatarCache"), g_profileRoot);
+ if (hAvatarFolder != NULL)
+ _tcsncpy_s(szFullPath, SIZEOF(szFullPath), tszAvatarRoot, _TRUNCATE);
+ else
+ mir_sntprintf(szFullPath, SIZEOF(szFullPath), _T("%s\\%s\\AvatarCache"), g_profileDir, g_shortProfileName);
break;
case 2:
- mir_sntprintf(szFullPath, SIZEOF(szFullPath), _T("%s\\Logs"), g_profileRoot);
+ mir_sntprintf(szFullPath, SIZEOF(szFullPath), _T("%s\\%s\\Logs"), g_profileDir, g_shortProfileName);
break;
case 3:
- _tcsncpy_s(szFullPath, SIZEOF(szFullPath), g_profileRoot, _TRUNCATE);
+ mir_sntprintf(szFullPath, SIZEOF(szFullPath), _T("%s\\%s"), g_profileDir, g_shortProfileName);
break;
}
return mir_tstrdup(szFullPath);
@@ -389,13 +384,6 @@ static INT_PTR replaceVars(WPARAM wParam, LPARAM lParam) return (INT_PTR)ReplaceVariables<char>((char *)wParam, data);
}
-void InitPathVar()
-{
- TCHAR szFullPath[MAX_PATH];
- mir_sntprintf(szFullPath, SIZEOF(szFullPath), _T("%s\\AvatarCache"), g_profileRoot);
- hAvatarFolder = FoldersRegisterCustomPathT( LPGEN("Avatars"), LPGEN("Avatars root folder"), szFullPath);
-}
-
int InitPathUtils(void)
{
CreateServiceFunction(MS_UTILS_PATHTORELATIVE, pathToRelative);
@@ -410,3 +398,26 @@ int InitPathUtils(void) CreateServiceFunction(MS_UTILS_REPLACEVARS, replaceVars);
return 0;
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+static int OnFoldersChanged(WPARAM, LPARAM)
+{
+ mir_sntprintf(tszAvatarRoot, SIZEOF(tszAvatarRoot), _T("%s\\%s\\AvatarCache"), g_profileDir, g_shortProfileName);
+
+ TCHAR tmpVar[MAX_PATH];
+ if ( !FoldersGetCustomPathT(hAvatarFolder, tmpVar, SIZEOF(tmpVar), tszAvatarRoot))
+ _tcsncpy_s(tszAvatarRoot, SIZEOF(tszAvatarRoot), tmpVar, SIZEOF(tmpVar));
+ return 0;
+}
+
+void InitPathVar()
+{
+ mir_sntprintf(tszAvatarRoot, SIZEOF(tszAvatarRoot), _T("%s\\%s\\AvatarCache"), g_profileDir, g_shortProfileName);
+ if (hAvatarFolder = FoldersRegisterCustomPathT( LPGEN("Avatars"), LPGEN("Avatars root folder"), tszAvatarRoot)) {
+ TCHAR tmpVar[MAX_PATH];
+ if ( !FoldersGetCustomPathT(hAvatarFolder, tmpVar, SIZEOF(tmpVar), tszAvatarRoot))
+ _tcsncpy_s(tszAvatarRoot, SIZEOF(tszAvatarRoot), tmpVar, SIZEOF(tmpVar));
+ HookEvent(ME_FOLDERS_PATH_CHANGED, OnFoldersChanged);
+ }
+}
|