About.cpp 11 KB

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