summaryrefslogtreecommitdiff
path: root/src/modules/database
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/database')
-rw-r--r--src/modules/database/database.cpp84
-rw-r--r--src/modules/database/dbini.cpp20
-rw-r--r--src/modules/database/profilemanager.cpp60
-rw-r--r--src/modules/database/profilemanager.h2
4 files changed, 73 insertions, 93 deletions
diff --git a/src/modules/database/database.cpp b/src/modules/database/database.cpp
index 168a6d5f27..adea9e0caa 100644
--- a/src/modules/database/database.cpp
+++ b/src/modules/database/database.cpp
@@ -26,7 +26,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// contains the location of mirandaboot.ini
extern TCHAR mirandabootini[MAX_PATH];
-bool dbCreated;
+bool g_bDbCreated;
TCHAR g_profileDir[MAX_PATH], g_profileName[MAX_PATH];
TCHAR* g_defaultProfile;
void EnsureCheckerLoaded(bool);
@@ -55,15 +55,11 @@ static void fillProfileName(const TCHAR* ptszFileName)
bool IsInsideRootDir(TCHAR* profiledir, bool exact)
{
- int res;
- TCHAR* pfd = Utils_ReplaceVarsT(_T("%miranda_path%"));
+ VARST pfd( _T("%miranda_path%"));
if (exact)
- res = _tcsicmp(profiledir, pfd);
- else
- res = _tcsnicmp(profiledir, pfd, _tcslen(pfd));
-
- mir_free(pfd);
- return res == 0;
+ return _tcsicmp(profiledir, pfd) == 0;
+
+ return _tcsnicmp(profiledir, pfd, _tcslen(pfd)) == 0;
}
// returns 1 if the profile path was returned, without trailing slash
@@ -75,9 +71,7 @@ int getProfilePath(TCHAR *buf, size_t cch)
if (profiledir[0] == 0)
_tcscpy(profiledir, _T("%miranda_path%\\Profiles"));
- TCHAR* exprofiledir = Utils_ReplaceVarsT(profiledir);
- size_t len = PathToAbsoluteT(exprofiledir, buf, NULL);
- mir_free(exprofiledir);
+ size_t len = PathToAbsoluteT( VARST(profiledir), buf, NULL);
if (buf[len-1] == '/' || buf[len-1] == '\\')
buf[len-1] = 0;
@@ -123,12 +117,11 @@ static void getDefaultProfile(TCHAR *szProfile, size_t cch, TCHAR *profiledir)
if (defaultProfile[0] == 0)
return;
- TCHAR* res = Utils_ReplaceVarsT(defaultProfile);
- if (res) {
- mir_sntprintf(szProfile, cch, _T("%s\\%s\\%s%s"), profiledir, res, res, isValidProfileName(res) ? _T("") : _T(".dat"));
- mir_free(res);
- }
- else szProfile[0] = 0;
+ VARST res(defaultProfile);
+ if (res)
+ mir_sntprintf(szProfile, cch, _T("%s\\%s\\%s%s"), 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
@@ -183,12 +176,10 @@ void getProfileDefault(TCHAR *szProfile, size_t cch, TCHAR *profiledir)
static void moveProfileDirProfiles(TCHAR *profiledir, BOOL isRootDir = TRUE)
{
TCHAR pfd[MAX_PATH];
- if (isRootDir) {
- TCHAR *path = Utils_ReplaceVarsT(_T("%miranda_path%\\*.dat"));
- mir_sntprintf(pfd, SIZEOF(pfd), _T("%s"), path);
- mir_free(path);
- }
- else mir_sntprintf(pfd, SIZEOF(pfd), _T("%s\\*.dat"), profiledir);
+ if (isRootDir)
+ _tcsncpy(pfd, VARST( _T("%miranda_path%\\*.dat")), SIZEOF(pfd));
+ else
+ mir_sntprintf(pfd, SIZEOF(pfd), _T("%s\\*.dat"), profiledir);
WIN32_FIND_DATA ffd;
HANDLE hFind = FindFirstFile(pfd, &ffd);
@@ -288,7 +279,6 @@ static int getProfileAutoRun(TCHAR *szProfile)
// returns 1 if a profile was selected
static int getProfile(TCHAR *szProfile, size_t cch)
{
- PROFILEMANAGERDATA pd = {0};
getProfilePath(g_profileDir, SIZEOF(g_profileDir));
if (IsInsideRootDir(g_profileDir, true))
if (WritePrivateProfileString(_T("Database"), _T("ProfileDir"), _T(""), mirandabootini))
@@ -304,6 +294,7 @@ static int getProfile(TCHAR *szProfile, size_t cch)
return 0;
}
+ PROFILEMANAGERDATA pd = {0};
if ( CmdLine_GetOption( _T("ForceShowPM"))) {
LBL_Show:
pd.szProfile = szProfile;
@@ -341,47 +332,6 @@ char* makeFileName(const TCHAR* tszOriginalName)
return szResult;
}
-// called by the UI, return 1 on success, use link to create profile, set error if any
-int makeDatabase(TCHAR *profile, DATABASELINK * link, HWND hwndDlg)
-{
- 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, SIZEOF(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(hwndDlg, 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, SIZEOF(buf), _T("%s\0"), profile);
- if (SHFileOperation(&sf) != 0) {
- mir_sntprintf(buf, SIZEOF(buf), TranslateT("Couldn't move '%s' to the Recycle Bin, Please select another profile name."), file);
- MessageBox(0, 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, SIZEOF(buf), TranslateT("Unable to create the profile '%s', the error was %x"), file, err);
- MessageBox(hwndDlg, buf, TranslateT("Problem creating profile"), MB_ICONERROR|MB_OK);
- return 0;
- }
- dbCreated = true;
- // the profile has been created! woot
- return 1;
-}
-
// enumerate all plugins that had valid DatabasePluginInfo()
int tryOpenDatabase(const TCHAR *tszProfile)
{
@@ -428,7 +378,7 @@ static int tryCreateDatabase(const TCHAR* ptszProfile)
int err = p->makeDatabase(tszProfile);
if (err == ERROR_SUCCESS) {
- dbCreated = true;
+ g_bDbCreated = true;
MIDatabase *pDb = p->Load(tszProfile);
if (pDb != NULL) {
fillProfileName(tszProfile);
diff --git a/src/modules/database/dbini.cpp b/src/modules/database/dbini.cpp
index 8a15b3eb08..0445da160e 100644
--- a/src/modules/database/dbini.cpp
+++ b/src/modules/database/dbini.cpp
@@ -22,12 +22,12 @@ 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;
extern TCHAR mirandabootini[MAX_PATH];
-extern bool dbCreated;
static INT_PTR CALLBACK InstallIniDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
@@ -395,7 +395,6 @@ static void ProcessIniFile(TCHAR* szIniPath, char *szSafeSections, char *szUnsaf
static void DoAutoExec(void)
{
TCHAR szUse[7], szIniPath[MAX_PATH], szFindPath[MAX_PATH];
- TCHAR *str2;
TCHAR buf[2048], szSecurity[11], szOverrideSecurityFilename[MAX_PATH], szOnCreateFilename[MAX_PATH];
char *szSafeSections, *szUnsafeSections;
int secur;
@@ -415,17 +414,12 @@ static void DoAutoExec(void)
GetPrivateProfileString(_T("AutoExec"), _T("OnCreateFilename"), _T(""), szOnCreateFilename, SIZEOF(szOnCreateFilename), mirandabootini);
GetPrivateProfileString(_T("AutoExec"), _T("Glob"), _T("autoexec_*.ini"), szFindPath, SIZEOF(szFindPath), mirandabootini);
- if (dbCreated && szOnCreateFilename[0]) {
- str2 = Utils_ReplaceVarsT(szOnCreateFilename);
- PathToAbsoluteT(str2, szIniPath, NULL);
- mir_free(str2);
-
+ if (g_bDbCreated && szOnCreateFilename[0]) {
+ PathToAbsoluteT( VARST(szOnCreateFilename), szIniPath, NULL);
ProcessIniFile(szIniPath, szSafeSections, szUnsafeSections, 0, 1);
}
- str2 = Utils_ReplaceVarsT(szFindPath);
- PathToAbsoluteT(str2, szFindPath, NULL);
- mir_free(str2);
+ PathToAbsoluteT( VARST(szFindPath), szFindPath, NULL);
WIN32_FIND_DATA fd;
HANDLE hFind = FindFirstFile(szFindPath, &fd);
@@ -435,7 +429,7 @@ static void DoAutoExec(void)
return;
}
- str2 = _tcsrchr(szFindPath, '\\');
+ TCHAR *str2 = _tcsrchr(szFindPath, '\\');
if (str2 == NULL) szFindPath[0] = 0;
else str2[1] = 0;
@@ -478,7 +472,9 @@ static void DoAutoExec(void)
else if ( !lstrcmpi(szOnCompletion, _T("ask")))
DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_INIIMPORTDONE), NULL, IniImportDoneDlgProc, (LPARAM)szIniPath);
}
- } while (FindNextFile(hFind, &fd));
+ }
+ while (FindNextFile(hFind, &fd));
+
FindClose(hFind);
mir_free(szSafeSections);
mir_free(szUnsafeSections);
diff --git a/src/modules/database/profilemanager.cpp b/src/modules/database/profilemanager.cpp
index 19f219a463..d597d50a3f 100644
--- a/src/modules/database/profilemanager.cpp
+++ b/src/modules/database/profilemanager.cpp
@@ -107,6 +107,47 @@ static int findProfiles(TCHAR *szProfileDir, ENUMPROFILECALLBACK callback, LPARA
return 1;
}
+static int CreateProfile(TCHAR *profile, DATABASELINK * link, HWND hwndDlg)
+{
+ 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, SIZEOF(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(hwndDlg, 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, SIZEOF(buf), _T("%s\0"), profile);
+ if (SHFileOperation(&sf) != 0) {
+ mir_sntprintf(buf, SIZEOF(buf), TranslateT("Couldn't move '%s' to the Recycle Bin, Please select another profile name."), file);
+ MessageBox(0, 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, SIZEOF(buf), TranslateT("Unable to create the profile '%s', the error was %x"), file, err);
+ MessageBox(hwndDlg, buf, TranslateT("Problem creating profile"), MB_ICONERROR|MB_OK);
+ return 0;
+ }
+
+ // the profile has been created!
+ g_bDbCreated = true;
+ return 1;
+}
+
static LRESULT CALLBACK ProfileNameValidate(HWND edit, UINT msg, WPARAM wParam, LPARAM lParam)
{
if (msg == WM_CHAR) {
@@ -119,7 +160,7 @@ static LRESULT CALLBACK ProfileNameValidate(HWND edit, UINT msg, WPARAM wParam,
static INT_PTR CALLBACK DlgProfileNew(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
- struct DlgProfData * dat = (struct DlgProfData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
+ struct DlgProfData *dat = (struct DlgProfData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
@@ -189,7 +230,7 @@ static INT_PTR CALLBACK DlgProfileNew(HWND hwndDlg, UINT msg, WPARAM wParam, LPA
case WM_NOTIFY:
{
- NMHDR* hdr = (NMHDR*)lParam;
+ NMHDR *hdr = (NMHDR*)lParam;
if (hdr && hdr->code == PSN_APPLY && dat && IsWindowVisible(hwndDlg)) {
TCHAR szName[MAX_PATH];
LRESULT curSel = SendDlgItemMessage(hwndDlg, IDC_PROFILEDRIVERS, CB_GETCURSEL, 0, 0);
@@ -203,9 +244,8 @@ static INT_PTR CALLBACK DlgProfileNew(HWND hwndDlg, UINT msg, WPARAM wParam, LPA
dat->pd->newProfile = 1;
dat->pd->dblink = (DATABASELINK *)SendDlgItemMessage(hwndDlg, IDC_PROFILEDRIVERS, CB_GETITEMDATA, (WPARAM)curSel, 0);
- if (makeDatabase(dat->pd->szProfile, dat->pd->dblink, hwndDlg) == 0) {
+ if ( CreateProfile(dat->pd->szProfile, dat->pd->dblink, hwndDlg) == 0)
SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
- }
}
}
break;
@@ -751,7 +791,7 @@ static INT_PTR CALLBACK DlgProfileManager(HWND hwndDlg, UINT msg, WPARAM wParam,
return FALSE;
}
-static int AddProfileManagerPage(struct DetailsPageInit * opi, OPTIONSDIALOGPAGE * odp)
+static int AddProfileManagerPage(struct DetailsPageInit *opi, OPTIONSDIALOGPAGE *odp)
{
if (odp->cbSize != sizeof(OPTIONSDIALOGPAGE))
return 1;
@@ -777,12 +817,9 @@ static int AddProfileManagerPage(struct DetailsPageInit * opi, OPTIONSDIALOGPAGE
int getProfileManager(PROFILEMANAGERDATA * pd)
{
- DetailsPageInit opi;
- opi.pageCount = 0;
- opi.odp = NULL;
+ DetailsPageInit opi = { 0 };
- OPTIONSDIALOGPAGE odp = { 0 };
- odp.cbSize = sizeof(odp);
+ OPTIONSDIALOGPAGE odp = { sizeof(odp) };
odp.pszTitle = LPGEN("My Profiles");
odp.pfnDlgProc = DlgProfileSelect;
odp.pszTemplate = MAKEINTRESOURCEA(IDD_PROFILE_SELECTION);
@@ -797,16 +834,13 @@ int getProfileManager(PROFILEMANAGERDATA * pd)
PROPSHEETHEADER psh = { 0 };
psh.dwSize = sizeof(psh);
psh.dwFlags = PSH_PROPSHEETPAGE|PSH_NOAPPLYNOW;
- psh.hwndParent = NULL;
psh.nPages = opi.pageCount;
- psh.pStartPage = 0;
psh.ppsp = (PROPSHEETPAGE*)opi.odp;
DlgProfData prof;
prof.pd = pd;
prof.psh = &psh;
int rc = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_PROFILEMANAGER), NULL, DlgProfileManager, (LPARAM)&prof);
-
if (rc != -1)
for (int i=0; i < opi.pageCount; i++) {
mir_free((char*)opi.odp[i].pszTitle);
diff --git a/src/modules/database/profilemanager.h b/src/modules/database/profilemanager.h
index ae68e20388..f289a77ef8 100644
--- a/src/modules/database/profilemanager.h
+++ b/src/modules/database/profilemanager.h
@@ -31,7 +31,6 @@ struct PROFILEMANAGERDATA
};
char* makeFileName(const TCHAR* tszOriginalName);
-int makeDatabase(TCHAR *profile, DATABASELINK * link, HWND hwndDlg);
int getProfileManager(PROFILEMANAGERDATA * pd);
int getProfilePath(TCHAR *buf, size_t cch);
int isValidProfileName(const TCHAR *name);
@@ -40,3 +39,4 @@ bool shouldAutoCreate(TCHAR *szProfile);
extern TCHAR g_profileDir[MAX_PATH];
extern TCHAR g_profileName[MAX_PATH];
+extern bool g_bDbCreated;