From 18a97b56e7042d69af69f0f5bf4c13436675ebc4 Mon Sep 17 00:00:00 2001 From: Alexander Lantsev Date: Tue, 9 Sep 2014 20:55:41 +0000 Subject: Tox: reworked profile manager logic git-svn-id: http://svn.miranda-ng.org/main/trunk@10414 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- protocols/Tox/src/tox_profile.cpp | 76 ++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 24 deletions(-) (limited to 'protocols/Tox/src/tox_profile.cpp') diff --git a/protocols/Tox/src/tox_profile.cpp b/protocols/Tox/src/tox_profile.cpp index 145b839f0c..1a23b85051 100644 --- a/protocols/Tox/src/tox_profile.cpp +++ b/protocols/Tox/src/tox_profile.cpp @@ -13,10 +13,23 @@ INT_PTR CToxProto::ToxProfileManagerProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP proto = (CToxProto*)lParam; SetWindowLongPtr(hwnd, GWLP_USERDATA, lParam); - profilePath = (TCHAR*)mir_calloc(sizeof(TCHAR)* MAX_PATH); + profilePath = (TCHAR*)mir_calloc(sizeof(TCHAR)*MAX_PATH); SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)profilePath); - CheckDlgButton(hwnd, IDC_CREATE_NEW, TRUE); + std::tstring toxProfilePath = proto->GetToxProfilePath(); + if (proto->IsFileExists(toxProfilePath)) + { + _tcscpy(profilePath, proto->GetToxProfilePath().c_str()); + SetDlgItemText(hwnd, IDC_PROFILE_PATH, profilePath); + + CheckDlgButton(hwnd, IDC_USE_EXISTING, TRUE); + EnableWindow(GetDlgItem(hwnd, IDC_PROFILE_PATH), IsDlgButtonChecked(hwnd, IDC_USE_EXISTING)); + EnableWindow(GetDlgItem(hwnd, IDC_BROWSE_PROFILE), IsDlgButtonChecked(hwnd, IDC_USE_EXISTING)); + } + else + { + CheckDlgButton(hwnd, IDC_CREATE_NEW, TRUE); + } } return TRUE; @@ -31,44 +44,59 @@ INT_PTR CToxProto::ToxProfileManagerProc(HWND hwnd, UINT uMsg, WPARAM wParam, LP case WM_COMMAND: switch (LOWORD(wParam)) { + case IDC_CREATE_NEW: case IDC_USE_EXISTING: EnableWindow(GetDlgItem(hwnd, IDC_PROFILE_PATH), IsDlgButtonChecked(hwnd, IDC_USE_EXISTING)); EnableWindow(GetDlgItem(hwnd, IDC_BROWSE_PROFILE), IsDlgButtonChecked(hwnd, IDC_USE_EXISTING)); break; case IDC_BROWSE_PROFILE: - { - TCHAR filter[MAX_PATH] = { 0 }; - mir_sntprintf(filter, MAX_PATH, _T("%s\0*.*"), TranslateT("All files (*.*)")); + { + TCHAR filter[MAX_PATH] = { 0 }; + mir_sntprintf(filter, MAX_PATH, _T("%s\0*.*"), TranslateT("All files (*.*)")); - OPENFILENAME ofn = { sizeof(ofn) }; - ofn.hwndOwner = hwnd; - ofn.lpstrFilter = filter; - ofn.nFilterIndex = 1; - ofn.lpstrFile = profilePath; - ofn.lpstrTitle = TranslateT("Select tox profile"); - ofn.nMaxFile = MAX_PATH; - ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER; + OPENFILENAME ofn = { sizeof(ofn) }; + ofn.hwndOwner = hwnd; + ofn.lpstrFilter = filter; + ofn.nFilterIndex = 1; + ofn.lpstrFile = profilePath; + ofn.lpstrTitle = TranslateT("Select tox profile"); + ofn.nMaxFile = MAX_PATH; + ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER; - if (GetOpenFileName(&ofn) && profilePath) - { - SetDlgItemText(hwnd, IDC_PROFILE_PATH, profilePath); + if (GetOpenFileName(&ofn) && profilePath) + { + SetDlgItemText(hwnd, IDC_PROFILE_PATH, profilePath); + } } - } break; case IDOK: - { - if (IsDlgButtonChecked(hwnd, IDC_USE_EXISTING)) { - if (profilePath != NULL) + std::tstring toxProfilePath = proto->GetToxProfilePath(); + if (IsDlgButtonChecked(hwnd, IDC_USE_EXISTING)) + { + if (profilePath[0] != 0 && toxProfilePath != profilePath) + { + CopyFile(profilePath, toxProfilePath.c_str(), FALSE); + } + } + else { - std::tstring toxProfilePath = proto->GetToxProfilePath(); - CopyFile(profilePath, toxProfilePath.c_str(), FALSE); + if (proto->IsFileExists(toxProfilePath)) + { + if (MessageBox(NULL, + TranslateT("Tox profile with same name already exists.\r\nIf you continue, the profile will be lost!"), + TranslateT("Tox profile"), + MB_OKCANCEL | MB_ICONWARNING) == IDCANCEL) + { + break; + } + DeleteFile(profilePath); + } } + EndDialog(hwnd, 1); } - EndDialog(hwnd, 1); - } break; } -- cgit v1.2.3