Properties.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  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 (DebugAlwaysTrue(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. // we should use TTerminal::CanRecurseToDirectory instead
  200. if (!File->IsSymLink)
  201. {
  202. FAllowCalculateStats = true;
  203. FStatsNotCalculated = true;
  204. FMultipleChecksum = true;
  205. }
  206. }
  207. else
  208. {
  209. Stats.Files++;
  210. }
  211. if (File->IsSymLink)
  212. {
  213. Stats.SymLinks++;
  214. }
  215. FilesSize += File->Size;
  216. }
  217. LoadRemoteTokens(GroupComboBox, FGroupList);
  218. LoadRemoteTokens(OwnerComboBox, FUserList);
  219. RightsFrame->AllowAddXToDirectories = (Stats.Directories > 0);
  220. RecursiveCheck->Visible = (Stats.Directories > 0);
  221. RecursiveBevel->Visible = (Stats.Directories > 0);
  222. LoadStats(FilesSize, Stats);
  223. RightsFrame->AllowUndef = FMultiple;
  224. if (!FMultiple)
  225. {
  226. TRemoteFile * File = (TRemoteFile *)(FFileList->Objects[0]);
  227. DebugAssert(File && FShellImageList);
  228. FileIconImage->Picture->Bitmap = NULL;
  229. // shell image list does not have fixed large icon size
  230. // (it is probably 32x32 min, but can be larger, on xp it is 48x48 if
  231. // large icons are enabled, on vista can be even larger).
  232. // so we stretch (shrink) the icon to 32x32 here to be sure.
  233. Graphics::TBitmap * Bitmap = new Graphics::TBitmap;
  234. try
  235. {
  236. FShellImageList->GetBitmap(File->IconIndex, Bitmap);
  237. int Size = DialogImageSize();
  238. // Use exact DPI-scaled size, not approximate scaling by font size.
  239. // Otherwise we stretch icons unnecessarily because the canvas
  240. // is one or two pixels off the icon size
  241. FileIconImage->Width = Size;
  242. FileIconImage->Height = Size;
  243. FileIconImage->Picture->Bitmap->Width = Size;
  244. FileIconImage->Picture->Bitmap->Height = Size;
  245. FileIconImage->Picture->Bitmap->Canvas->StretchDraw(
  246. TRect(0, 0, Size, Size),
  247. Bitmap);
  248. }
  249. __finally
  250. {
  251. delete Bitmap;
  252. }
  253. LinksToLabelLabel->Visible = File->IsSymLink;
  254. LinksToLabel->Visible = File->IsSymLink;
  255. if (File->IsSymLink)
  256. {
  257. LinksToLabel->Caption = File->LinkTo;
  258. }
  259. RightsFrame->AllowAddXToDirectories = File->IsDirectory;
  260. Caption = FMTLOAD(PROPERTIES_FILE_CAPTION, (File->FileName));
  261. RecursiveCheck->Visible = File->IsDirectory;
  262. RecursiveBevel->Visible = File->IsDirectory;
  263. }
  264. else
  265. {
  266. Caption = FMTLOAD(PROPERTIES_FILES_CAPTION, (FFileList->Strings[0]));
  267. LinksToLabelLabel->Hide();
  268. LinksToLabel->Hide();
  269. LoadDialogImage(FileIconImage, L"Multiple Files");
  270. }
  271. ChecksumGroup->Visible = !FMultipleChecksum;
  272. ChecksumView->Visible = FMultipleChecksum;
  273. }
  274. //---------------------------------------------------------------------------
  275. void __fastcall TPropertiesDialog::LoadStats(__int64 FilesSize,
  276. const TCalculateSizeStats & Stats)
  277. {
  278. UnicodeString SizeStr;
  279. UnicodeString FilesStr;
  280. if (FStatsNotCalculated)
  281. {
  282. SizeStr = LoadStr(PROPERTIES_UNKNOWN_SIZE);
  283. }
  284. else
  285. {
  286. SizeStr = FormatBytes(FilesSize);
  287. UnicodeString SizeUnorderedStr = FormatBytes(FilesSize, fbNone);
  288. if (SizeStr != SizeUnorderedStr)
  289. {
  290. SizeStr = FORMAT(L"%s (%s)", (SizeStr, SizeUnorderedStr));
  291. }
  292. }
  293. if (((Stats.Files + Stats.Directories) == 0) && !FMultiple)
  294. {
  295. TRemoteFile * File = (TRemoteFile *)(FFileList->Objects[0]);
  296. DebugAssert(File != NULL);
  297. FilesStr = File->FileName;
  298. }
  299. else
  300. {
  301. if (Stats.Files > 0)
  302. {
  303. FilesStr = (Stats.Files == 1) ? FMTLOAD(PROPERTIES_FILE, (Stats.Files)) :
  304. FMTLOAD(PROPERTIES_FILES, (Stats.Files));
  305. if (Stats.Directories > 0)
  306. {
  307. FilesStr = FORMAT(L"%s, ", (FilesStr));
  308. }
  309. }
  310. if (Stats.Directories > 0)
  311. {
  312. FilesStr += (Stats.Directories == 1) ? FMTLOAD(PROPERTIES_DIRECTORY, (Stats.Directories)) :
  313. FMTLOAD(PROPERTIES_DIRECTORIES, (Stats.Directories));
  314. }
  315. if (Stats.SymLinks > 0)
  316. {
  317. UnicodeString SymLinksStr;
  318. SymLinksStr = (Stats.SymLinks == 1) ? FMTLOAD(PROPERTIES_SYMLINK, (Stats.SymLinks)) :
  319. FMTLOAD(PROPERTIES_SYMLINKS, (Stats.SymLinks));
  320. FilesStr = FORMAT(L"%s (%s)", (FilesStr, SymLinksStr));
  321. }
  322. }
  323. SizeLabel->Caption = SizeStr;
  324. FileLabel->Caption = FilesStr;
  325. }
  326. //---------------------------------------------------------------------------
  327. void __fastcall TPropertiesDialog::SetFileProperties(const TRemoteProperties & value)
  328. {
  329. TValidProperties Valid;
  330. if (value.Valid.Contains(vpRights) && FAllowedChanges & cpMode) Valid << vpRights;
  331. if (value.Valid.Contains(vpOwner) && FAllowedChanges & cpOwner) Valid << vpOwner;
  332. if (value.Valid.Contains(vpGroup) && FAllowedChanges & cpGroup) Valid << vpGroup;
  333. FOrigProperties = value;
  334. FOrigProperties.Valid = Valid;
  335. FOrigProperties.Recursive = false;
  336. if (value.Valid.Contains(vpRights))
  337. {
  338. RightsFrame->Rights = value.Rights;
  339. RightsFrame->AddXToDirectories = value.AddXToDirectories;
  340. }
  341. else
  342. {
  343. RightsFrame->Rights = TRights();
  344. RightsFrame->AddXToDirectories = false;
  345. }
  346. LoadRemoteToken(GroupComboBox, value.Valid.Contains(vpGroup), value.Group);
  347. LoadRemoteToken(OwnerComboBox, value.Valid.Contains(vpOwner), value.Owner);
  348. RecursiveCheck->Checked = value.Recursive;
  349. UpdateControls();
  350. }
  351. //---------------------------------------------------------------------------
  352. void __fastcall TPropertiesDialog::StoreRemoteToken(unsigned int ID,
  353. const UnicodeString & Text, const TRemoteTokenList * List, TRemoteToken & Result)
  354. {
  355. DebugAssert(List != NULL);
  356. const TRemoteToken * Token = List->Find(ID);
  357. if (Token == NULL)
  358. {
  359. Result.ID = ID;
  360. Result.Name = Text;
  361. }
  362. else
  363. {
  364. Result = *Token;
  365. }
  366. }
  367. //---------------------------------------------------------------------------
  368. TRemoteToken __fastcall TPropertiesDialog::StoreRemoteToken(const TRemoteToken & Orig,
  369. UnicodeString Text, int Message, const TRemoteTokenList * List)
  370. {
  371. TRemoteToken Result;
  372. Text = Text.Trim();
  373. if (!Text.IsEmpty())
  374. {
  375. if (FUserGroupByID)
  376. {
  377. DebugAssert(List != NULL);
  378. int IDStart = Text.LastDelimiter(L"[");
  379. if (!Text.IsEmpty() && (IDStart >= 0) && (Text[Text.Length()] == L']'))
  380. {
  381. int ID;
  382. UnicodeString IDStr = Text.SubString(IDStart + 1, Text.Length() - IDStart - 1);
  383. if (!TryStrToInt(IDStr, ID))
  384. {
  385. throw Exception(Message);
  386. }
  387. else
  388. {
  389. StoreRemoteToken(ID, Text.SubString(1, IDStart - 1).Trim(), List, Result);
  390. }
  391. }
  392. else
  393. {
  394. const TRemoteToken * Token = List->Find(Text);
  395. if (Token == NULL)
  396. {
  397. int ID;
  398. if (TryStrToInt(Text, ID))
  399. {
  400. StoreRemoteToken(ID, Text, List, Result);
  401. }
  402. else
  403. {
  404. throw Exception(MainInstructions(FMTLOAD(PROPERTIES_UNKNOWN_TOKEN, (Text))));
  405. }
  406. }
  407. else
  408. {
  409. Result = *Token;
  410. }
  411. }
  412. }
  413. else
  414. {
  415. Result.Name = Text;
  416. }
  417. }
  418. if (LoadRemoteToken(Result) == LoadRemoteToken(Orig))
  419. {
  420. Result = Orig;
  421. }
  422. return Result;
  423. }
  424. //---------------------------------------------------------------------------
  425. void __fastcall TPropertiesDialog::StoreRemoteToken(TComboBox * ComboBox,
  426. int ChangeFlag, TValidProperty PropertyFlag, const TRemoteToken & Orig,
  427. TRemoteToken & Token, int Message, const TRemoteTokenList * List,
  428. TRemoteProperties & Properties)
  429. {
  430. UnicodeString Text = ComboBox->Text.Trim();
  431. if (FLAGSET(FAllowedChanges, ChangeFlag))
  432. {
  433. Token = StoreRemoteToken(Orig, Text, Message, List);
  434. if (Token.IsSet)
  435. {
  436. Properties.Valid << PropertyFlag;
  437. }
  438. }
  439. }
  440. //---------------------------------------------------------------------------
  441. TRemoteProperties __fastcall TPropertiesDialog::GetFileProperties()
  442. {
  443. TRemoteProperties Result;
  444. if (FAllowedChanges & cpMode)
  445. {
  446. Result.Valid << vpRights;
  447. Result.Rights = RightsFrame->Rights;
  448. Result.AddXToDirectories = RightsFrame->AddXToDirectories;
  449. }
  450. StoreRemoteToken(GroupComboBox, cpGroup, vpGroup, FOrigProperties.Group,
  451. Result.Group, PROPERTIES_INVALID_GROUP, FGroupList, Result);
  452. StoreRemoteToken(OwnerComboBox, cpOwner, vpOwner, FOrigProperties.Owner,
  453. Result.Owner, PROPERTIES_INVALID_OWNER, FUserList, Result);
  454. Result.Recursive = RecursiveCheck->Checked;
  455. return Result;
  456. }
  457. //---------------------------------------------------------------------------
  458. void __fastcall TPropertiesDialog::ControlChange(TObject * /*Sender*/)
  459. {
  460. if (Visible)
  461. {
  462. UpdateControls();
  463. }
  464. }
  465. //---------------------------------------------------------------------------
  466. void __fastcall TPropertiesDialog::UpdateControls()
  467. {
  468. // No point enabling recursive check if there's no change allowed (supported),
  469. // i.e. with WebDAV.
  470. EnableControl(RecursiveCheck, ((FAllowedChanges & (cpGroup | cpOwner | cpMode)) != 0));
  471. bool Allow;
  472. try
  473. {
  474. Allow =
  475. !TRemoteProperties::ChangedProperties(FOrigProperties, GetFileProperties()).Valid.Empty() ||
  476. (RecursiveCheck->Enabled && RecursiveCheck->Checked);
  477. }
  478. catch(...)
  479. {
  480. // when properties are invalid allow submitting the form,
  481. // because that reveals the cause to the user, otherwise he/she
  482. // may not be able to tell what is wrong
  483. Allow = true;
  484. }
  485. EnableControl(OkButton, Allow);
  486. EnableControl(GroupComboBox, FAllowedChanges & cpGroup);
  487. EnableControl(OwnerComboBox, FAllowedChanges & cpOwner);
  488. EnableControl(RightsFrame, FAllowedChanges & cpMode);
  489. CalculateSizeButton->Visible = FAllowCalculateStats;
  490. if (!FMultiple)
  491. {
  492. // when setting properties for one file only, allow undef state
  493. // only when the input right explicitly requires it or
  494. // when "recursive" is on (possible for directory only).
  495. bool AllowUndef =
  496. (FOrigProperties.Valid.Contains(vpRights) &&
  497. FOrigProperties.Rights.AllowUndef) ||
  498. (RecursiveCheck->Checked);
  499. if (!AllowUndef)
  500. {
  501. // when disallowing undef state, make sure, all undef are turned into unset
  502. RightsFrame->Rights = TRights(RightsFrame->Rights.NumberSet);
  503. }
  504. RightsFrame->AllowUndef = AllowUndef;
  505. }
  506. EnableControl(ChecksumSheet, ChecksumSupported());
  507. EnableControl(ChecksumButton, ChecksumSheet->Enabled &&
  508. !ChecksumAlgEdit->Text.IsEmpty());
  509. // hide checksum edit at least if it is disabled to get rid of ugly
  510. // visage on XP
  511. ChecksumEdit->Visible = ChecksumEdit->Enabled;
  512. DefaultButton(ChecksumButton, ChecksumAlgEdit->Focused());
  513. DefaultButton(OkButton, !ChecksumAlgEdit->Focused());
  514. }
  515. //---------------------------------------------------------------------------
  516. void __fastcall TPropertiesDialog::FormCloseQuery(TObject * /*Sender*/,
  517. bool & /*CanClose*/)
  518. {
  519. if (ModalResult == DefaultResult())
  520. {
  521. ExitActiveControl(this);
  522. }
  523. }
  524. //---------------------------------------------------------------------------
  525. void __fastcall TPropertiesDialog::CalculateSizeButtonClick(
  526. TObject * /*Sender*/)
  527. {
  528. DebugAssert(FOnCalculateSize != NULL);
  529. bool DoClose = false;
  530. try
  531. {
  532. __int64 Size;
  533. TCalculateSizeStats Stats;
  534. FOnCalculateSize(FFileList, Size, Stats, DoClose);
  535. FStatsNotCalculated = false;
  536. LoadStats(Size, Stats);
  537. }
  538. __finally
  539. {
  540. if (DoClose)
  541. {
  542. Close();
  543. }
  544. }
  545. }
  546. //---------------------------------------------------------------------------
  547. void __fastcall TPropertiesDialog::HelpButtonClick(TObject * /*Sender*/)
  548. {
  549. FormHelp(this);
  550. }
  551. //---------------------------------------------------------------------------
  552. void __fastcall TPropertiesDialog::ResetChecksum()
  553. {
  554. ChecksumView->Items->Clear();
  555. ChecksumEdit->Text = LoadStr(PROPERTIES_CHECKSUM_UNKNOWN);
  556. AutoSizeListColumnsWidth(ChecksumView);
  557. }
  558. //---------------------------------------------------------------------------
  559. void __fastcall TPropertiesDialog::CalculateChecksum()
  560. {
  561. DebugAssert(FOnCalculateChecksum != NULL);
  562. ResetChecksum();
  563. FChecksumLoaded = true;
  564. FAlgUsed = UnicodeString();
  565. bool DoClose = false;
  566. try
  567. {
  568. FOnCalculateChecksum(ChecksumAlgEdit->Text, FFileList, CalculatedChecksum, DoClose);
  569. }
  570. __finally
  571. {
  572. if (DoClose)
  573. {
  574. Close();
  575. }
  576. }
  577. // If we successfully used the selected checksum, remember it (in normalized form)
  578. if (!FAlgUsed.IsEmpty())
  579. {
  580. GUIConfiguration->ChecksumAlg = FAlgUsed;
  581. }
  582. AutoSizeListColumnsWidth(ChecksumView);
  583. }
  584. //---------------------------------------------------------------------------
  585. void __fastcall TPropertiesDialog::CalculatedChecksum(
  586. const UnicodeString & FileName, const UnicodeString & Alg,
  587. const UnicodeString & Hash)
  588. {
  589. if (FMultipleChecksum)
  590. {
  591. TListItem * Item = ChecksumView->Items->Add();
  592. Item->Caption = FileName;
  593. Item->SubItems->Add(Hash);
  594. // optimization
  595. int TopIndex = ListView_GetTopIndex(ChecksumView->Handle);
  596. int Index = Item->Index;
  597. if ((TopIndex <= Index) &&
  598. (Index <= TopIndex + ChecksumView->VisibleRowCount))
  599. {
  600. AutoSizeListColumnsWidth(ChecksumView);
  601. }
  602. }
  603. else
  604. {
  605. ChecksumEdit->Text = Hash;
  606. }
  607. FAlgUsed = Alg;
  608. }
  609. //---------------------------------------------------------------------------
  610. void __fastcall TPropertiesDialog::NeedChecksum()
  611. {
  612. if (!FChecksumLoaded && ChecksumSupported())
  613. {
  614. CalculateChecksum();
  615. }
  616. }
  617. //---------------------------------------------------------------------------
  618. bool __fastcall TPropertiesDialog::ChecksumSupported()
  619. {
  620. return (FOnCalculateChecksum != NULL);
  621. }
  622. //---------------------------------------------------------------------------
  623. void __fastcall TPropertiesDialog::ChecksumButtonClick(TObject * /*Sender*/)
  624. {
  625. CalculateChecksum();
  626. }
  627. //---------------------------------------------------------------------------
  628. void __fastcall TPropertiesDialog::PageControlChange(TObject * /*Sender*/)
  629. {
  630. if (PageControl->ActivePage == ChecksumSheet)
  631. {
  632. NeedChecksum();
  633. }
  634. }
  635. //---------------------------------------------------------------------------
  636. void __fastcall TPropertiesDialog::ChecksumAlgEditChange(TObject * /*Sender*/)
  637. {
  638. ResetChecksum();
  639. UpdateControls();
  640. }
  641. //---------------------------------------------------------------------------
  642. void __fastcall TPropertiesDialog::CopyClick(TObject * Sender)
  643. {
  644. TInstantOperationVisualizer Visualizer;
  645. TListView * ListView = dynamic_cast<TListView *>(GetPopupComponent(Sender));
  646. DebugAssert(ListView != NULL);
  647. int Count = 0;
  648. UnicodeString SingleText;
  649. UnicodeString Text;
  650. TListItem * Item = ListView->GetNextItem(NULL, sdAll, TItemStates() << isSelected);
  651. while (Item != NULL)
  652. {
  653. DebugAssert(Item->Selected);
  654. SingleText = Item->SubItems->Strings[0];
  655. Text += FORMAT(L"%s = %s\r\n", (Item->Caption, Item->SubItems->Strings[0]));
  656. Count++;
  657. Item = ListView->GetNextItem(Item, sdAll, TItemStates() << isSelected);
  658. }
  659. CopyToClipboard(Count == 1 ? SingleText : Text);
  660. }
  661. //---------------------------------------------------------------------------
  662. void __fastcall TPropertiesDialog::ChecksumViewContextPopup(
  663. TObject * Sender, TPoint & MousePos, bool & Handled)
  664. {
  665. MenuPopup(Sender, MousePos, Handled);
  666. }
  667. //---------------------------------------------------------------------------
  668. void __fastcall TPropertiesDialog::ResolveRemoteToken(
  669. const TRemoteToken & Orig, int Message, TComboBox * ComboBox,
  670. const TRemoteTokenList * List)
  671. {
  672. try
  673. {
  674. ComboBox->Text =
  675. LoadRemoteToken(StoreRemoteToken(Orig, ComboBox->Text, Message, List));
  676. }
  677. catch(...)
  678. {
  679. ComboBox->SetFocus();
  680. throw;
  681. }
  682. }
  683. //---------------------------------------------------------------------------
  684. void __fastcall TPropertiesDialog::GroupComboBoxExit(TObject * Sender)
  685. {
  686. ResolveRemoteToken(FOrigProperties.Group, PROPERTIES_INVALID_GROUP,
  687. dynamic_cast<TComboBox *>(Sender), FGroupList);
  688. }
  689. //---------------------------------------------------------------------------
  690. void __fastcall TPropertiesDialog::OwnerComboBoxExit(TObject * Sender)
  691. {
  692. ResolveRemoteToken(FOrigProperties.Owner, PROPERTIES_INVALID_OWNER,
  693. dynamic_cast<TComboBox *>(Sender), FUserList);
  694. }
  695. //---------------------------------------------------------------------------
  696. void __fastcall TPropertiesDialog::FormShow(TObject * /*Sender*/)
  697. {
  698. UpdateControls();
  699. }
  700. //---------------------------------------------------------------------------