About.cpp 13 KB

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