From cbe3cb21f5bca61a03bbd4ae811ee906e09b3f4f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 13 Jun 2015 16:55:17 +0000 Subject: - miranda32.exe now does nothing bug extends PATH to %miranda_root%\libs and loads mir_app.dll; - everything that was in miranda32.exe (including resources) moved to mir_app.dll; - exports from mir_app.dll now available for using directly, without perversions; - src/stdplug.h deleted; git-svn-id: http://svn.miranda-ng.org/main/trunk@14143 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/modules/database/database.cpp | 538 -------------------------- src/modules/database/database.h | 53 --- src/modules/database/dbini.cpp | 520 ------------------------- src/modules/database/dbintf.cpp | 167 -------- src/modules/database/dbutils.cpp | 367 ------------------ src/modules/database/mdatabasecache.cpp | 252 ------------- src/modules/database/profilemanager.cpp | 649 -------------------------------- src/modules/database/profilemanager.h | 45 --- 8 files changed, 2591 deletions(-) delete mode 100644 src/modules/database/database.cpp delete mode 100644 src/modules/database/database.h delete mode 100644 src/modules/database/dbini.cpp delete mode 100644 src/modules/database/dbintf.cpp delete mode 100644 src/modules/database/dbutils.cpp delete mode 100644 src/modules/database/mdatabasecache.cpp delete mode 100644 src/modules/database/profilemanager.cpp delete mode 100644 src/modules/database/profilemanager.h (limited to 'src/modules/database') diff --git a/src/modules/database/database.cpp b/src/modules/database/database.cpp deleted file mode 100644 index 0fdb7f7174..0000000000 --- a/src/modules/database/database.cpp +++ /dev/null @@ -1,538 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -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 "..\..\core\commonheaders.h" -#include "profilemanager.h" - -// contains the location of mirandaboot.ini -bool g_bDbCreated; -TCHAR g_profileDir[MAX_PATH], g_profileName[MAX_PATH], g_shortProfileName[MAX_PATH]; -TCHAR* g_defaultProfile; -void EnsureCheckerLoaded(bool); - -void LoadDatabaseServices(); - -bool fileExist(const TCHAR *fname) -{ - if (*fname == 0) - return false; - - FILE *fp = _tfopen(fname, _T("r+")); - bool res = (fp != NULL); - if (fp) fclose(fp); - return res; -} - -static void fillProfileName(const TCHAR* ptszFileName) -{ - const TCHAR* p = _tcsrchr(ptszFileName, '\\'); - if (p == NULL) - p = ptszFileName; - else - p++; - - _tcsncpy_s(g_profileName, p, _TRUNCATE); - - _tcsncpy_s(g_shortProfileName, p, _TRUNCATE); - TCHAR *pos = _tcsrchr(g_shortProfileName, '.'); - if (mir_tstrcmpi(pos, _T(".dat")) == 0) - *pos = 0; -} - -bool IsInsideRootDir(TCHAR* profiledir, bool exact) -{ - VARST pfd( _T("%miranda_path%")); - if (exact) - return mir_tstrcmpi(profiledir, pfd) == 0; - - return _tcsnicmp(profiledir, pfd, mir_tstrlen(pfd)) == 0; -} - -// returns 1 if the profile path was returned, without trailing slash -int getProfilePath(TCHAR *buf, size_t cch) -{ - TCHAR profiledir[MAX_PATH]; - GetPrivateProfileString(_T("Database"), _T("ProfileDir"), _T(""), profiledir, SIZEOF(profiledir), mirandabootini); - - if (profiledir[0] == 0) - mir_tstrcpy(profiledir, _T("%miranda_path%\\Profiles")); - - size_t len = PathToAbsoluteT( VARST(profiledir), buf); - - if (buf[len-1] == '/' || buf[len-1] == '\\') - buf[len-1] = 0; - - return 0; -} - -// returns 1 if *.dat spec is matched -int isValidProfileName(const TCHAR *name) -{ - size_t len = mir_tstrlen(name) - 4; - return len > 0 && mir_tstrcmpi(&name[len], _T(".dat")) == 0; -} - -// returns 1 if the profile manager should be shown -static bool showProfileManager(void) -{ - TCHAR Mgr[32]; - // is control pressed? - if (GetAsyncKeyState(VK_CONTROL) & 0x8000) - return 1; - - // wanna show it? - GetPrivateProfileString(_T("Database"), _T("ShowProfileMgr"), _T("never"), Mgr, SIZEOF(Mgr), mirandabootini); - return (mir_tstrcmpi(Mgr, _T("yes")) == 0); -} - -bool shouldAutoCreate(TCHAR *szProfile) -{ - if (szProfile[0] == 0) - return false; - - TCHAR ac[32]; - GetPrivateProfileString(_T("Database"), _T("AutoCreate"), _T(""), ac, SIZEOF(ac), mirandabootini); - return mir_tstrcmpi(ac, _T("yes")) == 0; -} - -static void getDefaultProfile(TCHAR *szProfile, size_t cch) -{ - TCHAR defaultProfile[MAX_PATH]; - GetPrivateProfileString(_T("Database"), _T("DefaultProfile"), _T(""), defaultProfile, SIZEOF(defaultProfile), mirandabootini); - - if (defaultProfile[0] == 0) - return; - - VARST res(defaultProfile); - if (res) - mir_sntprintf(szProfile, cch, _T("%s\\%s\\%s%s"), g_profileDir, (TCHAR*)res, (TCHAR*)res, isValidProfileName(res) ? _T("") : _T(".dat")); - else - szProfile[0] = 0; -} - -// returns 1 if something that looks like a profile is there -static void loadProfileByShortName(const TCHAR* src, TCHAR *szProfile, size_t cch) -{ - TCHAR buf[MAX_PATH]; - _tcsncpy_s(buf, src, _TRUNCATE); - - TCHAR *p = _tcsrchr(buf, '\\'); if (p) ++p; else p = buf; - if (!isValidProfileName(buf) && *p) - mir_tstrcat(buf, _T(".dat")); - - TCHAR profileName[MAX_PATH], newProfileDir[MAX_PATH]; - _tcsncpy_s(profileName, p, _TRUNCATE); - if (!isValidProfileName(profileName) && *p) - mir_tstrcat(profileName, _T(".dat")); - - _tcsncpy_s(profileName, p, _TRUNCATE); - p = _tcsrchr(profileName, '.'); if (p) *p = 0; - - mir_sntprintf(newProfileDir, cch, _T("%s\\%s\\"), g_profileDir, profileName); - PathToAbsoluteT(buf, szProfile, newProfileDir); - - if ( _tcschr(buf, '\\')) { - _tcsncpy_s(g_profileDir, szProfile, _TRUNCATE); - if (profileName[0]) { - p = _tcsrchr(g_profileDir, '\\'); *p = 0; - p = _tcsrchr(g_profileDir, '\\'); - if (p && mir_tstrcmpi(p + 1, profileName) == 0) - *p = 0; - } - else szProfile[0] = 0; - } -} - -void getProfileCmdLine(TCHAR *szProfile, size_t cch) -{ - LPCTSTR ptszProfileName = CmdLine_GetOption( _T("profile")); - if (ptszProfileName != NULL) - loadProfileByShortName(ptszProfileName, szProfile, cch); -} - -void getProfileDefault(TCHAR *szProfile, size_t cch) -{ - if (g_defaultProfile != NULL) { - loadProfileByShortName(g_defaultProfile, szProfile, cch); - mir_free(g_defaultProfile); - } -} - -// move profile from profile subdir -static void moveProfileDirProfiles(TCHAR *profiledir, BOOL isRootDir = TRUE) -{ - TCHAR pfd[MAX_PATH]; - if (isRootDir) - _tcsncpy_s(pfd, VARST(_T("%miranda_path%\\*.dat")), _TRUNCATE); - else - mir_sntprintf(pfd, SIZEOF(pfd), _T("%s\\*.dat"), profiledir); - - WIN32_FIND_DATA ffd; - HANDLE hFind = FindFirstFile(pfd, &ffd); - if (hFind != INVALID_HANDLE_VALUE) { - TCHAR *c = _tcsrchr(pfd, '\\'); if (c) *c = 0; - do { - TCHAR path[MAX_PATH], path2[MAX_PATH]; - TCHAR* profile = mir_tstrdup(ffd.cFileName); - TCHAR *c = _tcsrchr(profile, '.'); if (c) *c = 0; - mir_sntprintf(path, SIZEOF(path), _T("%s\\%s"), pfd, ffd.cFileName); - mir_sntprintf(path2, SIZEOF(path2), _T("%s\\%s"), profiledir, profile); - CreateDirectoryTreeT(path2); - mir_sntprintf(path2, SIZEOF(path2), _T("%s\\%s\\%s"), profiledir, profile, ffd.cFileName); - if (_taccess(path2, 0) == 0) { - TCHAR buf[512]; - mir_sntprintf(buf, - TranslateT("Miranda is trying to upgrade your profile structure.\nIt cannot move profile %s to the new location %s\nBecause profile with this name already exists. Please resolve the issue manually."), - path, path2); - MessageBox(NULL, buf, _T("Miranda NG"), MB_ICONERROR | MB_OK); - } - else if (MoveFile(path, path2) == 0) { - TCHAR buf[512]; - mir_sntprintf(buf, - TranslateT("Miranda is trying to upgrade your profile structure.\nIt cannot move profile %s to the new location %s automatically\nMost likely this is due to insufficient privileges. Please move profile manually."), - path, path2); - MessageBox(NULL, buf, _T("Miranda NG"), MB_ICONERROR | MB_OK); - mir_free(profile); - break; - } - mir_free(profile); - } - while (FindNextFile(hFind, &ffd)); - } - FindClose(hFind); -} - -// 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) -{ - int found = 0; - - if (IsInsideRootDir(profiledir, false)) - moveProfileDirProfiles(profiledir); - moveProfileDirProfiles(profiledir, FALSE); - - bool bNoDefaultProfile = (*szProfile == 0); - bool reqfd = !bNoDefaultProfile && (_taccess(szProfile, 0) == 0 || shouldAutoCreate(szProfile)); - bool bShowProfileManager = showProfileManager(); - - if (reqfd) - found++; - - if (bShowProfileManager || !reqfd) { - TCHAR searchspec[MAX_PATH]; - mir_sntprintf(searchspec, SIZEOF(searchspec), _T("%s\\*.*"), profiledir); - - WIN32_FIND_DATA ffd; - HANDLE hFind = FindFirstFile(searchspec, &ffd); - if (hFind != INVALID_HANDLE_VALUE) { - do { - // make sure the first hit is actually a *.dat file - if (!(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || !mir_tstrcmp(ffd.cFileName, _T(".")) || !mir_tstrcmp(ffd.cFileName, _T(".."))) - continue; - - TCHAR newProfile[MAX_PATH]; - mir_sntprintf(newProfile, SIZEOF(newProfile), _T("%s\\%s\\%s.dat"), profiledir, ffd.cFileName, ffd.cFileName); - if (_taccess(newProfile, 0) != 0) - continue; - - switch (touchDatabase(newProfile, NULL)) { - case 0: - case EGROKPRF_OBSOLETE: - if (++found == 1 && bNoDefaultProfile) - _tcsncpy_s(szProfile, cch, newProfile, _TRUNCATE); - break; - } - } - while (FindNextFile(hFind, &ffd)); - - FindClose(hFind); - } - reqfd = (!bShowProfileManager && found == 1 && bNoDefaultProfile); - } - - if (noProfiles) - *noProfiles = (found == 0); - - if (bNoDefaultProfile && !reqfd) - szProfile[0] = 0; - - return reqfd; -} - -// returns 1 if a default profile should be selected instead of showing the manager. -static int getProfileAutoRun(TCHAR *szProfile) -{ - if (*szProfile == 0) - return false; - - TCHAR Mgr[32]; - GetPrivateProfileString(_T("Database"), _T("ShowProfileMgr"), _T(""), Mgr, SIZEOF(Mgr), mirandabootini); - if (mir_tstrcmpi(Mgr, _T("never"))) - return 0; - - return fileExist(szProfile) || shouldAutoCreate(szProfile); -} - -// returns 1 if a profile was selected -static int getProfile(TCHAR *szProfile, size_t cch) -{ - getProfilePath(g_profileDir, SIZEOF(g_profileDir)); - if (IsInsideRootDir(g_profileDir, true)) - if (WritePrivateProfileString(_T("Database"), _T("ProfileDir"), _T(""), mirandabootini)) - getProfilePath(g_profileDir, SIZEOF(g_profileDir)); - - getDefaultProfile(szProfile, cch); - getProfileCmdLine(szProfile, cch); - getProfileDefault(szProfile, cch); - - if (IsInsideRootDir(g_profileDir, true)) { - MessageBox(NULL, - TranslateT("Profile cannot be placed into Miranda root folder.\nPlease move Miranda profile to some other location."), - LPGENT("Miranda NG"), MB_ICONERROR | MB_OK); - return 0; - } - - PROFILEMANAGERDATA pd = { 0 }; - if (CmdLine_GetOption(_T("ForceShowPM"))) { -LBL_Show: - pd.ptszProfile = szProfile; - pd.ptszProfileDir = g_profileDir; - if (!getProfileManager(&pd)) - return 0; - - if (!pd.bRun) - return CallService(MS_DB_CHECKPROFILE, WPARAM(szProfile), TRUE); - - return 1; - } - - if (getProfileAutoRun(szProfile)) - return 1; - - if (getProfile1(szProfile, cch, g_profileDir, &pd.noProfiles)) - return 1; - - goto LBL_Show; -} - -// carefully converts a file name from TCHAR* to char* -char* makeFileName(const TCHAR* tszOriginalName) -{ - char *szResult = NULL; - char *szFileName = mir_t2a(tszOriginalName); - TCHAR *tszFileName = mir_a2t(szFileName); - if (mir_tstrcmp(tszOriginalName, tszFileName)) { - TCHAR tszProfile[MAX_PATH]; - if (GetShortPathName(tszOriginalName, tszProfile, MAX_PATH) != 0) - szResult = mir_t2a(tszProfile); - } - - if (!szResult) - szResult = szFileName; - else - mir_free(szFileName); - mir_free(tszFileName); - - 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) -{ - bool bWasOpened = false; - - for (int i = arDbPlugins.getCount() - 1; i >= 0; i--) { - DATABASELINK *p = arDbPlugins[i]; - - // liked the profile? - int err = p->grokHeader(tszProfile); - if (err != ERROR_SUCCESS) { // smth went wrong - switch (err) { - case EGROKPRF_CANTREAD: - case EGROKPRF_UNKHEADER: - // just not supported. - continue; - - case EGROKPRF_OBSOLETE: - EnsureCheckerLoaded(true); - CallService(MS_DB_CHECKPROFILE, (WPARAM)tszProfile, 2); - break; - - default: - return err; - } - } - - bWasOpened = true; - - // try to load database - MIDatabase *pDb = p->Load(tszProfile, FALSE); - if (pDb) { - fillProfileName(tszProfile); - currDblink = p; - db_setCurrent(currDb = pDb); - return 0; - } - } - - return (bWasOpened) ? -1 : EGROKPRF_CANTREAD; -} - -// enumerate all plugins that had valid DatabasePluginInfo() -static int tryCreateDatabase(const TCHAR *ptszProfile) -{ - TCHAR *tszProfile = NEWTSTR_ALLOCA(ptszProfile); - CreatePathToFileT(tszProfile); - - for (int i = 0; i < arDbPlugins.getCount(); i++) { - DATABASELINK* p = arDbPlugins[i]; - - int err = p->makeDatabase(tszProfile); - if (err == ERROR_SUCCESS) { - g_bDbCreated = true; - MIDatabase *pDb = p->Load(tszProfile, FALSE); - if (pDb != NULL) { - fillProfileName(tszProfile); - currDblink = p; - db_setCurrent(currDb = pDb); - return 0; - } - return 1; - } - } - return 1; -} - -typedef struct { - TCHAR *profile; - UINT msg; - ATOM aPath; - int found; -} ENUMMIRANDAWINDOW; - -static BOOL CALLBACK EnumMirandaWindows(HWND hwnd, LPARAM lParam) -{ - TCHAR classname[256]; - ENUMMIRANDAWINDOW *x = (ENUMMIRANDAWINDOW *)lParam; - DWORD_PTR res = 0; - if (GetClassName(hwnd, classname, SIZEOF(classname)) && mir_tstrcmp(_T("Miranda"), classname) == 0) { - if (SendMessageTimeout(hwnd, x->msg, (WPARAM)x->aPath, 0, SMTO_ABORTIFHUNG, 100, &res) && res) { - x->found++; - return FALSE; - } - } - return TRUE; -} - -static int FindMirandaForProfile(TCHAR *szProfile) -{ - ENUMMIRANDAWINDOW x = { 0 }; - x.profile = szProfile; - x.msg = RegisterWindowMessage(_T("Miranda::ProcessProfile")); - x.aPath = GlobalAddAtom(szProfile); - EnumWindows(EnumMirandaWindows, (LPARAM)&x); - GlobalDeleteAtom(x.aPath); - return x.found; -} - -int LoadDatabaseModule(void) -{ - TCHAR szProfile[MAX_PATH]; - PathToAbsoluteT(_T("."), szProfile); - _tchdir(szProfile); - szProfile[0] = 0; - - LoadDatabaseServices(); - - // find out which profile to load - if (!getProfile(szProfile, SIZEOF(szProfile))) - return 1; - - if (arDbPlugins.getCount() == 0) { - TCHAR buf[256]; - TCHAR *p = _tcsrchr(szProfile, '\\'); - mir_sntprintf(buf, TranslateT("Miranda is unable to open '%s' because you do not have any profile plugins installed.\nYou need to install dbx_mmap.dll"), p ? ++p : szProfile); - MessageBox(0, buf, TranslateT("No profile support installed!"), MB_OK | MB_ICONERROR); - } - - // find a driver to support the given profile - bool retry; - int rc; - do { - retry = false; - if (_taccess(szProfile, 0) && shouldAutoCreate(szProfile)) - rc = tryCreateDatabase(szProfile); - else - rc = tryOpenDatabase(szProfile); - - if (rc > 0) { - // if there were drivers but they all failed cos the file is locked, try and find the miranda which locked it - if (fileExist(szProfile)) { - // file isn't locked, just no driver could open it. - TCHAR buf[256]; - TCHAR *p = _tcsrchr(szProfile, '\\'); - mir_sntprintf(buf, TranslateT("Miranda was unable to open '%s', it's in an unknown format.\nThis profile might also be damaged, please run DbChecker which should be installed."), p ? ++p : szProfile); - MessageBox(0, buf, TranslateT("Miranda can't understand that profile"), MB_OK | MB_ICONERROR); - } - else if (!FindMirandaForProfile(szProfile)) { - TCHAR buf[256]; - TCHAR *p = _tcsrchr(szProfile, '\\'); - mir_sntprintf(buf, TranslateT("Miranda was unable to open '%s'\nIt's inaccessible or used by other application or Miranda instance"), p ? ++p : szProfile); - retry = MessageBox(0, buf, TranslateT("Miranda can't open that profile"), MB_RETRYCANCEL | MB_ICONERROR) == IDRETRY; - } - } - } - while (retry); - - EnsureCheckerLoaded(false); // unload dbchecker - - if (rc == ERROR_SUCCESS) { - InitIni(); - return 0; - } - - return rc; -} diff --git a/src/modules/database/database.h b/src/modules/database/database.h deleted file mode 100644 index c0acab5c48..0000000000 --- a/src/modules/database/database.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright 2012-15 Miranda NG project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -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. -*/ - -class MDatabaseCache : public MIDatabaseCache -{ - HANDLE m_hCacheHeap; - char* m_lastSetting; - size_t m_contactSize; - DBCachedContact *m_lastVL; - mir_cs m_cs; - - LIST m_lContacts; - LIST m_lGlobalSettings; - LIST m_lSettings; - - void FreeCachedVariant(DBVARIANT* V); - -public: - MDatabaseCache(size_t); - ~MDatabaseCache(); - -protected: - STDMETHODIMP_(DBCachedContact*) AddContactToCache(MCONTACT contactID); - STDMETHODIMP_(DBCachedContact*) GetCachedContact(MCONTACT contactID); - STDMETHODIMP_(DBCachedContact*) GetFirstContact(void); - STDMETHODIMP_(DBCachedContact*) GetNextContact(MCONTACT contactID); - STDMETHODIMP_(void) FreeCachedContact(MCONTACT contactID); - - STDMETHODIMP_(char*) InsertCachedSetting(const char *szName, int); - STDMETHODIMP_(char*) GetCachedSetting(const char *szModuleName, const char *szSettingName, int, int); - STDMETHODIMP_(void) SetCachedVariant(DBVARIANT *s, DBVARIANT *d); - STDMETHODIMP_(DBVARIANT*) GetCachedValuePtr(MCONTACT contactID, char *szSetting, int bAllocate); -}; diff --git a/src/modules/database/dbini.cpp b/src/modules/database/dbini.cpp deleted file mode 100644 index d972d8cfd2..0000000000 --- a/src/modules/database/dbini.cpp +++ /dev/null @@ -1,520 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -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 "..\..\core\commonheaders.h" -#include "profilemanager.h" - -static bool bModuleInitialized = false; -static HANDLE hIniChangeNotification; - -static INT_PTR CALLBACK InstallIniDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - switch (message) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - SetDlgItemText(hwndDlg, IDC_ININAME, (TCHAR*)lParam); - { - TCHAR szSecurity[11]; - const TCHAR *pszSecurityInfo; - - GetPrivateProfileString(_T("AutoExec"), _T("Warn"), _T("notsafe"), szSecurity, SIZEOF(szSecurity), mirandabootini); - if (!mir_tstrcmpi(szSecurity, _T("all"))) - pszSecurityInfo = LPGENT("Security systems to prevent malicious changes are in place and you will be warned before every change that is made."); - else if (!mir_tstrcmpi(szSecurity, _T("onlyunsafe"))) - pszSecurityInfo = LPGENT("Security systems to prevent malicious changes are in place and you will be warned before changes that are known to be unsafe."); - else if (!mir_tstrcmpi(szSecurity, _T("none"))) - pszSecurityInfo = LPGENT("Security systems to prevent malicious changes have been disabled. You will receive no further warnings."); - else pszSecurityInfo = NULL; - if (pszSecurityInfo) SetDlgItemText(hwndDlg, IDC_SECURITYINFO, TranslateTS(pszSecurityInfo)); - } - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_VIEWINI: - { - TCHAR szPath[MAX_PATH]; - GetDlgItemText(hwndDlg, IDC_ININAME, szPath, SIZEOF(szPath)); - ShellExecute(hwndDlg, _T("open"), szPath, NULL, NULL, SW_SHOW); - } - break; - - case IDOK: - case IDCANCEL: - case IDC_NOTOALL: - EndDialog(hwndDlg, LOWORD(wParam)); - break; - } - break; - } - return FALSE; -} - -static bool IsInSpaceSeparatedList(const char *szWord, const char *szList) -{ - const char *szItem, *szEnd; - size_t wordLen = mir_strlen(szWord); - - for (szItem = szList;;) { - szEnd = strchr(szItem, ' '); - if (szEnd == NULL) - return !mir_strcmp(szItem, szWord); - - if (szEnd - szItem == wordLen) - if (!strncmp(szItem, szWord, wordLen)) - return true; - - szItem = szEnd + 1; - } -} - -struct warnSettingChangeInfo_t { - TCHAR *szIniPath; - char *szSection; - char *szSafeSections; - char *szUnsafeSections; - char *szName; - char *szValue; - int warnNoMore, cancel; -}; - -static INT_PTR CALLBACK WarnIniChangeDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - static warnSettingChangeInfo_t *warnInfo; - - switch(message) { - case WM_INITDIALOG: - { - char szSettingName[256]; - const TCHAR *pszSecurityInfo; - warnInfo = (warnSettingChangeInfo_t*)lParam; - TranslateDialogDefault(hwndDlg); - SetDlgItemText(hwndDlg, IDC_ININAME, warnInfo->szIniPath); - mir_strcpy(szSettingName, warnInfo->szSection); - mir_strcat(szSettingName, " / "); - mir_strcat(szSettingName, warnInfo->szName); - SetDlgItemTextA(hwndDlg, IDC_SETTINGNAME, szSettingName); - SetDlgItemTextA(hwndDlg, IDC_NEWVALUE, warnInfo->szValue); - if (IsInSpaceSeparatedList(warnInfo->szSection, warnInfo->szSafeSections)) - pszSecurityInfo = LPGENT("This change is known to be safe."); - else if (IsInSpaceSeparatedList(warnInfo->szSection, warnInfo->szUnsafeSections)) - pszSecurityInfo = LPGENT("This change is known to be potentially hazardous."); - else - pszSecurityInfo = LPGENT("This change is not known to be safe."); - SetDlgItemText(hwndDlg, IDC_SECURITYINFO, TranslateTS(pszSecurityInfo)); - } - return TRUE; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDCANCEL: - warnInfo->cancel = 1; - // fall through - case IDYES: - case IDNO: - warnInfo->warnNoMore = IsDlgButtonChecked(hwndDlg, IDC_WARNNOMORE); - EndDialog(hwndDlg, LOWORD(wParam)); - break; - } - break; - } - return FALSE; -} - -static INT_PTR CALLBACK IniImportDoneDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - TCHAR szIniPath[MAX_PATH]; - - switch (message) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - SetDlgItemText(hwndDlg, IDC_ININAME, (TCHAR*)lParam); - SetDlgItemText(hwndDlg, IDC_NEWNAME, (TCHAR*)lParam); - return TRUE; - - case WM_COMMAND: - GetDlgItemText(hwndDlg, IDC_ININAME, szIniPath, SIZEOF(szIniPath)); - switch (LOWORD(wParam)) { - case IDC_DELETE: - DeleteFile(szIniPath); - case IDC_LEAVE: - EndDialog(hwndDlg, LOWORD(wParam)); - break; - case IDC_RECYCLE: - { - SHFILEOPSTRUCT shfo = { 0 }; - shfo.wFunc = FO_DELETE; - shfo.pFrom = szIniPath; - szIniPath[mir_tstrlen(szIniPath) + 1] = '\0'; - shfo.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO; - SHFileOperation(&shfo); - } - EndDialog(hwndDlg, LOWORD(wParam)); - break; - case IDC_MOVE: - TCHAR szNewPath[MAX_PATH]; - GetDlgItemText(hwndDlg, IDC_NEWNAME, szNewPath, SIZEOF(szNewPath)); - MoveFile(szIniPath, szNewPath); - EndDialog(hwndDlg, LOWORD(wParam)); - break; - } - break; - } - return FALSE; -} - -// settings: -struct SettingsList -{ - char *name; - SettingsList *next; -} *setting_items = NULL; - -int SettingsEnumProc(const char *szSetting, LPARAM lParam) -{ - SettingsList *newItem = (SettingsList *)mir_alloc(sizeof(SettingsList)); - newItem->name = mir_strdup(szSetting); - newItem->next = setting_items; - setting_items = newItem; - return 0; -} - -static void ConvertBackslashes(char *str, UINT fileCp) -{ - char *pstr; - for (pstr = str; *pstr; pstr = CharNextExA(fileCp, pstr, 0)) { - if (*pstr == '\\') { - switch (pstr[1]) { - case 'n': *pstr = '\n'; break; - case 't': *pstr = '\t'; break; - case 'r': *pstr = '\r'; break; - default: *pstr = pstr[1]; break; - } - memmove(pstr + 1, pstr + 2, mir_strlen(pstr + 2) + 1); - } - } -} - -static void ProcessIniFile(TCHAR* szIniPath, char *szSafeSections, char *szUnsafeSections, int secur, bool secFN) -{ - FILE *fp = _tfopen(szIniPath, _T("rt")); - if (fp == NULL) - return; - - bool warnThisSection = false; - char szSection[128]; szSection[0] = 0; - - while (!feof(fp)) { - char szLine[2048]; - if (fgets(szLine, sizeof(szLine), fp) == NULL) - break; -LBL_NewLine: - size_t lineLength = mir_strlen(szLine); - while (lineLength && (BYTE)(szLine[lineLength - 1]) <= ' ') - szLine[--lineLength] = '\0'; - - if (szLine[0] == ';' || szLine[0] <= ' ') - continue; - - if (szLine[0] == '[') { - char *szEnd = strchr(szLine + 1, ']'); - if (szEnd == NULL) - continue; - - if (szLine[1] == '!') - szSection[0] = '\0'; - else { - mir_strncpy(szSection, szLine + 1, min(sizeof(szSection), (int)(szEnd - szLine))); - switch (secur) { - case 0: - warnThisSection = false; - break; - - case 1: - warnThisSection = !IsInSpaceSeparatedList(szSection, szSafeSections); - break; - - case 2: - warnThisSection = IsInSpaceSeparatedList(szSection, szUnsafeSections); - break; - - default: - warnThisSection = true; - break; - } - if (secFN) warnThisSection = 0; - } - if (szLine[1] == '?') { - DBCONTACTENUMSETTINGS dbces; - dbces.pfnEnumProc = SettingsEnumProc; - mir_strncpy(szSection, szLine+2, min(sizeof(szSection), (int)(szEnd-szLine-1))); - dbces.szModule = szSection; - dbces.ofsSettings = 0; - CallService(MS_DB_CONTACT_ENUMSETTINGS, 0, (LPARAM)&dbces); - while (setting_items) { - SettingsList *next = setting_items->next; - - db_unset(NULL, szSection, setting_items->name); - - mir_free(setting_items->name); - mir_free(setting_items); - setting_items = next; - } - } - continue; - } - - if (szSection[0] == '\0') - continue; - - char *szValue = strchr(szLine, '='); - if (szValue == NULL) - continue; - - char szName[128]; - mir_strncpy(szName, szLine, min(sizeof(szName), (int)(szValue-szLine+1))); - szValue++; - { - warnSettingChangeInfo_t warnInfo; - warnInfo.szIniPath = szIniPath; - warnInfo.szName = szName; - warnInfo.szSafeSections = szSafeSections; - warnInfo.szSection = szSection; - warnInfo.szUnsafeSections = szUnsafeSections; - warnInfo.szValue = szValue; - warnInfo.warnNoMore = 0; - warnInfo.cancel = 0; - if (warnThisSection && IDNO == DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_WARNINICHANGE), NULL, WarnIniChangeDlgProc, (LPARAM)&warnInfo)) - continue; - if (warnInfo.cancel) - break; - if (warnInfo.warnNoMore) - warnThisSection = 0; - } - - switch (szValue[0]) { - case 'b': - case 'B': - db_set_b(NULL, szSection, szName, (BYTE)strtol(szValue+1, NULL, 0)); - break; - case 'w': - case 'W': - db_set_w(NULL, szSection, szName, (WORD)strtol(szValue+1, NULL, 0)); - break; - case 'd': - case 'D': - db_set_dw(NULL, szSection, szName, (DWORD)strtoul(szValue+1, NULL, 0)); - break; - case 'l': - case 'L': - case '-': - db_unset(NULL, szSection, szName); - break; - case 'e': - case 'E': - ConvertBackslashes(szValue+1, Langpack_GetDefaultCodePage()); - case 's': - case 'S': - db_set_s(NULL, szSection, szName, szValue+1); - break; - case 'g': - case 'G': - for (char *pstr = szValue + 1; *pstr; pstr++) { - if (*pstr == '\\') { - switch (pstr[1]) { - case 'n': *pstr = '\n'; break; - case 't': *pstr = '\t'; break; - case 'r': *pstr = '\r'; break; - default: *pstr = pstr[1]; break; - } - memmove(pstr + 1, pstr + 2, mir_strlen(pstr + 2) + 1); - } - } - case 'u': - case 'U': - db_set_utf(NULL, szSection, szName, szValue + 1); - break; - case 'm': - case 'M': - { - CMStringA memo(szValue + 1); - memo.Append("\r\n"); - while (fgets(szLine, sizeof(szLine), fp) != NULL) { - switch (szLine[0]) { - case 0: case '\r': case '\n': case ' ': case '\t': - break; - default: - db_set_utf(NULL, szSection, szName, memo); - goto LBL_NewLine; - } - - memo.Append(rtrim(szLine + 1)); - memo.Append("\r\n"); - } - db_set_utf(NULL, szSection, szName, memo); - } - break; - case 'n': - case 'h': - case 'N': - case 'H': - { - int len; - char *pszValue, *pszEnd; - - PBYTE buf = (PBYTE)mir_alloc(mir_strlen(szValue + 1)); - for (len = 0, pszValue = szValue + 1;; len++) { - buf[len] = (BYTE)strtol(pszValue, &pszEnd, 0x10); - if (pszValue == pszEnd) - break; - pszValue = pszEnd; - } - db_set_blob(NULL, szSection, szName, buf, len); - mir_free(buf); - } - break; - default: - TCHAR buf[250]; - mir_sntprintf(buf, TranslateT("Invalid setting type for '%s'. The first character of every value must be b, w, d, l, s, e, u, g, h or n."), _A2T(szName)); - MessageBox(NULL, buf, TranslateT("Install database settings"), MB_ICONWARNING | MB_OK); - break; - } - } - fclose(fp); -} - -static void DoAutoExec(void) -{ - TCHAR szUse[7], szIniPath[MAX_PATH], szFindPath[MAX_PATH]; - TCHAR buf[2048], szSecurity[11], szOverrideSecurityFilename[MAX_PATH], szOnCreateFilename[MAX_PATH]; - int secur; - - GetPrivateProfileString(_T("AutoExec"), _T("Use"), _T("prompt"), szUse, SIZEOF(szUse), mirandabootini); - if (!mir_tstrcmpi(szUse, _T("no"))) return; - GetPrivateProfileString(_T("AutoExec"), _T("Safe"), _T("CLC Icons CLUI CList SkinSounds"), buf, SIZEOF(buf), mirandabootini); - ptrA szSafeSections(mir_t2a(buf)); - GetPrivateProfileString(_T("AutoExec"), _T("Unsafe"), _T("AIM Facebook GG ICQ IRC JABBER MRA MSN SKYPE Tlen TWITTER VKontakte XFire"), buf, SIZEOF(buf), mirandabootini); - ptrA szUnsafeSections(mir_t2a(buf)); - GetPrivateProfileString(_T("AutoExec"), _T("Warn"), _T("notsafe"), szSecurity, SIZEOF(szSecurity), mirandabootini); - if (!mir_tstrcmpi(szSecurity, _T("none"))) secur = 0; - else if (!mir_tstrcmpi(szSecurity, _T("notsafe"))) secur = 1; - else if (!mir_tstrcmpi(szSecurity, _T("onlyunsafe"))) secur = 2; - - GetPrivateProfileString(_T("AutoExec"), _T("OverrideSecurityFilename"), _T(""), szOverrideSecurityFilename, SIZEOF(szOverrideSecurityFilename), mirandabootini); - GetPrivateProfileString(_T("AutoExec"), _T("OnCreateFilename"), _T(""), szOnCreateFilename, SIZEOF(szOnCreateFilename), mirandabootini); - GetPrivateProfileString(_T("AutoExec"), _T("Glob"), _T("autoexec_*.ini"), szFindPath, SIZEOF(szFindPath), mirandabootini); - - if (g_bDbCreated && szOnCreateFilename[0]) { - PathToAbsoluteT(VARST(szOnCreateFilename), szIniPath); - ProcessIniFile(szIniPath, szSafeSections, szUnsafeSections, 0, 1); - } - - PathToAbsoluteT(VARST(szFindPath), szFindPath); - - WIN32_FIND_DATA fd; - HANDLE hFind = FindFirstFile(szFindPath, &fd); - if (hFind == INVALID_HANDLE_VALUE) - return; - - TCHAR *str2 = _tcsrchr(szFindPath, '\\'); - if (str2 == NULL) - szFindPath[0] = 0; - else - str2[1] = 0; - - do { - bool secFN = mir_tstrcmpi(fd.cFileName, szOverrideSecurityFilename) == 0; - - mir_sntprintf(szIniPath, SIZEOF(szIniPath), _T("%s%s"), szFindPath, fd.cFileName); - if (!mir_tstrcmpi(szUse, _T("prompt")) && !secFN) { - int result = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_INSTALLINI), NULL, InstallIniDlgProc, (LPARAM)szIniPath); - if (result == IDC_NOTOALL) break; - if (result == IDCANCEL) continue; - } - - ProcessIniFile(szIniPath, szSafeSections, szUnsafeSections, secur, secFN); - - if (secFN) - DeleteFile(szIniPath); - else { - TCHAR szOnCompletion[8]; - GetPrivateProfileString(_T("AutoExec"), _T("OnCompletion"), _T("recycle"), szOnCompletion, SIZEOF(szOnCompletion), mirandabootini); - if (!mir_tstrcmpi(szOnCompletion, _T("delete"))) - DeleteFile(szIniPath); - else if (!mir_tstrcmpi(szOnCompletion, _T("recycle"))) { - SHFILEOPSTRUCT shfo = { 0 }; - shfo.wFunc = FO_DELETE; - shfo.pFrom = szIniPath; - szIniPath[mir_tstrlen(szIniPath) + 1] = 0; - shfo.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO; - SHFileOperation(&shfo); - } - else if (!mir_tstrcmpi(szOnCompletion, _T("rename"))) { - TCHAR szRenamePrefix[MAX_PATH], szNewPath[MAX_PATH]; - GetPrivateProfileString(_T("AutoExec"), _T("RenamePrefix"), _T("done_"), szRenamePrefix, SIZEOF(szRenamePrefix), mirandabootini); - mir_tstrcpy(szNewPath, szFindPath); - mir_tstrcat(szNewPath, szRenamePrefix); - mir_tstrcat(szNewPath, fd.cFileName); - MoveFile(szIniPath, szNewPath); - } - else if (!mir_tstrcmpi(szOnCompletion, _T("ask"))) - DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_INIIMPORTDONE), NULL, IniImportDoneDlgProc, (LPARAM)szIniPath); - } - } - while (FindNextFile(hFind, &fd)); - - FindClose(hFind); -} - -static INT_PTR CheckIniImportNow(WPARAM, LPARAM) -{ - DoAutoExec(); - FindNextChangeNotification(hIniChangeNotification); - return 0; -} - -int InitIni(void) -{ - bModuleInitialized = true; - - DoAutoExec(); - - TCHAR szMirandaDir[MAX_PATH]; - PathToAbsoluteT(_T("."), szMirandaDir); - hIniChangeNotification = FindFirstChangeNotification(szMirandaDir, 0, FILE_NOTIFY_CHANGE_FILE_NAME); - if (hIniChangeNotification != INVALID_HANDLE_VALUE) { - CreateServiceFunction("DB/Ini/CheckImportNow", CheckIniImportNow); - CallService(MS_SYSTEM_WAITONHANDLE, (WPARAM)hIniChangeNotification, (LPARAM)"DB/Ini/CheckImportNow"); - } - return 0; -} - -void UninitIni(void) -{ - if (!bModuleInitialized) - return; - - CallService(MS_SYSTEM_REMOVEWAIT, (WPARAM)hIniChangeNotification, 0); - FindCloseChangeNotification(hIniChangeNotification); -} diff --git a/src/modules/database/dbintf.cpp b/src/modules/database/dbintf.cpp deleted file mode 100644 index fed80cd528..0000000000 --- a/src/modules/database/dbintf.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (C) 2012-15 Miranda NG project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -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 "..\..\core\commonheaders.h" -#include "database.h" - -MIDatabase *currDb = NULL; -DATABASELINK *currDblink = NULL; - -MIR_CORE_DLL(void) db_setCurrent(MIDatabase*); - -static INT_PTR srvSetSafetyMode(WPARAM wParam, LPARAM) -{ - if (!currDb) return 1; - - currDb->SetCacheSafetyMode(wParam != 0); - return 0; -} - -static INT_PTR srvGetContactCount(WPARAM, LPARAM) -{ - return (currDb) ? currDb->GetContactCount() : 0; -} - -/////////////////////////////////////////////////////////////////////////////// -// Contacts - -static INT_PTR srvDeleteContact(WPARAM wParam, LPARAM) -{ - DBVARIANT dbv = { 0 }; - if (!db_get_ts(wParam, "ContactPhoto", "File", &dbv)) { - DeleteFile(dbv.ptszVal); - db_free(&dbv); - } - return (currDb) ? currDb->DeleteContact(wParam) : 0; -} - -static INT_PTR srvAddContact(WPARAM wParam, LPARAM) -{ - MCONTACT hNew = (currDb) ? currDb->AddContact() : 0; - Netlib_Logf(NULL, "New contact created: %d", hNew); - return hNew; -} - -static INT_PTR srvIsDbContact(WPARAM wParam, LPARAM) -{ - return (currDb) ? currDb->IsDbContact(wParam) : 0; -} - -/////////////////////////////////////////////////////////////////////////////// -// Module chain - -static INT_PTR srvEnumModuleNames(WPARAM wParam, LPARAM lParam) -{ - return (currDb) ? (INT_PTR)currDb->EnumModuleNames((DBMODULEENUMPROC)lParam, (void*)wParam) : 0; -} - -/////////////////////////////////////////////////////////////////////////////// -// Settings - -static INT_PTR srvEnumContactSettings(WPARAM wParam, LPARAM lParam) -{ - return (currDb) ? (INT_PTR)currDb->EnumContactSettings(wParam, (DBCONTACTENUMSETTINGS*)lParam) : 0; -} - -static INT_PTR srvEnumResidentSettings(WPARAM wParam, LPARAM lParam) -{ - return (currDb) ? (INT_PTR)currDb->EnumResidentSettings((DBMODULEENUMPROC)wParam, (void*)lParam) : 0; -} - -/////////////////////////////////////////////////////////////////////////////// -// Database list - -LIST arDbPlugins(5); - -static INT_PTR srvRegisterPlugin(WPARAM wParam, LPARAM lParam) -{ - DATABASELINK* pPlug = (DATABASELINK*)lParam; - if (pPlug == NULL) - return 1; - - arDbPlugins.insert(pPlug); - return 0; -} - -static INT_PTR srvFindPlugin(WPARAM wParam, LPARAM lParam) -{ - for (int i = arDbPlugins.getCount() - 1; i >= 0; i--) { - int error = arDbPlugins[i]->grokHeader((TCHAR*)lParam); - if (error == ERROR_SUCCESS || error == EGROKPRF_OBSOLETE) - return (INT_PTR)arDbPlugins[i]; - } - - return NULL; -} - -static INT_PTR srvGetCurrentDb(WPARAM wParam, LPARAM lParam) -{ - return (INT_PTR)currDb; -} - -static INT_PTR srvInitInstance(WPARAM wParam, LPARAM lParam) -{ - MIDatabase* pDb = (MIDatabase*)lParam; - if (pDb != NULL) - pDb->m_cache = new MDatabaseCache(pDb->GetContactSize()); - return 0; -} - -static INT_PTR srvDestroyInstance(WPARAM wParam, LPARAM lParam) -{ - MIDatabase* pDb = (MIDatabase*)lParam; - if (pDb != NULL) { - MDatabaseCache *pCache = (MDatabaseCache*)pDb->m_cache; - pDb->m_cache = NULL; - delete pCache; - } - return 0; -} - -/////////////////////////////////////////////////////////////////////////////// - -int LoadDbintfModule() -{ - CreateServiceFunction(MS_DB_CONTACT_GETCOUNT, srvGetContactCount); - CreateServiceFunction(MS_DB_CONTACT_DELETE, srvDeleteContact); - CreateServiceFunction(MS_DB_CONTACT_ADD, srvAddContact); - CreateServiceFunction(MS_DB_CONTACT_IS, srvIsDbContact); - - CreateServiceFunction(MS_DB_MODULES_ENUM, srvEnumModuleNames); - - CreateServiceFunction(MS_DB_CONTACT_ENUMSETTINGS, srvEnumContactSettings); - CreateServiceFunction("DB/ResidentSettings/Enum", srvEnumResidentSettings); - - CreateServiceFunction(MS_DB_REGISTER_PLUGIN, srvRegisterPlugin); - CreateServiceFunction(MS_DB_FIND_PLUGIN, srvFindPlugin); - CreateServiceFunction(MS_DB_GET_CURRENT, srvGetCurrentDb); - - CreateServiceFunction(MS_DB_INIT_INSTANCE, srvInitInstance); - CreateServiceFunction(MS_DB_DESTROY_INSTANCE, srvDestroyInstance); - return 0; -} - -void LoadDatabaseServices() -{ - CreateServiceFunction(MS_DB_SETSAFETYMODE, srvSetSafetyMode); -} diff --git a/src/modules/database/dbutils.cpp b/src/modules/database/dbutils.cpp deleted file mode 100644 index 880e8a59d8..0000000000 --- a/src/modules/database/dbutils.cpp +++ /dev/null @@ -1,367 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -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 "..\..\core\commonheaders.h" -#include "profilemanager.h" - -static int CompareEventTypes(const DBEVENTTYPEDESCR *p1, const DBEVENTTYPEDESCR *p2) -{ - int result = mir_strcmp(p1->module, p2->module); - if (result) - return result; - - return p1->eventType - p2->eventType; -} - -static LIST eventTypes(10, CompareEventTypes); - -static BOOL bModuleInitialized = FALSE; - -static INT_PTR DbEventTypeRegister(WPARAM, LPARAM lParam) -{ - DBEVENTTYPEDESCR *et = (DBEVENTTYPEDESCR*)lParam; - if (et == NULL || et->cbSize != sizeof(DBEVENTTYPEDESCR)) - return -1; - - if (eventTypes.getIndex(et) != -1) - return -1; - - DBEVENTTYPEDESCR *p = (DBEVENTTYPEDESCR*)mir_calloc(sizeof(DBEVENTTYPEDESCR)); - p->cbSize = sizeof(DBEVENTTYPEDESCR); - p->module = mir_strdup(et->module); - p->eventType = et->eventType; - p->descr = mir_strdup(et->descr); - if (et->textService) - p->textService = mir_strdup(et->textService); - if (et->iconService) - p->iconService = mir_strdup(et->iconService); - p->eventIcon = et->eventIcon; - p->flags = et->flags; - - if (!p->textService) { - char szServiceName[100]; - mir_snprintf(szServiceName, SIZEOF(szServiceName), "%s/GetEventText%d", p->module, p->eventType); - p->textService = mir_strdup(szServiceName); - } - if (!p->iconService) { - char szServiceName[100]; - mir_snprintf(szServiceName, SIZEOF(szServiceName), "%s/GetEventIcon%d", p->module, p->eventType); - p->iconService = mir_strdup(szServiceName); - } - eventTypes.insert(p); - return 0; -} - -static INT_PTR DbEventTypeGet(WPARAM wParam, LPARAM lParam) -{ - DBEVENTTYPEDESCR tmp; - tmp.module = (char*)wParam; - tmp.eventType = lParam; - return (INT_PTR)eventTypes.find(&tmp); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -static TCHAR* getEventString(DBEVENTINFO *dbei, LPSTR &buf) -{ - LPSTR in = buf; - buf += mir_strlen(buf) + 1; - return (dbei->flags & DBEF_UTF) ? Utf8DecodeT(in) : mir_a2t(in); -} - -static INT_PTR DbEventGetText(WPARAM wParam, LPARAM lParam) -{ - DBEVENTGETTEXT* egt = (DBEVENTGETTEXT*)lParam; - if (egt == NULL) - return 0; - - DBEVENTINFO *dbei = egt->dbei; - if (dbei == NULL || dbei->szModule == NULL || dbei->cbSize != sizeof(DBEVENTINFO)) - return 0; - - DBEVENTTYPEDESCR *et = (DBEVENTTYPEDESCR*)DbEventTypeGet((WPARAM)dbei->szModule, (LPARAM)dbei->eventType); - if (et && ServiceExists(et->textService)) - return CallService(et->textService, wParam, lParam); - - if (!dbei->pBlob) - return 0; - - if (dbei->eventType == EVENTTYPE_AUTHREQUEST || dbei->eventType == EVENTTYPE_ADDED) { - // EVENTTYPE_AUTHREQUEST: uin(DWORD), hContact(DWORD), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ) - // EVENTTYPE_ADDED: uin(DWORD), hContact(HANDLE), nick(ASCIIZ), first(ASCIIZ), last(ASCIIZ), email(ASCIIZ) - DWORD uin = *(DWORD*)dbei->pBlob; - MCONTACT hContact = (MCONTACT)*(DWORD*)(dbei->pBlob + sizeof(DWORD)); - char *buf = LPSTR(dbei->pBlob) + sizeof(DWORD)*2; - ptrT tszNick(getEventString(dbei, buf)); - ptrT tszFirst(getEventString(dbei, buf)); - ptrT tszLast(getEventString(dbei, buf)); - ptrT tszEmail(getEventString(dbei, buf)); - - CMString nick, text; - if (tszFirst || tszLast) { - nick.AppendFormat(_T("%s %s"), tszFirst, tszLast); - nick.Trim(); - } - if (tszEmail) { - if (!nick.IsEmpty()) - nick.Append(_T(", ")); - nick.Append(tszEmail); - } - if (uin != 0) { - if (!nick.IsEmpty()) - nick.Append(_T(", ")); - nick.AppendFormat(_T("%d"), uin); - } - if (!nick.IsEmpty()) - nick = _T("(") + nick + _T(")"); - - if (dbei->eventType == EVENTTYPE_AUTHREQUEST) { - ptrT tszReason(getEventString(dbei, buf)); - text.Format(TranslateT("Authorization request from %s%s: %s"), - (tszNick == NULL) ? cli.pfnGetContactDisplayName(hContact, 0) : tszNick, nick, tszReason); - } - else text.Format(TranslateT("You were added by %s%s"), - (tszNick == NULL) ? cli.pfnGetContactDisplayName(hContact, 0) : tszNick, nick); - return (egt->datatype == DBVT_WCHAR) ? (INT_PTR)mir_tstrdup(text) : (INT_PTR)mir_t2a(text); - } - - if (dbei->eventType == EVENTTYPE_CONTACTS) { - CMString text(TranslateT("Contacts: ")); - // blob is: [uin(ASCIIZ), nick(ASCIIZ)]* - char *buf = LPSTR(dbei->pBlob), *limit = LPSTR(dbei->pBlob) + dbei->cbBlob; - while (buf < limit) { - ptrT tszUin(getEventString(dbei, buf)); - ptrT tszNick(getEventString(dbei, buf)); - if (tszNick && *tszNick) - text.AppendFormat(_T("\"%s\" "), tszNick); - if (tszUin && *tszUin) - text.AppendFormat(_T("<%s>; "), tszUin); - } - return (egt->datatype == DBVT_WCHAR) ? (INT_PTR)mir_tstrdup(text) : (INT_PTR)mir_t2a(text); - } - - if (dbei->eventType == EVENTTYPE_FILE) { - char *buf = LPSTR(dbei->pBlob) + sizeof(DWORD); - ptrT tszFileName(getEventString(dbei, buf)); - ptrT tszDescription(getEventString(dbei, buf)); - ptrT &ptszText = (mir_tstrlen(tszDescription) == 0) ? tszFileName : tszDescription; - switch (egt->datatype) { - case DBVT_WCHAR: - return (INT_PTR)ptszText.detach(); - case DBVT_ASCIIZ: - return (INT_PTR)mir_t2a(ptszText); - } - return 0; - } - - // by default treat an event's blob as a string - if (egt->datatype == DBVT_WCHAR) { - char *str = (char*)alloca(dbei->cbBlob + 1); - memcpy(str, dbei->pBlob, dbei->cbBlob); - str[dbei->cbBlob] = 0; - - if (dbei->flags & DBEF_UTF) { - WCHAR *msg = NULL; - Utf8DecodeCP(str, egt->codepage, &msg); - if (msg) - return (INT_PTR)msg; - } - - return (INT_PTR)mir_a2t_cp(str, egt->codepage); - } - - if (egt->datatype == DBVT_ASCIIZ) { - char *msg = mir_strdup((char*)dbei->pBlob); - if (dbei->flags & DBEF_UTF) - Utf8DecodeCP(msg, egt->codepage, NULL); - - return (INT_PTR)msg; - } - return 0; -} - -static INT_PTR DbEventGetIcon(WPARAM wParam, LPARAM lParam) -{ - DBEVENTINFO* dbei = (DBEVENTINFO*)lParam; - HICON icon = NULL; - DBEVENTTYPEDESCR* et = (DBEVENTTYPEDESCR*)DbEventTypeGet((WPARAM)dbei->szModule, (LPARAM)dbei->eventType); - - if (et && ServiceExists(et->iconService)) { - icon = (HICON)CallService(et->iconService, wParam, lParam); - if (icon) - return (INT_PTR)icon; - } - if (et && et->eventIcon) - icon = Skin_GetIconByHandle(et->eventIcon); - if (!icon) { - char szName[100]; - mir_snprintf(szName, SIZEOF(szName), "eventicon_%s%d", dbei->szModule, dbei->eventType); - icon = Skin_GetIcon(szName); - } - - if (!icon) { - switch(dbei->eventType) { - case EVENTTYPE_URL: - icon = LoadSkinIcon(SKINICON_EVENT_URL); - break; - - case EVENTTYPE_FILE: - icon = LoadSkinIcon(SKINICON_EVENT_FILE); - break; - - default: // EVENTTYPE_MESSAGE and unknown types - icon = LoadSkinIcon(SKINICON_EVENT_MESSAGE); - break; - } - } - - return (INT_PTR)((wParam & LR_SHARED) ? icon : CopyIcon(icon)); -} - -static INT_PTR DbEventGetStringT(WPARAM wParam, LPARAM lParam) -{ - DBEVENTINFO* dbei = (DBEVENTINFO*)wParam; - char *string = (char*)lParam; - - if (dbei->flags & DBEF_UTF) - return (INT_PTR)Utf8DecodeW(string); - - return (INT_PTR)mir_a2t(string); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -static int sttEnumVars(const char *szVarName, LPARAM lParam) -{ - LIST* vars = (LIST*)lParam; - vars->insert(mir_strdup(szVarName)); - return 0; -} - -static INT_PTR DbDeleteModule(WPARAM hContact, LPARAM lParam) -{ - LIST vars(20); - - DBCONTACTENUMSETTINGS dbces = { 0 }; - dbces.pfnEnumProc = sttEnumVars; - dbces.lParam = (LPARAM)&vars; - dbces.szModule = (char*)lParam; - CallService(MS_DB_CONTACT_ENUMSETTINGS, hContact, (LPARAM)&dbces); - - for (int i = vars.getCount()-1; i >= 0; i--) { - db_unset(hContact, (char*)lParam, vars[i]); - mir_free(vars[i]); - } - return 0; -} - -static INT_PTR GetProfilePath(WPARAM wParam, LPARAM lParam) -{ - if (!wParam || !lParam) - return 1; - - char *dst = (char*)lParam; - strncpy(dst, _T2A(g_profileDir), wParam); - dst[wParam-1] = 0; - return 0; -} - -static INT_PTR GetProfileName(WPARAM wParam, LPARAM lParam) -{ - if (!wParam || !lParam) - return 1; - - char *dst = (char*)lParam; - - char *tmp = makeFileName(g_profileName); - strncpy(dst, tmp, wParam); - mir_free(tmp); - - dst[wParam-1] = 0; - return 0; -} - -static INT_PTR GetProfilePathW(WPARAM wParam, LPARAM lParam) -{ - if (!wParam || !lParam) - return 1; - - wchar_t *dst = (wchar_t*)lParam; - wcsncpy(dst, g_profileDir, wParam); - dst[wParam-1] = 0; - return 0; -} - -static INT_PTR GetProfileNameW(WPARAM wParam, LPARAM lParam) -{ - wchar_t *dst = (wchar_t*)lParam; - wcsncpy(dst, g_profileName, wParam); - dst[wParam-1] = 0; - return 0; -} - -static INT_PTR SetDefaultProfile(WPARAM wParam, LPARAM lParam) -{ - extern TCHAR* g_defaultProfile; - replaceStrT(g_defaultProfile, (TCHAR*)wParam); - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -int LoadEventsModule() -{ - bModuleInitialized = TRUE; - - CreateServiceFunction(MS_DB_EVENT_REGISTERTYPE, DbEventTypeRegister); - CreateServiceFunction(MS_DB_EVENT_GETTYPE, DbEventTypeGet); - CreateServiceFunction(MS_DB_EVENT_GETTEXT, DbEventGetText); - CreateServiceFunction(MS_DB_EVENT_GETICON, DbEventGetIcon); - CreateServiceFunction(MS_DB_EVENT_GETSTRINGT, DbEventGetStringT); - - CreateServiceFunction(MS_DB_MODULE_DELETE, DbDeleteModule); - - CreateServiceFunction(MS_DB_GETPROFILEPATH, GetProfilePath); - CreateServiceFunction(MS_DB_GETPROFILENAME, GetProfileName); - CreateServiceFunction(MS_DB_GETPROFILEPATHW, GetProfilePathW); - CreateServiceFunction(MS_DB_GETPROFILENAMEW, GetProfileNameW); - - CreateServiceFunction(MS_DB_SETDEFAULTPROFILE, SetDefaultProfile); - return 0; -} - -void UnloadEventsModule() -{ - if (!bModuleInitialized) - return; - - for (int i=0; i < eventTypes.getCount(); i++) { - DBEVENTTYPEDESCR *p = eventTypes[i]; - mir_free(p->module); - mir_free(p->descr); - mir_free(p->textService); - mir_free(p->iconService); - mir_free(p); - } -} diff --git a/src/modules/database/mdatabasecache.cpp b/src/modules/database/mdatabasecache.cpp deleted file mode 100644 index ffc9631d77..0000000000 --- a/src/modules/database/mdatabasecache.cpp +++ /dev/null @@ -1,252 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (C) 2012-15 Miranda NG project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -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 "..\..\core\commonheaders.h" -#include "database.h" - -static int stringCompare(const char *p1, const char *p2) -{ - return mir_strcmp(p1, p2); -} - -static int compareGlobals(const DBCachedGlobalValue *p1, const DBCachedGlobalValue *p2) -{ - return mir_strcmp(p1->name, p2->name); -} - -MDatabaseCache::MDatabaseCache(size_t _size) : - m_contactSize(_size), - m_lSettings(100, stringCompare), - m_lContacts(50, NumericKeySortT), - m_lGlobalSettings(50, compareGlobals), - m_lastSetting(NULL), - m_lastVL(NULL) -{ - m_hCacheHeap = HeapCreate(0, 0, 0); -} - -MDatabaseCache::~MDatabaseCache() -{ - for (int i = 0; i < m_lContacts.getCount(); i++) - mir_free(m_lContacts[i]->pSubs); - - HeapDestroy(m_hCacheHeap); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -DBCachedContact* MDatabaseCache::AddContactToCache(MCONTACT contactID) -{ - mir_cslock lck(m_cs); - - int index = m_lContacts.getIndex((DBCachedContact*)&contactID); - if (index != -1) - return m_lContacts[index]; - - DBCachedContact *cc = (DBCachedContact*)HeapAlloc(m_hCacheHeap, HEAP_ZERO_MEMORY, m_contactSize); - cc->contactID = contactID; - cc->nSubs = -1; - m_lContacts.insert(cc); - return cc; -} - -DBCachedContact* MDatabaseCache::GetCachedContact(MCONTACT contactID) -{ - mir_cslock lck(m_cs); - - int index = m_lContacts.getIndex((DBCachedContact*)&contactID); - return (index == -1) ? NULL : m_lContacts[index]; -} - -DBCachedContact* MDatabaseCache::GetFirstContact() -{ - mir_cslock lck(m_cs); - return m_lContacts[0]; -} - -DBCachedContact* MDatabaseCache::GetNextContact(MCONTACT contactID) -{ - mir_cslock lck(m_cs); - - int index = m_lContacts.getIndex((DBCachedContact*)&contactID); - return (index == -1) ? NULL : m_lContacts[index+1]; -} - -void MDatabaseCache::FreeCachedContact(MCONTACT contactID) -{ - mir_cslock lck(m_cs); - - int index = m_lContacts.getIndex((DBCachedContact*)&contactID); - if (index == -1) - return; - - DBCachedContact *cc = m_lContacts[index]; - DBCachedContactValue* V = cc->first; - while (V != NULL) { - DBCachedContactValue* V1 = V->next; - FreeCachedVariant(&V->value); - HeapFree(m_hCacheHeap, 0, V); - V = V1; - } - - mir_free(cc->pSubs); - HeapFree(m_hCacheHeap, 0, cc); - - m_lContacts.remove(index); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -char* MDatabaseCache::InsertCachedSetting(const char* szName, int cbLen) -{ - char* newValue = (char*)HeapAlloc(m_hCacheHeap, 0, cbLen); - *newValue++ = 0; - mir_strcpy(newValue, szName); - m_lSettings.insert(newValue); - return newValue; -} - -char* MDatabaseCache::GetCachedSetting(const char *szModuleName, const char *szSettingName, int moduleNameLen, int settingNameLen) -{ - char szFullName[512]; - const char *szKey; - if (szModuleName != NULL) { - mir_strcpy(szFullName, szModuleName); - szFullName[moduleNameLen] = '/'; - mir_strcpy(szFullName + moduleNameLen + 1, szSettingName); - szKey = szFullName; - } - else szKey = szSettingName; - - if (m_lastSetting && !mir_strcmp(szKey, m_lastSetting)) - return m_lastSetting; - - int index = m_lSettings.getIndex((char*)szKey); - if (index != -1) - m_lastSetting = m_lSettings[index]; - else - m_lastSetting = InsertCachedSetting(szKey, settingNameLen + moduleNameLen + 3); - - return m_lastSetting; -} - -void MDatabaseCache::SetCachedVariant(DBVARIANT* s /* new */, DBVARIANT* d /* cached */) -{ - char* szSave = (d->type == DBVT_UTF8 || d->type == DBVT_ASCIIZ) ? d->pszVal : NULL; - - memcpy(d, s, sizeof(DBVARIANT)); - if ((s->type == DBVT_UTF8 || s->type == DBVT_ASCIIZ) && s->pszVal != NULL) { - if (szSave != NULL) - d->pszVal = (char*)HeapReAlloc(m_hCacheHeap, 0, szSave, mir_strlen(s->pszVal) + 1); - else - d->pszVal = (char*)HeapAlloc(m_hCacheHeap, 0, mir_strlen(s->pszVal) + 1); - mir_strcpy(d->pszVal, s->pszVal); - } - else if (szSave != NULL) - HeapFree(m_hCacheHeap, 0, szSave); -} - -void MDatabaseCache::FreeCachedVariant(DBVARIANT* V) -{ - if ((V->type == DBVT_ASCIIZ || V->type == DBVT_UTF8) && V->pszVal != NULL) - HeapFree(m_hCacheHeap, 0, V->pszVal); -} - -STDMETHODIMP_(DBVARIANT*) MDatabaseCache::GetCachedValuePtr(MCONTACT contactID, char *szSetting, int bAllocate) -{ - // a global setting - if (contactID == 0) { - DBCachedGlobalValue Vtemp, *V; - Vtemp.name = szSetting; - int index = m_lGlobalSettings.getIndex(&Vtemp); - if (index != -1) { - V = m_lGlobalSettings[index]; - if (bAllocate == -1) { - FreeCachedVariant(&V->value); - m_lGlobalSettings.remove(index); - HeapFree(m_hCacheHeap, 0, V); - return NULL; - } - } - else { - if (bAllocate != 1) - return NULL; - - V = (DBCachedGlobalValue*)HeapAlloc(m_hCacheHeap, HEAP_ZERO_MEMORY, sizeof(DBCachedGlobalValue)); - V->name = szSetting; - m_lGlobalSettings.insert(V); - } - - return &V->value; - } - - // a contact setting - DBCachedContactValue *V, *V1; - DBCachedContact ccTemp, *cc; - - ccTemp.contactID = contactID; - - int index = m_lContacts.getIndex(&ccTemp); - if (index == -1) - return NULL; - - m_lastVL = cc = m_lContacts[index]; - - for (V = cc->first; V != NULL; V = V->next) - if (V->name == szSetting) - break; - - if (V == NULL) { - if (bAllocate != 1) - return NULL; - - V = (DBCachedContactValue *)HeapAlloc(m_hCacheHeap, HEAP_ZERO_MEMORY, sizeof(DBCachedContactValue)); - if (cc->last) - cc->last->next = V; - else - cc->first = V; - cc->last = V; - V->name = szSetting; - } - else if (bAllocate == -1) { - m_lastVL = NULL; - FreeCachedVariant(&V->value); - if (cc->first == V) { - cc->first = V->next; - if (cc->last == V) - cc->last = V->next; // NULL - } - else - for (V1 = cc->first; V1 != NULL; V1 = V1->next) - if (V1->next == V) { - V1->next = V->next; - if (cc->last == V) - cc->last = V1; - break; - } - HeapFree(m_hCacheHeap, 0, V); - return NULL; - } - - return &V->value; -} diff --git a/src/modules/database/profilemanager.cpp b/src/modules/database/profilemanager.cpp deleted file mode 100644 index 0dc3c75304..0000000000 --- a/src/modules/database/profilemanager.cpp +++ /dev/null @@ -1,649 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -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 "..\..\core\commonheaders.h" -#include "..\plugins\plugins.h" -#include "..\langpack\langpack.h" -#include "profilemanager.h" -#include - -void EnsureCheckerLoaded(bool); - -#define WM_INPUTCHANGED (WM_USER + 0x3000) -#define WM_FOCUSTEXTBOX (WM_USER + 0x3001) - -typedef BOOL (__cdecl *ENUMPROFILECALLBACK) (TCHAR *tszFullPath, TCHAR *profile, LPARAM lParam); - -void SetServiceModePlugin(pluginEntry *p); - -///////////////////////////////////////////////////////////////////////////////////////// -// Profile creator - -static int findProfiles(TCHAR *szProfileDir, ENUMPROFILECALLBACK callback, LPARAM lParam) -{ - // find in Miranda NG profile subfolders - TCHAR searchspec[MAX_PATH]; - mir_sntprintf(searchspec, SIZEOF(searchspec), _T("%s\\*.*"), szProfileDir); - - WIN32_FIND_DATA ffd; - HANDLE hFind = FindFirstFile(searchspec, &ffd); - if (hFind == INVALID_HANDLE_VALUE) - return 0; - - do { - // find all subfolders except "." and ".." - if ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && mir_tstrcmp(ffd.cFileName, _T(".")) && mir_tstrcmp(ffd.cFileName, _T(".."))) { - TCHAR buf[MAX_PATH], profile[MAX_PATH]; - mir_sntprintf(buf, _T("%s\\%s\\%s.dat"), szProfileDir, ffd.cFileName, ffd.cFileName); - if (_taccess(buf, 0) == 0) { - mir_sntprintf(profile, SIZEOF(profile), _T("%s.dat"), ffd.cFileName); - if (!callback(buf, profile, lParam)) - break; - } - } - } - while (FindNextFile(hFind, &ffd)); - - FindClose(hFind); - return 1; -} - -static LRESULT CALLBACK ProfileNameValidate(HWND edit, UINT msg, WPARAM wParam, LPARAM lParam) -{ - if (msg == WM_CHAR) { - if (_tcschr(_T(".?/\\#' "), (TCHAR)wParam) != 0) - return 0; - PostMessage(GetParent(edit), WM_INPUTCHANGED, 0, 0); - } - return mir_callNextSubclass(edit, ProfileNameValidate, msg, wParam, lParam); -} - -class CCreateProfileDlg : public CDlgBase -{ - CCtrlButton &m_btnOk; - PROFILEMANAGERDATA *m_pd; - - int CreateProfile(TCHAR *profile, DATABASELINK *link) - { - TCHAR buf[256]; - int err = 0; - // check if the file already exists - TCHAR *file = _tcsrchr(profile, '\\'); - if (file) file++; - if (_taccess(profile, 0) == 0) { - // file already exists! - mir_sntprintf(buf, - TranslateT("The profile '%s' already exists. Do you want to move it to the Recycle Bin?\n\nWARNING: The profile will be deleted if Recycle Bin is disabled.\nWARNING: A profile may contain confidential information and should be properly deleted."), - file); - if (MessageBox(m_hwnd, buf, TranslateT("The profile already exists"), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2) != IDYES) - return 0; - - // move the file - SHFILEOPSTRUCT sf = { 0 }; - sf.wFunc = FO_DELETE; - sf.pFrom = buf; - sf.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_ALLOWUNDO; - mir_sntprintf(buf, _T("%s\0"), profile); - if (SHFileOperation(&sf) != 0) { - mir_sntprintf(buf, TranslateT("Couldn't move '%s' to the Recycle Bin. Please select another profile name."), file); - MessageBox(m_hwnd, buf, TranslateT("Problem moving profile"), MB_ICONINFORMATION | MB_OK); - return 0; - } - // now the file should be gone! - } - // ask the database to create the profile - CreatePathToFileT(profile); - if ((err = link->makeDatabase(profile)) != ERROR_SUCCESS) { - mir_sntprintf(buf, TranslateT("Unable to create the profile '%s', the error was %x"), file, err); - MessageBox(m_hwnd, buf, TranslateT("Problem creating profile"), MB_ICONERROR | MB_OK); - return 0; - } - - // the profile has been created! - g_bDbCreated = true; - return 1; - } - - CCtrlCombo m_driverList; - CCtrlEdit m_profileName; - CCtrlBase m_warning; - -public: - CCreateProfileDlg(CCtrlButton &_btn, PROFILEMANAGERDATA *_pd) : - CDlgBase(hInst, IDD_PROFILE_NEW), - m_btnOk(_btn), - m_pd(_pd), - m_driverList(this, IDC_PROFILEDRIVERS), - m_profileName(this, IDC_PROFILENAME), - m_warning(this, IDC_NODBDRIVERS) - {} - - virtual void OnInitDialog() - { - // what, no plugins?! - if (arDbPlugins.getCount() == 0) { - m_driverList.Enable(false); - m_profileName.Enable(false); - ShowWindow(m_warning.GetHwnd(), TRUE); - } - else { - for (int i = 0; i < arDbPlugins.getCount(); i++) { - DATABASELINK *p = arDbPlugins[i]; - m_driverList.AddString(TranslateTS(p->szFullName), (LPARAM)p); - } - } - - // default item - m_driverList.SetCurSel(0); - - // subclass the profile name box - mir_subclassWindow(m_profileName.GetHwnd(), ProfileNameValidate); - - // decide if there is a default profile name given in the INI and if it should be used - if (m_pd->noProfiles || (shouldAutoCreate(m_pd->ptszProfile) && _taccess(m_pd->ptszProfile, 0))) { - TCHAR *profile = _tcsrchr(m_pd->ptszProfile, '\\'); - if (profile) ++profile; - else profile = m_pd->ptszProfile; - - TCHAR *p = _tcsrchr(profile, '.'); - TCHAR c = 0; - if (p) { c = *p; *p = 0; } - - m_profileName.SetText(profile); - if (c) *p = c; - } - - // focus on the textbox - PostMessage(m_hwnd, WM_FOCUSTEXTBOX, 0, 0); - } - - virtual INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) - { - switch (msg) { - case WM_FOCUSTEXTBOX: - SetFocus(m_profileName.GetHwnd()); - break; - - case WM_INPUTCHANGED: // when input in the edit box changes - NotifyChange(); - m_btnOk.Enable(GetWindowTextLength(m_profileName.GetHwnd()) > 0); - break; - - case WM_SHOWWINDOW: - if (wParam) { - m_btnOk.SetText(TranslateT("&Create")); - SendMessage(m_hwnd, WM_INPUTCHANGED, 0, 0); - } - break; - } - return CDlgBase::DlgProc(msg, wParam, lParam); - } - - virtual void OnApply() - { - LRESULT curSel = m_driverList.GetCurSel(); - if (curSel == -1) - return; // should never happen - - ptrT szName(m_profileName.GetText()); - if (szName == 0) - return; - - // profile placed in "profile_name" subfolder - mir_sntprintf(m_pd->ptszProfile, MAX_PATH, _T("%s\\%s\\%s.dat"), m_pd->ptszProfileDir, szName, szName); - m_pd->newProfile = 1; - m_pd->dblink = (DATABASELINK *)m_driverList.GetItemData(curSel); - - if (CreateProfile(m_pd->ptszProfile, m_pd->dblink) == 0) - SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE); - else - m_pd->bRun = true; - } -}; - -///////////////////////////////////////////////////////////////////////////////////////// -// Profile selector - -class CChooseProfileDlg : public CDlgBase -{ - CCtrlButton &m_btnOk; - PROFILEMANAGERDATA *m_pd; - HANDLE m_hFileNotify; - - struct ProfileEnumData - { - CCtrlListView &list; - TCHAR* szProfile; - }; - - static BOOL EnumProfilesForList(TCHAR *tszFullPath, TCHAR *profile, LPARAM lParam) - { - ProfileEnumData *ped = (ProfileEnumData*)lParam; - CCtrlListView &list = ped->list; - - TCHAR sizeBuf[64]; - bool bFileLocked = true; - - TCHAR *p = _tcsrchr(profile, '.'); - mir_tstrcpy(sizeBuf, _T("0 KB")); - if (p != NULL) *p = 0; - - LVITEM item = { 0 }; - item.mask = LVIF_TEXT | LVIF_IMAGE; - item.pszText = profile; - item.iItem = 0; - - struct _stat statbuf; - if (_tstat(tszFullPath, &statbuf) == 0) { - if (statbuf.st_size > 1000000) { - mir_sntprintf(sizeBuf, SIZEOF(sizeBuf), _T("%.3lf"), (double)statbuf.st_size / 1048576.0); - mir_tstrcpy(sizeBuf + 5, _T(" MB")); - } - else { - mir_sntprintf(sizeBuf, SIZEOF(sizeBuf), _T("%.3lf"), (double)statbuf.st_size / 1024.0); - mir_tstrcpy(sizeBuf + 5, _T(" KB")); - } - bFileLocked = !fileExist(tszFullPath); - } - - DATABASELINK *dblink; - switch (touchDatabase(tszFullPath, &dblink)) { - case ERROR_SUCCESS: - item.iImage = bFileLocked; - break; - - case EGROKPRF_OBSOLETE: - item.iImage = 2; - break; - - default: - item.iImage = 3; - } - - int iItem = list.InsertItem(&item); - if (mir_tstrcmpi(ped->szProfile, tszFullPath) == 0) - list.SetItemState(iItem, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); - - list.SetItemText(iItem, 2, sizeBuf); - - if (dblink != NULL) { - if (bFileLocked) // file locked - list.SetItemText(iItem, 1, TranslateT("")); - else - list.SetItemText(iItem, 1, TranslateTS(dblink->szFullName)); - } - else list.SetItemText(iItem, 1, TranslateT("")); - - return TRUE; - } - - void CheckProfile(int iItem) - { - if (iItem < 0) - return; - - TCHAR profile[MAX_PATH], fullName[MAX_PATH]; - LVITEM item = { 0 }; - item.mask = LVIF_TEXT | LVIF_IMAGE; - item.iItem = iItem; - item.pszText = profile; - item.cchTextMax = SIZEOF(profile); - if (!m_profileList.GetItem(&item)) - return; - - mir_sntprintf(fullName, SIZEOF(fullName), _T("%s\\%s\\%s.dat"), m_pd->ptszProfileDir, profile, profile); - CallService(MS_DB_CHECKPROFILE, (WPARAM)fullName, item.iImage == 2); - } - - void DeleteProfile(int iItem) - { - if (iItem < 0) - return; - - TCHAR profile[MAX_PATH], profilef[MAX_PATH * 2]; - - LVITEM item = { 0 }; - item.mask = LVIF_TEXT; - item.iItem = iItem; - item.pszText = profile; - item.cchTextMax = SIZEOF(profile); - if (!m_profileList.GetItem(&item)) - return; - - mir_sntprintf(profilef, SIZEOF(profilef), TranslateT("Are you sure you want to remove profile \"%s\"?"), profile); - if (IDYES != MessageBox(NULL, profilef, _T("Miranda NG"), MB_YESNO | MB_TASKMODAL | MB_ICONWARNING)) - return; - - mir_sntprintf(profilef, SIZEOF(profilef), _T("%s\\%s%c"), m_pd->ptszProfileDir, profile, 0); - - SHFILEOPSTRUCT sf = { 0 }; - sf.wFunc = FO_DELETE; - sf.pFrom = profilef; - sf.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_ALLOWUNDO; - SHFileOperation(&sf); - m_profileList.DeleteItem(item.iItem); - } - - void CheckRun() - { - m_btnOk.Enable(m_profileList.GetSelectedCount() == 1); - - TCHAR profile[MAX_PATH]; - LVITEM item = { 0 }; - item.mask = LVIF_TEXT | LVIF_IMAGE; - item.iItem = m_profileList.GetNextItem(-1, LVNI_SELECTED | LVNI_ALL); - item.pszText = profile; - item.cchTextMax = SIZEOF(profile); - if (!m_profileList.GetItem(&item)) - return; - - switch(item.iImage) { - case 3: - m_btnOk.Enable(false); - return; - - case 2: - m_btnOk.SetText(TranslateT("&Convert")); - m_pd->bRun = false; - break; - - default: - m_btnOk.SetText(TranslateT("&Run")); - m_pd->bRun = true; - } - - // profile is placed in "profile_name" subfolder - - TCHAR tmpPath[MAX_PATH]; - mir_sntprintf(tmpPath, SIZEOF(tmpPath), _T("%s\\%s.dat"), m_pd->ptszProfileDir, profile); - if (_taccess(tmpPath, 2)) - mir_sntprintf(m_pd->ptszProfile, MAX_PATH, _T("%s\\%s\\%s.dat"), m_pd->ptszProfileDir, profile, profile); - else - _tcsncpy_s(m_pd->ptszProfile, MAX_PATH, tmpPath, _TRUNCATE); - } - - void ExecuteMenu(LPARAM lParam) - { - LVHITTESTINFO lvht = { 0 }; - lvht.pt.x = GET_X_LPARAM(lParam); - lvht.pt.y = GET_Y_LPARAM(lParam); - ScreenToClient(m_profileList.GetHwnd(), &lvht.pt); - - if (m_profileList.HitTest(&lvht) == -1) - return; - - if (lvht.iItem == -1) - return; - - LVITEM tvi = { 0 }; - tvi.mask = LVIF_IMAGE; - tvi.iItem = lvht.iItem; - if (!m_profileList.GetItem(&tvi)) - return; - - bool bConvert = (tvi.iImage == 2); - - lvht.pt.x = GET_X_LPARAM(lParam); - lvht.pt.y = GET_Y_LPARAM(lParam); - - HMENU hMenu = CreatePopupMenu(); - if (tvi.iImage < 2) { - AppendMenu(hMenu, MF_STRING, 1, TranslateT("Run")); - AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); - } - if (tvi.iImage != 3 && ServiceExists(MS_DB_CHECKPROFILE)) { - if (bConvert) - AppendMenu(hMenu, MF_STRING, 2, TranslateT("Convert database")); - else - AppendMenu(hMenu, MF_STRING, 2, TranslateT("Check database")); - AppendMenu(hMenu, MF_SEPARATOR, 0, NULL); - } - AppendMenu(hMenu, MF_STRING, 3, TranslateT("Delete")); - int index = TrackPopupMenu(hMenu, TPM_RETURNCMD, lvht.pt.x, lvht.pt.y, 0, m_hwnd, NULL); - switch (index) { - case 1: - SendMessage(GetParent(m_hwndParent), WM_COMMAND, IDOK, 0); - break; - - case 2: - CheckProfile(lvht.iItem); - break; - - case 3: - DeleteProfile(lvht.iItem); - break; - } - DestroyMenu(hMenu); - } - - CCtrlListView m_profileList; - -public: - CChooseProfileDlg(CCtrlButton &_btn, PROFILEMANAGERDATA *_pd) : - CDlgBase(hInst, IDD_PROFILE_SELECTION), - m_btnOk(_btn), - m_pd(_pd), - m_profileList(this, IDC_PROFILELIST) - { - m_profileList.OnItemChanged = Callback(this, &CChooseProfileDlg::list_OnItemChanged); - m_profileList.OnKeyDown = Callback(this, &CChooseProfileDlg::list_OnKeyDown); - m_profileList.OnGetInfoTip = Callback(this, &CChooseProfileDlg::list_OnGetTip); - m_profileList.OnDoubleClick = Callback(this, &CChooseProfileDlg::list_OnDblClick); - } - - virtual void OnInitDialog() - { - // set columns - LVCOLUMN col; - col.mask = LVCF_TEXT | LVCF_WIDTH; - col.pszText = TranslateT("Profile"); - col.cx = 100; - m_profileList.InsertColumn(0, &col); - - col.pszText = TranslateT("Driver"); - col.cx = 150 - GetSystemMetrics(SM_CXVSCROLL); - m_profileList.InsertColumn(1, &col); - - col.pszText = TranslateT("Size"); - col.cx = 60; - m_profileList.InsertColumn(2, &col); - - // icons - HIMAGELIST hImgList = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 2, 1); - ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_USERDETAILS)); - ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_DELETE)); - ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_MWARNING)); - ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_MFATAL)); - - // LV will destroy the image list - m_profileList.SetImageList(hImgList, LVSIL_SMALL); - m_profileList.SetExtendedListViewStyle(m_profileList.GetExtendedListViewStyle() | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_LABELTIP | LVS_EX_FULLROWSELECT); - - // find all the profiles - ProfileEnumData ped = { m_profileList, m_pd->ptszProfile }; - findProfiles(m_pd->ptszProfileDir, EnumProfilesForList, (LPARAM)&ped); - PostMessage(m_hwnd, WM_FOCUSTEXTBOX, 0, 0); - - m_hFileNotify = FindFirstChangeNotification(m_pd->ptszProfileDir, TRUE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE); - if (m_hFileNotify != INVALID_HANDLE_VALUE) - SetTimer(m_hwnd, 0, 1200, NULL); - } - - virtual void OnDestroy() - { - KillTimer(m_hwnd, 0); - FindCloseChangeNotification(m_hFileNotify); - } - - void list_OnItemChanged(CCtrlListView::TEventInfo*) - { - CheckRun(); - } - - void list_OnKeyDown(CCtrlListView::TEventInfo *evt) - { - if (evt->nmlvkey->wVKey == VK_DELETE) - DeleteProfile(m_profileList.GetNextItem(-1, LVNI_SELECTED | LVNI_ALL)); - } - - void list_OnGetTip(CCtrlListView::TEventInfo *evt) - { - if (auto pTip = evt->nmlvit) { - TCHAR profilename[MAX_PATH], tszFullPath[MAX_PATH]; - struct _stat statbuf; - m_profileList.GetItemText(pTip->iItem, 0, profilename, SIZEOF(profilename)); - mir_sntprintf(tszFullPath, SIZEOF(tszFullPath), _T("%s\\%s\\%s.dat"), m_pd->ptszProfileDir, profilename, profilename); - _tstat(tszFullPath, &statbuf); - mir_sntprintf(pTip->pszText, pTip->cchTextMax, _T("%s\n%s: %s\n%s: %s"), tszFullPath, TranslateT("Created"), rtrimt(NEWTSTR_ALLOCA(_tctime(&statbuf.st_ctime))), TranslateT("Modified"), rtrimt(NEWTSTR_ALLOCA(_tctime(&statbuf.st_mtime)))); - } - } - - void list_OnDblClick(CCtrlListView::TEventInfo *evt) - { - CheckRun(); - EndDialog(GetParent(m_hwndParent), 1); - } - - virtual INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) - { - switch (msg) { - case WM_TIMER: - if (WaitForSingleObject(m_hFileNotify, 0) == WAIT_OBJECT_0) { - m_profileList.DeleteAllItems(); - ProfileEnumData ped = { m_profileList, m_pd->ptszProfile }; - findProfiles(m_pd->ptszProfileDir, EnumProfilesForList, (LPARAM)&ped); - FindNextChangeNotification(m_hFileNotify); - } - break; - - case WM_FOCUSTEXTBOX: - SetFocus(m_profileList.GetHwnd()); - if (m_pd->ptszProfile[0] == 0 || m_profileList.GetSelectedCount() == 0) - m_profileList.SetItemState(0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED); - break; - - case WM_SHOWWINDOW: - if (wParam) - CheckRun(); - break; - - case WM_CONTEXTMENU: - ExecuteMenu(lParam); - break; - } - - return CDlgBase::DlgProc(msg, wParam, lParam); - } -}; - -///////////////////////////////////////////////////////////////////////////////////////// -// Tab manager + its envelope - -class CProfileManager : public CDlgBase -{ - PROFILEMANAGERDATA *m_pd; - - CCtrlPages m_tab; - CCtrlButton m_btnOk; - CCtrlCombo m_servicePlugs; - CCtrlBase m_warning; - -public: - CProfileManager(PROFILEMANAGERDATA *_pd) : - CDlgBase(hInst, IDD_PROFILEMANAGER), - m_btnOk(this, IDOK), - m_pd(_pd), - m_tab(this, IDC_TABS), - m_servicePlugs(this, IDC_SM_COMBO), - m_warning(this, IDC_SM_LABEL) - { - m_btnOk.OnClick = Callback(this, &CProfileManager::onOk); - - m_tab.AddPage(LPGENT("My profiles"), NULL, new CChooseProfileDlg(m_btnOk, m_pd)); - m_tab.AddPage(LPGENT("New profile"), NULL, new CCreateProfileDlg(m_btnOk, m_pd)); - } - - virtual void OnInitDialog() - { - SendMessage(m_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_DETAILSLOGO), IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0)); - SendMessage(m_hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadImage(hInst, MAKEINTRESOURCE(IDI_DETAILSLOGO), IMAGE_ICON, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0)); - - if (m_pd->noProfiles || shouldAutoCreate(m_pd->ptszProfile)) - m_tab.ActivatePage(1); - - // service mode combobox - if (servicePlugins.getCount() == 0) { - ShowWindow(m_warning.GetHwnd(), FALSE); - ShowWindow(m_servicePlugs.GetHwnd(), FALSE); - } - else { - m_servicePlugs.AddStringA("", -1); - m_servicePlugs.SetCurSel(0); - - for (int i = 0; i < servicePlugins.getCount(); i++) { - pluginEntry *p = servicePlugins[i]; - m_servicePlugs.AddString(TranslateTS(p->pluginname), i); - } - } - } - - virtual INT_PTR DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) - { - switch (msg) { - case WM_CTLCOLORSTATIC: - switch (GetDlgCtrlID((HWND)lParam)) { - case IDC_WHITERECT: - SetBkColor((HDC)wParam, GetSysColor(COLOR_WINDOW)); - return (INT_PTR)GetSysColorBrush(COLOR_WINDOW); - } - break; - } - return CDlgBase::DlgProc(msg, wParam, lParam); - } - - virtual void OnDestroy() - { - LRESULT curSel = m_servicePlugs.GetCurSel(); - if (curSel != -1) { - int idx = m_servicePlugs.GetItemData(curSel); - if (idx != -1) - SetServiceModePlugin(servicePlugins[idx]); - } - - DestroyIcon((HICON)SendMessage(m_hwnd, WM_SETICON, ICON_SMALL, 0)); - DestroyIcon((HICON)SendMessage(m_hwnd, WM_SETICON, ICON_BIG, 0)); - } - - void onOk(CCtrlButton*) - { - EndDialog(m_hwnd, 1); - } -}; - -int getProfileManager(PROFILEMANAGERDATA *pd) -{ - EnsureCheckerLoaded(true); - - return CProfileManager(pd).DoModal(); -} diff --git a/src/modules/database/profilemanager.h b/src/modules/database/profilemanager.h deleted file mode 100644 index 21650375a2..0000000000 --- a/src/modules/database/profilemanager.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (ñ) 2012-15 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -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. -*/ - -struct PROFILEMANAGERDATA -{ - TCHAR *ptszProfile; // in/out - TCHAR *ptszProfileDir; // in/out - BOOL noProfiles; // in - - BOOL bRun; // out - BOOL newProfile; // out - DATABASELINK *dblink; // out -}; - -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); -bool fileExist(const TCHAR *fname); -bool shouldAutoCreate(TCHAR *szProfile); - -extern TCHAR g_profileDir[MAX_PATH], g_profileName[MAX_PATH], g_shortProfileName[MAX_PATH]; -extern bool g_bDbCreated; -- cgit v1.2.3