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 task_generate_config.cpp
18 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
22 #include "task_prepare_files.h"
26 #include <dpl/file_output.h>
27 #include <dpl/file_input.h>
29 #include <dpl/wrt-dao-ro/feature_dao_read_only.h>
30 #include <dpl/foreach.h>
31 #include <widget_install/widget_install_context.h>
32 #include <widget_install_errors.h>
33 #include <task_commons.h>
34 #include <installer_log.h>
37 namespace WidgetInstall {
38 TaskPrepareFiles::TaskPrepareFiles(InstallerContext &installerContext) :
39 DPL::TaskDecl<TaskPrepareFiles>(this),
40 m_installerContext(installerContext)
42 AddStep(&TaskPrepareFiles::StartStep);
43 AddStep(&TaskPrepareFiles::StepCopyFiles);
44 AddStep(&TaskPrepareFiles::EndStep);
47 void TaskPrepareFiles::CopyFile(const std::string& source)
50 _W("No source file specified");
54 std::string filename = source;
55 size_t last = source.find_last_of("\\/");
56 if (last != std::string::npos) {
57 filename = source.substr(last + 1);
60 m_installerContext.locations->getSourceDir() + '/' +
62 _D("source %s", source.c_str());
63 _D("target %s", target.c_str());
67 DPL::FileInput input(source);
68 DPL::FileOutput output(target);
69 DPL::Copy(&input, &output);
71 Catch(DPL::FileInput::Exception::Base)
73 _E("File input error");
74 // Error while opening or closing source file
75 ReThrowMsg(Exceptions::CopyIconFailed, source);
77 Catch(DPL::FileOutput::Exception::Base)
79 _E("File output error");
80 // Error while opening or closing target file
81 ReThrowMsg(Exceptions::CopyIconFailed, target);
83 Catch(DPL::CopyFailed)
85 _E("File copy error");
86 // Error while copying
87 ReThrowMsg(Exceptions::CopyIconFailed, target);
91 void TaskPrepareFiles::StepCopyFiles()
93 CopyFile(m_installerContext.locations->getWidgetSource());
95 size_t last = m_installerContext.locations->getWidgetSource().find_last_of(
97 std::string sourceDir = "";
98 if (last != std::string::npos) {
99 sourceDir = m_installerContext.locations->getWidgetSource().substr(
106 FOREACH(it, m_installerContext.widgetConfig.configInfo.iconsList) {
107 std::ostringstream os;
108 _D("Coping: %s%ls", sourceDir.c_str(), (it->src).c_str());
109 os << sourceDir << DPL::ToUTF8String(it->src);
114 void TaskPrepareFiles::StartStep()
116 LOGD("--------- <TaskPrepareFiles> : START ----------");
119 void TaskPrepareFiles::EndStep()
121 LOGD("--------- <TaskPrepareFiles> : END ----------");
123 } // namespace WidgetInstall