5 * Moonlight List (moonlight-list@lists.ximian.com)
7 * Copyright 2009 Novell, Inc. (http://www.novell.com)
9 * See the LICENSE file included with the distribution for details.
14 using System
.Collections
;
15 using System
.Collections
.Generic
;
16 using System
.Diagnostics
;
20 string unzipped_filename
;
22 public Zip Zip { get; set; }
23 public string Type { get { return Path.GetExtension (Filename); }
}
24 public string Filename { get; set; }
25 public string UnzippedFilename
{
27 if (unzipped_filename
== null) {
29 unzipped_filename
= Path
.Combine (Zip
.UnzipDirectory
, Filename
);
31 return unzipped_filename
;
36 class Zip
: IDisposable
38 List
<ZipContent
> files
;
39 string unzip_directory
;
42 public string FileName { get; set; }
43 public string UnzipDirectory
{
45 if (unzip_directory
== null) {
46 unzip_directory
= Path
.Combine (Path
.GetTempPath (), "munxap");
47 unzip_directory
= Path
.Combine (unzip_directory
, Path
.GetFileName (FileName
));
48 unzip_directory
= Path
.Combine (unzip_directory
, "pid-" + System
.Diagnostics
.Process
.GetCurrentProcess ().Id
.ToString ());
49 Directory
.CreateDirectory (unzip_directory
);
51 return unzip_directory
;
54 public Zip (string filename
)
64 public void Dispose ()
66 if (unzip_directory
!= null) {
68 Directory
.Delete (unzip_directory
);
70 // Ignore any exceptions
80 using (System
.Diagnostics
.Process p
= new System
.Diagnostics
.Process ()) {
81 p
.StartInfo
.FileName
= "unzip";
82 p
.StartInfo
.Arguments
= string.Format ("\"{0}\" -d \"{1}\" ", FileName
, UnzipDirectory
);
83 p
.StartInfo
.RedirectStandardOutput
= true;
84 p
.StartInfo
.UseShellExecute
= false;
86 string output
= p
.StandardOutput
.ReadToEnd ();
89 throw new Exception (output
);
95 public List
<ZipContent
> Files
{
98 files
= new List
<ZipContent
> ();
100 using (System
.Diagnostics
.Process p
= new System
.Diagnostics
.Process ()) {
101 p
.StartInfo
.FileName
= "unzip";
102 p
.StartInfo
.Arguments
= "-lqq \"" + FileName
+ "\"";
103 p
.StartInfo
.RedirectStandardOutput
= true;
104 p
.StartInfo
.UseShellExecute
= false;
106 string output
= p
.StandardOutput
.ReadToEnd ();
107 foreach (string line
in output
.Split (new char [] {'\n', '\r'}
, StringSplitOptions
.RemoveEmptyEntries
)) {
108 string [] args
= line
.Split (new char [] { ' '}
, StringSplitOptions
.RemoveEmptyEntries
);
112 ZipContent content
= new ZipContent ();
114 content
.Filename
= args
[3];