2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file widget_location.cpp
18 * @author Iwanek Tomasz (t.iwanek@smasung.com)
20 #include "widget_location.h"
23 #include <dpl/utils/wrt_utility.h>
24 #include <dpl/wrt-dao-ro/global_config.h>
25 #include <dpl/assert.h>
26 #include <dpl/sstream.h>
27 #include <dpl/localization/localization_utils.h>
28 #include <widget_install/task_commons.h>
29 #include <installer_log.h>
31 WidgetLocation::DirectoryDeletor::DirectoryDeletor(bool isReadOnly) :
32 m_dirpath(Jobs::WidgetInstall::createTempPath(isReadOnly))
35 WidgetLocation::DirectoryDeletor::DirectoryDeletor(std::string tempPath) :
39 WidgetLocation::DirectoryDeletor::~DirectoryDeletor()
41 _D("Removing widget installation temporary directory: %s", m_dirpath.c_str());
42 std::string roPath = WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
44 if (0 != m_dirpath.compare(0, roPath.length(), roPath)) {
45 if (!WrtUtilRemove(m_dirpath)) {
46 _W("Fail at removing directory: %s", m_dirpath.c_str());
51 std::string WidgetLocation::DirectoryDeletor::getTempPath() const
56 WidgetLocation::WidgetLocation() :
57 m_temp(new WidgetLocation::DirectoryDeletor(true))
60 WidgetLocation::WidgetLocation(const std::string & widgetname) :
62 m_temp(new WidgetLocation::DirectoryDeletor(false))
65 WidgetLocation::~WidgetLocation()
68 WidgetLocation::WidgetLocation(const std::string & widgetname,
69 std::string sourcePath,
70 WrtDB::PackagingType t,
72 InstallMode::ExtensionType eType) :
74 m_widgetSource(sourcePath),
77 new WidgetLocation::DirectoryDeletor(isReadonly)),
78 m_extensionType(eType)
81 m_installedPath += WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
83 m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
85 if (access(m_widgetSource.c_str(), F_OK) != 0) {
86 m_widgetSource = m_installedPath + "/" + m_pkgid;
90 WidgetLocation::WidgetLocation(const std::string & widgetname,
91 std::string sourcePath,
93 WrtDB::PackagingType t,
95 InstallMode::ExtensionType eType) :
97 m_widgetSource(sourcePath),
99 m_temp(new WidgetLocation::DirectoryDeletor(dirPath)),
100 m_extensionType(eType)
103 m_installedPath += WrtDB::GlobalConfig::GetUserPreloadedWidgetPath();
105 m_installedPath += WrtDB::GlobalConfig::GetUserInstalledWidgetPath();
107 if (access(m_widgetSource.c_str(), F_OK) != 0) {
108 m_widgetSource = m_installedPath + "/" + m_pkgid;
112 // TODO cache all these paths
113 std::string WidgetLocation::getInstallationDir() const
115 return m_installedPath;
118 std::string WidgetLocation::getPackageInstallationDir() const
120 return m_installedPath + "/" + m_pkgid;
123 std::string WidgetLocation::getSourceDir() const
125 return m_installedPath + "/"
126 + m_pkgid + WrtDB::GlobalConfig::GetWidgetSrcPath();
129 std::string WidgetLocation::getBinaryDir() const
131 return m_installedPath + "/"
132 + m_pkgid + WrtDB::GlobalConfig::GetUserWidgetExecPath();
135 std::string WidgetLocation::getUserBinaryDir() const
137 return getUserDataRootDir() + "/"
138 + WrtDB::GlobalConfig::GetUserWidgetExecPath();
141 std::string WidgetLocation::getExecFile() const
143 return getBinaryDir() + "/" + m_appid;
146 std::string WidgetLocation::getBackupDir() const
148 return getPackageInstallationDir() + ".backup";
151 std::string WidgetLocation::getBackupSourceDir() const
153 return getBackupDir() + WrtDB::GlobalConfig::GetWidgetSrcPath();
156 std::string WidgetLocation::getBackupBinaryDir() const
158 return getBackupDir() + WrtDB::GlobalConfig::GetUserWidgetExecPath();
161 std::string WidgetLocation::getBackupExecFile() const
163 return getBackupBinaryDir() + "/" + m_appid;
166 std::string WidgetLocation::getBackupPrivateDir() const
168 return getBackupDir() + "/" +
169 WrtDB::GlobalConfig::GetWidgetPrivateStoragePath();
172 std::string WidgetLocation::getUserDataRootDir() const
174 return std::string(WrtDB::GlobalConfig::GetWidgetUserDataPath()) +
178 std::string WidgetLocation::getPrivateStorageDir() const
180 return getUserDataRootDir() + "/" +
181 WrtDB::GlobalConfig::GetWidgetPrivateStoragePath();
184 std::string WidgetLocation::getPrivateTempStorageDir() const
186 return getUserDataRootDir() + "/" +
187 WrtDB::GlobalConfig::GetWidgetPrivateTempStoragePath();
191 std::string WidgetLocation::getTemporaryPackageDir() const
193 return m_temp->getTempPath();
196 std::string WidgetLocation::getTemporaryRootDir() const
198 if (m_extensionType == InstallMode::ExtensionType::DIR) {
199 return getWidgetSource() + WrtDB::GlobalConfig::GetWidgetSrcPath();
201 return getSourceDir();
204 DPL::String WidgetLocation::getPkgId() const
206 return DPL::FromUTF8String(m_pkgid);
209 std::string WidgetLocation::getInstalledIconPath() const
214 std::string WidgetLocation::getWidgetSource() const
216 return m_widgetSource;
219 void WidgetLocation::setIconTargetFilenameForLocale(const std::string & icon)
224 void WidgetLocation::registerExternalLocation(const std::string & file)
226 m_externals.push_back(file);
229 WrtDB::ExternalLocationList WidgetLocation::listExternalLocations() const
234 void WidgetLocation::registerAppid(const std::string & appid)
239 #ifdef SERVICE_ENABLED
240 void WidgetLocation::registerServiceAppid(const std::string & svcAppid)
242 m_svcAppid = svcAppid;
246 std::string WidgetLocation::getSharedRootDir() const
248 /* TODO : add wrt-commons*/
249 return getUserDataRootDir() + "/shared";
252 std::string WidgetLocation::getSharedResourceDir() const
254 return getSharedRootDir() + "/res";
257 std::string WidgetLocation::getSharedDataDir() const
259 return getSharedRootDir() + "/data";
262 std::string WidgetLocation::getSharedTrustedDir() const
264 return getSharedRootDir() + "/trusted";
267 std::string WidgetLocation::getBackupSharedDir() const
269 return getBackupDir() + "/shared";
272 std::string WidgetLocation::getBackupSharedDataDir() const
274 return getBackupSharedDir() + "/data";
277 std::string WidgetLocation::getBackupSharedTrustedDir() const
279 return getBackupSharedDir() + "/trusted";
282 std::string WidgetLocation::getNPPluginsExecFile() const
284 return getBinaryDir() + "/" + m_appid + ".npruntime";
287 std::string WidgetLocation::getNPPluginsDir() const
289 return getSourceDir() + "/plugins";