About.cpp 11 KB

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