Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / shell / inc / zipfile.hxx
blob1b4a2770628bd5ac66f819029344828426b9ed37
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 #include <zlib.h>
25 #include <string>
26 #include <vector>
27 #include <memory>
28 #include "filepath.hxx"
30 class StreamInterface;
32 /** A simple zip content provider based on the zlib
35 class ZipFile
37 public:
38 typedef std::vector<std::string> Directory_t;
39 typedef std::unique_ptr<Directory_t> DirectoryPtr_t;
40 typedef std::vector<char> ZipContentBuffer_t;
42 public:
44 /** Checks whether a file is a zip file or not
46 @precond The given parameter must be a string with length > 0
47 The file must exist
48 The file must be readable for the current user
50 @returns true if the file is a zip file
51 false if the file is not a zip file
53 @throws ParameterException if the given file name is empty
54 IOException if the specified file doesn't exist
55 AccessViolationException if read access to the file is denied
57 static bool IsZipFile(const Filepath_t &FileName);
59 static bool IsZipFile(void *stream);
62 /** Returns whether the version of the specified zip file may be uncompressed with the
63 currently used zlib version or not
65 @precond The given parameter must be a string with length > 0
66 The file must exist
67 The file must be readable for the current user
68 The file must be a valid zip file
70 @returns true if the file may be uncompressed with the currently used zlib
71 false if the file may not be uncompressed with the currently used zlib
73 @throws ParameterException if the given file name is empty
74 IOException if the specified file doesn't exist or is no zip file
75 AccessViolationException if read access to the file is denied
77 static bool IsValidZipFileVersionNumber(const Filepath_t &FileName);
79 static bool IsValidZipFileVersionNumber(void *stream);
81 public:
83 /** Constructs a zip file from a zip file
85 @precond The given parameter must be a string with length > 0
86 The file must exist
87 The file must be readable for the current user
89 @throws ParameterException if the given file name is empty
90 IOException if the specified file doesn't exist or is no valid zip file
91 AccessViolationException if read access to the file is denied
92 WrongZipVersionException if the zip file cannot be uncompressed
93 with the used zlib version
95 ZipFile(const Filepath_t &FileName);
97 ZipFile(StreamInterface *stream);
100 /** Destroys a zip file
102 ~ZipFile();
104 /** Provides an interface to read the uncompressed data of a content of the zip file
106 @param ContentName
107 The name of the content in the zip file
109 @param ppstm
110 Pointer to pointer, will receive an interface pointer
111 to IUnknown on success
113 @precond The specified content must exist in this file
114 ppstm must not be NULL
116 @throws std::bad_alloc if the necessary buffer could not be
117 allocated
118 ZipException if a zip error occurs
119 ZipContentMissException if the specified zip content
120 does not exist in this zip file
122 void GetUncompressedContent(const std::string &ContentName, /*inout*/ ZipContentBuffer_t &ContentBuffer);
124 /** Returns a list with the content names contained within this file
126 @throws ZipException if an error in the zlib happens
128 DirectoryPtr_t GetDirectory() const;
130 /** Convenience query function may even realized with
131 iterating over a ZipFileDirectory returned by
132 GetDirectory
134 bool HasContent(const std::string &ContentName) const;
136 private:
138 /** Returns the length of the longest file name
139 in the current zip file
141 @throws ZipException if a zip error occurs
143 long GetFileLongestFileNameLength() const;
145 private:
146 StreamInterface *m_pStream;
147 bool m_bShouldFree;
150 #endif
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */