1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
26 #include "filepath.hxx"
28 class StreamInterface
;
30 /** A simple zip content provider based on the zlib
36 typedef std::vector
<std::string
> Directory_t
;
37 typedef std::unique_ptr
<Directory_t
> DirectoryPtr_t
;
38 typedef std::vector
<char> ZipContentBuffer_t
;
41 /** Checks whether a file is a zip file or not
43 @precond The given parameter must be a string with length > 0
45 The file must be readable for the current user
47 @returns true if the file is a zip file
48 false if the file is not a zip file
50 @throws ParameterException if the given file name is empty
51 IOException if the specified file doesn't exist
52 AccessViolationException if read access to the file is denied
54 static bool IsZipFile(const Filepath_t
& FileName
);
56 static bool IsZipFile(void* stream
);
58 /** Returns whether the version of the specified zip file may be uncompressed with the
59 currently used zlib version or not
61 @precond The given parameter must be a string with length > 0
63 The file must be readable for the current user
64 The file must be a valid zip file
66 @returns true if the file may be uncompressed with the currently used zlib
67 false if the file may not be uncompressed with the currently used zlib
69 @throws ParameterException if the given file name is empty
70 IOException if the specified file doesn't exist or is no zip file
71 AccessViolationException if read access to the file is denied
73 static bool IsValidZipFileVersionNumber(const Filepath_t
& FileName
);
75 static bool IsValidZipFileVersionNumber(void* stream
);
78 /** Constructs a zip file from a zip file
80 @precond The given parameter must be a string with length > 0
82 The file must be readable for the current user
84 @throws ParameterException if the given file name is empty
85 IOException if the specified file doesn't exist or is no valid zip file
86 AccessViolationException if read access to the file is denied
87 WrongZipVersionException if the zip file cannot be uncompressed
88 with the used zlib version
90 ZipFile(const Filepath_t
& FileName
);
92 ZipFile(StreamInterface
* stream
);
94 /** Destroys a zip file
98 /** Provides an interface to read the uncompressed data of a content of the zip file
101 The name of the content in the zip file
104 Pointer to pointer, will receive an interface pointer
105 to IUnknown on success
107 @precond The specified content must exist in this file
108 ppstm must not be NULL
110 @throws std::bad_alloc if the necessary buffer could not be
112 ZipException if a zip error occurs
113 ZipContentMissException if the specified zip content
114 does not exist in this zip file
116 void GetUncompressedContent(const std::string
& ContentName
,
117 /*inout*/ ZipContentBuffer_t
& ContentBuffer
);
119 /** Returns a list with the content names contained within this file
121 @throws ZipException if an error in the zlib happens
123 DirectoryPtr_t
GetDirectory() const;
125 /** Convenience query function may even realized with
126 iterating over a ZipFileDirectory returned by
129 bool HasContent(const std::string
& ContentName
) const;
132 StreamInterface
* m_pStream
;
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */