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