Properties.cpp 23 KB

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