Properties.cpp 22 KB

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