Subversion Repositories recyclebinunit

Rev

Rev 87 | Rev 90 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. unit RecyclerListingMain;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls, ComCtrls, ExtCtrls, ImgList;
  8.  
  9. type
  10.   TRecyclerListingMainForm = class(TForm)
  11.     TreeView1: TTreeView;
  12.     Panel1: TPanel;
  13.     Button1: TButton;
  14.     CheckBox1: TCheckBox;
  15.     Button2: TButton;
  16.     OpenDialog1: TOpenDialog;
  17.     LabeledEdit1: TLabeledEdit;
  18.     ImageList1: TImageList;
  19.     CheckBox2: TCheckBox;
  20.     procedure Button1Click(Sender: TObject);
  21.     procedure Button2Click(Sender: TObject);
  22.     procedure FormShow(Sender: TObject);
  23.     procedure TreeView1DblClick(Sender: TObject);
  24.   private
  25.     localRecyclersNode: TTreeNode;
  26.     individualRecyclersNode: TTreeNode;
  27.   end;
  28.  
  29. var
  30.   RecyclerListingMainForm: TRecyclerListingMainForm;
  31.  
  32. implementation
  33.  
  34. {$R *.dfm}
  35.  
  36. uses
  37.   RecBinUnit2, ContNrs, SIDUnit, ShellAPI;
  38.  
  39. // TODO: SID Namen auflösen und dementsprechend anzeigen
  40. // TODO: zu jedem element mehr informationen anzeigen, nicht nur den ursprungsnamen
  41. // TODO: Einstellungen usw anzeigen, so wie im alten Demo
  42.  
  43. procedure TRecyclerListingMainForm.Button1Click(Sender: TObject);
  44. var
  45.   drives: TObjectList{TRbDrive};
  46.   iDrive: integer;
  47.   drive: TRbDrive;
  48.   nDrive: TTreeNode;
  49.  
  50.   bins: TObjectList{TRbRecycleBin};
  51.   iBin: integer;
  52.   bin: TRbRecycleBin;
  53.   nBin: TTreeNode;
  54.  
  55.   items: TObjectList{TRbRecycleBinItem};
  56.   iItem: integer;
  57.   item: TRbRecycleBinItem;
  58.   nItem: TTreeNode;
  59.   sCaption: string;
  60. resourcestring
  61.   S_DRIVE = 'Drive %s';
  62. begin
  63.   localRecyclersNode.DeleteChildren; // TODO: Will the objects be freed? This is important to avoid memory leaks.
  64.  
  65.   TreeView1.Items.BeginUpdate;
  66.   drives := TObjectList.Create(false);
  67.   bins := TObjectList.Create(false);
  68.   items := TObjectList.Create(false);
  69.   try
  70.     drives.Clear;
  71.     TRecycleBinManager.ListDrives(drives);
  72.     for iDrive := 0 to drives.Count - 1 do
  73.     begin
  74.       drive := drives.Items[iDrive] as TRbDrive;
  75.  
  76.       if drive.VolumeGUIDAvailable then
  77.         nDrive := TreeView1.Items.AddChildObject(localRecyclersNode, Format(S_DRIVE, [drive.DriveLetter])+': ' + GUIDToString(drive.VolumeGUID), drive)
  78.       else
  79.         nDrive := TreeView1.Items.AddChildObject(localRecyclersNode, Format(S_DRIVE, [drive.DriveLetter])+':', drive);
  80.       nDrive.ImageIndex := 6;
  81.       nDrive.SelectedIndex := nDrive.ImageIndex;
  82.  
  83.       bins.Clear;
  84.       if CheckBox1.Checked then
  85.         drive.ListRecycleBins(bins, GetMySID)
  86.       else
  87.         drive.ListRecycleBins(bins);
  88.       for iBin := 0 to bins.Count - 1 do
  89.       begin
  90.         bin := bins.Items[iBin] as TRbRecycleBin;
  91.  
  92.         nBin := TreeView1.Items.AddChildObject(nDrive, bin.FileOrDirectory, bin);
  93.         nBin.ImageIndex := 4;
  94.         nBin.SelectedIndex := nBin.ImageIndex;
  95.  
  96.         items.Clear;
  97.         bin.ListItems(items);
  98.         for iItem := 0 to items.Count - 1 do
  99.         begin
  100.           item := items.Items[iItem] as TRbRecycleBinItem;
  101.  
  102.           if not FileExists(item.PhysicalFile) and
  103.              not DirectoryExists(item.PhysicalFile) and
  104.              CheckBox2.Checked then continue;
  105.  
  106.           sCaption := item.Source;
  107.           if item is TRbVistaItem (*item.IndexFile <> ''*) then sCaption := sCaption + ' ('+ExtractFileName(item.IndexFile)+')';
  108.           nItem := TreeView1.Items.AddChildObject(nBin, sCaption, item);
  109.  
  110.           if FileExists(item.PhysicalFile) then
  111.             nItem.ImageIndex := 0
  112.           else if DirectoryExists(item.PhysicalFile) then
  113.             nItem.ImageIndex := 10 // TODO: Feature: Read folder contents and display them in this treeview. (Also change icon to "open folder")
  114.           else
  115.             nItem.ImageIndex := 8;
  116.           nItem.SelectedIndex := nItem.ImageIndex;
  117.         end;
  118.       end;
  119.     end;
  120.   finally
  121.     drives.Free;
  122.     bins.Free;
  123.     items.Free;
  124.     TreeView1.Items.EndUpdate;
  125.   end;
  126.  
  127.   localRecyclersNode.Expand(false);
  128. end;
  129.  
  130. procedure TRecyclerListingMainForm.Button2Click(Sender: TObject);
  131. var
  132.   bin: TRbRecycleBin;
  133.   nBin: TTreeNode;
  134.  
  135.   items: TObjectList{TRbRecycleBinItem};
  136.   iItem: integer;
  137.   item: TRbRecycleBinItem;
  138.   nItem: TTreeNode;
  139.   sCaption: string;
  140. begin
  141.   bin := TRbRecycleBin.Create(LabeledEdit1.Text);
  142.  
  143.   nBin := TreeView1.Items.AddChildObject(individualRecyclersNode, bin.FileOrDirectory, bin);
  144.   individualRecyclersNode.Expand(false);
  145.  
  146.   items := TObjectList.Create(false);
  147.   try
  148.     items.Clear;
  149.     bin.ListItems(items);
  150.     for iItem := 0 to items.Count - 1 do
  151.     begin
  152.       item := items.Items[iItem] as TRbRecycleBinItem;
  153.  
  154.       if not FileExists(item.PhysicalFile) and
  155.          not DirectoryExists(item.PhysicalFile) and
  156.          CheckBox2.Checked then continue;
  157.  
  158.       sCaption := item.Source;
  159.       if item is TRbVistaItem (*item.IndexFile <> ''*) then sCaption := sCaption + ' ('+ExtractFileName(item.IndexFile)+')';
  160.       nItem := TreeView1.Items.AddChildObject(nBin, sCaption, item);
  161.  
  162.       if FileExists(item.PhysicalFile) then
  163.         nItem.ImageIndex := 0
  164.       else if DirectoryExists(item.PhysicalFile) then
  165.         nItem.ImageIndex := 10 // TODO: Feature: Read folder contents and display them in this treeview. (Also change icon to "open folder")
  166.       else
  167.         nItem.ImageIndex := 8;
  168.       nItem.SelectedIndex := nItem.ImageIndex;
  169.     end;
  170.   finally
  171.     items.Free;
  172.   end;
  173.  
  174.   nBin.Expand(false);
  175. end;
  176.  
  177. procedure TRecyclerListingMainForm.FormShow(Sender: TObject);
  178. resourcestring
  179.   S_LOCAL_RECYCLE_BINS = 'Local recycle bins';
  180.   S_MANUAL_RECYCLE_BINS ='Manually added recycle bins';
  181. begin
  182.   localRecyclersNode := TreeView1.Items.Add(nil, S_LOCAL_RECYCLE_BINS);
  183.   localRecyclersNode.ImageIndex := 2;
  184.   localRecyclersNode.SelectedIndex := localRecyclersNode.ImageIndex;
  185.  
  186.   individualRecyclersNode := TreeView1.Items.Add(nil, S_MANUAL_RECYCLE_BINS);
  187.   individualRecyclersNode.ImageIndex := 2;
  188.   individualRecyclersNode.SelectedIndex := individualRecyclersNode.ImageIndex;
  189. end;
  190.  
  191. procedure TRecyclerListingMainForm.TreeView1DblClick(Sender: TObject);
  192. var
  193.   item: TRbRecycleBinItem;
  194.   tempFile, tempDir: string;
  195. begin
  196.   if TreeView1.Selected.ImageIndex = 0 then
  197.   begin
  198.     // File
  199.     item := TRbRecycleBinItem(TreeView1.Selected.Data);
  200.     // TODO: Does not work if the file type is unknown
  201.     // TODO: Maybe we should add a feature to drag'n'drop a file/folder out of RecycleBinUnit into the explorer (With options copy or move, depending on the ShiftState)
  202.     ShellExecute(Handle, 'open', PChar(item.PhysicalFile), '', '', SW_NORMAL);
  203.   end;
  204.   if TreeView1.Selected.ImageIndex = 10 then
  205.   begin
  206.     // Folder
  207.     item := TRbRecycleBinItem(TreeView1.Selected.Data);
  208.     ShellExecute(Handle, 'open', PChar(item.PhysicalFile), '', '', SW_NORMAL);
  209.   end;
  210. end;
  211.  
  212. end.
  213.