About.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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 "WinInterface.h"
  12. #include "About.h"
  13. #include "TextsCore.h"
  14. #include "TextsWin.h"
  15. #ifndef NO_COMPONENTS
  16. // must be included before WebBrowserEx.hpp to avoid ambiguity of tagLOGFONTW
  17. #include <TB2Version.hpp>
  18. #include <TBX.hpp>
  19. #endif
  20. #include <WebBrowserEx.hpp>
  21. #include <JclBase.hpp>
  22. #include <StrUtils.hpp>
  23. #ifndef NO_FILEZILLA
  24. #include <FtpFileSystem.h>
  25. #endif
  26. //---------------------------------------------------------------------
  27. #pragma link "SHDocVw_OCX"
  28. #ifndef NO_RESOURCES
  29. #pragma resource "*.dfm"
  30. #endif
  31. //---------------------------------------------------------------------------
  32. static void __fastcall DoAboutDialog(TConfiguration * Configuration,
  33. bool AllowLicense, TRegistration * Registration, bool LoadThirdParty)
  34. {
  35. TAboutDialog * AboutDialog = NULL;
  36. try
  37. {
  38. AboutDialog = new TAboutDialog(Application, Configuration, AllowLicense,
  39. Registration, LoadThirdParty);
  40. AboutDialog->ShowModal();
  41. }
  42. __finally
  43. {
  44. delete AboutDialog;
  45. }
  46. }
  47. //---------------------------------------------------------------------------
  48. void __fastcall DoAboutDialog(TConfiguration * Configuration,
  49. bool AllowLicense, TRegistration * Registration)
  50. {
  51. try
  52. {
  53. DoAboutDialog(Configuration, AllowLicense, Registration, true);
  54. }
  55. catch (EOleException & E)
  56. {
  57. // This happens particularly on Wine that's does not support some
  58. // functionality of embedded IE we need.
  59. DoAboutDialog(Configuration, AllowLicense, Registration, false);
  60. }
  61. }
  62. //---------------------------------------------------------------------------
  63. __fastcall TAboutDialog::TAboutDialog(TComponent * AOwner,
  64. TConfiguration * Configuration, bool AllowLicense, TRegistration * Registration,
  65. bool ALoadThirdParty)
  66. : TForm(AOwner)
  67. {
  68. FConfiguration = Configuration;
  69. UseSystemSettings(this);
  70. LinkLabel(HomepageLabel, LoadStr(HOMEPAGE_URL));
  71. LinkLabel(ForumUrlLabel, LoadStr(FORUM_URL));
  72. ApplicationLabel->ParentFont = true;
  73. ApplicationLabel->Font->Style = ApplicationLabel->Font->Style << fsBold;
  74. ApplicationLabel->Caption = AppName;
  75. WinSCPCopyrightLabel->Caption = LoadStr(WINSCP_COPYRIGHT);
  76. UnicodeString Translator = LoadStr(TRANSLATOR_INFO);
  77. if (Registration == NULL)
  78. {
  79. RegistrationLabel->Visible = false;
  80. RegistrationBox->Visible = false;
  81. ClientHeight = ClientHeight -
  82. (ThirdPartyPanel->Top - RegistrationBox->Top);
  83. }
  84. else
  85. {
  86. RegistrationSubjectLabel->Caption = Registration->Subject;
  87. if (Registration->Registered)
  88. {
  89. UnicodeString Text;
  90. Text = FORMAT(LoadStrPart(ABOUT_REGISTRATION_LICENSES, 1),
  91. (Registration->Licenses >= 0 ? IntToStr(Registration->Licenses) :
  92. UnicodeString(LoadStrPart(ABOUT_REGISTRATION_LICENSES, 2))));
  93. if (!Registration->NeverExpires)
  94. {
  95. Text = FMTLOAD(ABOUT_REGISTRATION_EXPIRES,
  96. (Text, FormatDateTime(L"ddddd", Registration->Expiration)));
  97. }
  98. RegistrationLicensesLabel->Caption = Text;
  99. Text = FMTLOAD(ABOUT_REGISTRATION_PRODUCTID, (Registration->ProductId));
  100. if (Registration->EduLicense)
  101. {
  102. Text = FMTLOAD(ABOUT_REGISTRATION_EDULICENSE, (Text));
  103. }
  104. RegistrationProductIdLabel->Caption = Text;
  105. RegistrationProductIdLabel->Font->Style =
  106. RegistrationProductIdLabel->Font->Style << fsBold;
  107. }
  108. else
  109. {
  110. RegistrationLicensesLabel->Visible = false;
  111. FOnRegistrationLink = Registration->OnRegistrationLink;
  112. RegistrationProductIdLabel->Caption = LoadStr(ABOUT_REGISTRATION_LINK);
  113. LinkLabel(RegistrationProductIdLabel, L"");
  114. }
  115. }
  116. if (Translator.IsEmpty())
  117. {
  118. TranslatorLabel->Visible = false;
  119. TranslatorUrlLabel->Visible = false;
  120. ClientHeight = ClientHeight -
  121. (TranslatorLabel->Top - ProductSpecificMessageLabel->Top);
  122. }
  123. else
  124. {
  125. TranslatorLabel->Caption = LoadStr(TRANSLATOR_INFO);
  126. UnicodeString TranslatorUrl = LoadStr(TRANSLATOR_URL);
  127. if (!TranslatorUrl.IsEmpty())
  128. {
  129. LinkLabel(TranslatorUrlLabel, TranslatorUrl);
  130. }
  131. else
  132. {
  133. TranslatorUrlLabel->Visible = false;
  134. // allow two lines of text, if there's no URL
  135. TranslatorLabel->AutoSize = false;
  136. TranslatorLabel->Width = ThirdPartyPanel->Width;
  137. TranslatorLabel->Height = TranslatorLabel->Height * 2;
  138. TranslatorLabel->WordWrap = true;
  139. }
  140. }
  141. LicenseButton->Visible = AllowLicense;
  142. LoadData();
  143. if (ALoadThirdParty)
  144. {
  145. LoadThirdParty();
  146. }
  147. else
  148. {
  149. CreateLabelPanel(ThirdPartyPanel, LoadStr(MESSAGE_DISPLAY_ERROR));
  150. }
  151. }
  152. //---------------------------------------------------------------------------
  153. void __fastcall TAboutDialog::LoadData()
  154. {
  155. UnicodeString Version = FConfiguration->VersionStr;
  156. if (!FConfiguration->ProductName.IsEmpty() &&
  157. (FConfiguration->Version != FConfiguration->ProductVersion))
  158. {
  159. Version = FMTLOAD(ABOUT_BASED_ON_PRODUCT,
  160. (Version, FConfiguration->ProductName, FConfiguration->ProductVersion));
  161. }
  162. VersionLabel->Caption = Version;
  163. }
  164. //---------------------------------------------------------------------------
  165. void __fastcall TAboutDialog::LoadThirdParty()
  166. {
  167. TWebBrowserEx * ThirdPartyWebBrowser =
  168. CreateBrowserViewer(ThirdPartyPanel, L"");
  169. reinterpret_cast<TLabel *>(ThirdPartyWebBrowser)->Color = clBtnFace;
  170. ThirdPartyWebBrowser->Navigate(L"about:blank");
  171. while (ThirdPartyWebBrowser->ReadyState < ::READYSTATE_INTERACTIVE)
  172. {
  173. Application->ProcessMessages();
  174. }
  175. std::unique_ptr<TFont> DefaultFont(new TFont());
  176. UnicodeString ThirdParty;
  177. ThirdParty +=
  178. L"<!DOCTYPE html>\n"
  179. L"<meta charset=\"utf-8\">\n"
  180. L"<html>\n"
  181. L"<head>\n"
  182. L"<style>\n"
  183. L"\n"
  184. L"body\n"
  185. L"{\n"
  186. L" font-family: '" + DefaultFont->Name + L"';\n"
  187. L" margin: 0.5em;\n"
  188. L" background-color: " + ColorToWebColorStr(Color) + L";\n"
  189. L"}\n"
  190. L"\n"
  191. L"body\n"
  192. L"{\n"
  193. L" font-size: " + IntToStr(DefaultFont->Size) + L"pt;\n"
  194. L"}\n"
  195. L"\n"
  196. L"p\n"
  197. L"{\n"
  198. L" margin-top: 0;\n"
  199. L" margin-bottom: 1em;\n"
  200. L"}\n"
  201. L"\n"
  202. L"a, a:visited, a:hover, a:visited, a:current\n"
  203. L"{\n"
  204. L" color: " + ColorToWebColorStr(LinkColor) + L";\n"
  205. L"}\n"
  206. L"</style>\n"
  207. L"</head>\n"
  208. L"<body>\n";
  209. UnicodeString Br = "<br/>\n";
  210. AddPara(ThirdParty, LoadStr(ABOUT_THIRDPARTY_HEADER));
  211. AddPara(ThirdParty,
  212. FMTLOAD(PUTTY_BASED_ON, (LoadStr(PUTTY_VERSION))) + Br +
  213. LoadStr(PUTTY_COPYRIGHT) + Br +
  214. CreateLink(LoadStr(PUTTY_LICENSE_URL), LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
  215. CreateLink(LoadStr(PUTTY_URL)));
  216. #ifndef NO_FILEZILLA
  217. UnicodeString OpenSSLVersionText = GetOpenSSLVersionText();
  218. CutToChar(OpenSSLVersionText, L' ', true); // "OpenSSL"
  219. UnicodeString OpenSSLVersion = CutToChar(OpenSSLVersionText, L' ', true);
  220. CutToChar(OpenSSLVersionText, L' ', true); // day
  221. CutToChar(OpenSSLVersionText, L' ', true); // month
  222. UnicodeString OpenSSLYear = CutToChar(OpenSSLVersionText, L' ', true);
  223. AddPara(ThirdParty,
  224. FMTLOAD(OPENSSL_BASED_ON, (OpenSSLVersion)) + Br +
  225. FMTLOAD(OPENSSL_COPYRIGHT2, (OpenSSLYear)) + Br +
  226. CreateLink(LoadStr(OPENSSL_URL)));
  227. AddPara(ThirdParty,
  228. LoadStr(FILEZILLA_BASED_ON2) + Br +
  229. LoadStr(FILEZILLA_COPYRIGHT2) + Br +
  230. CreateLink(LoadStr(FILEZILLA_URL)));
  231. #endif
  232. AddPara(ThirdParty,
  233. FMTLOAD(NEON_BASED_ON, (NeonVersion())) + Br +
  234. LoadStr(NEON_COPYRIGHT) + Br +
  235. CreateLink(LoadStr(NEON_URL)));
  236. #define EXPAT_LICENSE_URL L"license:expat"
  237. AddPara(ThirdParty,
  238. FMTLOAD(EXPAT_BASED_ON, (ExpatVersion())) + Br +
  239. CreateLink(EXPAT_LICENSE_URL, LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
  240. CreateLink(LoadStr(EXPAT_URL)));
  241. AddBrowserLinkHandler(ThirdPartyWebBrowser, EXPAT_LICENSE_URL, ExpatLicenceHandler);
  242. #ifndef NO_COMPONENTS
  243. AddPara(ThirdParty,
  244. FMTLOAD(ABOUT_TOOLBAR2000, (Toolbar2000Version)) + Br +
  245. LoadStr(ABOUT_TOOLBAR2000_COPYRIGHT) + Br +
  246. CreateLink(LoadStr(ABOUT_TOOLBAR2000_URL)));
  247. AddPara(ThirdParty,
  248. FMTLOAD(ABOUT_TBX, (TBXVersionString)) + Br +
  249. LoadStr(ABOUT_TBX_COPYRIGHT) + Br +
  250. CreateLink(LoadStr(ABOUT_TBX_URL)));
  251. AddPara(ThirdParty,
  252. LoadStr(ABOUT_FILEMANAGER) + Br +
  253. LoadStr(ABOUT_FILEMANAGER_COPYRIGHT));
  254. #endif
  255. UnicodeString JclVersion =
  256. FormatVersion(JclVersionMajor, JclVersionMinor, JclVersionRelease);
  257. AddPara(ThirdParty,
  258. FMTLOAD(ABOUT_JCL, (JclVersion)) + Br +
  259. CreateLink(LoadStr(ABOUT_JCL_URL)));
  260. AddPara(ThirdParty,
  261. LoadStr(ABOUT_PNG) + Br +
  262. LoadStr(ABOUT_PNG_COPYRIGHT) + Br +
  263. CreateLink(LoadStr(ABOUT_PNG_URL)));
  264. ThirdParty +=
  265. L"</body>\n"
  266. L"</html>\n";
  267. std::unique_ptr<TMemoryStream> ThirdPartyStream(new TMemoryStream());
  268. UTF8String ThirdPartyUTF8 = UTF8String(ThirdParty);
  269. ThirdPartyStream->Write(ThirdPartyUTF8.c_str(), ThirdPartyUTF8.Length());
  270. ThirdPartyStream->Seek(0, 0);
  271. // For stream-loaded document, when set only after loading from OnDocumentComplete,
  272. // browser stops working
  273. SetBrowserDesignModeOff(ThirdPartyWebBrowser);
  274. TStreamAdapter * ThirdPartyStreamAdapter = new TStreamAdapter(ThirdPartyStream.get(), soReference);
  275. IPersistStreamInit * PersistStreamInit = NULL;
  276. if (ALWAYS_TRUE(ThirdPartyWebBrowser->Document != NULL) &&
  277. SUCCEEDED(ThirdPartyWebBrowser->Document->QueryInterface(IID_IPersistStreamInit, (void **)&PersistStreamInit)) &&
  278. ALWAYS_TRUE(PersistStreamInit != NULL))
  279. {
  280. PersistStreamInit->Load(static_cast<_di_IStream>(*ThirdPartyStreamAdapter));
  281. }
  282. }
  283. //---------------------------------------------------------------------------
  284. void __fastcall TAboutDialog::AddPara(UnicodeString & Text, const UnicodeString & S)
  285. {
  286. Text += L"<p>" + S + L"</p>\n";
  287. }
  288. //---------------------------------------------------------------------------
  289. UnicodeString __fastcall TAboutDialog::CreateLink(const UnicodeString & URL, const UnicodeString & Title)
  290. {
  291. return FORMAT(L"<a href=\"%s\">%s</a>", (URL, Title.IsEmpty() ? URL : Title));
  292. }
  293. //---------------------------------------------------------------------------
  294. void __fastcall TAboutDialog::LicenseButtonClick(TObject * /*Sender*/)
  295. {
  296. DoProductLicense();
  297. }
  298. //---------------------------------------------------------------------------
  299. void __fastcall TAboutDialog::HelpButtonClick(TObject * /*Sender*/)
  300. {
  301. FormHelp(this);
  302. }
  303. //---------------------------------------------------------------------------
  304. void __fastcall TAboutDialog::RegistrationProductIdLabelClick(
  305. TObject * /*Sender*/)
  306. {
  307. if (FOnRegistrationLink != NULL)
  308. {
  309. FOnRegistrationLink(this);
  310. }
  311. }
  312. //---------------------------------------------------------------------------
  313. void __fastcall TAboutDialog::OKButtonMouseDown(TObject * /*Sender*/,
  314. TMouseButton Button, TShiftState Shift, int /*X*/, int /*Y*/)
  315. {
  316. if ((Button == mbRight) && Shift.Contains(ssAlt))
  317. {
  318. try
  319. {
  320. ACCESS_VIOLATION_TEST;
  321. }
  322. catch (Exception & E)
  323. {
  324. throw ExtException(&E, MainInstructions(L"Internal error test."));
  325. }
  326. }
  327. }
  328. //---------------------------------------------------------------------------
  329. void __fastcall TAboutDialog::ExpatLicenceHandler(TObject * /*Sender*/)
  330. {
  331. DoLicenseDialog(lcExpat);
  332. }
  333. //---------------------------------------------------------------------------