About.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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) + Br +
  270. CreateLink(LoadStr(NEON_URL)));
  271. AddPara(ThirdParty,
  272. FMTLOAD(S3_BASED_ON, (S3LibVersion())) + Br +
  273. LoadStr(S3_COPYRIGHT) + Br +
  274. CreateLink(LoadStr(S3_LICENSE_URL), LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
  275. CreateLink(LoadStr(S3_URL)));
  276. #define EXPAT_LICENSE_URL L"license:expat"
  277. AddPara(ThirdParty,
  278. FMTLOAD(EXPAT_BASED_ON, (ExpatVersion())) + Br +
  279. CreateLink(EXPAT_LICENSE_URL, LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
  280. CreateLink(LoadStr(EXPAT_URL)));
  281. AddBrowserLinkHandler(FThirdPartyWebBrowser, EXPAT_LICENSE_URL, ExpatLicenceHandler);
  282. #ifndef NO_COMPONENTS
  283. AddPara(ThirdParty,
  284. FMTLOAD(ABOUT_TOOLBAR2000, (Toolbar2000Version)) + Br +
  285. LoadStr(ABOUT_TOOLBAR2000_COPYRIGHT) + Br +
  286. CreateLink(LoadStr(ABOUT_TOOLBAR2000_URL)));
  287. AddPara(ThirdParty,
  288. FMTLOAD(ABOUT_TBX, (TBXVersionString)) + Br +
  289. LoadStr(ABOUT_TBX_COPYRIGHT) + Br +
  290. CreateLink(LoadStr(ABOUT_TBX_URL)));
  291. AddPara(ThirdParty,
  292. LoadStr(ABOUT_FILEMANAGER) + Br +
  293. LoadStr(ABOUT_FILEMANAGER_COPYRIGHT));
  294. #endif
  295. UnicodeString JclVersion =
  296. FormatVersion(JclVersionMajor, JclVersionMinor, JclVersionRelease);
  297. AddPara(ThirdParty,
  298. FMTLOAD(ABOUT_JCL, (JclVersion)) + Br +
  299. CreateLink(LoadStr(ABOUT_JCL_URL)));
  300. AddPara(ThirdParty,
  301. LoadStr(ABOUT_PNG) + Br +
  302. LoadStr(ABOUT_PNG_COPYRIGHT) + Br +
  303. CreateLink(LoadStr(ABOUT_PNG_URL)));
  304. ThirdParty +=
  305. L"</body>\n"
  306. L"</html>\n";
  307. std::unique_ptr<TMemoryStream> ThirdPartyStream(new TMemoryStream());
  308. UTF8String ThirdPartyUTF8 = UTF8String(ThirdParty);
  309. ThirdPartyStream->Write(ThirdPartyUTF8.c_str(), ThirdPartyUTF8.Length());
  310. ThirdPartyStream->Seek(0, 0);
  311. // For stream-loaded document, when set only after loading from OnDocumentComplete,
  312. // browser stops working
  313. SetBrowserDesignModeOff(FThirdPartyWebBrowser);
  314. TStreamAdapter * ThirdPartyStreamAdapter = new TStreamAdapter(ThirdPartyStream.get(), soReference);
  315. IPersistStreamInit * PersistStreamInit = NULL;
  316. if (DebugAlwaysTrue(FThirdPartyWebBrowser->Document != NULL) &&
  317. SUCCEEDED(FThirdPartyWebBrowser->Document->QueryInterface(IID_IPersistStreamInit, (void **)&PersistStreamInit)) &&
  318. DebugAlwaysTrue(PersistStreamInit != NULL))
  319. {
  320. PersistStreamInit->Load(static_cast<_di_IStream>(*ThirdPartyStreamAdapter));
  321. }
  322. }
  323. //---------------------------------------------------------------------------
  324. void __fastcall TAboutDialog::AddPara(UnicodeString & Text, const UnicodeString & S)
  325. {
  326. Text += L"<p>" + S + L"</p>\n";
  327. }
  328. //---------------------------------------------------------------------------
  329. UnicodeString __fastcall TAboutDialog::CreateLink(const UnicodeString & URL, const UnicodeString & Title)
  330. {
  331. return FORMAT(L"<a href=\"%s\">%s</a>", (URL, Title.IsEmpty() ? URL : Title));
  332. }
  333. //---------------------------------------------------------------------------
  334. void __fastcall TAboutDialog::LicenseButtonClick(TObject * /*Sender*/)
  335. {
  336. DoProductLicense();
  337. }
  338. //---------------------------------------------------------------------------
  339. void __fastcall TAboutDialog::HelpButtonClick(TObject * /*Sender*/)
  340. {
  341. FormHelp(this);
  342. }
  343. //---------------------------------------------------------------------------
  344. void __fastcall TAboutDialog::RegistrationProductIdLabelClick(
  345. TObject * /*Sender*/)
  346. {
  347. if (FOnRegistrationLink != NULL)
  348. {
  349. FOnRegistrationLink(this);
  350. }
  351. }
  352. //---------------------------------------------------------------------------
  353. void __fastcall TAboutDialog::OKButtonMouseDown(TObject * /*Sender*/,
  354. TMouseButton Button, TShiftState Shift, int /*X*/, int /*Y*/)
  355. {
  356. if (Button == mbRight)
  357. {
  358. if (Shift.Contains(ssAlt))
  359. {
  360. AccessViolationTest();
  361. }
  362. else if (Shift.Contains(ssCtrl))
  363. {
  364. LookupAddress();
  365. }
  366. }
  367. }
  368. //---------------------------------------------------------------------------
  369. void __fastcall TAboutDialog::LookupAddress()
  370. {
  371. UnicodeString S;
  372. if (InputQuery(L"Address lookup", L"&Address:", S))
  373. {
  374. void * Address = reinterpret_cast<void *>(StrToInt(L"$" + S));
  375. ShowMessage(GetLocationInfoStr(Address, true, true, true, true));
  376. }
  377. }
  378. //---------------------------------------------------------------------------
  379. void __fastcall TAboutDialog::AccessViolationTest()
  380. {
  381. try
  382. {
  383. ACCESS_VIOLATION_TEST;
  384. }
  385. catch (Exception & E)
  386. {
  387. throw ExtException(&E, MainInstructions(L"Internal error test."));
  388. }
  389. }
  390. //---------------------------------------------------------------------------
  391. void __fastcall TAboutDialog::ExpatLicenceHandler(TObject * /*Sender*/)
  392. {
  393. DoLicenseDialog(lcExpat);
  394. }
  395. //---------------------------------------------------------------------------
  396. void __fastcall TAboutDialog::IconPaintBoxPaint(TObject * /*Sender*/)
  397. {
  398. DrawIconEx(IconPaintBox->Canvas->Handle,
  399. 0, 0, FIconHandle, IconPaintBox->Width, IconPaintBox->Height, 0, NULL, DI_NORMAL);
  400. }
  401. //---------------------------------------------------------------------------
  402. void __fastcall TAboutDialog::Dispatch(void * Message)
  403. {
  404. TMessage * M = reinterpret_cast<TMessage*>(Message);
  405. if (M->Msg == CM_DPICHANGED)
  406. {
  407. if (FThirdPartyWebBrowser != NULL)
  408. {
  409. DoLoadThirdParty();
  410. }
  411. TForm::Dispatch(Message);
  412. }
  413. else
  414. {
  415. TForm::Dispatch(Message);
  416. }
  417. }
  418. //---------------------------------------------------------------------------