From ab502692721d3904912577e3aeab6e273d0aee5c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 20 Jul 2014 13:01:37 +0000 Subject: single profile that requires conversion also to raise up Profile Manager git-svn-id: http://svn.miranda-ng.org/main/trunk@9885 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/modules/database/database.cpp | 40 ++++++++++++++++++++++++++++----- src/modules/database/profilemanager.cpp | 30 +++++++++++-------------- src/modules/database/profilemanager.h | 1 + 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/src/modules/database/database.cpp b/src/modules/database/database.cpp index cab6cbfadb..0b1b8f8b06 100644 --- a/src/modules/database/database.cpp +++ b/src/modules/database/database.cpp @@ -225,7 +225,7 @@ static void moveProfileDirProfiles(TCHAR *profiledir, BOOL isRootDir = TRUE) // returns 1 if a single profile (full path) is found within the profile dir static int getProfile1(TCHAR *szProfile, size_t cch, TCHAR *profiledir, BOOL * noProfiles) { - unsigned int found = 0; + int found = 0, allfound = 0; if (IsInsideRootDir(profiledir, false)) moveProfileDirProfiles(profiledir); @@ -250,9 +250,13 @@ static int getProfile1(TCHAR *szProfile, size_t cch, TCHAR *profiledir, BOOL * n if ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && _tcscmp(ffd.cFileName, _T(".")) && _tcscmp(ffd.cFileName, _T(".."))) { TCHAR newProfile[MAX_PATH]; mir_sntprintf(newProfile, MAX_PATH, _T("%s\\%s\\%s.dat"), profiledir, ffd.cFileName, ffd.cFileName); - if (_taccess(newProfile, 0) == 0) + if (_taccess(newProfile, 0) != 0) + continue; + + allfound++; + if (touchDatabase(newProfile, NULL) == 0) if (++found == 1 && nodprof) - _tcscpy(szProfile, newProfile); + _tcsncpy_s(szProfile, cch, newProfile, _TRUNCATE); } } while (FindNextFile(hFind, &ffd)); @@ -263,7 +267,7 @@ static int getProfile1(TCHAR *szProfile, size_t cch, TCHAR *profiledir, BOOL * n } if (noProfiles) - *noProfiles = found == 0; + *noProfiles = allfound == 0; if (nodprof && !reqfd) szProfile[0] = 0; @@ -344,6 +348,28 @@ char* makeFileName(const TCHAR* tszOriginalName) return szResult; } +int touchDatabase(const TCHAR *tszProfile, DATABASELINK **dblink) +{ + for (int i = arDbPlugins.getCount() - 1; i >= 0; i--) { + DATABASELINK *p = arDbPlugins[i]; + int iErrorCode = p->grokHeader(tszProfile); + if (iErrorCode == 0) { + if (dblink) + *dblink = p; + return 0; + } + if (iErrorCode == EGROKPRF_OBSOLETE) { + if (dblink) + *dblink = p; + return EGROKPRF_OBSOLETE; + } + } + + if (dblink) + *dblink = NULL; + return EGROKPRF_CANTREAD; +} + // enumerate all plugins that had valid DatabasePluginInfo() int tryOpenDatabase(const TCHAR *tszProfile) { @@ -360,6 +386,9 @@ int tryOpenDatabase(const TCHAR *tszProfile) case EGROKPRF_UNKHEADER: // just not supported. continue; + + case EGROKPRF_OBSOLETE: + break; } return err; } @@ -482,7 +511,8 @@ int LoadDatabaseModule(void) retry = MessageBox(0, buf, TranslateT("Miranda can't open that profile"), MB_RETRYCANCEL | MB_ICONERROR) == IDRETRY; } } - } while (retry); + } + while (retry); if (rc == ERROR_SUCCESS) { InitIni(); diff --git a/src/modules/database/profilemanager.cpp b/src/modules/database/profilemanager.cpp index 8caf67b35b..f48beb47a4 100644 --- a/src/modules/database/profilemanager.cpp +++ b/src/modules/database/profilemanager.cpp @@ -291,25 +291,21 @@ BOOL EnumProfilesForList(TCHAR *tszFullPath, TCHAR *profile, LPARAM lParam) bFileLocked = !fileExist(tszFullPath); } - DATABASELINK *dblink = NULL; + DATABASELINK *dblink; bool bNeedConversion = false; - for (int i = arDbPlugins.getCount() - 1; i >= 0; i--) { - DATABASELINK *p = arDbPlugins[i]; - int iErrorCode = p->grokHeader(tszFullPath); - if (iErrorCode == 0) { - dblink = p; - item.iImage = bFileLocked; - break; - } - if (iErrorCode == EGROKPRF_OBSOLETE) { - dblink = p; - bNeedConversion = true; - item.iImage = 2; - break; - } - } - if (dblink == NULL) + switch (touchDatabase(tszFullPath, &dblink)) { + case ERROR_SUCCESS: + item.iImage = bFileLocked; + break; + + case EGROKPRF_OBSOLETE: + bNeedConversion = true; + item.iImage = 2; + break; + + default: item.iImage = 3; + } int iItem = SendMessage(hwndList, LVM_INSERTITEM, 0, (LPARAM)&item); if (lstrcmpi(ped->szProfile, tszFullPath) == 0) diff --git a/src/modules/database/profilemanager.h b/src/modules/database/profilemanager.h index fa8e758edc..f920b464b2 100644 --- a/src/modules/database/profilemanager.h +++ b/src/modules/database/profilemanager.h @@ -34,6 +34,7 @@ struct PROFILEMANAGERDATA }; char* makeFileName(const TCHAR *tszOriginalName); +int touchDatabase(const TCHAR *tszProfile, DATABASELINK **pDblink); int getProfileManager(PROFILEMANAGERDATA *pd); int getProfilePath(TCHAR *buf, size_t cch); int isValidProfileName(const TCHAR *name); -- cgit v1.2.3