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