[Release] wrt-installer_0.1.85
[platform/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 #include <wrt_common_types.h>
29 #include <wrt_install_mode.h>
30
31 /**
32  * @brief The WidgetLocation class
33  *
34  * Object that stores locations of several files/directories according
35  * to package name
36  *
37  * Current package layout (of installed package) is following:
38  *
39  * /opt/apps/[package_name]
40  *           \_____________ /data
41  *           \_____________ /share
42  *           \_____________ /bin
43  *           \_____________ /bin/[id_of_installed_package]
44  *           \_____________ /res/wgt/
45  *                               \___ config.xml
46  *                               \___ [widgets_archive_content]
47  *
48  * 1) Normal Widget
49  *  Developer provides content of res/wgt directory (package contains that
50  * directory as root).
51  *
52  * 2) For OSP Service Hybrid App is actually a bit different:
53  *  Root is OSP Service directory, WebApp content is located in [root]/res/wgt
54  *
55  * Temporary directory is directory when widget is placed at the begining
56  * of installation process. After parsing process of config.xml, destination
57  * directory is created.
58  */
59 class WidgetLocation
60 {
61     class DirectoryDeletor
62     {
63       public:
64         DirectoryDeletor();
65         DirectoryDeletor(std::string tempPath);
66         DirectoryDeletor(bool isPreload);
67
68         ~DirectoryDeletor();
69         std::string getTempPath() const;
70
71       private:
72         std::string m_dirpath;
73     };
74
75   public:
76     DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
77     DECLARE_EXCEPTION_TYPE(Base, NoTemporaryPath)
78     /**
79      * @brief WidgetLocation
80      *
81      * Creates useless object. Needed by DPL::Optional
82      */
83     WidgetLocation();
84     /**
85      * @brief WidgetLocation Builds paths for widget location during
86      * uninstallation
87      *
88      * Uninstallation process needs only installed package directory.
89      *
90      * @param widgetname name of widget
91      */
92     explicit WidgetLocation(const std::string & widgetname);
93     /**
94      * @brief WidgetLocation Builds paths for widget location during
95      * installation
96      *
97      * @param widgetname name of widget
98      * @param sourcePath given source path
99      * @param t declaraced type of widget if type is needed
100      *
101      * In destruction removes temporary directory
102      */
103     WidgetLocation(const std::string & widgetname, std::string sourcePath,
104                    WrtDB::PackagingType t = WrtDB::PKG_TYPE_NOMAL_WEB_APP,
105                    bool isReadonly = false,
106                    InstallMode::ExtensionType eType =
107                    InstallMode::ExtensionType::WGT);
108
109     WidgetLocation(const std::string & widgetname, std::string sourcePath,
110                    std::string dirPath,
111                    WrtDB::PackagingType t = WrtDB::PKG_TYPE_NOMAL_WEB_APP,
112                    bool isReadonly = false,
113                    InstallMode::ExtensionType eType =
114                    InstallMode::ExtensionType::WGT);
115
116     ~WidgetLocation();
117
118     // Installed paths
119     std::string getInstallationDir() const; // /opt/apps or /usr/apps
120     std::string getPackageInstallationDir() const; // /opt/apps/[package]
121     std::string getSourceDir() const;  // /opt/apps/[package]/res/wgt
122     std::string getBinaryDir() const;  // /opt/apps/[package]/bin or /usr/apps/[package]/bin
123     std::string getUserBinaryDir() const;  // /opt/apps/[package]/bin
124     std::string getExecFile() const;   // /opt/apps/[package]/bin/[package]
125     std::string getBackupDir() const;  // /opt/apps/[package].backup
126     std::string getBackupSourceDir() const; // /opt/apps/[pkg].backup/res/wgt
127     std::string getBackupBinaryDir() const; // /opt/apps/[pkg].backup/bin
128     std::string getBackupExecFile() const;  // /opt/apps/[pkg].backup/bin/[pkg]
129     std::string getBackupPrivateDir() const;  // /opt/apps/[pkg].backup/data
130     std::string getUserDataRootDir() const; // /opt/usr/apps/[package]
131     std::string getPrivateStorageDir() const; // /opt/usr/apps/[package]/data
132     std::string getPrivateTempStorageDir() const; // /opt/usr/apps/[package]/tmp
133     std::string getSharedRootDir() const; // /opt/usr/apps/[package]/shared
134     std::string getSharedResourceDir() const; // /opt/usr/apps/[package]/shared/res
135     std::string getSharedDataDir() const; // /opt/usr/apps/[package]/shared/data
136     std::string getSharedTrustedDir() const; // /opt/usr/apps/[package]/shared/trusted
137     std::string getBackupSharedDir() const; // /opt/usr/apps/[package].backup/shared
138
139     // Temporary paths
140     /**
141      * @brief getTemporaryRootDir
142      * @return value of root for developer's provide package (root of unpacked
143      * .wgt file)
144      */
145     std::string getTemporaryPackageDir() const;
146     /**
147      * @brief getTemporaryRootDir
148      *
149      * Value of this will differs according to type of installed widget.
150      *
151      * @return value of root for content in temporary directory to be copied
152      * into 'res/wgt'
153      */
154     std::string getTemporaryRootDir() const;
155     /**
156      * @brief getConfigurationDir Returns rott directory for configuration
157      * requirements
158      *
159      * 1) For packed widgets it is just root of unpacked sources
160      * 2) For browser installation it is directory name of widget passed to
161      * installer
162      *
163      * @return configuration directory
164      */
165     std::string getConfigurationDir() const;
166
167     //icons
168     /**
169      * @brief setIconTargetFilenameForLocale set installed ion path according to
170      * locale
171      * @param icon path of application icon
172      */
173     void setIconTargetFilenameForLocale(const std::string &icon);
174
175     /**
176      * @brief getIconTargetFilename gets icon full path
177      * @param languageTag language tag
178      * @return value of full path
179      */
180     std::string getInstalledIconPath() const;
181
182     /**
183      * @brief getWidgetSourcePath return widget's source path given to installer
184      * @return value of source path
185      */
186     std::string getWidgetSource() const;
187     /**
188      * @brief pkgid Returns pkgid
189      * @return pkgid
190      */
191     DPL::String getPkgId() const;
192
193     //external files
194     /**
195      * @brief registerExternalFile Registers file for database registration
196      * @param file
197      *
198      * Registered file will be stored in database and removed automatically a
199      *
200      * @return
201      */
202     void registerExternalLocation(const std::string & file);
203     /**
204      * @brief listExternalFile list all file to be registered
205      */
206     WrtDB::ExternalLocationList listExternalLocations() const;
207
208     /*
209      * @brief set appid
210      */
211     void registerAppid(const std::string & appid);
212
213   private:
214     std::string m_pkgid;                        //id of package
215     std::string m_widgetSource;                   // Source widget zip
216                                                   // file/widget url
217     std::string m_appid;                        //id of app
218     std::string m_iconPath;                       //installed icon path
219     WrtDB::PackagingType m_type;
220     std::shared_ptr<DirectoryDeletor> m_temp;      //directory
221     WrtDB::ExternalLocationList m_externals;
222     std::string m_installedPath;
223     InstallMode::ExtensionType m_extensionType;
224 };
225
226 #endif // WRT_INSTALLER_SRC_MISC_WIDGET_LOCATION_H