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