1
0

About.cpp 14 KB

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