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