merge the formfield patch from ooo-build
[ooovba.git] / shell / inc / internal / zipfile.hxx
blob5efbcdf130d2d77a3b4ec4e91cb43f8a7e34087d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: zipfile.hxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef ZIPFILE_HXX_INCLUDED
32 #define ZIPFILE_HXX_INCLUDED
34 #ifndef _WINDOWS
35 #define _WINDOWS
36 #endif
39 #include <external/zlib/unzip.h>
42 #include <string>
43 #include <vector>
44 #include <memory>
46 /** A simple zip content provider based on the zlib
49 class ZipFile
51 public:
53 typedef std::vector<std::string> Directory_t;
54 typedef std::auto_ptr<Directory_t> DirectoryPtr_t;
55 typedef std::vector<char> ZipContentBuffer_t;
57 public:
59 /** Checks whether a file is a zip file or not
61 @precond The given parameter must be a string with length > 0
62 The file must exist
63 The file must be readable for the current user
65 @returns true if the file is a zip file
66 false if the file is not a zip file
68 @throws ParameterException if the given file name is empty
69 IOException if the specified file doesn't exist
70 AccessViolationException if read access to the file is denied
72 static bool IsZipFile(const std::string& FileName);
74 static bool IsZipFile(void* stream);
77 /** Returns wheter the version of the specified zip file may be uncompressed with the
78 currently used zlib version or not
80 @precond The given parameter must be a string with length > 0
81 The file must exist
82 The file must be readable for the current user
83 The file must be a valid zip file
85 @returns true if the file may be uncompressed with the currently used zlib
86 false if the file may not be uncompressed with the currently used zlib
88 @throws ParameterException if the given file name is empty
89 IOException if the specified file doesn't exist or is no zip file
90 AccessViolationException if read access to the file is denied
92 static bool IsValidZipFileVersionNumber(const std::string& FileName);
94 static bool IsValidZipFileVersionNumber(void* stream);
96 public:
98 /** Constructs a zip file from a zip file
100 @precond The given parameter must be a string with length > 0
101 The file must exist
102 The file must be readable for the current user
104 @throws ParameterException if the given file name is empty
105 IOException if the specified file doesn't exist or is no valid zip file
106 AccessViolationException if read access to the file is denied
107 WrongZipVersionException if the zip file cannot be uncompressed
108 with the used zlib version
110 ZipFile(const std::string& FileName);
112 ZipFile(void* stream, zlib_filefunc_def* fa);
115 /** Destroys a zip file
117 ~ZipFile();
119 /** Provides an interface to read the uncompressed data of a content of the zip file
121 @param ContentName
122 The name of the content in the zip file
124 @param ppstm
125 Pointer to pointer, will receive an interface pointer
126 to IUnknown on success
128 @precond The specified content must exist in this file
129 ppstm must not be NULL
131 @throws std::bad_alloc if the necessary buffer could not be
132 allocated
133 ZipException if an zip error occurs
134 ZipContentMissException if the specified zip content
135 does not exist in this zip file
137 void GetUncompressedContent(const std::string& ContentName, /*inout*/ ZipContentBuffer_t& ContentBuffer);
139 /** Returns a list with the content names contained within this file
141 @throws ZipException if an error in the zlib happens
143 DirectoryPtr_t GetDirectory() const;
145 /** Convinience query function may even realized with
146 iterating over a ZipFileDirectory returned by
147 GetDirectory
149 bool HasContent(const std::string& ContentName) const;
151 private:
153 /** Returns the length of the longest file name
154 in the current zip file
156 @throws ZipException if an zip error occurs
158 long GetFileLongestFileNameLength() const;
160 private:
161 unzFile m_uzFile;
164 #endif