Installer SignatureValidator implementation
[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         // check version info
58         String versionFile = path + VERSION_INFO_FILE;
59         if (File::IsFileExist(versionFile) == true)
60         {
61                 AppLog("install preloaded app again.")
62                 pContext->__isUpdated = true;
63         }
64
65         String destRootPath(PATH_OPT_USR_APPS);
66         destRootPath += L"/";
67         destRootPath += appId;
68
69         Directory::Create(destRootPath);
70
71         String srcPath;
72         String destPath;
73
74         // /setting
75         srcPath = path + DIR_SETTING;
76         destPath = destRootPath + DIR_SETTING;
77         InstallerUtil::CopyDirectory(srcPath, destPath);
78
79         // /data
80         srcPath = path + DIR_DATA;
81         destPath = destRootPath + DIR_DATA;
82         InstallerUtil::CopyDirectory(srcPath, destPath);
83
84         srcPath = path + DIR_INFO;
85         destPath = destRootPath + DIR_INFO;
86         InstallerUtil::CreateSymlink(srcPath, destPath);
87
88         srcPath = path + DIR_BIN;
89         destPath = destRootPath + DIR_BIN;
90         InstallerUtil::CreateSymlink(srcPath, destPath);
91
92         srcPath = path + DIR_RES;
93         destPath = destRootPath + DIR_RES;
94         InstallerUtil::CreateSymlink(srcPath, destPath);
95
96         srcPath = path + DIR_LIB;
97         destPath = destRootPath + DIR_LIB;
98         InstallerUtil::CreateSymlink(srcPath, destPath);
99
100         srcPath = path + DIR_SHARED;
101         destPath = destRootPath + DIR_SHARED;
102         if (File::IsFileExist(srcPath) == true)
103         {
104                 InstallerUtil::CopyDirectory(srcPath, destPath);
105         }
106         else
107         {
108                 Directory::Create(destPath);
109         }
110
111         srcPath += DIR_RES;
112         destPath += DIR_RES;
113         if (File::IsFileExist(destPath) == false)
114         {
115                 srcPath = path + DIR_ICONS;
116                 InstallerUtil::CreateSymlink(srcPath, destPath);
117         }
118
119         pContext->__installDir = pContext->__inputPath;
120         if ((File::IsFileExist(pContext->GetSignatureXmlPath()) == true) &&
121                         (File::IsFileExist(pContext->GetAuthorSignatureXmlPath()) == true))
122         {
123                 srcPath = path + SIGNATURE1_XML_FILE;
124                 destPath = destRootPath + SIGNATURE1_XML_FILE;
125                 InstallerUtil::CreateSymlink(srcPath, destPath);
126
127                 srcPath = path + AUTHOR_SIGNATURE_XML_FILE;
128                 destPath = destRootPath + AUTHOR_SIGNATURE_XML_FILE;
129                 InstallerUtil::CreateSymlink(srcPath, destPath);
130
131                 AppLog("[VerifySignature] VerificationMode ON");
132                 pContext->__isVerificationMode = true;
133         }
134
135         pContext->__installDir = destRootPath;
136
137         return DirectoryInstaller::OnInit();
138 }
139
140 InstallerError
141 PreloadedInstaller::OnRegister(void)
142 {
143         return DirectoryInstaller::OnRegister();
144 }
145
146 InstallerError
147 PreloadedInstaller::OnEnd(void)
148 {
149         return DirectoryInstaller::OnEnd();
150 }
151
152 InstallerError
153 PreloadedInstaller::OnError(void)
154 {
155         AppLog("PreloadedInstaller::OnError()");
156         return DirectoryInstaller::OnError();
157 }
158
159 InstallerError
160 PreloadedInstaller::OnRollback(void)
161 {
162         AppLog("PreloadedInstaller::OnRollback()");
163         return DirectoryInstaller::OnRollback();
164 }
165
166 InstallerError
167 PreloadedInstaller::OnUserCancel(void)
168 {
169         AppLog("PreloadedInstaller::OnUserCancel()");
170         return DirectoryInstaller::OnUserCancel();
171 }