ProfilePasswordResult
CheckProfileFilePassword(Path path)
{
  ProfileMap map;
  Profile::LoadFile(map, path);
  return CheckProfilePassword(map);
}
ProfilePasswordResult
CheckProfileFilePassword(Path path, Error &error)
{
  ProfileMap map;
  if (!Profile::LoadFile(map, path, error))
    return ProfilePasswordResult::ERROR;

  return CheckProfilePassword(map);
}
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);
}
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);
}