Rev 86 | Rev 88 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
75 | daniel-mar | 1 | unit RecyclerListingMain; |
2 | |||
3 | interface |
||
4 | |||
5 | uses |
||
6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
||
77 | daniel-mar | 7 | Dialogs, StdCtrls, ComCtrls, ExtCtrls, ImgList; |
75 | daniel-mar | 8 | |
9 | type |
||
10 | TRecyclerListingMainForm = class(TForm) |
||
11 | TreeView1: TTreeView; |
||
12 | Panel1: TPanel; |
||
13 | Button1: TButton; |
||
14 | CheckBox1: TCheckBox; |
||
77 | daniel-mar | 15 | Button2: TButton; |
16 | OpenDialog1: TOpenDialog; |
||
17 | LabeledEdit1: TLabeledEdit; |
||
18 | ImageList1: TImageList; |
||
83 | daniel-mar | 19 | CheckBox2: TCheckBox; |
75 | daniel-mar | 20 | procedure Button1Click(Sender: TObject); |
77 | daniel-mar | 21 | procedure Button2Click(Sender: TObject); |
22 | procedure FormShow(Sender: TObject); |
||
87 | daniel-mar | 23 | procedure TreeView1DblClick(Sender: TObject); |
75 | daniel-mar | 24 | private |
77 | daniel-mar | 25 | localRecyclersNode: TTreeNode; |
26 | individualRecyclersNode: TTreeNode; |
||
75 | daniel-mar | 27 | end; |
28 | |||
29 | var |
||
30 | RecyclerListingMainForm: TRecyclerListingMainForm; |
||
31 | |||
32 | implementation |
||
33 | |||
34 | {$R *.dfm} |
||
35 | |||
36 | uses |
||
87 | daniel-mar | 37 | RecBinUnit2, ContNrs, SIDUnit, ShellAPI; |
75 | daniel-mar | 38 | |
39 | // TODO: SID Namen auflösen und dementsprechend anzeigen |
||
40 | // TODO: zu jedem element mehr informationen anzeigen, nicht nur den ursprungsnamen |
||
77 | daniel-mar | 41 | // TODO: Einstellungen usw anzeigen, so wie im alten Demo |
75 | daniel-mar | 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; |
||
86 | daniel-mar | 59 | sCaption: string; |
60 | resourcestring |
||
61 | S_DRIVE = 'Drive %s'; |
||
75 | daniel-mar | 62 | begin |
87 | daniel-mar | 63 | localRecyclersNode.DeleteChildren; // TODO: Will the objects be freed? This is important to avoid memory leaks. |
77 | daniel-mar | 64 | |
75 | daniel-mar | 65 | TreeView1.Items.BeginUpdate; |
87 | daniel-mar | 66 | drives := TObjectList.Create(false); |
67 | bins := TObjectList.Create(false); |
||
68 | items := TObjectList.Create(false); |
||
75 | daniel-mar | 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 | |||
77 | daniel-mar | 76 | if drive.VolumeGUIDAvailable then |
86 | daniel-mar | 77 | nDrive := TreeView1.Items.AddChildObject(localRecyclersNode, Format(S_DRIVE, [drive.DriveLetter])+': ' + GUIDToString(drive.VolumeGUID), drive) |
77 | daniel-mar | 78 | else |
86 | daniel-mar | 79 | nDrive := TreeView1.Items.AddChildObject(localRecyclersNode, Format(S_DRIVE, [drive.DriveLetter])+':', drive); |
77 | daniel-mar | 80 | nDrive.ImageIndex := 6; |
83 | daniel-mar | 81 | nDrive.SelectedIndex := nDrive.ImageIndex; |
75 | daniel-mar | 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); |
||
77 | daniel-mar | 93 | nBin.ImageIndex := 4; |
83 | daniel-mar | 94 | nBin.SelectedIndex := nBin.ImageIndex; |
75 | daniel-mar | 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; |
||
83 | daniel-mar | 101 | |
86 | daniel-mar | 102 | if not FileExists(item.PhysicalFile) and |
103 | not DirectoryExists(item.PhysicalFile) and |
||
104 | CheckBox2.Checked then continue; |
||
83 | daniel-mar | 105 | |
86 | daniel-mar | 106 | sCaption := item.Source; |
87 | daniel-mar | 107 | if item is TRbVistaItem (*item.IndexFile <> ''*) then sCaption := sCaption + ' ('+ExtractFileName(item.IndexFile)+')'; |
108 | nItem := TreeView1.Items.AddChildObject(nBin, sCaption, item); |
||
83 | daniel-mar | 109 | |
110 | if FileExists(item.PhysicalFile) then |
||
111 | nItem.ImageIndex := 0 |
||
86 | daniel-mar | 112 | else if DirectoryExists(item.PhysicalFile) then |
87 | daniel-mar | 113 | nItem.ImageIndex := 10 // TODO: Feature: Read folder contents and display them in this treeview. (Also change icon to "open folder") |
83 | daniel-mar | 114 | else |
115 | nItem.ImageIndex := 8; |
||
116 | nItem.SelectedIndex := nItem.ImageIndex; |
||
75 | daniel-mar | 117 | end; |
118 | end; |
||
119 | end; |
||
120 | finally |
||
121 | drives.Free; |
||
122 | bins.Free; |
||
123 | items.Free; |
||
124 | TreeView1.Items.EndUpdate; |
||
125 | end; |
||
77 | daniel-mar | 126 | |
127 | localRecyclersNode.Expand(false); |
||
75 | daniel-mar | 128 | end; |
129 | |||
77 | daniel-mar | 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; |
||
86 | daniel-mar | 139 | sCaption: string; |
77 | daniel-mar | 140 | begin |
141 | bin := TRbRecycleBin.Create(LabeledEdit1.Text); |
||
142 | |||
143 | nBin := TreeView1.Items.AddChildObject(individualRecyclersNode, bin.FileOrDirectory, bin); |
||
144 | individualRecyclersNode.Expand(false); |
||
145 | |||
87 | daniel-mar | 146 | items := TObjectList.Create(false); |
77 | daniel-mar | 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; |
||
83 | daniel-mar | 153 | |
86 | daniel-mar | 154 | if not FileExists(item.PhysicalFile) and |
155 | not DirectoryExists(item.PhysicalFile) and |
||
156 | CheckBox2.Checked then continue; |
||
83 | daniel-mar | 157 | |
86 | daniel-mar | 158 | sCaption := item.Source; |
87 | daniel-mar | 159 | if item is TRbVistaItem (*item.IndexFile <> ''*) then sCaption := sCaption + ' ('+ExtractFileName(item.IndexFile)+')'; |
160 | nItem := TreeView1.Items.AddChildObject(nBin, sCaption, item); |
||
83 | daniel-mar | 161 | |
162 | if FileExists(item.PhysicalFile) then |
||
163 | nItem.ImageIndex := 0 |
||
86 | daniel-mar | 164 | else if DirectoryExists(item.PhysicalFile) then |
87 | daniel-mar | 165 | nItem.ImageIndex := 10 // TODO: Feature: Read folder contents and display them in this treeview. (Also change icon to "open folder") |
83 | daniel-mar | 166 | else |
167 | nItem.ImageIndex := 8; |
||
168 | nItem.SelectedIndex := nItem.ImageIndex; |
||
77 | daniel-mar | 169 | end; |
170 | finally |
||
171 | items.Free; |
||
172 | end; |
||
173 | |||
174 | nBin.Expand(false); |
||
175 | end; |
||
176 | |||
177 | procedure TRecyclerListingMainForm.FormShow(Sender: TObject); |
||
86 | daniel-mar | 178 | resourcestring |
179 | S_LOCAL_RECYCLE_BINS = 'Local recycle bins'; |
||
180 | S_MANUAL_RECYCLE_BINS ='Manually added recycle bins'; |
||
77 | daniel-mar | 181 | begin |
86 | daniel-mar | 182 | localRecyclersNode := TreeView1.Items.Add(nil, S_LOCAL_RECYCLE_BINS); |
77 | daniel-mar | 183 | localRecyclersNode.ImageIndex := 2; |
83 | daniel-mar | 184 | localRecyclersNode.SelectedIndex := localRecyclersNode.ImageIndex; |
77 | daniel-mar | 185 | |
86 | daniel-mar | 186 | individualRecyclersNode := TreeView1.Items.Add(nil, S_MANUAL_RECYCLE_BINS); |
77 | daniel-mar | 187 | individualRecyclersNode.ImageIndex := 2; |
83 | daniel-mar | 188 | individualRecyclersNode.SelectedIndex := individualRecyclersNode.ImageIndex; |
77 | daniel-mar | 189 | end; |
190 | |||
87 | daniel-mar | 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 | ShellExecute(Handle, 'open', PChar(item.PhysicalFile), '', '', SW_NORMAL); |
||
202 | end; |
||
203 | if TreeView1.Selected.ImageIndex = 10 then |
||
204 | begin |
||
205 | // Folder |
||
206 | item := TRbRecycleBinItem(TreeView1.Selected.Data); |
||
207 | ShellExecute(Handle, 'open', PChar(item.PhysicalFile), '', '', SW_NORMAL); |
||
208 | end; |
||
209 | end; |
||
210 | |||
75 | daniel-mar | 211 | end. |