ba18b4e21502b3e1d48b60a1dc3d091fb5050d91
[platform/framework/native/installer.git] / src / Installer / PreloadedInstaller.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file        PreloadedInstaller.cpp
19  * @brief       This is the implementation file for %PreloadedInstaller class.
20  */
21
22 #include <FBaseLog.h>
23 #include <FIoDirectory.h>
24 #include <FIoFile.h>
25
26 #include "PreloadedInstaller.h"
27 #include "InstallerUtil.h"
28
29 using namespace Tizen::Base;
30 using namespace Tizen::Io;
31
32 PreloadedInstaller::PreloadedInstaller(void)
33 {
34 }
35
36 PreloadedInstaller::~PreloadedInstaller(void)
37 {
38 }
39
40 InstallationStep
41 PreloadedInstaller::GetNext(InstallationStep step)
42 {
43         return DirectoryInstaller::GetNext(step);
44 }
45
46 InstallerError
47 PreloadedInstaller::OnInit(void)
48 {
49         InstallationContext* pContext = GetContext();
50         String path = pContext->__inputPath;
51         String appId;
52         String prefix(PATH_USR_APPS);
53         prefix += L"/";
54
55         path.SubString(prefix.GetLength(), PACKAGE_ID_LENGTH, appId);
56
57         String destRootPath(PATH_OPT_USR_APPS);
58         destRootPath += L"/";
59         destRootPath += appId;
60
61         Directory::Create(destRootPath);
62
63         String srcPath;
64         String destPath;
65
66         // /setting
67         srcPath = path + DIR_SETTING;
68         destPath = destRootPath + DIR_SETTING;
69         InstallerUtil::CopyDirectory(srcPath, destPath);
70
71         // /data
72         srcPath = path + DIR_DATA;
73         destPath = destRootPath + DIR_DATA;
74         InstallerUtil::CopyDirectory(srcPath, destPath);
75
76         srcPath = path + DIR_INFO;
77         destPath = destRootPath + DIR_INFO;
78         InstallerUtil::CreateSymlink(srcPath, destPath);
79
80         srcPath = path + DIR_BIN;
81         destPath = destRootPath + DIR_BIN;
82         InstallerUtil::CreateSymlink(srcPath, destPath);
83
84         srcPath = path + DIR_RES;
85         destPath = destRootPath + DIR_RES;
86         InstallerUtil::CreateSymlink(srcPath, destPath);
87
88         srcPath = path + DIR_LIB;
89         destPath = destRootPath + DIR_LIB;
90         InstallerUtil::CreateSymlink(srcPath, destPath);
91
92         srcPath = path + DIR_SHARED;
93         destPath = destRootPath + DIR_SHARED;
94         if (File::IsFileExist(srcPath) == true)
95         {
96                 InstallerUtil::CopyDirectory(srcPath, destPath);
97         }
98         else
99         {
100                 Directory::Create(destPath);
101         }
102
103         srcPath += DIR_RES;
104         destPath += DIR_RES;
105         if (File::IsFileExist(destPath) == false)
106         {
107                 srcPath = path + DIR_ICONS;
108                 InstallerUtil::CreateSymlink(srcPath, destPath);
109         }
110
111         pContext->__installDir = pContext->__inputPath;
112         if ((File::IsFileExist(pContext->GetSignatureXmlPath()) == true) &&
113                         (File::IsFileExist(pContext->GetAuthorSignatureXmlPath()) == true))
114         {
115                 srcPath = path + SIGNATURE1_XML_FILE;
116                 destPath = destRootPath + SIGNATURE1_XML_FILE;
117                 InstallerUtil::CreateSymlink(srcPath, destPath);
118
119                 srcPath = path + AUTHOR_SIGNATURE_XML_FILE;
120                 destPath = destRootPath + AUTHOR_SIGNATURE_XML_FILE;
121                 InstallerUtil::CreateSymlink(srcPath, destPath);
122
123                 AppLog("[VerifySignature] VerificationMode ON");
124                 pContext->__isVerificationMode = true;
125         }
126
127         pContext->__installDir = destRootPath;
128
129         return DirectoryInstaller::OnInit();
130 }
131
132 InstallerError
133 PreloadedInstaller::OnRegister(void)
134 {
135         return DirectoryInstaller::OnRegister();
136 }
137
138 InstallerError
139 PreloadedInstaller::OnEnd(void)
140 {
141         return DirectoryInstaller::OnEnd();
142 }
143
144 InstallerError
145 PreloadedInstaller::OnError(void)
146 {
147         AppLog("PreloadedInstaller::OnError()");
148         return DirectoryInstaller::OnError();
149 }
150
151 InstallerError
152 PreloadedInstaller::OnRollback(void)
153 {
154         AppLog("PreloadedInstaller::OnRollback()");
155         return DirectoryInstaller::OnRollback();
156 }
157
158 InstallerError
159 PreloadedInstaller::OnUserCancel(void)
160 {
161         AppLog("PreloadedInstaller::OnUserCancel()");
162         return DirectoryInstaller::OnUserCancel();
163 }