inline void ProfileListWidget::DeleteClicked() { assert(GetList().GetCursorIndex() < list.size()); const auto &item = list[GetList().GetCursorIndex()]; const auto password_result = CheckProfileFilePassword(item.path); switch (password_result) { case ProfilePasswordResult::UNPROTECTED: if (!ConfirmDeleteProfile(item.name)) return; break; case ProfilePasswordResult::MATCH: break; case ProfilePasswordResult::MISMATCH: case ProfilePasswordResult::CANCEL: CheckProfilePasswordResult(password_result); return; } File::Delete(item.path); UpdateList(); }
inline void ProfileListWidget::CopyClicked() { assert(GetList().GetCursorIndex() < list.size()); const auto &item = list[GetList().GetCursorIndex()]; const TCHAR *old_path = item.path; const TCHAR *old_filename = item.name; ProfileMap data; if (!Profile::LoadFile(data, old_path)) { ShowMessageBox(old_filename, _("Failed to load file."), MB_OK|MB_ICONEXCLAMATION); return; } if (!CheckProfilePasswordResult(CheckProfilePassword(data))) return; StaticString<64> new_name; new_name.clear(); if (!TextEntryDialog(new_name, _("Profile name"))) return; StaticString<80> new_filename; new_filename = new_name; new_filename += _T(".prf"); StaticString<MAX_PATH> new_path; LocalPath(new_path.buffer(), new_filename); if (File::ExistsAny(new_path)) { ShowMessageBox(new_name, _("File exists already."), MB_OK|MB_ICONEXCLAMATION); return; } if (!Profile::SaveFile(data, new_path)) { ShowMessageBox(new_name, _("Failed to save file."), MB_OK|MB_ICONEXCLAMATION); return; } UpdateList(); SelectPath(new_path); }
static bool SelectProfile(Path path) { try { if (!CheckProfilePasswordResult(CheckProfileFilePassword(path))) return false; } catch (const std::runtime_error &e) { ShowError(e, _("Password")); return false; } Profile::SetFiles(path); if (RelativePath(path) == nullptr) /* When a profile from a secondary data path is used, this path becomes the primary data path */ SetPrimaryDataPath(path.GetParent()); File::Touch(path); return true; }
inline void ProfileListWidget::PasswordClicked() { assert(GetList().GetCursorIndex() < list.size()); const auto &item = list[GetList().GetCursorIndex()]; ProfileMap data; if (!Profile::LoadFile(data, item.path)) { ShowMessageBox(item.name, _("Failed to load file."), MB_OK|MB_ICONEXCLAMATION); return; } if (!CheckProfilePasswordResult(CheckProfilePassword(data)) || !SetProfilePasswordDialog(data)) return; if (!Profile::SaveFile(data, item.path)) ShowMessageBox(item.name, _("Failed to save file."), MB_OK|MB_ICONEXCLAMATION); }