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