GenerateUrl.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "VCLCommon.h"
  5. #include "GenerateUrl.h"
  6. #include "CoreMain.h"
  7. #include "WinConfiguration.h"
  8. #include <StrUtils.hpp>
  9. #include <Tools.h>
  10. #include <PuttyTools.h>
  11. //---------------------------------------------------------------------------
  12. #pragma package(smart_init)
  13. #ifndef NO_RESOURCES
  14. #pragma resource "*.dfm"
  15. #endif
  16. //---------------------------------------------------------------------------
  17. void __fastcall DoGenerateUrlDialog(TSessionData * Data, TStrings * Paths)
  18. {
  19. std::unique_ptr<TGenerateUrlDialog> Dialog(new TGenerateUrlDialog(GetFormOwner(), Data, Paths));
  20. Dialog->Execute();
  21. }
  22. //---------------------------------------------------------------------------
  23. __fastcall TGenerateUrlDialog::TGenerateUrlDialog(
  24. TComponent * Owner, TSessionData * Data, TStrings * Paths)
  25. : TForm(Owner)
  26. {
  27. UseSystemSettings(this);
  28. FData = Data;
  29. FPaths = Paths;
  30. FChanging = false;
  31. ReadOnlyControl(UrlMemo);
  32. }
  33. //---------------------------------------------------------------------------
  34. UnicodeString __fastcall TGenerateUrlDialog::GenerateUrl(UnicodeString Path)
  35. {
  36. UnicodeString Url =
  37. FData->GenerateSessionUrl(
  38. FLAGMASK(WinSCPSpecificCheck->Checked, sufSpecific) |
  39. FLAGMASK(UserNameCheck->Enabled && UserNameCheck->Checked, sufUserName) |
  40. FLAGMASK(PasswordCheck->Enabled && PasswordCheck->Checked, sufPassword) |
  41. FLAGMASK(HostKeyCheck->Enabled && HostKeyCheck->Checked, sufHostKey));
  42. if ((RemoteDirectoryCheck->Enabled && RemoteDirectoryCheck->Checked) ||
  43. (FPaths != NULL))
  44. {
  45. if (StartsStr(L"/", Path));
  46. {
  47. Path.Delete(1, 1);
  48. }
  49. Url += EncodeUrlPath(Path);
  50. }
  51. if (SaveExtensionCheck->Enabled && SaveExtensionCheck->Checked)
  52. {
  53. Url += UnicodeString(UrlParamSeparator) + UrlSaveParamName;
  54. }
  55. return Url;
  56. }
  57. //---------------------------------------------------------------------------
  58. void __fastcall TGenerateUrlDialog::UpdateControls()
  59. {
  60. if (!FChanging)
  61. {
  62. EnableControl(UserNameCheck, !FData->UserNameExpanded.IsEmpty());
  63. bool UserNameIncluded = UserNameCheck->Enabled && UserNameCheck->Checked;
  64. EnableControl(PasswordCheck, UserNameIncluded && FData->HasPassword());
  65. EnableControl(HostKeyCheck, UserNameIncluded && !FData->HostKey.IsEmpty());
  66. EnableControl(RemoteDirectoryCheck, !FData->RemoteDirectory.IsEmpty() && (FPaths == NULL));
  67. EnableControl(SaveExtensionCheck, (FPaths == NULL));
  68. UnicodeString Urls;
  69. if (FPaths == NULL)
  70. {
  71. UnicodeString Path = FData->RemoteDirectory;
  72. if (!Path.IsEmpty() && !EndsStr(L"/", Path))
  73. {
  74. Path += L"/";
  75. }
  76. Urls = GenerateUrl(Path);
  77. }
  78. else
  79. {
  80. for (int Index = 0; Index < FPaths->Count; Index++)
  81. {
  82. Urls += GenerateUrl(FPaths->Strings[Index]) + L"\n";
  83. }
  84. }
  85. UrlMemo->Lines->Text = Urls;
  86. }
  87. }
  88. //---------------------------------------------------------------------------
  89. void __fastcall TGenerateUrlDialog::Execute()
  90. {
  91. int Components = WinConfiguration->GenerateUrlComponents;
  92. if (Components < 0)
  93. {
  94. Components = UserNameCheck->Tag | RemoteDirectoryCheck->Tag;
  95. }
  96. {
  97. TAutoFlag ChangingFlag(FChanging);
  98. for (int Index = 0; Index < OptionsGroup->ControlCount; Index++)
  99. {
  100. TCheckBox * CheckBox = dynamic_cast<TCheckBox *>(OptionsGroup->Controls[Index]);
  101. if (ALWAYS_TRUE((CheckBox != NULL) && (CheckBox->Tag != 0)))
  102. {
  103. CheckBox->Checked = FLAGSET(Components, CheckBox->Tag);
  104. }
  105. }
  106. }
  107. UpdateControls();
  108. ShowModal();
  109. Components = 0;
  110. for (int Index = 0; Index < OptionsGroup->ControlCount; Index++)
  111. {
  112. TCheckBox * CheckBox = dynamic_cast<TCheckBox *>(OptionsGroup->Controls[Index]);
  113. if (ALWAYS_TRUE((CheckBox != NULL) && (CheckBox->Tag != 0)) &&
  114. CheckBox->Checked)
  115. {
  116. Components |= CheckBox->Tag;
  117. }
  118. }
  119. WinConfiguration->GenerateUrlComponents = Components;
  120. }
  121. //---------------------------------------------------------------------------
  122. void __fastcall TGenerateUrlDialog::ControlChange(TObject * /*Sender*/)
  123. {
  124. UpdateControls();
  125. }
  126. //---------------------------------------------------------------------------
  127. void __fastcall TGenerateUrlDialog::ClipboardButtonClick(TObject * /*Sender*/)
  128. {
  129. TInstantOperationVisualizer Visualizer;
  130. CopyToClipboard(UrlMemo->Lines);
  131. }
  132. //---------------------------------------------------------------------------
  133. void __fastcall TGenerateUrlDialog::HelpButtonClick(TObject * /*Sender*/)
  134. {
  135. FormHelp(this);
  136. }
  137. //---------------------------------------------------------------------------