From 65c4f834ce1895cf4f3127f584458cc0af15c255 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sat, 19 Jul 2014 18:52:00 +0000 Subject: more fixes for Profile Manager git-svn-id: http://svn.miranda-ng.org/main/trunk@9867 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/modules/database/database.cpp | 10 +++- src/modules/database/profilemanager.cpp | 87 ++++++++++++++++++++++----------- src/modules/database/profilemanager.h | 12 +++-- 3 files changed, 75 insertions(+), 34 deletions(-) diff --git a/src/modules/database/database.cpp b/src/modules/database/database.cpp index aa0c86045c..74a110ee2f 100644 --- a/src/modules/database/database.cpp +++ b/src/modules/database/database.cpp @@ -306,7 +306,15 @@ static int getProfile(TCHAR *szProfile, size_t cch) LBL_Show: pd.szProfile = szProfile; pd.szProfileDir = g_profileDir; - return getProfileManager(&pd); + if (!getProfileManager(&pd)) + return 0; + + if (!pd.bRun) { + CallService(MS_DB_CHECKPROFILE, WPARAM(szProfile), 0); + return 0; + } + + return 1; } if (getProfileAutoRun(szProfile)) diff --git a/src/modules/database/profilemanager.cpp b/src/modules/database/profilemanager.cpp index 6e0751b3d6..d54e1340f8 100644 --- a/src/modules/database/profilemanager.cpp +++ b/src/modules/database/profilemanager.cpp @@ -302,6 +302,8 @@ BOOL EnumProfilesForList(TCHAR *tszFullPath, TCHAR *profile, LPARAM lParam) break; } } + if (dblink == NULL) + item.iImage = 3; int iItem = SendMessage(hwndList, LVM_INSERTITEM, 0, (LPARAM)&item); if (lstrcmpi(ped->szProfile, tszFullPath) == 0) @@ -373,6 +375,52 @@ void DeleteProfile(HWND hwndList, int iItem, DlgProfData *dat) ListView_DeleteItem(hwndList, item.iItem); } +static void CheckRun(HWND hwndDlg, int uMsg) +{ + DlgProfData *dat = (DlgProfData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + if (dat == NULL) + return; + + HWND hwndList = GetDlgItem(hwndDlg, IDC_PROFILELIST); + EnableWindow(dat->hwndOK, ListView_GetSelectedCount(hwndList) == 1); + + TCHAR profile[MAX_PATH]; + LVITEM item = { 0 }; + item.mask = LVIF_TEXT | LVIF_IMAGE; + item.iItem = ListView_GetNextItem(hwndList, -1, LVNI_SELECTED | LVNI_ALL); + item.pszText = profile; + item.cchTextMax = SIZEOF(profile); + if (!ListView_GetItem(hwndList, &item)) + return; + + switch(item.iImage) { + case 3: + EnableWindow(dat->hwndOK, false); + return; + + case 2: + SetWindowText(dat->hwndOK, TranslateT("&Convert")); + dat->pd->bRun = false; + break; + + default: + SetWindowText(dat->hwndOK, TranslateT("&Run")); + dat->pd->bRun = true; + } + + // profile is placed in "profile_name" subfolder + + TCHAR tmpPath[MAX_PATH]; + mir_sntprintf(tmpPath, SIZEOF(tmpPath), _T("%s\\%s.dat"), dat->pd->szProfileDir, profile); + if (_taccess(tmpPath, 2)) + mir_sntprintf(dat->pd->szProfile, MAX_PATH, _T("%s\\%s\\%s.dat"), dat->pd->szProfileDir, profile, profile); + else + _tcsncpy_s(dat->pd->szProfile, MAX_PATH, tmpPath, _TRUNCATE); + + if (uMsg == NM_DBLCLK) + EndDialog(GetParent(hwndDlg), 1); +} + static INT_PTR CALLBACK DlgProfileSelect(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { DlgProfData *dat = (DlgProfData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); @@ -406,6 +454,7 @@ static INT_PTR CALLBACK DlgProfileSelect(HWND hwndDlg, UINT msg, WPARAM wParam, 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_MERROR)); // LV will destroy the image list SetWindowLongPtr(hwndList, GWL_STYLE, GetWindowLongPtr(hwndList, GWL_STYLE) | LVS_SORTASCENDING); @@ -446,9 +495,8 @@ static INT_PTR CALLBACK DlgProfileSelect(HWND hwndDlg, UINT msg, WPARAM wParam, case WM_SHOWWINDOW: if (wParam) { - SetWindowText(dat->hwndOK, TranslateT("&Run")); + CheckRun(hwndDlg, 0); EnableWindow(dat->hwndSM, TRUE); - EnableWindow(dat->hwndOK, ListView_GetSelectedCount(hwndList) == 1); } break; @@ -508,36 +556,19 @@ static INT_PTR CALLBACK DlgProfileSelect(HWND hwndDlg, UINT msg, WPARAM wParam, case WM_NOTIFY: LPNMHDR hdr = (LPNMHDR)lParam; - if (hdr && hdr->code == PSN_INFOCHANGED) + if (hdr == NULL) + break; + + if (hdr->idFrom == 0) { + CheckRun(hwndDlg, 0); break; + } - if (hdr && hdr->idFrom == IDC_PROFILELIST) { + if (hdr->idFrom == IDC_PROFILELIST) { switch (hdr->code) { case LVN_ITEMCHANGED: - EnableWindow(dat->hwndOK, ListView_GetSelectedCount(hwndList) == 1); - case NM_DBLCLK: - if (dat != NULL) { - TCHAR profile[MAX_PATH]; - LVITEM item = { 0 }; - item.mask = LVIF_TEXT; - item.iItem = ListView_GetNextItem(hwndList, -1, LVNI_SELECTED | LVNI_ALL); - item.pszText = profile; - item.cchTextMax = SIZEOF(profile); - - if (ListView_GetItem(hwndList, &item)) { - // profile is placed in "profile_name" subfolder - TCHAR tmpPath[MAX_PATH]; - mir_sntprintf(tmpPath, SIZEOF(tmpPath), _T("%s\\%s.dat"), dat->pd->szProfileDir, profile); - HANDLE hFile = CreateFile(tmpPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); - if (hFile == INVALID_HANDLE_VALUE) - mir_sntprintf(dat->pd->szProfile, MAX_PATH, _T("%s\\%s\\%s.dat"), dat->pd->szProfileDir, profile, profile); - else - _tcscpy(dat->pd->szProfile, tmpPath); - CloseHandle(hFile); - if (hdr->code == NM_DBLCLK) EndDialog(GetParent(hwndDlg), 1); - } - } + CheckRun(hwndDlg, hdr->code); return TRUE; case LVN_KEYDOWN: @@ -817,7 +848,7 @@ static int AddProfileManagerPage(struct DetailsPageInit *opi, OPTIONSDIALOGPAGE return 0; } -int getProfileManager(PROFILEMANAGERDATA * pd) +int getProfileManager(PROFILEMANAGERDATA *pd) { DetailsPageInit opi = { 0 }; diff --git a/src/modules/database/profilemanager.h b/src/modules/database/profilemanager.h index f23aff2271..dd16750c47 100644 --- a/src/modules/database/profilemanager.h +++ b/src/modules/database/profilemanager.h @@ -24,11 +24,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. struct PROFILEMANAGERDATA { - TCHAR *szProfile; // in/out - TCHAR *szProfileDir; // in/out - BOOL noProfiles; // in - BOOL newProfile; // out - DATABASELINK *dblink; // out + TCHAR *szProfile; // in/out + TCHAR *szProfileDir; // in/out + BOOL noProfiles; // in + + BOOL bRun; // out + BOOL newProfile; // out + DATABASELINK *dblink; // out }; char* makeFileName(const TCHAR *tszOriginalName); -- cgit v1.2.3