About.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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->Caption = AppName;
  75. TColor MainInstructionColor;
  76. HFONT MainInstructionFont;
  77. HFONT InstructionFont;
  78. GetInstrutionsTheme(MainInstructionColor, MainInstructionFont, InstructionFont);
  79. if (MainInstructionFont != 0)
  80. {
  81. int PrevHeight = ApplicationLabel->Height;
  82. ApplicationLabel->Font->Handle = MainInstructionFont;
  83. if (MainInstructionColor != Graphics::clNone)
  84. {
  85. ApplicationLabel->Font->Color = MainInstructionColor;
  86. }
  87. ShiftControls(ApplicationLabel->Top + 1, (ApplicationLabel->Height - PrevHeight));
  88. }
  89. else
  90. {
  91. ApplicationLabel->ParentFont = true;
  92. ApplicationLabel->Font->Style = ApplicationLabel->Font->Style << fsBold;
  93. }
  94. WinSCPCopyrightLabel->Caption = LoadStr(WINSCP_COPYRIGHT);
  95. if (Registration == NULL)
  96. {
  97. RegistrationLabel->Visible = false;
  98. RegistrationBox->Visible = false;
  99. ShiftControls(RegistrationLabel->Top, (RegistrationBox->Top - ThirdPartyPanel->Top));
  100. }
  101. else
  102. {
  103. RegistrationSubjectLabel->Caption = Registration->Subject;
  104. if (Registration->Registered)
  105. {
  106. UnicodeString Text;
  107. Text = FORMAT(LoadStrPart(ABOUT_REGISTRATION_LICENSES, 1),
  108. (Registration->Licenses >= 0 ? IntToStr(Registration->Licenses) :
  109. UnicodeString(LoadStrPart(ABOUT_REGISTRATION_LICENSES, 2))));
  110. if (!Registration->NeverExpires)
  111. {
  112. Text = FMTLOAD(ABOUT_REGISTRATION_EXPIRES,
  113. (Text, FormatDateTime(L"ddddd", Registration->Expiration)));
  114. }
  115. RegistrationLicensesLabel->Caption = Text;
  116. Text = FMTLOAD(ABOUT_REGISTRATION_PRODUCTID, (Registration->ProductId));
  117. if (Registration->EduLicense)
  118. {
  119. Text = FMTLOAD(ABOUT_REGISTRATION_EDULICENSE, (Text));
  120. }
  121. RegistrationProductIdLabel->Caption = Text;
  122. RegistrationProductIdLabel->Font->Style =
  123. RegistrationProductIdLabel->Font->Style << fsBold;
  124. }
  125. else
  126. {
  127. RegistrationLicensesLabel->Visible = false;
  128. FOnRegistrationLink = Registration->OnRegistrationLink;
  129. RegistrationProductIdLabel->Caption = LoadStr(ABOUT_REGISTRATION_LINK);
  130. LinkLabel(RegistrationProductIdLabel, L"");
  131. }
  132. }
  133. LicenseButton->Visible = AllowLicense;
  134. LoadData();
  135. if (ALoadThirdParty)
  136. {
  137. LoadThirdParty();
  138. }
  139. else
  140. {
  141. CreateLabelPanel(ThirdPartyPanel, LoadStr(MESSAGE_DISPLAY_ERROR));
  142. }
  143. int IconSize = ScaleByPixelsPerInch(48, this);
  144. FIconHandle = (HICON)LoadImage(MainInstance, L"MAINICON", IMAGE_ICON, IconSize, IconSize, 0);
  145. IconPaintBox->Width = IconSize;
  146. IconPaintBox->Height = IconSize;
  147. }
  148. //---------------------------------------------------------------------------
  149. __fastcall TAboutDialog::~TAboutDialog()
  150. {
  151. DestroyIcon(FIconHandle);
  152. }
  153. //---------------------------------------------------------------------------
  154. void __fastcall TAboutDialog::ShiftControls(int From, int Diff)
  155. {
  156. for (int Index = 0; Index < Panel->ControlCount; Index++)
  157. {
  158. if (Panel->Controls[Index]->Top > From)
  159. {
  160. Panel->Controls[Index]->Top = Panel->Controls[Index]->Top + Diff;
  161. }
  162. }
  163. ClientHeight = ClientHeight + Diff;
  164. }
  165. //---------------------------------------------------------------------------
  166. void __fastcall TAboutDialog::LoadData()
  167. {
  168. UnicodeString Version = FConfiguration->VersionStr;
  169. if (!FConfiguration->ProductName.IsEmpty() &&
  170. (FConfiguration->Version != FConfiguration->ProductVersion))
  171. {
  172. Version = FMTLOAD(ABOUT_BASED_ON_PRODUCT,
  173. (Version, FConfiguration->ProductName, FConfiguration->ProductVersion));
  174. }
  175. VersionLabel->Caption = Version;
  176. }
  177. //---------------------------------------------------------------------------
  178. void __fastcall TAboutDialog::LoadThirdParty()
  179. {
  180. FThirdPartyWebBrowser = CreateBrowserViewer(ThirdPartyPanel, L"");
  181. reinterpret_cast<TLabel *>(FThirdPartyWebBrowser)->Color = ThirdPartyPanel->Color;
  182. ReadyBrowserForStreaming(FThirdPartyWebBrowser);
  183. DoLoadThirdParty();
  184. }
  185. //---------------------------------------------------------------------------
  186. void __fastcall TAboutDialog::DoLoadThirdParty()
  187. {
  188. WaitBrowserToIdle(FThirdPartyWebBrowser);
  189. UnicodeString ThirdParty;
  190. UnicodeString Br = "<br/>\n";
  191. if (GUIConfiguration->AppliedLocale != GUIConfiguration->InternalLocale())
  192. {
  193. UnicodeString TranslatorUrl = LoadStr(TRANSLATOR_URL);
  194. UnicodeString TranslatorInfo = LoadStr(TRANSLATOR_INFO2);
  195. wchar_t LocaleNameStr[255];
  196. GetLocaleInfo(
  197. GUIConfiguration->AppliedLocale, LOCALE_SLOCALIZEDLANGUAGENAME,
  198. LocaleNameStr, LENOF(LocaleNameStr));
  199. UnicodeString LocaleName(LocaleNameStr);
  200. // The {language} should be present only if we are using an untranslated
  201. // (=english) string
  202. UnicodeString TranslationHeader = ReplaceStr(LoadStr(ABOUT_TRANSLATIONS_HEADER), L"{language}", LocaleName);
  203. AddPara(ThirdParty,
  204. TranslationHeader + Br +
  205. FMTLOAD(ABOUT_TRANSLATIONS_COPYRIGHT, (GUIConfiguration->AppliedLocaleCopyright())) + Br +
  206. (!TranslatorInfo.IsEmpty() ? TranslatorInfo + Br : UnicodeString()) +
  207. (!TranslatorUrl.IsEmpty() ? CreateLink(TranslatorUrl) : UnicodeString()));
  208. }
  209. AddPara(ThirdParty, LoadStr(ABOUT_THIRDPARTY_HEADER));
  210. AddPara(ThirdParty,
  211. FMTLOAD(PUTTY_BASED_ON, (GetPuTTYVersion())) + Br +
  212. LoadStr(PUTTY_COPYRIGHT) + Br +
  213. CreateLink(LoadStr(PUTTY_LICENSE_URL), LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
  214. CreateLink(LoadStr(PUTTY_URL)));
  215. UnicodeString OpenSSLVersionText = GetOpenSSLVersionText();
  216. CutToChar(OpenSSLVersionText, L' ', true); // "OpenSSL"
  217. UnicodeString OpenSSLVersion = CutToChar(OpenSSLVersionText, L' ', true);
  218. CutToChar(OpenSSLVersionText, L' ', true); // day
  219. CutToChar(OpenSSLVersionText, L' ', true); // month
  220. UnicodeString OpenSSLYear = CutToChar(OpenSSLVersionText, L' ', true);
  221. AddPara(ThirdParty,
  222. FMTLOAD(OPENSSL_BASED_ON, (OpenSSLVersion)) + Br +
  223. FMTLOAD(OPENSSL_COPYRIGHT2, (OpenSSLYear)) + Br +
  224. CreateLink(LoadStr(OPENSSL_URL)));
  225. AddPara(ThirdParty,
  226. LoadStr(FILEZILLA_BASED_ON2) + Br +
  227. LoadStr(FILEZILLA_COPYRIGHT2) + Br +
  228. CreateLink(LoadStr(FILEZILLA_URL)));
  229. AddPara(ThirdParty,
  230. FMTLOAD(NEON_BASED_ON2, (NeonVersion())) + Br +
  231. LoadStr(NEON_COPYRIGHT) + Br +
  232. CreateLink(LoadStr(NEON_URL)));
  233. AddPara(ThirdParty,
  234. FMTLOAD(S3_BASED_ON, (S3LibVersion())) + Br +
  235. LoadStr(S3_COPYRIGHT) + Br +
  236. CreateLink(LoadStr(S3_LICENSE_URL), LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
  237. CreateLink(LoadStr(S3_URL)));
  238. #define EXPAT_LICENSE_URL L"license:expat"
  239. AddPara(ThirdParty,
  240. FMTLOAD(EXPAT_BASED_ON, (ExpatVersion())) + Br +
  241. CreateLink(EXPAT_LICENSE_URL, LoadStr(ABOUT_THIRDPARTY_LICENSE)) + Br +
  242. CreateLink(LoadStr(EXPAT_URL)));
  243. AddBrowserLinkHandler(FThirdPartyWebBrowser, EXPAT_LICENSE_URL, ExpatLicenceHandler);
  244. #ifndef NO_COMPONENTS
  245. AddPara(ThirdParty,
  246. FMTLOAD(ABOUT_TOOLBAR2000, (Toolbar2000Version)) + Br +
  247. LoadStr(ABOUT_TOOLBAR2000_COPYRIGHT) + Br +
  248. CreateLink(LoadStr(ABOUT_TOOLBAR2000_URL)));
  249. AddPara(ThirdParty,
  250. FMTLOAD(ABOUT_TBX, (TBXVersionString)) + Br +
  251. LoadStr(ABOUT_TBX_COPYRIGHT) + Br +
  252. CreateLink(LoadStr(ABOUT_TBX_URL)));
  253. AddPara(ThirdParty,
  254. LoadStr(ABOUT_FILEMANAGER) + Br +
  255. LoadStr(ABOUT_FILEMANAGER_COPYRIGHT));
  256. #endif
  257. UnicodeString JclVersion =
  258. FormatVersion(JclVersionMajor, JclVersionMinor, JclVersionRelease);
  259. AddPara(ThirdParty,
  260. FMTLOAD(ABOUT_JCL, (JclVersion)) + Br +
  261. CreateLink(LoadStr(ABOUT_JCL_URL)));
  262. AddPara(ThirdParty,
  263. LoadStr(ABOUT_PNG) + Br +
  264. LoadStr(ABOUT_PNG_COPYRIGHT) + Br +
  265. CreateLink(LoadStr(ABOUT_PNG_URL)));
  266. std::unique_ptr<TFont> DefaultFont(new TFont());
  267. DefaultFont->Assign(Application->DefaultFont);
  268. DefaultFont->Height = ScaleByPixelsPerInchFromSystem(DefaultFont->Height, this);
  269. ThirdParty = GenerateAppHtmlPage(DefaultFont.get(), ThirdPartyPanel, ThirdParty, false);
  270. LoadBrowserDocument(FThirdPartyWebBrowser, ThirdParty);
  271. }
  272. //---------------------------------------------------------------------------
  273. void __fastcall TAboutDialog::AddPara(UnicodeString & Text, const UnicodeString & S)
  274. {
  275. Text += L"<p>" + S + L"</p>\n";
  276. }
  277. //---------------------------------------------------------------------------
  278. UnicodeString __fastcall TAboutDialog::CreateLink(const UnicodeString & URL, const UnicodeString & Title)
  279. {
  280. return FORMAT(L"<a href=\"%s\">%s</a>", (URL, Title.IsEmpty() ? URL : Title));
  281. }
  282. //---------------------------------------------------------------------------
  283. void __fastcall TAboutDialog::LicenseButtonClick(TObject * /*Sender*/)
  284. {
  285. DoProductLicense();
  286. }
  287. //---------------------------------------------------------------------------
  288. void __fastcall TAboutDialog::HelpButtonClick(TObject * /*Sender*/)
  289. {
  290. FormHelp(this);
  291. }
  292. //---------------------------------------------------------------------------
  293. void __fastcall TAboutDialog::RegistrationProductIdLabelClick(
  294. TObject * /*Sender*/)
  295. {
  296. if (FOnRegistrationLink != NULL)
  297. {
  298. FOnRegistrationLink(this);
  299. }
  300. }
  301. //---------------------------------------------------------------------------
  302. void __fastcall TAboutDialog::OKButtonMouseDown(TObject * /*Sender*/,
  303. TMouseButton Button, TShiftState Shift, int /*X*/, int /*Y*/)
  304. {
  305. if (Button == mbRight)
  306. {
  307. if (Shift.Contains(ssAlt))
  308. {
  309. AccessViolationTest();
  310. }
  311. else if (Shift.Contains(ssCtrl))
  312. {
  313. LookupAddress();
  314. }
  315. }
  316. }
  317. //---------------------------------------------------------------------------
  318. void __fastcall TAboutDialog::LookupAddress()
  319. {
  320. UnicodeString S;
  321. if (InputQuery(L"Address lookup", L"&Address:", S))
  322. {
  323. void * Address = reinterpret_cast<void *>(StrToInt(L"$" + S));
  324. ShowMessage(GetLocationInfoStr(Address, true, true, true, true));
  325. }
  326. }
  327. //---------------------------------------------------------------------------
  328. void __fastcall TAboutDialog::AccessViolationTest()
  329. {
  330. try
  331. {
  332. ACCESS_VIOLATION_TEST;
  333. }
  334. catch (Exception & E)
  335. {
  336. throw ExtException(&E, MainInstructions(L"Internal error test."));
  337. }
  338. }
  339. //---------------------------------------------------------------------------
  340. void __fastcall TAboutDialog::ExpatLicenceHandler(TObject * /*Sender*/)
  341. {
  342. DoLicenseDialog(lcExpat);
  343. }
  344. //---------------------------------------------------------------------------
  345. void __fastcall TAboutDialog::IconPaintBoxPaint(TObject * /*Sender*/)
  346. {
  347. DrawIconEx(IconPaintBox->Canvas->Handle,
  348. 0, 0, FIconHandle, IconPaintBox->Width, IconPaintBox->Height, 0, NULL, DI_NORMAL);
  349. }
  350. //---------------------------------------------------------------------------
  351. void __fastcall TAboutDialog::Dispatch(void * Message)
  352. {
  353. TMessage * M = reinterpret_cast<TMessage*>(Message);
  354. if (M->Msg == CM_DPICHANGED)
  355. {
  356. if (FThirdPartyWebBrowser != NULL)
  357. {
  358. DoLoadThirdParty();
  359. }
  360. TForm::Dispatch(Message);
  361. }
  362. else
  363. {
  364. TForm::Dispatch(Message);
  365. }
  366. }
  367. //---------------------------------------------------------------------------