Rev 99 | 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; |
99 | daniel-mar | 20 | Button3: TButton; |
106 | daniel-mar | 21 | Button4: TButton; |
22 | SaveDialog1: TSaveDialog; |
||
75 | daniel-mar | 23 | procedure Button1Click(Sender: TObject); |
77 | daniel-mar | 24 | procedure Button2Click(Sender: TObject); |
25 | procedure FormShow(Sender: TObject); |
||
87 | daniel-mar | 26 | procedure TreeView1DblClick(Sender: TObject); |
99 | daniel-mar | 27 | procedure Button3Click(Sender: TObject); |
106 | daniel-mar | 28 | procedure Button4Click(Sender: TObject); |
75 | daniel-mar | 29 | private |
77 | daniel-mar | 30 | localRecyclersNode: TTreeNode; |
31 | individualRecyclersNode: TTreeNode; |
||
75 | daniel-mar | 32 | end; |
33 | |||
34 | var |
||
35 | RecyclerListingMainForm: TRecyclerListingMainForm; |
||
36 | |||
37 | implementation |
||
38 | |||
39 | {$R *.dfm} |
||
40 | |||
41 | uses |
||
87 | daniel-mar | 42 | RecBinUnit2, ContNrs, SIDUnit, ShellAPI; |
75 | daniel-mar | 43 | |
44 | // TODO: SID Namen auflösen und dementsprechend anzeigen |
||
45 | // TODO: zu jedem element mehr informationen anzeigen, nicht nur den ursprungsnamen |
||
77 | daniel-mar | 46 | // TODO: Einstellungen usw anzeigen, so wie im alten Demo |
75 | daniel-mar | 47 | |
99 | daniel-mar | 48 | const |
49 | ICON_FILE = 0; |
||
50 | ICON_TREEVIEW = 2; |
||
51 | ICON_BIN = 4; |
||
52 | ICON_DRIVE = 6; |
||
53 | ICON_UNKNOWN = 8; |
||
54 | ICON_FOLDER = 10; |
||
55 | |||
106 | daniel-mar | 56 | resourcestring |
57 | S_PLEASE_WAIT = 'Please wait'; |
||
58 | |||
75 | daniel-mar | 59 | procedure TRecyclerListingMainForm.Button1Click(Sender: TObject); |
60 | var |
||
61 | drives: TObjectList{TRbDrive}; |
||
62 | iDrive: integer; |
||
63 | drive: TRbDrive; |
||
64 | nDrive: TTreeNode; |
||
65 | |||
66 | bins: TObjectList{TRbRecycleBin}; |
||
67 | iBin: integer; |
||
68 | bin: TRbRecycleBin; |
||
69 | nBin: TTreeNode; |
||
70 | |||
71 | items: TObjectList{TRbRecycleBinItem}; |
||
72 | iItem: integer; |
||
73 | item: TRbRecycleBinItem; |
||
74 | nItem: TTreeNode; |
||
86 | daniel-mar | 75 | sCaption: string; |
106 | daniel-mar | 76 | |
77 | bakCaption: string; |
||
86 | daniel-mar | 78 | resourcestring |
79 | S_DRIVE = 'Drive %s'; |
||
75 | daniel-mar | 80 | begin |
106 | daniel-mar | 81 | bakCaption := Button1.Caption; |
82 | Button1.Caption := S_PLEASE_WAIT; |
||
75 | daniel-mar | 83 | try |
106 | daniel-mar | 84 | localRecyclersNode.DeleteChildren; // TODO: Will the objects be freed? This is important to avoid memory leaks. |
75 | daniel-mar | 85 | |
106 | daniel-mar | 86 | TreeView1.Items.BeginUpdate; |
87 | drives := TObjectList.Create(false); |
||
88 | bins := TObjectList.Create(false); |
||
89 | items := TObjectList.Create(false); |
||
90 | try |
||
91 | drives.Clear; |
||
92 | TRecycleBinManager.ListDrives(drives); |
||
93 | for iDrive := 0 to drives.Count - 1 do |
||
75 | daniel-mar | 94 | begin |
106 | daniel-mar | 95 | drive := drives.Items[iDrive] as TRbDrive; |
75 | daniel-mar | 96 | |
106 | daniel-mar | 97 | if drive.VolumeGUIDAvailable then |
98 | nDrive := TreeView1.Items.AddChildObject(localRecyclersNode, Format(S_DRIVE, [drive.DriveLetter])+': ' + GUIDToString(drive.VolumeGUID), drive) |
||
99 | else |
||
100 | nDrive := TreeView1.Items.AddChildObject(localRecyclersNode, Format(S_DRIVE, [drive.DriveLetter])+':', drive); |
||
101 | nDrive.ImageIndex := ICON_DRIVE; |
||
102 | nDrive.SelectedIndex := nDrive.ImageIndex; |
||
75 | daniel-mar | 103 | |
106 | daniel-mar | 104 | bins.Clear; |
105 | if CheckBox1.Checked then |
||
106 | drive.ListRecycleBins(bins, GetMySID) |
||
107 | else |
||
108 | drive.ListRecycleBins(bins); |
||
109 | for iBin := 0 to bins.Count - 1 do |
||
75 | daniel-mar | 110 | begin |
106 | daniel-mar | 111 | bin := bins.Items[iBin] as TRbRecycleBin; |
83 | daniel-mar | 112 | |
106 | daniel-mar | 113 | nBin := TreeView1.Items.AddChildObject(nDrive, bin.FileOrDirectory, bin); |
114 | nBin.ImageIndex := ICON_BIN; |
||
115 | nBin.SelectedIndex := nBin.ImageIndex; |
||
83 | daniel-mar | 116 | |
106 | daniel-mar | 117 | items.Clear; |
118 | bin.ListItems(items); |
||
119 | for iItem := 0 to items.Count - 1 do |
||
120 | begin |
||
121 | item := items.Items[iItem] as TRbRecycleBinItem; |
||
83 | daniel-mar | 122 | |
106 | daniel-mar | 123 | if not FileExists(item.PhysicalFile) and |
124 | not DirectoryExists(item.PhysicalFile) and |
||
125 | CheckBox2.Checked then continue; |
||
126 | |||
127 | sCaption := item.Source; |
||
128 | if item is TRbVistaItem (*item.IndexFile <> ''*) then sCaption := sCaption + ' ('+ExtractFileName(item.IndexFile)+')'; |
||
129 | nItem := TreeView1.Items.AddChildObject(nBin, sCaption, item); |
||
130 | |||
131 | if FileExists(item.PhysicalFile) then |
||
132 | nItem.ImageIndex := ICON_FILE |
||
133 | else if DirectoryExists(item.PhysicalFile) then |
||
134 | nItem.ImageIndex := ICON_FOLDER // TODO: Feature: Read folder contents and display them in this treeview. (Also change icon to "open folder") |
||
135 | else |
||
136 | nItem.ImageIndex := ICON_UNKNOWN; |
||
137 | nItem.SelectedIndex := nItem.ImageIndex; |
||
138 | end; |
||
75 | daniel-mar | 139 | end; |
140 | end; |
||
106 | daniel-mar | 141 | finally |
142 | drives.Free; |
||
143 | bins.Free; |
||
144 | items.Free; |
||
145 | TreeView1.Items.EndUpdate; |
||
75 | daniel-mar | 146 | end; |
106 | daniel-mar | 147 | |
148 | localRecyclersNode.Expand(false); |
||
75 | daniel-mar | 149 | finally |
106 | daniel-mar | 150 | Button1.Caption := bakCaption; |
75 | daniel-mar | 151 | end; |
152 | end; |
||
153 | |||
77 | daniel-mar | 154 | procedure TRecyclerListingMainForm.Button2Click(Sender: TObject); |
155 | var |
||
156 | bin: TRbRecycleBin; |
||
157 | nBin: TTreeNode; |
||
158 | |||
159 | items: TObjectList{TRbRecycleBinItem}; |
||
160 | iItem: integer; |
||
161 | item: TRbRecycleBinItem; |
||
162 | nItem: TTreeNode; |
||
86 | daniel-mar | 163 | sCaption: string; |
106 | daniel-mar | 164 | bakCaption: string; |
77 | daniel-mar | 165 | begin |
106 | daniel-mar | 166 | bakCaption := Button2.Caption; |
167 | Button2.Caption := S_PLEASE_WAIT; |
||
168 | try |
||
169 | bin := TRbRecycleBin.Create(LabeledEdit1.Text); |
||
77 | daniel-mar | 170 | |
106 | daniel-mar | 171 | nBin := TreeView1.Items.AddChildObject(individualRecyclersNode, bin.FileOrDirectory, bin); |
172 | nBin.ImageIndex := ICON_BIN; |
||
173 | nBin.SelectedIndex := nBin.ImageIndex; |
||
174 | individualRecyclersNode.Expand(false); |
||
77 | daniel-mar | 175 | |
106 | daniel-mar | 176 | items := TObjectList.Create(false); |
177 | try |
||
178 | items.Clear; |
||
179 | bin.ListItems(items); |
||
180 | for iItem := 0 to items.Count - 1 do |
||
181 | begin |
||
182 | item := items.Items[iItem] as TRbRecycleBinItem; |
||
83 | daniel-mar | 183 | |
106 | daniel-mar | 184 | if not FileExists(item.PhysicalFile) and |
185 | not DirectoryExists(item.PhysicalFile) and |
||
186 | CheckBox2.Checked then continue; |
||
83 | daniel-mar | 187 | |
106 | daniel-mar | 188 | sCaption := item.Source; |
189 | if item is TRbVistaItem (*item.IndexFile <> ''*) then sCaption := sCaption + ' ('+ExtractFileName(item.IndexFile)+')'; |
||
190 | nItem := TreeView1.Items.AddChildObject(nBin, sCaption, item); |
||
83 | daniel-mar | 191 | |
106 | daniel-mar | 192 | if FileExists(item.PhysicalFile) then |
193 | nItem.ImageIndex := ICON_FILE |
||
194 | else if DirectoryExists(item.PhysicalFile) then |
||
195 | nItem.ImageIndex := ICON_FOLDER // TODO: Feature: Read folder contents and display them in this treeview. (Also change icon to "open folder") |
||
196 | else |
||
197 | nItem.ImageIndex := ICON_UNKNOWN; |
||
198 | nItem.SelectedIndex := nItem.ImageIndex; |
||
199 | end; |
||
200 | finally |
||
201 | items.Free; |
||
77 | daniel-mar | 202 | end; |
106 | daniel-mar | 203 | |
204 | nBin.Expand(false); |
||
77 | daniel-mar | 205 | finally |
106 | daniel-mar | 206 | Button2.Caption := bakCaption; |
77 | daniel-mar | 207 | end; |
208 | end; |
||
209 | |||
99 | daniel-mar | 210 | procedure TRecyclerListingMainForm.Button3Click(Sender: TObject); |
211 | begin |
||
212 | if OpenDialog1.Execute then |
||
213 | LabeledEdit1.Text := OpenDialog1.FileName; |
||
214 | end; |
||
215 | |||
106 | daniel-mar | 216 | procedure TRecyclerListingMainForm.Button4Click(Sender: TObject); |
217 | begin |
||
218 | if SaveDialog1.Execute then |
||
219 | begin |
||
220 | TreeView1.SaveToFile(SaveDialog1.FileName); |
||
221 | end; |
||
222 | end; |
||
223 | |||
77 | daniel-mar | 224 | procedure TRecyclerListingMainForm.FormShow(Sender: TObject); |
86 | daniel-mar | 225 | resourcestring |
226 | S_LOCAL_RECYCLE_BINS = 'Local recycle bins'; |
||
227 | S_MANUAL_RECYCLE_BINS ='Manually added recycle bins'; |
||
77 | daniel-mar | 228 | begin |
86 | daniel-mar | 229 | localRecyclersNode := TreeView1.Items.Add(nil, S_LOCAL_RECYCLE_BINS); |
99 | daniel-mar | 230 | localRecyclersNode.ImageIndex := ICON_TREEVIEW; |
83 | daniel-mar | 231 | localRecyclersNode.SelectedIndex := localRecyclersNode.ImageIndex; |
77 | daniel-mar | 232 | |
86 | daniel-mar | 233 | individualRecyclersNode := TreeView1.Items.Add(nil, S_MANUAL_RECYCLE_BINS); |
99 | daniel-mar | 234 | individualRecyclersNode.ImageIndex := ICON_TREEVIEW; |
83 | daniel-mar | 235 | individualRecyclersNode.SelectedIndex := individualRecyclersNode.ImageIndex; |
77 | daniel-mar | 236 | end; |
237 | |||
87 | daniel-mar | 238 | procedure TRecyclerListingMainForm.TreeView1DblClick(Sender: TObject); |
239 | var |
||
240 | item: TRbRecycleBinItem; |
||
241 | begin |
||
99 | daniel-mar | 242 | if TreeView1.Selected.ImageIndex = ICON_FILE then |
87 | daniel-mar | 243 | begin |
244 | // File |
||
245 | item := TRbRecycleBinItem(TreeView1.Selected.Data); |
||
246 | // TODO: Does not work if the file type is unknown |
||
88 | daniel-mar | 247 | // 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) |
87 | daniel-mar | 248 | ShellExecute(Handle, 'open', PChar(item.PhysicalFile), '', '', SW_NORMAL); |
249 | end; |
||
99 | daniel-mar | 250 | if TreeView1.Selected.ImageIndex = ICON_FOLDER then |
87 | daniel-mar | 251 | begin |
252 | // Folder |
||
253 | item := TRbRecycleBinItem(TreeView1.Selected.Data); |
||
254 | ShellExecute(Handle, 'open', PChar(item.PhysicalFile), '', '', SW_NORMAL); |
||
255 | end; |
||
256 | end; |
||
257 | |||
75 | daniel-mar | 258 | end. |