add to create share directory
[framework/web/wrt-installer.git] / src / misc / widget_location.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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  * @file        widget_location.h
18  * @author      Iwanek Tomasz (t.iwanek@smasung.com)
19  */
20 #ifndef WRT_INSTALLER_SRC_MISC_WIDGET_LOCATION_H
21 #define WRT_INSTALLER_SRC_MISC_WIDGET_LOCATION_H
22
23 #include <string>
24 #include <memory>
25
26 #include <dpl/wrt-dao-ro/common_dao_types.h>
27 #include <dpl/wrt-dao-ro/widget_dao_read_only.h>
28
29 /**
30  * @brief The WidgetLocation class
31  *
32  * Object that stores locations of several files/directories according
33  * to package name
34  *
35  * Current package layout (of installed package) is following:
36  *
37  * /opt/apps/[package_name]
38  *           \_____________ /data
39  *           \_____________ /share
40  *           \_____________ /bin
41  *           \_____________ /bin/[id_of_installed_package]
42  *           \_____________ /res/wgt/
43  *                               \___ config.xml
44  *                               \___ [widgets_archive_content]
45  *
46  * 1) Normal Widget
47  *  Developer provides content of res/wgt directory (package contains that directory as root).
48  *
49  * 2) For OSP Service Hybrid App is actually a bit different:
50  *  Root is OSP Service directory, WebApp content is located in [root]/res/wgt
51  *
52  * Temporary directory is directory when widget is placed at the begining
53  * of installation process. After parsing process of config.xml, destination directory is created.
54  */
55 class WidgetLocation
56 {
57     class DirectoryDeletor
58     {
59     public:
60         DirectoryDeletor();
61         DirectoryDeletor(std::string tempPath);
62         ~DirectoryDeletor();
63         std::string getTempPath() const;
64     private:
65         std::string m_dirpath;
66     };
67
68 public:
69     DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
70     DECLARE_EXCEPTION_TYPE(Base, NoTemporaryPath)
71     /**
72      * @brief WidgetLocation
73      *
74      * Creates useless object. Needed by DPL::Optional
75      */
76     WidgetLocation();
77     /**
78      * @brief WidgetLocation Builds paths for widget location during uninstallation
79      *
80      * Uninstallation process needs only installed package directory.
81      *
82      * @param widgetname name of widget
83      */
84     WidgetLocation(const std::string & widgetname);
85     /**
86      * @brief WidgetLocation Builds paths for widget location during installation
87      *
88      * @param widgetname name of widget
89      * @param sourcePath given source path
90      * @param t declaraced type of widget if type is needed
91      *
92      * In destruction removes temporary directory
93      */
94     WidgetLocation(const std::string & widgetname, std::string sourcePath,
95                    WrtDB::PackagingType t = WrtDB::PKG_TYPE_NOMAL_WEB_APP,
96                    bool preload = false);
97
98     WidgetLocation(const std::string & widgetname, std::string sourcePath,
99                    std::string dirPath,
100                    WrtDB::PackagingType t = WrtDB::PKG_TYPE_NOMAL_WEB_APP,
101                    bool preload = false);
102
103     ~WidgetLocation();
104
105     // Installed paths
106     std::string getInstallationDir() const;              // /opt/apps or /usr/apps
107     std::string getPackageInstallationDir() const;       // /opt/apps/[package]
108     std::string getSourceDir() const;                    // /opt/apps/[package]/res/wgt
109     std::string getBinaryDir() const;                    // /opt/apps/[package]/bin
110     std::string getExecFile() const;                    // /opt/apps/[package]/bin/[package]
111     std::string getBackupDir() const;                    // /opt/apps/[package]/backup
112     std::string getBackupSourceDir() const;              // /opt/apps/[package]/backup/res/wgt
113     std::string getBackupBinaryDir() const;              // /opt/apps/[package]/backup/bin
114     std::string getBackupExecFile() const;              // /opt/apps/[package]/backup/bin/[package]
115     std::string getUserDataRootDir() const;             // /opt/usr/apps/[package]
116     std::string getPrivateStorageDir() const;                 // /opt/usr/apps/[package]/data
117     std::string getShareDir() const;                    // /opt/usr/apps/[package]/share
118
119     // Temporary paths
120     /**
121      * @brief getTemporaryRootDir
122      * @return value of root for developer's provide package (root of unpacked .wgt file)
123      */
124     std::string getTemporaryPackageDir() const;
125     /**
126      * @brief getTemporaryRootDir
127      *
128      * Value of this will differs according to type of installed widget.
129      *
130      * @return value of root for content in temporary directory to be copied into 'res/wgt'
131      */
132     std::string getTemporaryRootDir() const;
133     /**
134      * @brief getConfigurationDir Returns rott directory for configuration requirements
135      *
136      * 1) For packed widgets it is just root of unpacked sources
137      * 2) For browser installation it is directory name of widget passed to installer
138      *
139      * @return configuration directory
140      */
141     std::string getConfigurationDir() const;
142
143     //icons
144     /**
145      * @brief setIconTargetFilenameForLocale set installed ion path according to locale
146      * @param icon path of application icon
147      */
148     void setIconTargetFilenameForLocale(const std::string &icon);
149     /**
150      * @brief getIconTargetFilename gets icon path suffix for locale
151      * @param languageTag language tag
152      * @return value of suffix of path
153      */
154     DPL::String getIconTargetFilename(const DPL::String& languageTag) const;
155     /**
156      * @brief getIconTargetFilename gets icon full path
157      * @param languageTag language tag
158      * @return value of full path
159      */
160     std::string getInstalledIconPath() const;
161
162     /**
163      * @brief getWidgetSourcePath return widget's source path given to installer
164      * @return value of source path
165      */
166     std::string getWidgetSource() const;
167     /**
168      * @brief pkgname Returns pkgname
169      * @return pkgname
170      */
171     DPL::String getPkgname() const;
172
173     //external files
174     /**
175      * @brief registerExternalFile Registers file for database registration
176      * @param file
177      *
178      * Registered file will be stored in database and removed automatically a
179      *
180      * @return
181      */
182     void registerExternalLocation(const std::string & file);
183     /**
184      * @brief listExternalFile list all file to be registered
185      */
186     WrtDB::ExternalLocationList listExternalLocations() const;
187
188 private:
189     std::string m_widgetSource;                   // Source widget zip file/widget url
190     std::string m_pkgname;                        //name of package
191     std::string m_iconPath;                       //installed icon path
192     WrtDB::PackagingType m_type;
193     std::shared_ptr<DirectoryDeletor> m_temp;      //directory
194     WrtDB::ExternalLocationList m_externals;
195     std::string m_installedPath;
196 };
197
198 #endif // WRT_INSTALLER_SRC_MISC_WIDGET_LOCATION_H