bump product version to 5.0.4.1
[LibreOffice.git] / shell / inc / internal / zipfile.hxx
blob7ccd4bb65ec3717960ca95601416084daf0c6afe
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SHELL_INC_INTERNAL_ZIPFILE_HXX
21 #define INCLUDED_SHELL_INC_INTERNAL_ZIPFILE_HXX
23 #ifndef _WINDOWS
24 #define _WINDOWS
25 #endif
27 #include <zlib.h>
29 #include <string>
30 #include <vector>
31 #include <memory>
33 class StreamInterface;
35 /** A simple zip content provider based on the zlib
38 class ZipFile
40 public:
42 typedef std::vector<std::string> Directory_t;
43 typedef std::unique_ptr<Directory_t> DirectoryPtr_t;
44 typedef std::vector<char> ZipContentBuffer_t;
46 public:
48 /** Checks whether a file is a zip file or not
50 @precond The given parameter must be a string with length > 0
51 The file must exist
52 The file must be readable for the current user
54 @returns true if the file is a zip file
55 false if the file is not a zip file
57 @throws ParameterException if the given file name is empty
58 IOException if the specified file doesn't exist
59 AccessViolationException if read access to the file is denied
61 static bool IsZipFile(const std::string &FileName);
63 static bool IsZipFile(void *stream);
66 /** Returns whether the version of the specified zip file may be uncompressed with the
67 currently used zlib version or not
69 @precond The given parameter must be a string with length > 0
70 The file must exist
71 The file must be readable for the current user
72 The file must be a valid zip file
74 @returns true if the file may be uncompressed with the currently used zlib
75 false if the file may not be uncompressed with the currently used zlib
77 @throws ParameterException if the given file name is empty
78 IOException if the specified file doesn't exist or is no zip file
79 AccessViolationException if read access to the file is denied
81 static bool IsValidZipFileVersionNumber(const std::string &FileName);
83 static bool IsValidZipFileVersionNumber(void *stream);
85 public:
87 /** Constructs a zip file from a zip file
89 @precond The given parameter must be a string with length > 0
90 The file must exist
91 The file must be readable for the current user
93 @throws ParameterException if the given file name is empty
94 IOException if the specified file doesn't exist or is no valid zip file
95 AccessViolationException if read access to the file is denied
96 WrongZipVersionException if the zip file cannot be uncompressed
97 with the used zlib version
99 ZipFile(const std::string &FileName);
101 ZipFile(StreamInterface *stream);
104 /** Destroys a zip file
106 ~ZipFile();
108 /** Provides an interface to read the uncompressed data of a content of the zip file
110 @param ContentName
111 The name of the content in the zip file
113 @param ppstm
114 Pointer to pointer, will receive an interface pointer
115 to IUnknown on success
117 @precond The specified content must exist in this file
118 ppstm must not be NULL
120 @throws std::bad_alloc if the necessary buffer could not be
121 allocated
122 ZipException if an zip error occurs
123 ZipContentMissException if the specified zip content
124 does not exist in this zip file
126 void GetUncompressedContent(const std::string &ContentName, /*inout*/ ZipContentBuffer_t &ContentBuffer);
128 /** Returns a list with the content names contained within this file
130 @throws ZipException if an error in the zlib happens
132 DirectoryPtr_t GetDirectory() const;
134 /** Convinience query function may even realized with
135 iterating over a ZipFileDirectory returned by
136 GetDirectory
138 bool HasContent(const std::string &ContentName) const;
140 private:
142 /** Returns the length of the longest file name
143 in the current zip file
145 @throws ZipException if an zip error occurs
147 long GetFileLongestFileNameLength() const;
149 private:
150 StreamInterface *m_pStream;
151 bool m_bShouldFree;
154 #endif
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */