1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/*
* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @file task_generate_config.cpp
* @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
* @version 1.0
*/
#include "task_prepare_files.h"
#include <memory>
#include <string>
#include <iostream>
#include <dpl/file_output.h>
#include <dpl/file_input.h>
#include <dpl/copy.h>
#include <dpl/log/log.h>
#include <dpl/wrt-dao-ro/feature_dao_read_only.h>
#include <dpl/foreach.h>
#include <widget_install/widget_install_context.h>
#include <widget_install_errors.h>
#include <task_commons.h>
namespace Jobs {
namespace WidgetInstall {
TaskPrepareFiles::TaskPrepareFiles(InstallerContext &installerContext) :
DPL::TaskDecl<TaskPrepareFiles>(this),
m_installerContext(installerContext)
{
// Install steps
AddStep(&TaskPrepareFiles::StepCopyFiles);
}
void TaskPrepareFiles::CopyFile(const std::string& source)
{
if(source.empty()) {
LogWarning("No source file specified");
return;
}
std::string filename = source;
size_t last = source.find_last_of( "\\/" );
if(last != std::string::npos) {
filename = source.substr( last+1 );
}
std::string target = m_installerContext.locations->getTemporaryPackageDir() + '/' + filename;
LogDebug("source " << source);
LogDebug("target " << target);
Try
{
DPL::FileInput input(source);
DPL::FileOutput output(target);
DPL::Copy(&input, &output);
}
Catch(DPL::FileInput::Exception::Base)
{
LogError("File input error");
// Error while opening or closing source file
ReThrowMsg(Exceptions::CopyIconFailed, source);
}
Catch(DPL::FileOutput::Exception::Base)
{
LogError("File output error");
// Error while opening or closing target file
ReThrowMsg(Exceptions::CopyIconFailed, target);
}
Catch(DPL::CopyFailed)
{
LogError("File copy error");
// Error while copying
ReThrowMsg(Exceptions::CopyIconFailed, target);
}
}
void TaskPrepareFiles::StepCopyFiles()
{
CopyFile(m_installerContext.locations->getWidgetSource());
size_t last = m_installerContext.locations->getWidgetSource().find_last_of("\\/");
std::string sourceDir = "";
if (last != std::string::npos) {
sourceDir = m_installerContext.locations->getWidgetSource().substr(0,last+1);
}
LogDebug("Icons copy...");
FOREACH(it, m_installerContext.widgetConfig.configInfo.iconsList) {
std::ostringstream os;
LogDebug("Coping: " << sourceDir << DPL::ToUTF8String(it->src));
os << sourceDir << DPL::ToUTF8String(it->src);
CopyFile(os.str());
}
}
} // namespace WidgetInstall
} // namespace Jobs
|