Properties.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "WinInterface.h"
  5. #include "Properties.h"
  6. #include <VCLCommon.h>
  7. #include <Common.h>
  8. #include <Terminal.h>
  9. #include <TextsWin.h>
  10. #include <GUITools.h>
  11. #include <CoreMain.h>
  12. #include <Tools.h>
  13. #include <BaseUtils.hpp>
  14. //---------------------------------------------------------------------
  15. #pragma link "PathLabel"
  16. #pragma link "Rights"
  17. #pragma resource "*.dfm"
  18. //---------------------------------------------------------------------
  19. bool __fastcall DoPropertiesDialog(TStrings * FileList,
  20. const UnicodeString Directory, const TRemoteTokenList * GroupList,
  21. const TRemoteTokenList * UserList, TStrings * ChecksumAlgs,
  22. TRemoteProperties * Properties,
  23. int AllowedChanges, bool UserGroupByID, TCalculateSizeEvent OnCalculateSize,
  24. TCalculateChecksumEvent OnCalculateChecksum)
  25. {
  26. bool Result;
  27. TPropertiesDialog * PropertiesDialog = new TPropertiesDialog(Application,
  28. FileList, Directory, GroupList, UserList, ChecksumAlgs, AllowedChanges, UserGroupByID,
  29. OnCalculateSize, OnCalculateChecksum);
  30. try
  31. {
  32. Result = PropertiesDialog->Execute(*Properties);
  33. }
  34. __finally
  35. {
  36. delete PropertiesDialog;
  37. }
  38. return Result;
  39. }
  40. //---------------------------------------------------------------------
  41. __fastcall TPropertiesDialog::TPropertiesDialog(TComponent* AOwner,
  42. TStrings * FileList, const UnicodeString Directory,
  43. const TRemoteTokenList * GroupList, const TRemoteTokenList * UserList,
  44. TStrings * ChecksumAlgs,
  45. int AllowedChanges, bool UserGroupByID, TCalculateSizeEvent OnCalculateSize,
  46. TCalculateChecksumEvent OnCalculateChecksum)
  47. : TForm(AOwner)
  48. {
  49. FOnCalculateSize = OnCalculateSize;
  50. FOnCalculateChecksum = OnCalculateChecksum;
  51. RightsFrame->OnChange = ControlChange;
  52. FFileList = new TStringList();
  53. FFileList->Assign(FileList);
  54. FAllowedChanges = AllowedChanges;
  55. FUserGroupByID = UserGroupByID;
  56. FAllowCalculateStats = false;
  57. FStatsNotCalculated = false;
  58. FChecksumLoaded = false;
  59. FMultipleChecksum = false;
  60. LocationLabel->Caption = Directory;
  61. FGroupList = GroupList;
  62. FUserList = UserList;
  63. FChecksumAlgs = ChecksumAlgs;
  64. ReadOnlyControl(ChecksumEdit);
  65. ChecksumUnknownLabel->Caption = LoadStr(PROPERTIES_CHECKSUM_UNKNOWN);
  66. LoadInfo();
  67. UseSystemSettings(this);
  68. }
  69. //---------------------------------------------------------------------------
  70. __fastcall TPropertiesDialog::~TPropertiesDialog()
  71. {
  72. delete FFileList;
  73. FFileList = NULL;
  74. }
  75. //---------------------------------------------------------------------
  76. bool __fastcall TPropertiesDialog::Execute(TRemoteProperties & Properties)
  77. {
  78. SetFileProperties(Properties);
  79. PageControl->ActivePage = CommonSheet;
  80. if (OwnerComboBox->Visible && OwnerComboBox->Enabled)
  81. {
  82. ActiveControl = OwnerComboBox;
  83. }
  84. else if (GroupComboBox->Visible && GroupComboBox->Enabled)
  85. {
  86. ActiveControl = GroupComboBox;
  87. }
  88. else if (RightsFrame->Visible && RightsFrame->Enabled)
  89. {
  90. ActiveControl = RightsFrame;
  91. }
  92. else if (DebugAlwaysTrue(CancelButton->Visible && CancelButton->Enabled))
  93. {
  94. ActiveControl = CancelButton;
  95. }
  96. if (DebugAlwaysTrue(FChecksumAlgs != NULL))
  97. {
  98. ChecksumAlgEdit->Items->Assign(FChecksumAlgs);
  99. int ChecksumIndex = FChecksumAlgs->IndexOf(GUIConfiguration->ChecksumAlg);
  100. if (ChecksumIndex < 0)
  101. {
  102. ChecksumIndex = 0;
  103. }
  104. ChecksumAlgEdit->ItemIndex = ChecksumIndex;
  105. }
  106. ResetChecksum();
  107. UpdateControls();
  108. bool Result = (ShowModal() == DefaultResult());
  109. if (Result)
  110. {
  111. Properties = GetFileProperties();
  112. }
  113. return Result;
  114. }
  115. //---------------------------------------------------------------------------
  116. TModalResult __fastcall TPropertiesDialog::DefaultResult()
  117. {
  118. // Fallback when ChecksumButton is default
  119. return ::DefaultResult(this, OkButton);
  120. }
  121. //---------------------------------------------------------------------------
  122. UnicodeString __fastcall TPropertiesDialog::LoadRemoteToken(
  123. const TRemoteToken & Token)
  124. {
  125. UnicodeString Result;
  126. if (FUserGroupByID)
  127. {
  128. if (Token.IDValid)
  129. {
  130. if (Token.NameValid)
  131. {
  132. Result = FORMAT(L"%s [%d]", (Token.Name, int(Token.ID)));
  133. }
  134. else
  135. {
  136. Result = FORMAT(L"[%d]", (int(Token.ID)));
  137. }
  138. }
  139. else
  140. {
  141. // be it valid or not
  142. Result = Token.Name;
  143. }
  144. }
  145. else
  146. {
  147. // what if name is not filled in?
  148. Result = Token.Name;
  149. }
  150. return Result;
  151. }
  152. //---------------------------------------------------------------------------
  153. void __fastcall TPropertiesDialog::LoadRemoteToken(
  154. TComboBox * ComboBox, bool Valid, const TRemoteToken & Token)
  155. {
  156. if (Valid)
  157. {
  158. ComboBox->Text = LoadRemoteToken(Token);
  159. }
  160. else
  161. {
  162. ComboBox->Text = L"";
  163. }
  164. }
  165. //---------------------------------------------------------------------------
  166. void __fastcall TPropertiesDialog::LoadRemoteTokens(TComboBox * ComboBox,
  167. const TRemoteTokenList * List)
  168. {
  169. TStrings * Items = ComboBox->Items;
  170. Items->BeginUpdate();
  171. try
  172. {
  173. Items->Clear();
  174. if (List != NULL)
  175. {
  176. int Count = List->Count();
  177. for (int Index = 0; Index < Count; Index++)
  178. {
  179. Items->Add(LoadRemoteToken(*List->Token(Index)));
  180. }
  181. }
  182. }
  183. __finally
  184. {
  185. Items->EndUpdate();
  186. }
  187. }
  188. //---------------------------------------------------------------------------
  189. void __fastcall TPropertiesDialog::LoadInfo()
  190. {
  191. DebugAssert(FFileList->Count > 0);
  192. FMultiple = FFileList->Count > 1;
  193. FMultipleChecksum = FMultiple;
  194. FAllowCalculateStats = false;
  195. FStatsNotCalculated = false;
  196. __int64 FilesSize = 0;
  197. TCalculateSizeStats Stats;
  198. for (int Index = 0; Index < FFileList->Count; Index++)
  199. {
  200. TRemoteFile * File = (TRemoteFile *)(FFileList->Objects[Index]);
  201. if (File->IsDirectory)
  202. {
  203. Stats.Directories++;
  204. // we should use TTerminal::CanRecurseToDirectory instead
  205. if (!File->IsSymLink)
  206. {
  207. FAllowCalculateStats = true;
  208. FStatsNotCalculated = true;
  209. FMultipleChecksum = true;
  210. }
  211. }
  212. else
  213. {
  214. Stats.Files++;
  215. }
  216. if (File->IsSymLink)
  217. {
  218. Stats.SymLinks++;
  219. }
  220. FilesSize += File->Size;
  221. }
  222. LoadRemoteTokens(GroupComboBox, FGroupList);
  223. LoadRemoteTokens(OwnerComboBox, FUserList);
  224. FAnyDirectories = (Stats.Directories > 0);
  225. RightsFrame->AllowAddXToDirectories = FAnyDirectories;
  226. if (!FMultiple)
  227. {
  228. // Show only file name, if we have only single file/directory.
  229. // For directory, this changes, once "Calculate" button is pressed
  230. Stats = TCalculateSizeStats();
  231. }
  232. LoadStats(FilesSize, Stats);
  233. RightsFrame->AllowUndef = FMultiple;
  234. if (!FMultiple)
  235. {
  236. TRemoteFile * File = (TRemoteFile *)(FFileList->Objects[0]);
  237. DebugAssert(File);
  238. UpdateFileImage();
  239. LinksToLabelLabel->Visible = File->IsSymLink;
  240. LinksToLabel->Visible = File->IsSymLink;
  241. if (File->IsSymLink)
  242. {
  243. LinksToLabel->Caption = File->LinkTo;
  244. }
  245. Caption = FMTLOAD(PROPERTIES_FILE_CAPTION, (File->FileName));
  246. }
  247. else
  248. {
  249. Caption = FMTLOAD(PROPERTIES_FILES_CAPTION, (FFileList->Strings[0]));
  250. LinksToLabelLabel->Hide();
  251. LinksToLabel->Hide();
  252. LoadDialogImage(FileIconImage, L"Multiple Files");
  253. }
  254. ChecksumGroup->Visible = !FMultipleChecksum;
  255. ChecksumView->Visible = FMultipleChecksum;
  256. }
  257. //---------------------------------------------------------------------------
  258. void __fastcall TPropertiesDialog::UpdateFileImage()
  259. {
  260. TImageList * ImageList = ShellImageListForControl(this, ilsLarge);
  261. FileIconImage->Picture->Bitmap = NULL;
  262. TRemoteFile * File = (TRemoteFile *)(FFileList->Objects[0]);
  263. // shell image list does not have fixed large icon size
  264. // (it is probably 32x32 min, but can be larger, on xp it is 48x48 if
  265. // large icons are enabled, on vista can be even larger).
  266. // so we stretch (shrink) the icon to 32x32 here to be sure.
  267. Graphics::TBitmap * Bitmap = new Graphics::TBitmap;
  268. try
  269. {
  270. ImageList->GetBitmap(File->IconIndex, Bitmap);
  271. int Size = DialogImageSize(this);
  272. // Use exact DPI-scaled size, not approximate scaling by font size.
  273. // Otherwise we stretch icons unnecessarily because the canvas
  274. // is one or two pixels off the icon size
  275. FileIconImage->Width = Size;
  276. FileIconImage->Height = Size;
  277. FileIconImage->Picture->Bitmap->Width = Size;
  278. FileIconImage->Picture->Bitmap->Height = Size;
  279. FileIconImage->Picture->Bitmap->Canvas->StretchDraw(
  280. TRect(0, 0, Size, Size),
  281. Bitmap);
  282. }
  283. __finally
  284. {
  285. delete Bitmap;
  286. }
  287. }
  288. //---------------------------------------------------------------------------
  289. void __fastcall TPropertiesDialog::LoadStats(__int64 FilesSize,
  290. const TCalculateSizeStats & Stats)
  291. {
  292. UnicodeString SizeStr;
  293. UnicodeString FilesStr;
  294. if (FStatsNotCalculated)
  295. {
  296. SizeStr = LoadStr(PROPERTIES_UNKNOWN_SIZE);
  297. }
  298. else
  299. {
  300. SizeStr = FormatBytes(FilesSize);
  301. UnicodeString SizeUnorderedStr = FormatBytes(FilesSize, fbNone);
  302. if (SizeStr != SizeUnorderedStr)
  303. {
  304. SizeStr = FORMAT(L"%s (%s)", (SizeStr, SizeUnorderedStr));
  305. }
  306. }
  307. if (((Stats.Files + Stats.Directories) == 0) && !FMultiple)
  308. {
  309. TRemoteFile * File = (TRemoteFile *)(FFileList->Objects[0]);
  310. DebugAssert(File != NULL);
  311. FilesStr = File->FileName;
  312. }
  313. else
  314. {
  315. if (Stats.Files > 0)
  316. {
  317. FilesStr = (Stats.Files == 1) ? FMTLOAD(PROPERTIES_FILE, (Stats.Files)) :
  318. FMTLOAD(PROPERTIES_FILES, (Stats.Files));
  319. if (Stats.Directories > 0)
  320. {
  321. FilesStr = FORMAT(L"%s, ", (FilesStr));
  322. }
  323. }
  324. if (Stats.Directories > 0)
  325. {
  326. FilesStr += (Stats.Directories == 1) ? FMTLOAD(PROPERTIES_DIRECTORY, (Stats.Directories)) :
  327. FMTLOAD(PROPERTIES_DIRECTORIES, (Stats.Directories));
  328. }
  329. if (Stats.SymLinks > 0)
  330. {
  331. UnicodeString SymLinksStr;
  332. SymLinksStr = (Stats.SymLinks == 1) ? FMTLOAD(PROPERTIES_SYMLINK, (Stats.SymLinks)) :
  333. FMTLOAD(PROPERTIES_SYMLINKS, (Stats.SymLinks));
  334. FilesStr = FORMAT(L"%s (%s)", (FilesStr, SymLinksStr));
  335. }
  336. }
  337. SizeLabel->Caption = SizeStr;
  338. FileLabel->Caption = FilesStr;
  339. }
  340. //---------------------------------------------------------------------------
  341. void __fastcall TPropertiesDialog::SetFileProperties(const TRemoteProperties & value)
  342. {
  343. TValidProperties Valid;
  344. if (value.Valid.Contains(vpRights) && FAllowedChanges & cpMode) Valid << vpRights;
  345. if (value.Valid.Contains(vpOwner) && FAllowedChanges & cpOwner) Valid << vpOwner;
  346. if (value.Valid.Contains(vpGroup) && FAllowedChanges & cpGroup) Valid << vpGroup;
  347. FOrigProperties = value;
  348. FOrigProperties.Valid = Valid;
  349. FOrigProperties.Recursive = false;
  350. bool HasRights = value.Valid.Contains(vpRights);
  351. RightsFrame->Visible = HasRights;
  352. RightsLabel->Visible = RightsFrame->Visible;
  353. if (HasRights)
  354. {
  355. RightsFrame->Rights = value.Rights;
  356. RightsFrame->AddXToDirectories = value.AddXToDirectories;
  357. }
  358. else
  359. {
  360. RightsFrame->Rights = TRights();
  361. RightsFrame->AddXToDirectories = false;
  362. }
  363. bool HasGroup = value.Valid.Contains(vpGroup);
  364. LoadRemoteToken(GroupComboBox, HasGroup, value.Group);
  365. bool HasOwner = value.Valid.Contains(vpOwner);
  366. LoadRemoteToken(OwnerComboBox, HasOwner, value.Owner);
  367. bool HasGroupOrOwner = HasGroup || HasOwner;
  368. bool HasAnything = HasGroupOrOwner || HasRights;
  369. // Not necesarily true, let's find the scenario when it is not and then decide how to render that (shift rights up?)
  370. DebugAssert(HasGroupOrOwner || !HasRights);
  371. bool ShowGroupAndOwner = HasAnything;
  372. OwnerComboBox->Visible = HasGroupOrOwner;
  373. OwnerLabel->Visible = OwnerComboBox->Visible;
  374. GroupComboBox->Visible = HasGroupOrOwner;
  375. GroupLabel->Visible = GroupComboBox->Visible;
  376. GroupOwnerRightsBevel->Visible = ShowGroupAndOwner;
  377. RecursiveCheck2->Checked = value.Recursive;
  378. RecursiveCheck2->Visible = HasAnything && FAnyDirectories;
  379. RecursiveBevel->Visible = RecursiveCheck2->Visible || HasRights;
  380. UpdateControls();
  381. }
  382. //---------------------------------------------------------------------------
  383. void __fastcall TPropertiesDialog::StoreRemoteToken(unsigned int ID,
  384. const UnicodeString & Text, const TRemoteTokenList * List, TRemoteToken & Result)
  385. {
  386. DebugAssert(List != NULL);
  387. const TRemoteToken * Token = List->Find(ID);
  388. if (Token == NULL)
  389. {
  390. Result.ID = ID;
  391. Result.Name = Text;
  392. }
  393. else
  394. {
  395. Result = *Token;
  396. }
  397. }
  398. //---------------------------------------------------------------------------
  399. TRemoteToken __fastcall TPropertiesDialog::StoreRemoteToken(const TRemoteToken & Orig,
  400. UnicodeString Text, int Message, const TRemoteTokenList * List)
  401. {
  402. TRemoteToken Result;
  403. Text = Text.Trim();
  404. if (!Text.IsEmpty())
  405. {
  406. if (FUserGroupByID)
  407. {
  408. DebugAssert(List != NULL);
  409. int IDStart = Text.LastDelimiter(L"[");
  410. if (!Text.IsEmpty() && (IDStart >= 0) && (Text[Text.Length()] == L']'))
  411. {
  412. int ID;
  413. UnicodeString IDStr = Text.SubString(IDStart + 1, Text.Length() - IDStart - 1);
  414. if (!TryStrToInt(IDStr, ID))
  415. {
  416. throw Exception(Message);
  417. }
  418. else
  419. {
  420. StoreRemoteToken(ID, Text.SubString(1, IDStart - 1).Trim(), List, Result);
  421. }
  422. }
  423. else
  424. {
  425. const TRemoteToken * Token = List->Find(Text);
  426. if (Token == NULL)
  427. {
  428. int ID;
  429. if (TryStrToInt(Text, ID))
  430. {
  431. StoreRemoteToken(ID, Text, List, Result);
  432. }
  433. else
  434. {
  435. throw Exception(MainInstructions(FMTLOAD(PROPERTIES_UNKNOWN_TOKEN, (Text))));
  436. }
  437. }
  438. else
  439. {
  440. Result = *Token;
  441. }
  442. }
  443. }
  444. else
  445. {
  446. Result.Name = Text;
  447. }
  448. }
  449. if (LoadRemoteToken(Result) == LoadRemoteToken(Orig))
  450. {
  451. Result = Orig;
  452. }
  453. return Result;
  454. }
  455. //---------------------------------------------------------------------------
  456. void __fastcall TPropertiesDialog::StoreRemoteToken(TComboBox * ComboBox,
  457. int ChangeFlag, TValidProperty PropertyFlag, const TRemoteToken & Orig,
  458. TRemoteToken & Token, int Message, const TRemoteTokenList * List,
  459. TRemoteProperties & Properties)
  460. {
  461. UnicodeString Text = ComboBox->Text.Trim();
  462. if (FLAGSET(FAllowedChanges, ChangeFlag))
  463. {
  464. Token = StoreRemoteToken(Orig, Text, Message, List);
  465. if (Token.IsSet)
  466. {
  467. Properties.Valid << PropertyFlag;
  468. }
  469. }
  470. }
  471. //---------------------------------------------------------------------------
  472. TRemoteProperties __fastcall TPropertiesDialog::GetFileProperties()
  473. {
  474. TRemoteProperties Result;
  475. if (FAllowedChanges & cpMode)
  476. {
  477. Result.Valid << vpRights;
  478. Result.Rights = RightsFrame->Rights;
  479. Result.AddXToDirectories = RightsFrame->AddXToDirectories;
  480. }
  481. StoreRemoteToken(GroupComboBox, cpGroup, vpGroup, FOrigProperties.Group,
  482. Result.Group, PROPERTIES_INVALID_GROUP, FGroupList, Result);
  483. StoreRemoteToken(OwnerComboBox, cpOwner, vpOwner, FOrigProperties.Owner,
  484. Result.Owner, PROPERTIES_INVALID_OWNER, FUserList, Result);
  485. Result.Recursive = RecursiveCheck2->Checked;
  486. return Result;
  487. }
  488. //---------------------------------------------------------------------------
  489. void __fastcall TPropertiesDialog::ControlChange(TObject * /*Sender*/)
  490. {
  491. if (Visible)
  492. {
  493. UpdateControls();
  494. }
  495. }
  496. //---------------------------------------------------------------------------
  497. void __fastcall TPropertiesDialog::UpdateControls()
  498. {
  499. // No point enabling recursive check if there's no change allowed (supported),
  500. // i.e. with WebDAV.
  501. EnableControl(RecursiveCheck2, ((FAllowedChanges & (cpGroup | cpOwner | cpMode)) != 0));
  502. bool Allow;
  503. try
  504. {
  505. Allow =
  506. !TRemoteProperties::ChangedProperties(FOrigProperties, GetFileProperties()).Valid.Empty() ||
  507. (RecursiveCheck2->Enabled && RecursiveCheck2->Checked);
  508. }
  509. catch(...)
  510. {
  511. // when properties are invalid allow submitting the form,
  512. // because that reveals the cause to the user, otherwise he/she
  513. // may not be able to tell what is wrong
  514. Allow = true;
  515. }
  516. EnableControl(OkButton, Allow);
  517. EnableControl(GroupComboBox, FAllowedChanges & cpGroup);
  518. EnableControl(OwnerComboBox, FAllowedChanges & cpOwner);
  519. EnableControl(RightsFrame, FAllowedChanges & cpMode);
  520. CalculateSizeButton->Visible = FAllowCalculateStats;
  521. if (!FMultiple)
  522. {
  523. // when setting properties for one file only, allow undef state
  524. // only when the input right explicitly requires it or
  525. // when "recursive" is on (possible for directory only).
  526. bool AllowUndef =
  527. (FOrigProperties.Valid.Contains(vpRights) &&
  528. FOrigProperties.Rights.AllowUndef) ||
  529. (RecursiveCheck2->Checked);
  530. if (!AllowUndef)
  531. {
  532. // when disallowing undef state, make sure, all undef are turned into unset
  533. RightsFrame->Rights = TRights(RightsFrame->Rights.NumberSet);
  534. }
  535. RightsFrame->AllowUndef = AllowUndef;
  536. }
  537. EnableControl(ChecksumSheet, ChecksumSupported());
  538. EnableControl(ChecksumButton, ChecksumSheet->Enabled &&
  539. !ChecksumAlgEdit->Text.IsEmpty());
  540. ChecksumEdit->Visible = !ChecksumEdit->Text.IsEmpty();
  541. ChecksumUnknownLabel->Visible = !ChecksumEdit->Visible;
  542. DefaultButton(ChecksumButton, ChecksumAlgEdit->Focused());
  543. DefaultButton(OkButton, !ChecksumAlgEdit->Focused());
  544. }
  545. //---------------------------------------------------------------------------
  546. void __fastcall TPropertiesDialog::FormCloseQuery(TObject * /*Sender*/,
  547. bool & /*CanClose*/)
  548. {
  549. if (ModalResult == DefaultResult())
  550. {
  551. ExitActiveControl(this);
  552. }
  553. }
  554. //---------------------------------------------------------------------------
  555. void __fastcall TPropertiesDialog::CalculateSizeButtonClick(
  556. TObject * /*Sender*/)
  557. {
  558. DebugAssert(FOnCalculateSize != NULL);
  559. bool DoClose = false;
  560. Enabled = false;
  561. try
  562. {
  563. __int64 Size;
  564. TCalculateSizeStats Stats;
  565. FOnCalculateSize(FFileList, Size, Stats, DoClose);
  566. FStatsNotCalculated = false;
  567. LoadStats(Size, Stats);
  568. }
  569. __finally
  570. {
  571. Enabled = true;
  572. if (DoClose)
  573. {
  574. Close();
  575. }
  576. }
  577. }
  578. //---------------------------------------------------------------------------
  579. void __fastcall TPropertiesDialog::HelpButtonClick(TObject * /*Sender*/)
  580. {
  581. FormHelp(this);
  582. }
  583. //---------------------------------------------------------------------------
  584. void __fastcall TPropertiesDialog::ResetChecksum()
  585. {
  586. ChecksumView->Items->Clear();
  587. ChecksumEdit->Text = UnicodeString();
  588. AutoSizeListColumnsWidth(ChecksumView);
  589. }
  590. //---------------------------------------------------------------------------
  591. void __fastcall TPropertiesDialog::CalculateChecksum()
  592. {
  593. DebugAssert(FOnCalculateChecksum != NULL);
  594. ResetChecksum();
  595. FChecksumLoaded = true;
  596. FAlgUsed = UnicodeString();
  597. bool DoClose = false;
  598. try
  599. {
  600. FOnCalculateChecksum(ChecksumAlgEdit->Text, FFileList, CalculatedChecksum, DoClose);
  601. }
  602. __finally
  603. {
  604. if (DoClose)
  605. {
  606. Close();
  607. }
  608. }
  609. // If we successfully used the selected checksum, remember it (in normalized form)
  610. if (!FAlgUsed.IsEmpty())
  611. {
  612. GUIConfiguration->ChecksumAlg = FAlgUsed;
  613. }
  614. AutoSizeListColumnsWidth(ChecksumView);
  615. }
  616. //---------------------------------------------------------------------------
  617. void __fastcall TPropertiesDialog::CalculatedChecksum(
  618. const UnicodeString & FileName, const UnicodeString & Alg,
  619. const UnicodeString & Hash)
  620. {
  621. if (FMultipleChecksum)
  622. {
  623. TListItem * Item = ChecksumView->Items->Add();
  624. Item->Caption = FileName;
  625. Item->SubItems->Add(Hash);
  626. // optimization
  627. int TopIndex = ListView_GetTopIndex(ChecksumView->Handle);
  628. int Index = Item->Index;
  629. if ((TopIndex <= Index) &&
  630. (Index <= TopIndex + ChecksumView->VisibleRowCount))
  631. {
  632. AutoSizeListColumnsWidth(ChecksumView);
  633. }
  634. }
  635. else
  636. {
  637. ChecksumEdit->Text = Hash;
  638. }
  639. FAlgUsed = Alg;
  640. UpdateControls();
  641. }
  642. //---------------------------------------------------------------------------
  643. void __fastcall TPropertiesDialog::NeedChecksum()
  644. {
  645. if (!FChecksumLoaded && ChecksumSupported())
  646. {
  647. CalculateChecksum();
  648. }
  649. }
  650. //---------------------------------------------------------------------------
  651. bool __fastcall TPropertiesDialog::ChecksumSupported()
  652. {
  653. return (FOnCalculateChecksum != NULL);
  654. }
  655. //---------------------------------------------------------------------------
  656. void __fastcall TPropertiesDialog::ChecksumButtonClick(TObject * /*Sender*/)
  657. {
  658. CalculateChecksum();
  659. }
  660. //---------------------------------------------------------------------------
  661. void __fastcall TPropertiesDialog::PageControlChange(TObject * /*Sender*/)
  662. {
  663. if (PageControl->ActivePage == ChecksumSheet)
  664. {
  665. NeedChecksum();
  666. }
  667. }
  668. //---------------------------------------------------------------------------
  669. void __fastcall TPropertiesDialog::ChecksumAlgEditChange(TObject * /*Sender*/)
  670. {
  671. ResetChecksum();
  672. UpdateControls();
  673. }
  674. //---------------------------------------------------------------------------
  675. void __fastcall TPropertiesDialog::CopyClick(TObject * Sender)
  676. {
  677. TInstantOperationVisualizer Visualizer;
  678. TListView * ListView = dynamic_cast<TListView *>(GetPopupComponent(Sender));
  679. DebugAssert(ListView != NULL);
  680. int Count = 0;
  681. UnicodeString SingleText;
  682. UnicodeString Text;
  683. TListItem * Item = ListView->GetNextItem(NULL, sdAll, TItemStates() << isSelected);
  684. while (Item != NULL)
  685. {
  686. DebugAssert(Item->Selected);
  687. SingleText = Item->SubItems->Strings[0];
  688. Text += FORMAT(L"%s = %s\r\n", (Item->Caption, Item->SubItems->Strings[0]));
  689. Count++;
  690. Item = ListView->GetNextItem(Item, sdAll, TItemStates() << isSelected);
  691. }
  692. CopyToClipboard(Count == 1 ? SingleText : Text);
  693. }
  694. //---------------------------------------------------------------------------
  695. void __fastcall TPropertiesDialog::ChecksumViewContextPopup(
  696. TObject * Sender, TPoint & MousePos, bool & Handled)
  697. {
  698. MenuPopup(Sender, MousePos, Handled);
  699. }
  700. //---------------------------------------------------------------------------
  701. void __fastcall TPropertiesDialog::ValidateRemoteToken(
  702. const TRemoteToken & Orig, int Message, TComboBox * ComboBox,
  703. const TRemoteTokenList * List)
  704. {
  705. if (!IsCancelButtonBeingClicked(this))
  706. {
  707. try
  708. {
  709. ComboBox->Text =
  710. LoadRemoteToken(StoreRemoteToken(Orig, ComboBox->Text, Message, List));
  711. }
  712. catch(...)
  713. {
  714. ComboBox->SetFocus();
  715. throw;
  716. }
  717. }
  718. }
  719. //---------------------------------------------------------------------------
  720. void __fastcall TPropertiesDialog::GroupComboBoxExit(TObject * Sender)
  721. {
  722. ValidateRemoteToken(FOrigProperties.Group, PROPERTIES_INVALID_GROUP,
  723. dynamic_cast<TComboBox *>(Sender), FGroupList);
  724. }
  725. //---------------------------------------------------------------------------
  726. void __fastcall TPropertiesDialog::OwnerComboBoxExit(TObject * Sender)
  727. {
  728. ValidateRemoteToken(FOrigProperties.Owner, PROPERTIES_INVALID_OWNER,
  729. dynamic_cast<TComboBox *>(Sender), FUserList);
  730. }
  731. //---------------------------------------------------------------------------
  732. void __fastcall TPropertiesDialog::FormShow(TObject * /*Sender*/)
  733. {
  734. UpdateControls();
  735. }
  736. //---------------------------------------------------------------------------
  737. void __fastcall TPropertiesDialog::CMDpiChanged(TMessage & Message)
  738. {
  739. TForm::Dispatch(&Message);
  740. if (!FMultiple)
  741. {
  742. UpdateFileImage();
  743. }
  744. // WORKAROUND: Mere presence of the RightsFrame breaks automatic layout on DPI change in some situation, fixing it manually.
  745. // (opening on a secondary display with 100%, while primary display has 150%)
  746. SizeLabel->Width = CalculateSizeButton->Left - ScaleByTextHeight(this, 8) - SizeLabel->Left;
  747. Bevel1->Width = CommonSheet->ClientWidth - (Bevel1->Left * 2);
  748. Bevel2->Width = Bevel1->Width;
  749. GroupOwnerRightsBevel->Width = Bevel1->Width;
  750. RecursiveBevel->Width = Bevel1->Width;
  751. }
  752. //---------------------------------------------------------------------------
  753. void __fastcall TPropertiesDialog::Dispatch(void * Message)
  754. {
  755. TMessage * M = reinterpret_cast<TMessage*>(Message);
  756. if (M->Msg == CM_DPICHANGED)
  757. {
  758. CMDpiChanged(*M);
  759. }
  760. else
  761. {
  762. TForm::Dispatch(Message);
  763. }
  764. }
  765. //---------------------------------------------------------------------------