tizen 2.3.1 release
[framework/web/wearable/wrt-plugins-tizen.git] / src / Archive / UnZipExtractRequest.h
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2014 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 #ifndef __TIZEN_ARCHIVE_UNZIP_EXTRACT_REQUEST_H__
19 #define __TIZEN_ARCHIVE_UNZIP_EXTRACT_REQUEST_H__
20
21 #include <stdio.h>
22 #include <string>
23 #include "UnZip.h"
24
25 namespace DeviceAPI {
26 namespace Archive {
27
28 enum FilePathStatus {
29     FPS_NOT_EXIST = 0,
30     FPS_FILE = 1,
31     FPS_DIRECTORY = 2
32 };
33
34 class UnZipExtractRequest
35 {
36 public:
37     static void execute(UnZip& owner,
38             const std::string& extract_path,
39             const std::string& base_strip_path,
40             BaseProgressCallback* callback);
41
42     ~UnZipExtractRequest();
43
44 private:
45     UnZipExtractRequest(UnZip& owner,
46             const std::string& extract_path,
47             const std::string& base_strip_path,
48             BaseProgressCallback* callback);
49     void run();
50
51     void getCurrentFileInfo();
52
53     void handleDirectoryEntry();
54
55     void handleFileEntry();
56     bool prepareOutputSubdirectory();
57
58     //-----------------------------------------------------------------------------
59     //Input request variables
60     UnZip& m_owner;
61     const std::string m_extract_path;
62     const std::string m_base_strip_path;
63     BaseProgressCallback* m_callback;
64
65     //-----------------------------------------------------------------------------
66     //Working variables
67     FILE* m_output_file; //Used to write extracted file into output directory
68     char* m_buffer; //Memory buffer passed between Minizip lib and fwrite function
69
70     bool m_delete_output_file;
71     bool m_close_unz_current_file;
72
73     unz_file_info m_file_info; //Informations about current archive entry (from minizip)
74     char m_filename_inzip[512]; //Name of archive file entry (from minizip)
75     std::string m_output_filepath; //Extracted output file name with full path
76
77     FilePathStatus m_new_dir_status;
78     bool m_is_directory_entry; //Is this request for directory
79     std::string m_new_dir_path;
80 };
81
82 } //namespace Archive
83 } //namespace DeviceAPI
84
85 #endif // __TIZEN_ARCHIVE_UNZIP_EXTRACT_REQUEST_H__