About.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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. #ifndef NO_RESOURCES
  31. #pragma resource "*.dfm"
  32. #endif
  33. //---------------------------------------------------------------------------
  34. static void __fastcall DoAboutDialog(TConfiguration * Configuration,
  35. bool AllowLicense, TRegistration * Registration, bool LoadThirdParty)
  36. {
  37. TAboutDialog * AboutDialog = NULL;
  38. try
  39. {
  40. AboutDialog = new TAboutDialog(Application, Configuration, AllowLicense,
  41. Registration, LoadThirdParty);
  42. AboutDialog->ShowModal();
  43. }
  44. __finally
  45. {
  46. delete AboutDialog;
  47. }
  48. }
  49. //---------------------------------------------------------------------------
  50. void __fastcall DoAboutDialog(TConfiguration * Configuration,
  51. bool AllowLicense, TRegistration * Registration)
  52. {
  53. try
  54. {
  55. DoAboutDialog(Configuration, AllowLicense, Registration, true);
  56. }
  57. catch (EOleException & E)
  58. {
  59. // This happens particularly on Wine that does not support some
  60. // functionality of embedded IE we need.
  61. DoAboutDialog(Configuration, AllowLicense, Registration, false);
  62. }
  63. }
  64. //---------------------------------------------------------------------------
  65. __fastcall TAboutDialog::TAboutDialog(TComponent * AOwner,
  66. TConfiguration * Configuration, bool AllowLicense, TRegistration * Registration,
  67. bool ALoadThirdParty)
  68. : TForm(AOwner)
  69. {
  70. FConfiguration = Configuration;
  71. UseSystemSettings(this);
  72. LinkLabel(HomepageLabel, LoadStr(HOMEPAGE_URL));
  73. LinkLabel(ForumUrlLabel, LoadStr(FORUM_URL));
  74. ApplicationLabel->Caption = AppName;
  75. TColor MainInstructionColor;
  76. HFONT MainInstructionFont;
  77. HFONT InstructionFont;
  78. GetInstrutionsTheme(MainInstructionColor, MainInstructionFont, InstructionFont);
  79. if (MainInstructionFont != 0)
  80. {
  81. int PrevHeight = ApplicationLabel->Height;
  82. ApplicationLabel->Font->Handle = MainInstructionFont;
  83. if (MainInstructionColor != Graphics::clNone)
  84. {
  85. ApplicationLabel->Font->Color = MainInstructionColor;
  86. }
  87. ShiftControls(ApplicationLabel->Top + 1, (ApplicationLabel->Height - PrevHeight));
  88. }
  89. else
  90. {
  91. ApplicationLabel->ParentFont = true;
  92. ApplicationLabel->Font->Style = ApplicationLabel->Font->Style << fsBold;
  93. }
  94. WinSCPCopyrightLabel->Caption = LoadStr(WINSCP_COPYRIGHT);
  95. if (Registration == NULL)
  96. {
  97. RegistrationLabel->Visible = false;
  98. RegistrationBox->Visible = false;
  99. ShiftControls(RegistrationLabel->Top, (RegistrationBox->Top - ThirdPartyPanel->Top));
  100. }
  101. else
  102. {
  103. RegistrationSubjectLabel->Caption = Registration->Subject;
  104. if (Registration->Registered)
  105. {
  106. UnicodeString Text;
  107. Text = FORMAT(LoadStrPart(ABOUT_REGISTRATION_LICENSES, 1),
  108. (Registration->Licenses >= 0 ? IntToStr(Registration->Licenses) :
  109. UnicodeString(LoadStrPart(ABOUT_REGISTRATION_LICENSES, 2))));
  110. if (!Registration->NeverExpires)
  111. {
  112. Text = FMTLOAD(ABOUT_REGISTRATION_EXPIRES,
  113. (Text, FormatDateTime(L"ddddd", Registration->Expiration)));
  114. }
  115. RegistrationLicensesLabel->Caption = Text;
  116. Text = FMTLOAD(ABOUT_REGISTRATION_PRODUCTID, (Registration->ProductId));
  117. if (Registration->EduLicense)
  118. {
  119. Text = FMTLOAD(ABOUT_REGISTRATION_EDULICENSE, (Text));
  120. }
  121. RegistrationProductIdLabel->Caption = Text;
  122. RegistrationProductIdLabel->Font->Style =
  123. RegistrationProductIdLabel->Font->Style << fsBold;
  124. }
  125. else
  126. {
  127. RegistrationLicensesLabel->Visible = false;
  128. FOnRegistrationLink = Registration->OnRegistrationLink;
  129. RegistrationProductIdLabel->Caption = LoadStr(ABOUT_REGISTRATION_LINK);
  130. LinkLabel(RegistrationProductIdLabel, L"");
  131. }
  132. }
  133. LicenseButton->Visible = AllowLicense;
  134. LoadData();
  135. if (ALoadThirdParty)
  136. {
  137. LoadThirdParty();
  138. }
  139. else
  140. {
  141. CreateLabelPanel(ThirdPartyPanel, LoadStr(MESSAGE_DISPLAY_ERROR));
  142. }
  143. int IconSize = ScaleByPixelsPerInch(48, this);
  144. FIconHandle = (HICON)LoadImage(MainInstance, L"MAINICON", IMAGE_ICON, IconSize, IconSize, 0);
  145. IconPaintBox->Width = IconSize;
  146. IconPaintBox->Height = IconSize;
  147. }
  148. //---------------------------------------------------------------------------
  149. __fastcall TAboutDialog::~TAboutDialog()
  150. {
  151. DestroyIcon(FIconHandle);
  152. }
  153. //---------------------------------------------------------------------------
  154. void __fastcall TAboutDialog::ShiftControls(int From, int Diff)
  155. {
  156. for (int Index = 0; Index < Panel->ControlCount; Index++)
  157. {
  158. if (Panel->Controls[Index]->Top > From)
  159. {
  160. Panel->Controls[Index]->Top = Panel->Controls[Index]->Top + Diff;
  161. }
  162. }
  163. ClientHeight = ClientHeight + Diff;
  164. }
  165. //---------------------------------------------------------------------------
  166. void __fastcall TAboutDialog::LoadData()
  167. {
  168. UnicodeString Version = FConfiguration->VersionStr;
  169. if (!FConfiguration->ProductName.IsEmpty() &&
  170. (FConfiguration->Version != FConfiguration->ProductVersion))
  171. {
  172. Version = FMTLOAD(ABOUT_BASED_ON_PRODUCT,
  173. (Version, FConfiguration->ProductName, FConfiguration->ProductVersion));
  174. }
  175. VersionLabel->Caption = Version;
  176. }
  177. //---------------------------------------------------------------------------
  178. void __fastcall TAboutDialog::LoadThirdParty()
  179. {
  180. FThirdPartyWebBrowser = CreateBrowserViewer(ThirdPartyPanel, L"");
  181. reinterpret_cast<TLabel *>(FThirdPartyWebBrowser)->Color = ThirdPartyPanel->Color;
  182. NavigateBrowserToUrl(FThirdPartyWebBrowser, L"about:blank");
  183. DoLoadThirdParty();
  184. }
  185. //---------------------------------------------------------------------------
  186. void __fastcall TAboutDialog::DoLoadThirdParty()
  187. {
  188. while (FThirdPartyWebBrowser->ReadyState < ::READYSTATE_INTERACTIVE)
  189. {
  190. Application->ProcessMessages();
  191. }
  192. std::unique_ptr<TFont> DefaultFont(new TFont());
  193. DefaultFont->Assign(Application->DefaultFont);
  194. DefaultFont->Height = ScaleByPixelsPerInchFromSystem(DefaultFont->Height, this);
  195. UnicodeString ThirdParty;
  196. ThirdParty +=
  197. L"<!DOCTYPE html>\n"
  198. L"<meta charset=\"utf-8\">\n"
  199. L"<html>\n"
  200. L"<head>\n"
  201. L"<style>\n"
  202. L"\n"
  203. L"body\n"
  204. L"{\n"
  205. L" font-family: '" + DefaultFont->Name + L"';\n"
  206. L" margin: 0.5em;\n"
  207. L" background-color: " + ColorToWebColorStr(ThirdPartyPanel->Color) + L";\n"
  208. L"}\n"
  209. L"\n"
  210. L"body\n"
  211. L"{\n"
  212. L" font-size: " + IntToStr(DefaultFont->Size) + L"pt;\n"
  213. L"}\n"
  214. L"\n"
  215. L"p\n"
  216. L"{\n"
  217. L" margin-top: 0;\n"
  218. L" margin-bottom: 1em;\n"
  219. L"}\n"
  220. L"\n"
  221. L"a, a:visited, a:hover, a:visited, a:current\n"
  222. L"{\n"
  223. L" color: " + ColorToWebColorStr(LinkColor) + L";\n"
  224. L"}\n"
  225. L"</style>\n"
  226. L"</head>\n"
  227. L"<body>\n";
  228. UnicodeString Br = "<br/>\n";
  229. if (GUIConfiguration->AppliedLocale != GUIConfiguration->InternalLocale())
  230. {
  231. UnicodeString TranslatorUrl = LoadStr(TRANSLATOR_URL);
  232. UnicodeString TranslatorInfo = LoadStr(TRANSLATOR_INFO2);
  233. wchar_t LocaleNameStr[255];
  234. GetLocaleInfo(
  235. GUIConfiguration->AppliedLocale, LOCALE_SLOCALIZEDLANGUAGENAME,
  236. LocaleNameStr, LENOF(LocaleNameStr));
  237. UnicodeString LocaleName(LocaleNameStr);
  238. // The {language} should be present only if we are using an untranslated
  239. // (=english) string
  240. UnicodeString TranslationHeader = ReplaceStr(LoadStr(ABOUT_TRANSLATIONS_HEADER), L"{language}", LocaleName);
  241. AddPara(ThirdParty,
  242. TranslationHeader + Br +
  243. FMTLOAD(ABOUT_TRANSLATIONS_COPYRIGHT, (GUIConfiguration->AppliedLocaleCopyright())) + Br +
  244. (!TranslatorInfo.IsEmpty() ? TranslatorInfo + Br : UnicodeString()) +
  245. (!TranslatorUrl.IsEmpty() ? CreateLink(TranslatorUrl) : UnicodeString()));
  246. }
  247. AddPara(ThirdParty, LoadStr(ABOUT_THIRDPARTY_HEADER));
  248. AddPara(ThirdParty,
  249. FMTLOAD(PUTTY_BASED_ON, (GetPuTTYVersion())) + Br +
  250. LoadStr(PUTTY_COPYRIGHT) + Br +
  251. CreateLink(LoadStr(PUTTY_LICENSE_URL), LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
  252. CreateLink(LoadStr(PUTTY_URL)));
  253. UnicodeString OpenSSLVersionText = GetOpenSSLVersionText();
  254. CutToChar(OpenSSLVersionText, L' ', true); // "OpenSSL"
  255. UnicodeString OpenSSLVersion = CutToChar(OpenSSLVersionText, L' ', true);
  256. CutToChar(OpenSSLVersionText, L' ', true); // day
  257. CutToChar(OpenSSLVersionText, L' ', true); // month
  258. UnicodeString OpenSSLYear = CutToChar(OpenSSLVersionText, L' ', true);
  259. AddPara(ThirdParty,
  260. FMTLOAD(OPENSSL_BASED_ON, (OpenSSLVersion)) + Br +
  261. FMTLOAD(OPENSSL_COPYRIGHT2, (OpenSSLYear)) + Br +
  262. CreateLink(LoadStr(OPENSSL_URL)));
  263. AddPara(ThirdParty,
  264. LoadStr(FILEZILLA_BASED_ON2) + Br +
  265. LoadStr(FILEZILLA_COPYRIGHT2) + Br +
  266. CreateLink(LoadStr(FILEZILLA_URL)));
  267. AddPara(ThirdParty,
  268. FMTLOAD(NEON_BASED_ON2, (NeonVersion())) + Br +
  269. LoadStr(NEON_COPYRIGHT));
  270. AddPara(ThirdParty,
  271. FMTLOAD(S3_BASED_ON, (S3LibVersion())) + Br +
  272. LoadStr(S3_COPYRIGHT) + Br +
  273. CreateLink(LoadStr(S3_LICENSE_URL), LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
  274. CreateLink(LoadStr(S3_URL)));
  275. #define EXPAT_LICENSE_URL L"license:expat"
  276. AddPara(ThirdParty,
  277. FMTLOAD(EXPAT_BASED_ON, (ExpatVersion())) + Br +
  278. CreateLink(EXPAT_LICENSE_URL, LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
  279. CreateLink(LoadStr(EXPAT_URL)));
  280. AddBrowserLinkHandler(FThirdPartyWebBrowser, EXPAT_LICENSE_URL, ExpatLicenceHandler);
  281. #ifndef NO_COMPONENTS
  282. AddPara(ThirdParty,
  283. FMTLOAD(ABOUT_TOOLBAR2000, (Toolbar2000Version)) + Br +
  284. LoadStr(ABOUT_TOOLBAR2000_COPYRIGHT) + Br +
  285. CreateLink(LoadStr(ABOUT_TOOLBAR2000_URL)));
  286. AddPara(ThirdParty,
  287. FMTLOAD(ABOUT_TBX, (TBXVersionString)) + Br +
  288. LoadStr(ABOUT_TBX_COPYRIGHT) + Br +
  289. CreateLink(LoadStr(ABOUT_TBX_URL)));
  290. AddPara(ThirdParty,
  291. LoadStr(ABOUT_FILEMANAGER) + Br +
  292. LoadStr(ABOUT_FILEMANAGER_COPYRIGHT));
  293. #endif
  294. UnicodeString JclVersion =
  295. FormatVersion(JclVersionMajor, JclVersionMinor, JclVersionRelease);
  296. AddPara(ThirdParty,
  297. FMTLOAD(ABOUT_JCL, (JclVersion)) + Br +
  298. CreateLink(LoadStr(ABOUT_JCL_URL)));
  299. AddPara(ThirdParty,
  300. LoadStr(ABOUT_PNG) + Br +
  301. LoadStr(ABOUT_PNG_COPYRIGHT) + Br +
  302. CreateLink(LoadStr(ABOUT_PNG_URL)));
  303. ThirdParty +=
  304. L"</body>\n"
  305. L"</html>\n";
  306. std::unique_ptr<TMemoryStream> ThirdPartyStream(new TMemoryStream());
  307. UTF8String ThirdPartyUTF8 = UTF8String(ThirdParty);
  308. ThirdPartyStream->Write(ThirdPartyUTF8.c_str(), ThirdPartyUTF8.Length());
  309. ThirdPartyStream->Seek(0, 0);
  310. // For stream-loaded document, when set only after loading from OnDocumentComplete,
  311. // browser stops working
  312. SetBrowserDesignModeOff(FThirdPartyWebBrowser);
  313. TStreamAdapter * ThirdPartyStreamAdapter = new TStreamAdapter(ThirdPartyStream.get(), soReference);
  314. IPersistStreamInit * PersistStreamInit = NULL;
  315. if (DebugAlwaysTrue(FThirdPartyWebBrowser->Document != NULL) &&
  316. SUCCEEDED(FThirdPartyWebBrowser->Document->QueryInterface(IID_IPersistStreamInit, (void **)&PersistStreamInit)) &&
  317. DebugAlwaysTrue(PersistStreamInit != NULL))
  318. {
  319. PersistStreamInit->Load(static_cast<_di_IStream>(*ThirdPartyStreamAdapter));
  320. }
  321. }
  322. //---------------------------------------------------------------------------
  323. void __fastcall TAboutDialog::AddPara(UnicodeString & Text, const UnicodeString & S)
  324. {
  325. Text += L"<p>" + S + L"</p>\n";
  326. }
  327. //---------------------------------------------------------------------------
  328. UnicodeString __fastcall TAboutDialog::CreateLink(const UnicodeString & URL, const UnicodeString & Title)
  329. {
  330. return FORMAT(L"<a href=\"%s\">%s</a>", (URL, Title.IsEmpty() ? URL : Title));
  331. }
  332. //---------------------------------------------------------------------------
  333. void __fastcall TAboutDialog::LicenseButtonClick(TObject * /*Sender*/)
  334. {
  335. DoProductLicense();
  336. }
  337. //---------------------------------------------------------------------------
  338. void __fastcall TAboutDialog::HelpButtonClick(TObject * /*Sender*/)
  339. {
  340. FormHelp(this);
  341. }
  342. //---------------------------------------------------------------------------
  343. void __fastcall TAboutDialog::RegistrationProductIdLabelClick(
  344. TObject * /*Sender*/)
  345. {
  346. if (FOnRegistrationLink != NULL)
  347. {
  348. FOnRegistrationLink(this);
  349. }
  350. }
  351. //---------------------------------------------------------------------------
  352. void __fastcall TAboutDialog::OKButtonMouseDown(TObject * /*Sender*/,
  353. TMouseButton Button, TShiftState Shift, int /*X*/, int /*Y*/)
  354. {
  355. if (Button == mbRight)
  356. {
  357. if (Shift.Contains(ssAlt))
  358. {
  359. AccessViolationTest();
  360. }
  361. else if (Shift.Contains(ssCtrl))
  362. {
  363. LookupAddress();
  364. }
  365. }
  366. }
  367. //---------------------------------------------------------------------------
  368. void __fastcall TAboutDialog::LookupAddress()
  369. {
  370. UnicodeString S;
  371. if (InputQuery(L"Address lookup", L"&Address:", S))
  372. {
  373. void * Address = reinterpret_cast<void *>(StrToInt(L"$" + S));
  374. ShowMessage(GetLocationInfoStr(Address, true, true, true, true));
  375. }
  376. }
  377. //---------------------------------------------------------------------------
  378. void __fastcall TAboutDialog::AccessViolationTest()
  379. {
  380. try
  381. {
  382. ACCESS_VIOLATION_TEST;
  383. }
  384. catch (Exception & E)
  385. {
  386. throw ExtException(&E, MainInstructions(L"Internal error test."));
  387. }
  388. }
  389. //---------------------------------------------------------------------------
  390. void __fastcall TAboutDialog::ExpatLicenceHandler(TObject * /*Sender*/)
  391. {
  392. DoLicenseDialog(lcExpat);
  393. }
  394. //---------------------------------------------------------------------------
  395. void __fastcall TAboutDialog::IconPaintBoxPaint(TObject * /*Sender*/)
  396. {
  397. DrawIconEx(IconPaintBox->Canvas->Handle,
  398. 0, 0, FIconHandle, IconPaintBox->Width, IconPaintBox->Height, 0, NULL, DI_NORMAL);
  399. }
  400. //---------------------------------------------------------------------------
  401. void __fastcall TAboutDialog::Dispatch(void * Message)
  402. {
  403. TMessage * M = reinterpret_cast<TMessage*>(Message);
  404. if (M->Msg == CM_DPICHANGED)
  405. {
  406. if (FThirdPartyWebBrowser != NULL)
  407. {
  408. DoLoadThirdParty();
  409. }
  410. TForm::Dispatch(Message);
  411. }
  412. else
  413. {
  414. TForm::Dispatch(Message);
  415. }
  416. }
  417. //---------------------------------------------------------------------------