void __fastcall TSiteRawDialog::AddButtonClick(TObject *)
{
  std::unique_ptr<TSessionData> FactoryDefaults(new TSessionData(L""));
  std::unique_ptr<TSessionData> BasicData(new TSessionData(L""));
  BasicData->FSProtocol = TFSProtocol(FactoryDefaults->FSProtocol + 1);
  UnicodeString RandomAppendix(L"_");
  BasicData->HostName = FactoryDefaults->HostName + RandomAppendix;
  BasicData->Ftps = TFtps(FactoryDefaults->Ftps + 1);
  BasicData->PortNumber = DefaultPort(BasicData->FSProtocol, BasicData->Ftps) + 1;
  BasicData->UserName = FactoryDefaults->UserName + RandomAppendix;
  BasicData->Password = FactoryDefaults->Password + RandomAppendix;

  std::unique_ptr<TStrings> BasicOptions(BasicData->SaveToOptions(FactoryDefaults.get(), false, false));

  std::unique_ptr<TStrings> AllOptions(TSessionData::GetAllOptionNames(false));

  std::unique_ptr<TStrings> Names(CreateSortedStringList());
  for (int Index = 0; Index < AllOptions->Count; Index++)
  {
    Names->Add(AllOptions->Names[Index]);
  }
  DeleteNames(Names.get(), BasicOptions.get());
  DeleteNames(Names.get(), SettingsMemo->Lines);

  std::unique_ptr<TCustomDialog> AddDialog(new TCustomDialog(HelpKeyword));
  AddDialog->Caption = LoadStr(SITE_RAW_ADD_CAPTION);
  TComboBox * AddComboBox = new TComboBox(AddDialog.get());
  AddComboBox->Style = csDropDownList;
  AddComboBox->DropDownCount = Max(AddComboBox->DropDownCount, 16);
  AddDialog->AddComboBox(AddComboBox, CreateLabel(LoadStr(SITE_RAW_ADD_LABEL)), Names.get(), true);
  AddComboBox->ItemIndex = 0;
  if (AddDialog->Execute())
  {
    UnicodeString Name = AddComboBox->Items->Strings[AddComboBox->ItemIndex];
    UnicodeString Value = AllOptions->Values[Name];
    UnicodeString NameAndSeparator = Name + SettingsMemo->Lines->NameValueSeparator;
    int Start = (SettingsMemo->Lines->Text + NameAndSeparator).Length();
    SettingsMemo->Lines->Add(NameAndSeparator + Value);
    SettingsMemo->SetFocus();
    SettingsMemo->SelStart = Start;
    SettingsMemo->SelLength = Value.Length();
  }
}

void __fastcall TSiteRawDialog::AddButtonClick(TObject *)
{
  std::unique_ptr<TSessionData> FactoryDefaults(new TSessionData(L""));
  std::unique_ptr<TSessionData> BasicData(new TSessionData(L""));
  BasicData->FSProtocol = TFSProtocol(FactoryDefaults->FSProtocol + 1);
  UnicodeString RandomAppendix(L"_");
  BasicData->HostName = FactoryDefaults->HostName + RandomAppendix;
  BasicData->Ftps = TFtps(FactoryDefaults->Ftps + 1);
  BasicData->PortNumber = DefaultPort(BasicData->FSProtocol, BasicData->Ftps) + 1;
  BasicData->UserName = FactoryDefaults->UserName + RandomAppendix;
  BasicData->Password = FactoryDefaults->Password + RandomAppendix;

  std::unique_ptr<TStrings> BasicOptions(BasicData->SaveToOptions(FactoryDefaults.get(), false, false));

  std::unique_ptr<TStrings> AllOptions(TSessionData::GetAllOptionNames(false));

  std::unique_ptr<TStrings> Names(CreateSortedStringList());
  for (int Index = 0; Index < AllOptions->Count; Index++)
  {
    Names->Add(AllOptions->Names[Index]);
  }
  DeleteNames(Names.get(), BasicOptions.get());
  DeleteNames(Names.get(), SettingsMemo->Lines);

  std::unique_ptr<TCustomDialog> AddDialog(new TCustomDialog(HelpKeyword));
  AddDialog->Caption = LoadStr(SITE_RAW_ADD_CAPTION);
  TComboBox * AddComboBox = new TComboBox(AddDialog.get());
  AddComboBox->Style = csDropDownList;
  AddComboBox->DropDownCount = Max(AddComboBox->DropDownCount, 16);
  AddDialog->AddComboBox(AddComboBox, CreateLabel(LoadStr(SITE_RAW_ADD_LABEL)), Names.get(), true);
  AddComboBox->ItemIndex = 0;
  if (AddDialog->Execute())
  {
    UnicodeString Name = AddComboBox->Items->Strings[AddComboBox->ItemIndex];
    UnicodeString Value = AllOptions->Values[Name];
    UnicodeString NameAndSeparator = Name + SettingsMemo->Lines->NameValueSeparator;
    int Start = (SettingsMemo->Lines->Text + NameAndSeparator).Length();
    SettingsMemo->Lines->Add(NameAndSeparator + Value);
    SettingsMemo->SetFocus();
    SettingsMemo->SelStart = Start;
    SettingsMemo->SelLength = Value.Length();
  }
}
