sync with tizen_2.0
[platform/framework/native/appfw.git] / inc / FBaseUtilFileZipper.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FBaseUtilFileZipper.h
20  * @brief               This is the header file for the %FileZipper class.
21  *
22  * This header file contains the declarations of the %FileZipper class.
23  */
24
25 #ifndef _FBASE_UTIL_FILE_ZIPPER_H_
26 #define _FBASE_UTIL_FILE_ZIPPER_H_
27
28 #include <FBaseUtilTypes.h>
29 #include <FBaseString.h>
30
31
32 namespace Tizen { namespace Base { namespace Utility
33 {
34 /**
35  * @class       FileZipper
36  * @brief       This class provides methods that compress data to a zip-archive using zlib.
37  *
38  * @since 2.0
39  *
40  * The %FileZipper class provides a zip operation for a simple and efficient file-based access to a zip-archive.
41  * It is possible to create a zip file, and add the file to an already existing zip-archive.
42  *
43  * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/base/utility_namespace.htm">Utility</a>.
44  *
45  * The following example demonstrates how to use the %FileZipper class.
46  *
47  * @code
48  *      #include <FBase.h>
49  *
50  *      using namespace Tizen::App;
51  *      using namespace Tizen::Base;
52  *      using namespace Tizen::Base::Utility;
53  *
54  *      void
55  *      MyClass::FileZipperSample(void)
56  *      {
57  *              FileZipper zip;
58  *              String dataPath = App::GetInstance()->GetAppDataPath();
59  *              zip.Construct(dataPath + L"sample.zip");
60  *
61  *              // Adds files to the zip file-archive
62  *              zip.AddToZip(dataPath + L"data1.txt");
63  *              zip.AddToZip(dataPath + L"dataDir/data2.txt");
64  *      }
65  * @endcode
66  */
67 class _OSP_EXPORT_ FileZipper
68         : public Tizen::Base::Object
69 {
70 public:
71         /**
72          * The object is not fully constructed after this constructor is called. @n
73          * For full construction, the Construct() method must be called right after calling this constructor.
74          *
75          * @since 2.0
76          */
77         FileZipper(void);
78
79         /**
80          * This destructor overrides Tizen::Base::Object::~Object().
81          *
82          * @since 2.0
83          */
84         virtual ~FileZipper(void);
85
86         /**
87          * Initializes this instance of %FileZipper with the specified filepath. @n
88          * This method opens an existing zip file in append mode. If the file does not exist, it creates and opens the file in
89          * append mode.
90          *
91          * @if OSPCOMPAT
92          * @brief <i> [Compatibility] </i>
93          * @endif
94          * @since 2.0
95          * @if OSPCOMPAT
96          * @compatibility       This method has compatibility issues with OSP compatible applications. @n
97          *                                      For more information, see @ref CompIoPathPage "here".
98          * @endif
99          *
100          * @return                      An error code
101          * @param [in]          filePath                The path of the zip file to open or create
102          * @exception           E_SUCCESS               The method is successful.
103          * @exception           E_INVALID_ARG           Either of the following conditions has occurred: @n
104          *                                                                              - The length of the specified path is @c 0 or exceeds system limitations. @n
105          *                                                                              - The specified path contains prohibited character(s). @n
106          *                                                                              - The specified path is invalid.
107          * @exception           E_ILLEGAL_ACCESS        The specified path is not permitted, or
108          *                                                                              access is denied due to insufficient permission.
109          * @exception           E_IO                    An unexpected device failure has occurred.
110          * @remarks                     The paths for @b Tizen::App::AppManager::GetAppSharedPath(appId) + L"data" and @b Tizen::App::AppManager::GetAppSharedPath(appId) + L"trusted" are not supported.
111          * @see                         Tizen::Io::File
112          */
113         result Construct(const String& filePath);
114
115         /**
116          * Adds a new file to an already opened zip file.
117          *
118          * @if OSPCOMPAT
119          * @brief <i> [Compatibility] </i>
120          * @endif
121          * @since 2.0
122          * @if OSPCOMPAT
123          * @compatibility       This method has compatibility issues with OSP compatible applications. @n
124          *                                      For more information, see @ref CompIoPathPage "here".
125          * @endif
126          *
127          * @return                      An error code
128          * @param [in]          filePath        The path of the file to add to the zip file
129          * @param [in]          excludePath     Set to @c true to exclude the path and to store only the file name, @n
130          *                                                               else @c false to insert the entire path name in the zip-archive
131          * @param [in]          level           Set to @c BEST_SPEED or @c BEST_COMPRESSION @n
132          *                                                              By default, it is set to @c DEFAULT_COMPRESSION.
133          * @exception           E_SUCCESS                       The method is successful.
134          * @exception           E_INVALID_ARG           Either of the following conditions has occurred: @n
135          *                                                                              - The length of the specified path is @c 0 or exceeds system limitations. @n
136          *                                                                              - The specified path contains prohibited character(s). @n
137          *                                                                              - The specified path is invalid.
138          * @exception           E_ILLEGAL_ACCESS        The specified path is not permitted, or
139          *                                                                              access is denied due to insufficient permission.
140          * @exception           E_FILE_NOT_FOUND        The specified file cannot be found.
141          * @exception           E_FILE_ALREADY_EXIST    The specified file already exists in the zip-archive, but the
142          *                                                                                      flag for overwriting the file is not set.
143          * @exception           E_IO                    An unexpected device failure has occurred.
144          * @remarks                     The paths for @b Tizen::App::AppManager::GetAppSharedPath(appId) + L"data" and @b Tizen::App::AppManager::GetAppSharedPath(appId) + L"trusted" are not supported.
145          * @remarks                     If the value of @c excludePath is set to @c false, full path name is inserted to the zip-
146          *                                      archive. Therefore, developers should handle the path name carefully. @n
147          *                                      For example, if you add @b '/Test/data.txt' file to the zip-archive, and if the
148          *                                      @c excludePath parameter is set to @c false, while unzipping the file in @b '/Test'
149          *                                      directory, then the file is extracted in @b '/Test/Test/data.txt'.
150          * @see                         Tizen::Io::File
151          */
152         result AddToZip(const String& filePath, bool excludePath = true, CompressionLevel level = DEFAULT_COMPRESSION);
153
154         /**
155          * Gets the value of the overwritten flag. @n
156          * If @c true, it overwrites the existing file.
157          *
158          * @since 2.0
159          *
160          * @return                      The value of the overwrite flag for the zip file
161          */
162         bool GetOverwriteFlag(void) const;
163
164         /**
165          * Sets the value of the overwritten flag. @n
166          * If @c true, the existing file gets overwritten during file addition.
167          * The default value of this flag is @c false.
168          *
169          * @since 2.0
170          *
171          * @param [in]          flag    The flag value to set
172          */
173         void SetOverwriteFlag(bool flag);
174
175
176 private:
177         /**
178          * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
179          *
180          * @param [in]          fileZipper              The instance of the FileZip class to copy from
181          * @remarks                     This constructor is hidden.
182          */
183         FileZipper(const FileZipper& fileZipper);
184
185         /**
186          * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
187          *
188          * @param [in]          fileZipper              An instance of %FileZipper
189          * @remarks                     This operator is hidden.
190          */
191         FileZipper& operator =(const FileZipper& fileZipper);
192
193
194         friend class _FileZipperImpl;
195         class _FileZipperImpl* __pFileZipperImpl;
196
197 }; // FileZipper
198
199 }}} // Tizen::Base::FileZipper
200
201 #endif // _FBASE_UTIL_FILE_ZIPPER_H_