About.cpp 14 KB

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