forked from svn2github/dotnetzip
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZipContentsDialog.cs
More file actions
226 lines (187 loc) · 7.68 KB
/
Copy pathZipContentsDialog.cs
File metadata and controls
226 lines (187 loc) · 7.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
// ZipContentsDialog.cs
// ------------------------------------------------------------------
//
// Copyright (c) 2009 Dino Chiesa
// All rights reserved.
//
// This code module is part of DotNetZip, a zipfile class library.
//
// ------------------------------------------------------------------
//
// This code is licensed under the Microsoft Public License.
// See the file License.txt for the license details.
// More info on: http://dotnetzip.codeplex.com
//
// ------------------------------------------------------------------
//
namespace Ionic.Zip.Forms
{
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Ionic.Zip;
public partial class ZipContentsDialog : Form
{
public ZipContentsDialog()
{
InitializeComponent();
FixTitle();
}
private void FixTitle()
{
this.Text = String.Format("Contents of the zip archive (DotNetZip v{0})",
Ionic.Zip.ZipFile.LibraryVersion.ToString());
}
public ZipFile ZipFile
{
set
{
listView1.Clear();
listView1.BeginUpdate();
string[] columnHeaders = new string[] { "name", "lastmod", "original", "ratio", "compressed", "enc?", "CRC" };
foreach (string label in columnHeaders)
{
SortableColumnHeader ch = new SortableColumnHeader(label);
if (label != "name" && label != "lastmod")
ch.TextAlign = HorizontalAlignment.Right;
listView1.Columns.Add(ch);
}
foreach (ZipEntry e in value)
{
ListViewItem item = new ListViewItem(e.FileName);
string[] subitems = new string[] {
e.LastModified.ToString("yyyy-MM-dd HH:mm:ss"),
e.UncompressedSize.ToString(),
String.Format("{0,5:F0}%", e.CompressionRatio),
e.CompressedSize.ToString(),
(e.UsesEncryption) ? "Y" : "N",
String.Format("{0:X8}", e.Crc)};
foreach (String s in subitems)
{
ListViewItem.ListViewSubItem subitem = new ListViewItem.ListViewSubItem();
subitem.Text = s;
item.SubItems.Add(subitem);
}
this.listView1.Items.Add(item);
}
listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
// adjust size of the entire form
int aggWidth= 0;
for (int i = 0; i < this.listView1.Columns.Count; i++)
{
aggWidth += this.listView1.Columns[i].Width + 1;
}
// plus a fudge factor
//aggWidth += this.listView1.Columns[this.listView1.Columns.Count - 1].Width / 2 + this.listView1.Location.X * 4;
aggWidth += this.listView1.Location.X * 4 + 4;
this.Size = new System.Drawing.Size(aggWidth, this.Height);
this.listView1.EndUpdate();
}
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
{
// Create an instance of the ColHeader class.
SortableColumnHeader clickedCol = (SortableColumnHeader)this.listView1.Columns[e.Column];
// Set the ascending property to sort in the opposite order.
clickedCol.SortAscending = !clickedCol.SortAscending;
// Get the number of items in the list.
int numItems = this.listView1.Items.Count;
// Turn off display while data is repoplulated.
this.listView1.BeginUpdate();
// Populate an ArrayList with a SortWrapper of each list item.
List<ItemWrapper> list = new List<ItemWrapper>();
for (int i = 0; i < numItems; i++)
{
list.Add(new ItemWrapper(this.listView1.Items[i], e.Column));
}
if (e.Column == 2 || e.Column == 4)
list.Sort(new ItemWrapper.NumericComparer(clickedCol.SortAscending));
else
list.Sort(new ItemWrapper.StringComparer(clickedCol.SortAscending));
// Clear the list, and repopulate with the sorted items.
this.listView1.Items.Clear();
for (int i = 0; i < numItems; i++)
this.listView1.Items.Add(list[i].Item);
// Turn display back on.
this.listView1.EndUpdate();
}
}
// The ColHeader class is a ColumnHeader object with an
// added property for determining an ascending or descending sort.
// True specifies an ascending order, false specifies a descending order.
public class SortableColumnHeader : ColumnHeader
{
public bool SortAscending;
public SortableColumnHeader(string text)
{
this.Text = text;
this.SortAscending = true;
}
}
// An instance of the SortWrapper class is created for
// each item and added to the ArrayList for sorting.
public class ItemWrapper
{
internal ListViewItem Item;
internal int Column;
// A SortWrapper requires the item and the index of the clicked column.
public ItemWrapper(ListViewItem item, int column)
{
Item = item;
Column = column;
}
// Text property for getting the text of an item.
public string Text
{
get { return Item.SubItems[Column].Text; }
}
// Implementation of the IComparer
public class StringComparer : IComparer<ItemWrapper>
{
bool ascending;
// Constructor requires the sort order;
// true if ascending, otherwise descending.
public StringComparer(bool asc)
{
this.ascending = asc;
}
// Implemnentation of the IComparer:Compare
// method for comparing two objects.
public int Compare(ItemWrapper xItem, ItemWrapper yItem)
{
string xText = xItem.Item.SubItems[xItem.Column].Text;
string yText = yItem.Item.SubItems[yItem.Column].Text;
return xText.CompareTo(yText) * (this.ascending ? 1 : -1);
}
}
public class NumericComparer : IComparer<ItemWrapper>
{
bool ascending;
// Constructor requires the sort order;
// true if ascending, otherwise descending.
public NumericComparer(bool asc)
{
this.ascending = asc;
}
// Implemnentation of the IComparer:Compare
// method for comparing two objects.
public int Compare(ItemWrapper xItem, ItemWrapper yItem)
{
int x = 0, y = 0;
try
{
x = Int32.Parse(xItem.Item.SubItems[xItem.Column].Text);
y = Int32.Parse(yItem.Item.SubItems[yItem.Column].Text);
}
catch
{
}
return (x - y) * (this.ascending ? 1 : -1);
}
}
}
}