Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ExpansionZipFile.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under Apache 2.0 License. See LICENSE.md for details.
3 //
4 // --------------------------------------------------------------------------------------------------------------------
5 // <copyright file="ExpansionZipFile.cs" company="Matthew Leibowitz">
6 // Copyright (c) Matthew Leibowitz
7 // This code is licensed under the Apache 2.0 License
8 // http://www.apache.org/licenses/LICENSE-2.0.html
9 // </copyright>
10 // <summary>
11 // The expansion zip file.
12 // </summary>
13 // --------------------------------------------------------------------------------------------------------------------
14 
15 namespace System.IO.Compression.Zip
16 {
17  using System.Collections.Generic;
18  using System.Linq;
19 
20  /// <summary>
21  /// The expansion zip file.
22  /// </summary>
23  public class ExpansionZipFile
24  {
25  #region Fields
26 
27  /// <summary>
28  /// The files.
29  /// </summary>
30  private readonly Dictionary<string, ZipFileEntry> files;
31 
32  #endregion
33 
34  #region Constructors and Destructors
35 
36  /// <summary>
37  /// Initializes a new instance of the <see cref="ExpansionZipFile"/> class.
38  /// </summary>
39  /// <param name="entries">
40  /// The entries.
41  /// </param>
43  {
44  this.files = entries.ToDictionary(x => x.FilenameInZip, x => x);
45  }
46 
47  /// <summary>
48  /// Initializes a new instance of the <see cref="ExpansionZipFile"/> class.
49  /// </summary>
51  {
52  this.files = new Dictionary<string, ZipFileEntry>(StringComparer.InvariantCultureIgnoreCase);
53  }
54 
55  /// <summary>
56  /// Initializes a new instance of the <see cref="ExpansionZipFile"/> class.
57  /// class from a collection of zip file paths.
58  /// </summary>
59  /// <param name="zipPaths">
60  /// Collection of zip file paths
61  /// </param>
63  : this()
64  {
65  foreach (string expansionFile in zipPaths)
66  {
67  this.MergeZipFile(expansionFile);
68  }
69  }
70 
71  #endregion
72 
73  #region Public Methods and Operators
74 
75  /// <summary>
76  /// Add all the entries from an existing <see cref="ExpansionZipFile"/>
77  /// </summary>
78  /// <param name="merge">
79  /// The ExpansionZipFile to use.
80  /// </param>
82  {
83  foreach (var entry in merge.ToDictionary(x => x.FilenameInZip, x => x))
84  {
85  if (this.files.ContainsKey(entry.Key))
86  {
87  this.files[entry.Key] = entry.Value;
88  }
89  else
90  {
91  this.files.Add(entry.Key, entry.Value);
92  }
93  }
94  }
95 
96  /// <summary>
97  /// The get all entries.
98  /// </summary>
99  /// <returns>
100  /// A list of all the entries for this app.
101  /// </returns>
103  {
104  return this.files.Values.ToArray();
105  }
106 
107  /// <summary>
108  /// The get entry.
109  /// </summary>
110  /// <param name="path">
111  /// The path.
112  /// </param>
113  /// <returns>
114  /// The entry at a specified relative path
115  /// </returns>
116  public ZipFileEntry GetEntry(string path)
117  {
118  return this.files.ContainsKey(path) ? this.files[path] : null;
119  }
120 
121  /// <summary>
122  /// Add all the entries from an existing <see cref="ExpansionZipFile"/>
123  /// </summary>
124  /// <param name="merge">
125  /// The ExpansionZipFile to use.
126  /// </param>
127  public void MergeZipFile(ExpansionZipFile merge)
128  {
129  foreach (var entry in merge.files)
130  {
131  if (this.files.ContainsKey(entry.Key))
132  {
133  this.files[entry.Key] = entry.Value;
134  }
135  else
136  {
137  this.files.Add(entry.Key, entry.Value);
138  }
139  }
140  }
141 
142  /// <summary>
143  /// Add all the entries from a zip file on the system.
144  /// </summary>
145  /// <param name="path">
146  /// Path to the zip file
147  /// </param>
148  public void MergeZipFile(string path)
149  {
150  ZipFileEntry[] merge;
151  using (var zip = new ZipFile(path))
152  {
153  merge = zip.GetAllEntries();
154  }
155 
156  this.AddZipFileEntries(merge);
157  }
158 
159  #endregion
160  }
161 }
Represents an entry in Zip file directory
Definition: ZipFileEntry.cs:20
ZipFileEntry GetEntry(string path)
The get entry.
Unique class for compression/decompression file. Represents a Zip file.
Definition: ZipFile.cs:25
void MergeZipFile(ExpansionZipFile merge)
Add all the entries from an existing ExpansionZipFile
ExpansionZipFile()
Initializes a new instance of the ExpansionZipFile class.
void AddZipFileEntries(IEnumerable< ZipFileEntry > merge)
Add all the entries from an existing ExpansionZipFile
void MergeZipFile(string path)
Add all the entries from a zip file on the system.
ZipFileEntry[] GetAllEntries()
The get all entries.
Compression
Compression method enumeration
Definition: Compression.cs:20
ExpansionZipFile(IEnumerable< ZipFileEntry > entries)
Initializes a new instance of the ExpansionZipFile class.
ExpansionZipFile(IEnumerable< string > zipPaths)
Initializes a new instance of the ExpansionZipFile class. class from a collection of zip file paths...