About.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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();
  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. TWebBrowserEx * ThirdPartyWebBrowser =
  154. CreateBrowserViewer(ThirdPartyPanel, L"");
  155. reinterpret_cast<TLabel *>(ThirdPartyWebBrowser)->Color = clBtnFace;
  156. ThirdPartyWebBrowser->Navigate(L"about:blank");
  157. while (ThirdPartyWebBrowser->ReadyState < ::READYSTATE_INTERACTIVE)
  158. {
  159. Application->ProcessMessages();
  160. }
  161. std::unique_ptr<TFont> DefaultFont(new TFont());
  162. UnicodeString ThirdParty;
  163. ThirdParty +=
  164. L"<!DOCTYPE html>\n"
  165. L"<meta charset=\"utf-8\">\n"
  166. L"<html>\n"
  167. L"<head>\n"
  168. L"<style>\n"
  169. L"\n"
  170. L"body\n"
  171. L"{\n"
  172. L" font-family: '" + DefaultFont->Name + L"';\n"
  173. L" margin: 0.5em;\n"
  174. L" background-color: " + ColorToWebColorStr(Color) + L";\n"
  175. L"}\n"
  176. L"\n"
  177. L"body\n"
  178. L"{\n"
  179. L" font-size: " + IntToStr(DefaultFont->Size) + L"pt;\n"
  180. L"}\n"
  181. L"\n"
  182. L"p\n"
  183. L"{\n"
  184. L" margin-top: 0;\n"
  185. L" margin-bottom: 1em;\n"
  186. L"}\n"
  187. L"\n"
  188. L"a, a:visited, a:hover, a:visited, a:current\n"
  189. L"{\n"
  190. L" color: " + ColorToWebColorStr(LinkColor) + L";\n"
  191. L"}\n"
  192. L"</style>\n"
  193. L"</head>\n"
  194. L"<body>\n";
  195. UnicodeString Br = "<br/>\n";
  196. if (GUIConfiguration->AppliedLocale != GUIConfiguration->InternalLocale())
  197. {
  198. UnicodeString TranslatorUrl = LoadStr(TRANSLATOR_URL);
  199. UnicodeString TranslatorInfo = LoadStr(TRANSLATOR_INFO2);
  200. AddPara(ThirdParty,
  201. LoadStr(ABOUT_TRANSLATIONS_HEADER) + Br +
  202. FMTLOAD(ABOUT_TRANSLATIONS_COPYRIGHT, (GUIConfiguration->LocaleCopyright())) + Br +
  203. (!TranslatorInfo.IsEmpty() ? TranslatorInfo + Br : UnicodeString()) +
  204. (!TranslatorUrl.IsEmpty() ? CreateLink(TranslatorUrl) : UnicodeString()));
  205. }
  206. AddPara(ThirdParty, LoadStr(ABOUT_THIRDPARTY_HEADER));
  207. AddPara(ThirdParty,
  208. FMTLOAD(PUTTY_BASED_ON, (GetPuTTYVersion())) + Br +
  209. LoadStr(PUTTY_COPYRIGHT) + Br +
  210. CreateLink(LoadStr(PUTTY_LICENSE_URL), LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
  211. CreateLink(LoadStr(PUTTY_URL)));
  212. #ifndef NO_FILEZILLA
  213. UnicodeString OpenSSLVersionText = GetOpenSSLVersionText();
  214. CutToChar(OpenSSLVersionText, L' ', true); // "OpenSSL"
  215. UnicodeString OpenSSLVersion = CutToChar(OpenSSLVersionText, L' ', true);
  216. CutToChar(OpenSSLVersionText, L' ', true); // day
  217. CutToChar(OpenSSLVersionText, L' ', true); // month
  218. UnicodeString OpenSSLYear = CutToChar(OpenSSLVersionText, L' ', true);
  219. AddPara(ThirdParty,
  220. FMTLOAD(OPENSSL_BASED_ON, (OpenSSLVersion)) + Br +
  221. FMTLOAD(OPENSSL_COPYRIGHT2, (OpenSSLYear)) + Br +
  222. CreateLink(LoadStr(OPENSSL_URL)));
  223. AddPara(ThirdParty,
  224. LoadStr(FILEZILLA_BASED_ON2) + Br +
  225. LoadStr(FILEZILLA_COPYRIGHT2) + Br +
  226. CreateLink(LoadStr(FILEZILLA_URL)));
  227. #endif
  228. AddPara(ThirdParty,
  229. FMTLOAD(NEON_BASED_ON, (NeonVersion())) + Br +
  230. LoadStr(NEON_COPYRIGHT) + Br +
  231. CreateLink(LoadStr(NEON_URL)));
  232. #define EXPAT_LICENSE_URL L"license:expat"
  233. AddPara(ThirdParty,
  234. FMTLOAD(EXPAT_BASED_ON, (ExpatVersion())) + Br +
  235. CreateLink(EXPAT_LICENSE_URL, LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
  236. CreateLink(LoadStr(EXPAT_URL)));
  237. AddBrowserLinkHandler(ThirdPartyWebBrowser, EXPAT_LICENSE_URL, ExpatLicenceHandler);
  238. #ifndef NO_COMPONENTS
  239. AddPara(ThirdParty,
  240. FMTLOAD(ABOUT_TOOLBAR2000, (Toolbar2000Version)) + Br +
  241. LoadStr(ABOUT_TOOLBAR2000_COPYRIGHT) + Br +
  242. CreateLink(LoadStr(ABOUT_TOOLBAR2000_URL)));
  243. AddPara(ThirdParty,
  244. FMTLOAD(ABOUT_TBX, (TBXVersionString)) + Br +
  245. LoadStr(ABOUT_TBX_COPYRIGHT) + Br +
  246. CreateLink(LoadStr(ABOUT_TBX_URL)));
  247. AddPara(ThirdParty,
  248. LoadStr(ABOUT_FILEMANAGER) + Br +
  249. LoadStr(ABOUT_FILEMANAGER_COPYRIGHT));
  250. #endif
  251. UnicodeString JclVersion =
  252. FormatVersion(JclVersionMajor, JclVersionMinor, JclVersionRelease);
  253. AddPara(ThirdParty,
  254. FMTLOAD(ABOUT_JCL, (JclVersion)) + Br +
  255. CreateLink(LoadStr(ABOUT_JCL_URL)));
  256. AddPara(ThirdParty,
  257. LoadStr(ABOUT_PNG) + Br +
  258. LoadStr(ABOUT_PNG_COPYRIGHT) + Br +
  259. CreateLink(LoadStr(ABOUT_PNG_URL)));
  260. ThirdParty +=
  261. L"</body>\n"
  262. L"</html>\n";
  263. std::unique_ptr<TMemoryStream> ThirdPartyStream(new TMemoryStream());
  264. UTF8String ThirdPartyUTF8 = UTF8String(ThirdParty);
  265. ThirdPartyStream->Write(ThirdPartyUTF8.c_str(), ThirdPartyUTF8.Length());
  266. ThirdPartyStream->Seek(0, 0);
  267. // For stream-loaded document, when set only after loading from OnDocumentComplete,
  268. // browser stops working
  269. SetBrowserDesignModeOff(ThirdPartyWebBrowser);
  270. TStreamAdapter * ThirdPartyStreamAdapter = new TStreamAdapter(ThirdPartyStream.get(), soReference);
  271. IPersistStreamInit * PersistStreamInit = NULL;
  272. if (ALWAYS_TRUE(ThirdPartyWebBrowser->Document != NULL) &&
  273. SUCCEEDED(ThirdPartyWebBrowser->Document->QueryInterface(IID_IPersistStreamInit, (void **)&PersistStreamInit)) &&
  274. ALWAYS_TRUE(PersistStreamInit != NULL))
  275. {
  276. PersistStreamInit->Load(static_cast<_di_IStream>(*ThirdPartyStreamAdapter));
  277. }
  278. }
  279. //---------------------------------------------------------------------------
  280. void __fastcall TAboutDialog::AddPara(UnicodeString & Text, const UnicodeString & S)
  281. {
  282. Text += L"<p>" + S + L"</p>\n";
  283. }
  284. //---------------------------------------------------------------------------
  285. UnicodeString __fastcall TAboutDialog::CreateLink(const UnicodeString & URL, const UnicodeString & Title)
  286. {
  287. return FORMAT(L"<a href=\"%s\">%s</a>", (URL, Title.IsEmpty() ? URL : Title));
  288. }
  289. //---------------------------------------------------------------------------
  290. void __fastcall TAboutDialog::LicenseButtonClick(TObject * /*Sender*/)
  291. {
  292. DoProductLicense();
  293. }
  294. //---------------------------------------------------------------------------
  295. void __fastcall TAboutDialog::HelpButtonClick(TObject * /*Sender*/)
  296. {
  297. FormHelp(this);
  298. }
  299. //---------------------------------------------------------------------------
  300. void __fastcall TAboutDialog::RegistrationProductIdLabelClick(
  301. TObject * /*Sender*/)
  302. {
  303. if (FOnRegistrationLink != NULL)
  304. {
  305. FOnRegistrationLink(this);
  306. }
  307. }
  308. //---------------------------------------------------------------------------
  309. void __fastcall TAboutDialog::OKButtonMouseDown(TObject * /*Sender*/,
  310. TMouseButton Button, TShiftState Shift, int /*X*/, int /*Y*/)
  311. {
  312. if (Button == mbRight)
  313. {
  314. if (Shift.Contains(ssAlt))
  315. {
  316. AccessViolationTest();
  317. }
  318. else if (Shift.Contains(ssCtrl))
  319. {
  320. LookupAddress();
  321. }
  322. }
  323. }
  324. //---------------------------------------------------------------------------
  325. void __fastcall TAboutDialog::LookupAddress()
  326. {
  327. UnicodeString S;
  328. if (InputQuery(L"Address lookup", L"&Address:", S))
  329. {
  330. void * Address = reinterpret_cast<void *>(StrToInt(L"$" + S));
  331. ShowMessage(GetLocationInfoStr(Address, true, true, true, true));
  332. }
  333. }
  334. //---------------------------------------------------------------------------
  335. void __fastcall TAboutDialog::AccessViolationTest()
  336. {
  337. try
  338. {
  339. ACCESS_VIOLATION_TEST;
  340. }
  341. catch (Exception & E)
  342. {
  343. throw ExtException(&E, MainInstructions(L"Internal error test."));
  344. }
  345. }
  346. //---------------------------------------------------------------------------
  347. void __fastcall TAboutDialog::ExpatLicenceHandler(TObject * /*Sender*/)
  348. {
  349. DoLicenseDialog(lcExpat);
  350. }
  351. //---------------------------------------------------------------------------
  352. void __fastcall TAboutDialog::IconPaintBoxPaint(TObject * /*Sender*/)
  353. {
  354. DrawIconEx(IconPaintBox->Canvas->Handle,
  355. 0, 0, FIconHandle, IconPaintBox->Width, IconPaintBox->Height, 0, NULL, DI_NORMAL);
  356. }
  357. //---------------------------------------------------------------------------