About.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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->ParentFont = true;
  75. ApplicationLabel->Font->Style = ApplicationLabel->Font->Style << fsBold;
  76. ApplicationLabel->Caption = AppName;
  77. WinSCPCopyrightLabel->Caption = LoadStr(WINSCP_COPYRIGHT);
  78. if (Registration == NULL)
  79. {
  80. RegistrationLabel->Visible = false;
  81. RegistrationBox->Visible = false;
  82. ClientHeight = ClientHeight -
  83. (ThirdPartyPanel->Top - RegistrationBox->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 = DialogImageSize(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::LoadData()
  139. {
  140. UnicodeString Version = FConfiguration->VersionStr;
  141. if (!FConfiguration->ProductName.IsEmpty() &&
  142. (FConfiguration->Version != FConfiguration->ProductVersion))
  143. {
  144. Version = FMTLOAD(ABOUT_BASED_ON_PRODUCT,
  145. (Version, FConfiguration->ProductName, FConfiguration->ProductVersion));
  146. }
  147. VersionLabel->Caption = Version;
  148. }
  149. //---------------------------------------------------------------------------
  150. void __fastcall TAboutDialog::LoadThirdParty()
  151. {
  152. FThirdPartyWebBrowser = CreateBrowserViewer(ThirdPartyPanel, L"");
  153. reinterpret_cast<TLabel *>(FThirdPartyWebBrowser)->Color = clBtnFace;
  154. NavigateBrowserToUrl(FThirdPartyWebBrowser, L"about:blank");
  155. DoLoadThirdParty();
  156. }
  157. //---------------------------------------------------------------------------
  158. void __fastcall TAboutDialog::DoLoadThirdParty()
  159. {
  160. while (FThirdPartyWebBrowser->ReadyState < ::READYSTATE_INTERACTIVE)
  161. {
  162. Application->ProcessMessages();
  163. }
  164. std::unique_ptr<TFont> DefaultFont(new TFont());
  165. DefaultFont->Assign(Application->DefaultFont);
  166. DefaultFont->Height = ScaleByPixelsPerInchFromSystem(DefaultFont->Height, this);
  167. UnicodeString ThirdParty;
  168. ThirdParty +=
  169. L"<!DOCTYPE html>\n"
  170. L"<meta charset=\"utf-8\">\n"
  171. L"<html>\n"
  172. L"<head>\n"
  173. L"<style>\n"
  174. L"\n"
  175. L"body\n"
  176. L"{\n"
  177. L" font-family: '" + DefaultFont->Name + L"';\n"
  178. L" margin: 0.5em;\n"
  179. L" background-color: " + ColorToWebColorStr(Color) + L";\n"
  180. L"}\n"
  181. L"\n"
  182. L"body\n"
  183. L"{\n"
  184. L" font-size: " + IntToStr(DefaultFont->Size) + L"pt;\n"
  185. L"}\n"
  186. L"\n"
  187. L"p\n"
  188. L"{\n"
  189. L" margin-top: 0;\n"
  190. L" margin-bottom: 1em;\n"
  191. L"}\n"
  192. L"\n"
  193. L"a, a:visited, a:hover, a:visited, a:current\n"
  194. L"{\n"
  195. L" color: " + ColorToWebColorStr(LinkColor) + L";\n"
  196. L"}\n"
  197. L"</style>\n"
  198. L"</head>\n"
  199. L"<body>\n";
  200. UnicodeString Br = "<br/>\n";
  201. if (GUIConfiguration->AppliedLocale != GUIConfiguration->InternalLocale())
  202. {
  203. UnicodeString TranslatorUrl = LoadStr(TRANSLATOR_URL);
  204. UnicodeString TranslatorInfo = LoadStr(TRANSLATOR_INFO2);
  205. wchar_t LocaleNameStr[255];
  206. GetLocaleInfo(
  207. GUIConfiguration->AppliedLocale, LOCALE_SLOCALIZEDLANGUAGENAME,
  208. LocaleNameStr, LENOF(LocaleNameStr));
  209. UnicodeString LocaleName(LocaleNameStr);
  210. // The {language} should be present only if we are using an untranslated
  211. // (=english) string
  212. UnicodeString TranslationHeader = ReplaceStr(LoadStr(ABOUT_TRANSLATIONS_HEADER), L"{language}", LocaleName);
  213. AddPara(ThirdParty,
  214. TranslationHeader + Br +
  215. FMTLOAD(ABOUT_TRANSLATIONS_COPYRIGHT, (GUIConfiguration->AppliedLocaleCopyright())) + Br +
  216. (!TranslatorInfo.IsEmpty() ? TranslatorInfo + Br : UnicodeString()) +
  217. (!TranslatorUrl.IsEmpty() ? CreateLink(TranslatorUrl) : UnicodeString()));
  218. }
  219. AddPara(ThirdParty, LoadStr(ABOUT_THIRDPARTY_HEADER));
  220. AddPara(ThirdParty,
  221. FMTLOAD(PUTTY_BASED_ON, (GetPuTTYVersion())) + Br +
  222. LoadStr(PUTTY_COPYRIGHT) + Br +
  223. CreateLink(LoadStr(PUTTY_LICENSE_URL), LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
  224. CreateLink(LoadStr(PUTTY_URL)));
  225. UnicodeString OpenSSLVersionText = GetOpenSSLVersionText();
  226. CutToChar(OpenSSLVersionText, L' ', true); // "OpenSSL"
  227. UnicodeString OpenSSLVersion = CutToChar(OpenSSLVersionText, L' ', true);
  228. CutToChar(OpenSSLVersionText, L' ', true); // day
  229. CutToChar(OpenSSLVersionText, L' ', true); // month
  230. UnicodeString OpenSSLYear = CutToChar(OpenSSLVersionText, L' ', true);
  231. AddPara(ThirdParty,
  232. FMTLOAD(OPENSSL_BASED_ON, (OpenSSLVersion)) + Br +
  233. FMTLOAD(OPENSSL_COPYRIGHT2, (OpenSSLYear)) + Br +
  234. CreateLink(LoadStr(OPENSSL_URL)));
  235. AddPara(ThirdParty,
  236. LoadStr(FILEZILLA_BASED_ON2) + Br +
  237. LoadStr(FILEZILLA_COPYRIGHT2) + Br +
  238. CreateLink(LoadStr(FILEZILLA_URL)));
  239. AddPara(ThirdParty,
  240. FMTLOAD(NEON_BASED_ON2, (NeonVersion())) + Br +
  241. LoadStr(NEON_COPYRIGHT) + Br +
  242. CreateLink(LoadStr(NEON_URL)));
  243. AddPara(ThirdParty,
  244. FMTLOAD(S3_BASED_ON, (S3LibVersion())) + Br +
  245. LoadStr(S3_COPYRIGHT) + Br +
  246. CreateLink(LoadStr(S3_LICENSE_URL), LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
  247. CreateLink(LoadStr(S3_URL)));
  248. #define EXPAT_LICENSE_URL L"license:expat"
  249. AddPara(ThirdParty,
  250. FMTLOAD(EXPAT_BASED_ON, (ExpatVersion())) + Br +
  251. CreateLink(EXPAT_LICENSE_URL, LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
  252. CreateLink(LoadStr(EXPAT_URL)));
  253. AddBrowserLinkHandler(FThirdPartyWebBrowser, EXPAT_LICENSE_URL, ExpatLicenceHandler);
  254. #ifndef NO_COMPONENTS
  255. AddPara(ThirdParty,
  256. FMTLOAD(ABOUT_TOOLBAR2000, (Toolbar2000Version)) + Br +
  257. LoadStr(ABOUT_TOOLBAR2000_COPYRIGHT) + Br +
  258. CreateLink(LoadStr(ABOUT_TOOLBAR2000_URL)));
  259. AddPara(ThirdParty,
  260. FMTLOAD(ABOUT_TBX, (TBXVersionString)) + Br +
  261. LoadStr(ABOUT_TBX_COPYRIGHT) + Br +
  262. CreateLink(LoadStr(ABOUT_TBX_URL)));
  263. AddPara(ThirdParty,
  264. LoadStr(ABOUT_FILEMANAGER) + Br +
  265. LoadStr(ABOUT_FILEMANAGER_COPYRIGHT));
  266. #endif
  267. UnicodeString JclVersion =
  268. FormatVersion(JclVersionMajor, JclVersionMinor, JclVersionRelease);
  269. AddPara(ThirdParty,
  270. FMTLOAD(ABOUT_JCL, (JclVersion)) + Br +
  271. CreateLink(LoadStr(ABOUT_JCL_URL)));
  272. AddPara(ThirdParty,
  273. LoadStr(ABOUT_PNG) + Br +
  274. LoadStr(ABOUT_PNG_COPYRIGHT) + Br +
  275. CreateLink(LoadStr(ABOUT_PNG_URL)));
  276. ThirdParty +=
  277. L"</body>\n"
  278. L"</html>\n";
  279. std::unique_ptr<TMemoryStream> ThirdPartyStream(new TMemoryStream());
  280. UTF8String ThirdPartyUTF8 = UTF8String(ThirdParty);
  281. ThirdPartyStream->Write(ThirdPartyUTF8.c_str(), ThirdPartyUTF8.Length());
  282. ThirdPartyStream->Seek(0, 0);
  283. // For stream-loaded document, when set only after loading from OnDocumentComplete,
  284. // browser stops working
  285. SetBrowserDesignModeOff(FThirdPartyWebBrowser);
  286. TStreamAdapter * ThirdPartyStreamAdapter = new TStreamAdapter(ThirdPartyStream.get(), soReference);
  287. IPersistStreamInit * PersistStreamInit = NULL;
  288. if (DebugAlwaysTrue(FThirdPartyWebBrowser->Document != NULL) &&
  289. SUCCEEDED(FThirdPartyWebBrowser->Document->QueryInterface(IID_IPersistStreamInit, (void **)&PersistStreamInit)) &&
  290. DebugAlwaysTrue(PersistStreamInit != NULL))
  291. {
  292. PersistStreamInit->Load(static_cast<_di_IStream>(*ThirdPartyStreamAdapter));
  293. }
  294. }
  295. //---------------------------------------------------------------------------
  296. void __fastcall TAboutDialog::AddPara(UnicodeString & Text, const UnicodeString & S)
  297. {
  298. Text += L"<p>" + S + L"</p>\n";
  299. }
  300. //---------------------------------------------------------------------------
  301. UnicodeString __fastcall TAboutDialog::CreateLink(const UnicodeString & URL, const UnicodeString & Title)
  302. {
  303. return FORMAT(L"<a href=\"%s\">%s</a>", (URL, Title.IsEmpty() ? URL : Title));
  304. }
  305. //---------------------------------------------------------------------------
  306. void __fastcall TAboutDialog::LicenseButtonClick(TObject * /*Sender*/)
  307. {
  308. DoProductLicense();
  309. }
  310. //---------------------------------------------------------------------------
  311. void __fastcall TAboutDialog::HelpButtonClick(TObject * /*Sender*/)
  312. {
  313. FormHelp(this);
  314. }
  315. //---------------------------------------------------------------------------
  316. void __fastcall TAboutDialog::RegistrationProductIdLabelClick(
  317. TObject * /*Sender*/)
  318. {
  319. if (FOnRegistrationLink != NULL)
  320. {
  321. FOnRegistrationLink(this);
  322. }
  323. }
  324. //---------------------------------------------------------------------------
  325. void __fastcall TAboutDialog::OKButtonMouseDown(TObject * /*Sender*/,
  326. TMouseButton Button, TShiftState Shift, int /*X*/, int /*Y*/)
  327. {
  328. if (Button == mbRight)
  329. {
  330. if (Shift.Contains(ssAlt))
  331. {
  332. AccessViolationTest();
  333. }
  334. else if (Shift.Contains(ssCtrl))
  335. {
  336. LookupAddress();
  337. }
  338. }
  339. }
  340. //---------------------------------------------------------------------------
  341. void __fastcall TAboutDialog::LookupAddress()
  342. {
  343. UnicodeString S;
  344. if (InputQuery(L"Address lookup", L"&Address:", S))
  345. {
  346. void * Address = reinterpret_cast<void *>(StrToInt(L"$" + S));
  347. ShowMessage(GetLocationInfoStr(Address, true, true, true, true));
  348. }
  349. }
  350. //---------------------------------------------------------------------------
  351. void __fastcall TAboutDialog::AccessViolationTest()
  352. {
  353. try
  354. {
  355. ACCESS_VIOLATION_TEST;
  356. }
  357. catch (Exception & E)
  358. {
  359. throw ExtException(&E, MainInstructions(L"Internal error test."));
  360. }
  361. }
  362. //---------------------------------------------------------------------------
  363. void __fastcall TAboutDialog::ExpatLicenceHandler(TObject * /*Sender*/)
  364. {
  365. DoLicenseDialog(lcExpat);
  366. }
  367. //---------------------------------------------------------------------------
  368. void __fastcall TAboutDialog::IconPaintBoxPaint(TObject * /*Sender*/)
  369. {
  370. DrawIconEx(IconPaintBox->Canvas->Handle,
  371. 0, 0, FIconHandle, IconPaintBox->Width, IconPaintBox->Height, 0, NULL, DI_NORMAL);
  372. }
  373. //---------------------------------------------------------------------------
  374. void __fastcall TAboutDialog::Dispatch(void * Message)
  375. {
  376. TMessage * M = reinterpret_cast<TMessage*>(Message);
  377. if (M->Msg == CM_DPICHANGED)
  378. {
  379. if (FThirdPartyWebBrowser != NULL)
  380. {
  381. DoLoadThirdParty();
  382. }
  383. TForm::Dispatch(Message);
  384. }
  385. else
  386. {
  387. TForm::Dispatch(Message);
  388. }
  389. }
  390. //---------------------------------------------------------------------------