About.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. //---------------------------------------------------------------------
  2. #include <FormsPCH.h>
  3. #pragma hdrstop
  4. #include <PuttyTools.h>
  5. #include "About.h"
  6. // must be included before WebBrowserEx.hpp to avoid ambiguity of tagLOGFONTW
  7. #include <TB2Version.hpp>
  8. #include <TBX.hpp>
  9. #include <JclBase.hpp>
  10. #include <JclDebug.hpp>
  11. #include <WebBrowserEx.hpp>
  12. #include <FtpFileSystem.h>
  13. #include <S3FileSystem.h>
  14. //---------------------------------------------------------------------
  15. #pragma link "SHDocVw_OCX"
  16. #pragma resource "*.dfm"
  17. //---------------------------------------------------------------------------
  18. static void __fastcall DoAboutDialog(TConfiguration * Configuration,
  19. bool AllowLicense, TRegistration * Registration, bool LoadThirdParty)
  20. {
  21. TAboutDialog * AboutDialog = NULL;
  22. try
  23. {
  24. AboutDialog = new TAboutDialog(Application, Configuration, AllowLicense,
  25. Registration, LoadThirdParty);
  26. AboutDialog->ShowModal();
  27. }
  28. __finally
  29. {
  30. delete AboutDialog;
  31. }
  32. }
  33. //---------------------------------------------------------------------------
  34. void __fastcall DoAboutDialog(TConfiguration * Configuration,
  35. bool AllowLicense, TRegistration * Registration)
  36. {
  37. try
  38. {
  39. DoAboutDialog(Configuration, AllowLicense, Registration, true);
  40. }
  41. catch (EOleException &)
  42. {
  43. // This happens particularly on Wine that does not support some
  44. // functionality of embedded IE we need.
  45. DoAboutDialog(Configuration, AllowLicense, Registration, false);
  46. }
  47. }
  48. //---------------------------------------------------------------------------
  49. __fastcall TAboutDialog::TAboutDialog(TComponent * AOwner,
  50. TConfiguration * Configuration, bool AllowLicense, TRegistration * Registration,
  51. bool ALoadThirdParty)
  52. : TForm(AOwner)
  53. {
  54. FConfiguration = Configuration;
  55. UseSystemSettings(this);
  56. LinkLabel(HomepageLabel, LoadStr(HOMEPAGE_URL));
  57. LinkLabel(ForumUrlLabel, LoadStr(FORUM_URL));
  58. ApplicationLabel->Caption = AppName;
  59. TColor MainInstructionColor;
  60. HFONT MainInstructionFont;
  61. HFONT InstructionFont;
  62. GetInstrutionsTheme(MainInstructionColor, MainInstructionFont, InstructionFont);
  63. if (MainInstructionFont != 0)
  64. {
  65. int PrevHeight = ApplicationLabel->Height;
  66. ApplicationLabel->Font->Handle = MainInstructionFont;
  67. if (MainInstructionColor != Graphics::clNone)
  68. {
  69. ApplicationLabel->Font->Color = MainInstructionColor;
  70. }
  71. ShiftControls(ApplicationLabel->Top + 1, (ApplicationLabel->Height - PrevHeight));
  72. }
  73. else
  74. {
  75. ApplicationLabel->ParentFont = true;
  76. ApplicationLabel->Font->Style = ApplicationLabel->Font->Style << fsBold;
  77. }
  78. WinSCPCopyrightLabel->Caption = LoadStr(WINSCP_COPYRIGHT);
  79. if (Registration == NULL)
  80. {
  81. RegistrationLabel->Visible = false;
  82. RegistrationBox->Visible = false;
  83. ShiftControls(RegistrationLabel->Top, (RegistrationBox->Top - ThirdPartyPanel->Top));
  84. }
  85. else
  86. {
  87. RegistrationSubjectLabel->Caption = Registration->Subject;
  88. if (Registration->Registered)
  89. {
  90. UnicodeString Text;
  91. Text = FORMAT(LoadStrPart(ABOUT_REGISTRATION_LICENSES, 1),
  92. (Registration->Licenses >= 0 ? IntToStr(Registration->Licenses) :
  93. UnicodeString(LoadStrPart(ABOUT_REGISTRATION_LICENSES, 2))));
  94. if (!Registration->NeverExpires)
  95. {
  96. Text = FMTLOAD(ABOUT_REGISTRATION_EXPIRES,
  97. (Text, FormatDateTime(L"ddddd", Registration->Expiration)));
  98. }
  99. RegistrationLicensesLabel->Caption = Text;
  100. Text = FMTLOAD(ABOUT_REGISTRATION_PRODUCTID, (Registration->ProductId));
  101. if (Registration->EduLicense)
  102. {
  103. Text = FMTLOAD(ABOUT_REGISTRATION_EDULICENSE, (Text));
  104. }
  105. RegistrationProductIdLabel->Caption = Text;
  106. RegistrationProductIdLabel->Font->Style =
  107. RegistrationProductIdLabel->Font->Style << fsBold;
  108. }
  109. else
  110. {
  111. RegistrationLicensesLabel->Visible = false;
  112. FOnRegistrationLink = Registration->OnRegistrationLink;
  113. RegistrationProductIdLabel->Caption = LoadStr(ABOUT_REGISTRATION_LINK);
  114. LinkLabel(RegistrationProductIdLabel, L"");
  115. }
  116. }
  117. LicenseButton->Visible = AllowLicense;
  118. LoadData();
  119. if (ALoadThirdParty)
  120. {
  121. LoadThirdParty();
  122. }
  123. else
  124. {
  125. CreateLabelPanel(ThirdPartyPanel, LoadStr(MESSAGE_DISPLAY_ERROR));
  126. }
  127. int IconSize = ScaleByPixelsPerInch(48, this);
  128. FIconHandle = (HICON)LoadImage(MainInstance, L"MAINICON", IMAGE_ICON, IconSize, IconSize, 0);
  129. IconPaintBox->Width = IconSize;
  130. IconPaintBox->Height = IconSize;
  131. }
  132. //---------------------------------------------------------------------------
  133. __fastcall TAboutDialog::~TAboutDialog()
  134. {
  135. DestroyIcon(FIconHandle);
  136. }
  137. //---------------------------------------------------------------------------
  138. void __fastcall TAboutDialog::ShiftControls(int From, int Diff)
  139. {
  140. for (int Index = 0; Index < Panel->ControlCount; Index++)
  141. {
  142. if (Panel->Controls[Index]->Top > From)
  143. {
  144. Panel->Controls[Index]->Top = Panel->Controls[Index]->Top + Diff;
  145. }
  146. }
  147. ClientHeight = ClientHeight + Diff;
  148. }
  149. //---------------------------------------------------------------------------
  150. void __fastcall TAboutDialog::LoadData()
  151. {
  152. UnicodeString Version = FConfiguration->VersionStr;
  153. if (!FConfiguration->ProductName.IsEmpty() &&
  154. (FConfiguration->Version != FConfiguration->ProductVersion))
  155. {
  156. Version = FMTLOAD(ABOUT_BASED_ON_PRODUCT,
  157. (Version, FConfiguration->ProductName, FConfiguration->ProductVersion));
  158. }
  159. VersionLabel->Caption = Version;
  160. }
  161. //---------------------------------------------------------------------------
  162. void __fastcall TAboutDialog::LoadThirdParty()
  163. {
  164. FThirdPartyWebBrowser = CreateBrowserViewer(ThirdPartyPanel, L"");
  165. reinterpret_cast<TLabel *>(FThirdPartyWebBrowser)->Color = ThirdPartyPanel->Color;
  166. ReadyBrowserForStreaming(FThirdPartyWebBrowser);
  167. DoLoadThirdParty();
  168. }
  169. //---------------------------------------------------------------------------
  170. void __fastcall TAboutDialog::DoLoadThirdParty()
  171. {
  172. WaitBrowserToIdle(FThirdPartyWebBrowser);
  173. UnicodeString ThirdParty;
  174. UnicodeString Br = "<br/>\n";
  175. if (!GUIConfiguration->UsingInternalTranslation())
  176. {
  177. UnicodeString TranslatorUrl = LoadStr(TRANSLATOR_URL);
  178. UnicodeString TranslatorInfo = LoadStr(TRANSLATOR_INFO2);
  179. wchar_t LocaleNameStr[255];
  180. GetLocaleInfo(
  181. GUIConfiguration->AppliedLocale, LOCALE_SLOCALIZEDLANGUAGENAME,
  182. LocaleNameStr, LENOF(LocaleNameStr));
  183. UnicodeString LocaleName(LocaleNameStr);
  184. // The {language} should be present only if we are using an untranslated
  185. // (=english) string
  186. UnicodeString TranslationHeader = ReplaceStr(LoadStr(ABOUT_TRANSLATIONS_HEADER), L"{language}", LocaleName);
  187. AddPara(ThirdParty,
  188. TranslationHeader + Br +
  189. FMTLOAD(ABOUT_TRANSLATIONS_COPYRIGHT, (GUIConfiguration->AppliedLocaleCopyright())) + Br +
  190. (!TranslatorInfo.IsEmpty() ? TranslatorInfo + Br : UnicodeString()) +
  191. (!TranslatorUrl.IsEmpty() ? CreateLink(TranslatorUrl) : UnicodeString()));
  192. }
  193. AddPara(ThirdParty, LoadStr(ABOUT_THIRDPARTY_HEADER));
  194. AddPara(ThirdParty,
  195. FMTLOAD(PUTTY_BASED_ON, (GetPuTTYVersion())) + Br +
  196. LoadStr(PUTTY_COPYRIGHT) + Br +
  197. CreateLink(LoadStr(PUTTY_LICENSE_URL), LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
  198. CreateLink(LoadStr(PUTTY_URL)));
  199. UnicodeString OpenSSLVersionText = GetOpenSSLVersionText();
  200. CutToChar(OpenSSLVersionText, L' ', true); // "OpenSSL"
  201. UnicodeString OpenSSLVersion = CutToChar(OpenSSLVersionText, L' ', true);
  202. CutToChar(OpenSSLVersionText, L' ', true); // day
  203. CutToChar(OpenSSLVersionText, L' ', true); // month
  204. UnicodeString OpenSSLYear = CutToChar(OpenSSLVersionText, L' ', true);
  205. AddPara(ThirdParty,
  206. FMTLOAD(OPENSSL_BASED_ON, (OpenSSLVersion)) + Br +
  207. FMTLOAD(OPENSSL_COPYRIGHT2, (OpenSSLYear)) + Br +
  208. CreateLink(LoadStr(OPENSSL_URL)));
  209. AddPara(ThirdParty,
  210. LoadStr(FILEZILLA_BASED_ON2) + Br +
  211. LoadStr(FILEZILLA_COPYRIGHT2) + Br +
  212. CreateLink(LoadStr(FILEZILLA_URL)));
  213. AddPara(ThirdParty,
  214. FMTLOAD(NEON_BASED_ON2, (NeonVersion())) + Br +
  215. LoadStr(NEON_COPYRIGHT) + Br +
  216. CreateLink(LoadStr(NEON_URL)));
  217. AddPara(ThirdParty,
  218. FMTLOAD(S3_BASED_ON, (S3LibVersion())) + Br +
  219. LoadStr(S3_COPYRIGHT) + Br +
  220. CreateLink(LoadStr(S3_LICENSE_URL), LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
  221. CreateLink(LoadStr(S3_URL)));
  222. #define EXPAT_LICENSE_URL L"license:expat"
  223. AddPara(ThirdParty,
  224. FMTLOAD(EXPAT_BASED_ON, (ExpatVersion())) + Br +
  225. CreateLink(EXPAT_LICENSE_URL, LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
  226. CreateLink(LoadStr(EXPAT_URL)));
  227. AddBrowserLinkHandler(FThirdPartyWebBrowser, EXPAT_LICENSE_URL, ExpatLicenceHandler);
  228. AddPara(ThirdParty,
  229. FMTLOAD(ABOUT_TOOLBAR2000, (Toolbar2000Version)) + Br +
  230. LoadStr(ABOUT_TOOLBAR2000_COPYRIGHT) + Br +
  231. CreateLink(LoadStr(ABOUT_TOOLBAR2000_URL)));
  232. AddPara(ThirdParty,
  233. FMTLOAD(ABOUT_TBX, (TBXVersionString)) + Br +
  234. LoadStr(ABOUT_TBX_COPYRIGHT) + Br +
  235. CreateLink(LoadStr(ABOUT_TBX_URL)));
  236. AddPara(ThirdParty,
  237. LoadStr(ABOUT_FILEMANAGER) + Br +
  238. LoadStr(ABOUT_FILEMANAGER_COPYRIGHT));
  239. UnicodeString JclVersion =
  240. FormatVersion(JclVersionMajor, JclVersionMinor, JclVersionRelease) + L" " + JclCommit;
  241. AddPara(ThirdParty,
  242. FMTLOAD(ABOUT_JCL, (JclVersion)) + Br +
  243. CreateLink(LoadStr(ABOUT_JCL_URL)));
  244. AddPara(ThirdParty,
  245. LoadStr(ABOUT_PNG) + Br +
  246. LoadStr(ABOUT_PNG_COPYRIGHT) + Br +
  247. CreateLink(LoadStr(ABOUT_PNG_URL)));
  248. ThirdParty = GenerateAppHtmlPage(Font, ThirdPartyPanel, ThirdParty, false);
  249. LoadBrowserDocument(FThirdPartyWebBrowser, ThirdParty);
  250. }
  251. //---------------------------------------------------------------------------
  252. void __fastcall TAboutDialog::AddPara(UnicodeString & Text, const UnicodeString & S)
  253. {
  254. Text += L"<p>" + S + L"</p>\n";
  255. }
  256. //---------------------------------------------------------------------------
  257. UnicodeString __fastcall TAboutDialog::CreateLink(const UnicodeString & URL, const UnicodeString & Title)
  258. {
  259. return FORMAT(L"<a href=\"%s\">%s</a>", (URL, Title.IsEmpty() ? URL : Title));
  260. }
  261. //---------------------------------------------------------------------------
  262. void __fastcall TAboutDialog::LicenseButtonClick(TObject * /*Sender*/)
  263. {
  264. DoProductLicense();
  265. }
  266. //---------------------------------------------------------------------------
  267. void __fastcall TAboutDialog::HelpButtonClick(TObject * /*Sender*/)
  268. {
  269. FormHelp(this);
  270. }
  271. //---------------------------------------------------------------------------
  272. void __fastcall TAboutDialog::RegistrationProductIdLabelClick(
  273. TObject * /*Sender*/)
  274. {
  275. if (FOnRegistrationLink != NULL)
  276. {
  277. FOnRegistrationLink(this);
  278. }
  279. }
  280. //---------------------------------------------------------------------------
  281. void __fastcall TAboutDialog::OKButtonMouseDown(TObject * /*Sender*/,
  282. TMouseButton Button, TShiftState Shift, int /*X*/, int /*Y*/)
  283. {
  284. if (Button == mbRight)
  285. {
  286. if (Shift.Contains(ssAlt))
  287. {
  288. AccessViolationTest();
  289. }
  290. else if (Shift.Contains(ssCtrl))
  291. {
  292. LookupAddress();
  293. }
  294. }
  295. }
  296. //---------------------------------------------------------------------------
  297. void __fastcall TAboutDialog::LookupAddress()
  298. {
  299. UnicodeString S;
  300. if (InputQuery(L"Address lookup", L"&Address:", S))
  301. {
  302. void * Address = reinterpret_cast<void *>(StrToInt(L"$" + S));
  303. ShowMessage(GetLocationInfoStr(Address, true, true, true, true));
  304. }
  305. }
  306. //---------------------------------------------------------------------------
  307. void __fastcall TAboutDialog::AccessViolationTest()
  308. {
  309. try
  310. {
  311. ACCESS_VIOLATION_TEST;
  312. }
  313. catch (Exception & E)
  314. {
  315. throw ExtException(&E, MainInstructions(L"Internal error test."));
  316. }
  317. }
  318. //---------------------------------------------------------------------------
  319. void __fastcall TAboutDialog::ExpatLicenceHandler(TObject * /*Sender*/)
  320. {
  321. DoLicenseDialog(lcExpat);
  322. }
  323. //---------------------------------------------------------------------------
  324. void __fastcall TAboutDialog::IconPaintBoxPaint(TObject * /*Sender*/)
  325. {
  326. DrawIconEx(IconPaintBox->Canvas->Handle,
  327. 0, 0, FIconHandle, IconPaintBox->Width, IconPaintBox->Height, 0, NULL, DI_NORMAL);
  328. }
  329. //---------------------------------------------------------------------------
  330. void __fastcall TAboutDialog::FormAfterMonitorDpiChanged(TObject *, int OldDPI, int NewDPI)
  331. {
  332. DebugUsedParam2(OldDPI, NewDPI);
  333. if (FThirdPartyWebBrowser != NULL)
  334. {
  335. DoLoadThirdParty();
  336. }
  337. }
  338. //---------------------------------------------------------------------------
  339. void __fastcall TAboutDialog::FormKeyDown(TObject *, WORD & Key, TShiftState Shift)
  340. {
  341. if ((Key == L'C') && Shift.Contains(ssCtrl))
  342. {
  343. if ((FThirdPartyWebBrowser != NULL) &&
  344. FThirdPartyWebBrowser->Focused() &&
  345. (FThirdPartyWebBrowser->SelLength() > 0))
  346. {
  347. // Let the browser handle the Ctrl+C
  348. }
  349. else
  350. {
  351. UnicodeString Text =
  352. ApplicationLabel->Caption + sLineBreak +
  353. VersionLabel->Caption + sLineBreak +
  354. sLineBreak +
  355. WinSCPCopyrightLabel->Caption + sLineBreak +
  356. HomepageLabel->Caption + sLineBreak +
  357. sLineBreak +
  358. ProductSpecificMessageLabel->Caption + sLineBreak +
  359. ForumUrlLabel->Caption + sLineBreak;
  360. UnicodeString ThirdPartyText;
  361. if ((FThirdPartyWebBrowser != NULL) &&
  362. CopyTextFromBrowser(FThirdPartyWebBrowser, ThirdPartyText))
  363. {
  364. Text +=
  365. sLineBreak +
  366. GetDividerLine() + sLineBreak +
  367. Label3->Caption + sLineBreak +
  368. ThirdPartyText + sLineBreak;
  369. }
  370. TInstantOperationVisualizer Visualizer;
  371. CopyToClipboard(Text);
  372. Key = 0;
  373. }
  374. }
  375. }
  376. //---------------------------------------------------------------------------