Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(994)

Side by Side Diff: Tools/Google.Build.Utils/Zip.cs

Issue 12767046: Issue 377: New build for releasing a new version (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Patch Set: david comments Created 10 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Tools/Google.Build.Utils/Text/TextUtils.cs ('k') | Tools/Lib/Google.Apis.Samples.Helper.dll » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 Copyright 2011 Google Inc
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 using System;
18 using System.Collections.Generic;
19 using System.IO;
20 using System.Linq;
21 using Google.Apis.Samples.Helper;
22 using Ionic.Zip;
23
24 namespace Google.Build.Utils
25 {
26 /// <summary>
27 /// Zip support class.
28 /// </summary>
29 public class Zip : IDisposable
30 {
31 private readonly ZipFile zipFile;
32
33 public Zip(string file)
34 {
35 CommandLine.WriteAction("Creating zip: " Path.GetFileName(file));
36 zipFile = new ZipFile(file);
37 }
38
39 /// <summary>
40 /// Adds the specified file to the zip archive under "zipDir".
41 /// </summary>
42 public void AddFile(string file, string zipDir)
43 {
44 CommandLine.WriteResult("Adding File", Path.Combine(zipDir, Path.Get FileName(file)));
45 zipFile.AddFile(file, zipDir);
46 }
47
48 /// <summary>
49 /// Adds the specified folder to the zip archive as "zipDir".
50 /// </summary>
51 public void AddDirectory(string dir, string zipDir)
52 {
53 CommandLine.WriteResult("Adding Directory", Path.GetFileName(dir) " -> " zipDir);
54 zipFile.AddDirectory(dir, zipDir);
55 }
56
57 /// <summary>
58 /// Removes the specified entry from this zip if it existed in the first place.
59 /// </summary>
60 /// <returns>True if an entry was removed.</returns>
61 public bool RemoveFile(string entry)
62 {
63 if (!zipFile.ContainsEntry(entry))
64 {
65 return false;
66 }
67 zipFile.RemoveEntry(entry);
68 return true;
69 }
70
71 /// <summary>
72 /// Removes the specified directory from this zip.
73 /// </summary>
74 /// <returns>True if the directory existed before.</returns>
75 public bool RemoveDirectory(string entry)
76 {
77 if (!entry.EndsWith("/"))
78 {
79 entry = entry "/";
80 }
81 List<ZipEntry> toRemove = (from file in zipFile·
82 where file.FileName.StartsWith(entry)·
83 select file).ToList();
84 zipFile.RemoveEntries(toRemove);
85 return toRemove.Count > 0;
86 }
87
88 public void Dispose()
89 {
90 CommandLine.WriteAction("Saving zip...");
91 zipFile.Save();
92 zipFile.Dispose();···
93 }
94 }
95 }
OLDNEW
« no previous file with comments | « Tools/Google.Build.Utils/Text/TextUtils.cs ('k') | Tools/Lib/Google.Apis.Samples.Helper.dll » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b