diff options
author | jh0522.choi <jh0522.choi@samsung.com> | 2012-10-05 13:54:12 +0900 |
---|---|---|
committer | jh0522.choi <jh0522.choi@samsung.com> | 2012-10-05 13:54:12 +0900 |
commit | c6fdf2fe68fbab516825cb00afd34c86262e9fbd (patch) | |
tree | b2662be0980746c19f0ddf8b7d7acb55eef74f29 /src/Step/ManifestXmlStep.cpp | |
parent | f064727a492edc71d743c53bb9b906ea8d3f379f (diff) | |
download | installer-c6fdf2fe68fbab516825cb00afd34c86262e9fbd.tar.gz installer-c6fdf2fe68fbab516825cb00afd34c86262e9fbd.tar.bz2 installer-c6fdf2fe68fbab516825cb00afd34c86262e9fbd.zip |
Seperate the osp-installer
Diffstat (limited to 'src/Step/ManifestXmlStep.cpp')
-rwxr-xr-x | src/Step/ManifestXmlStep.cpp | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/src/Step/ManifestXmlStep.cpp b/src/Step/ManifestXmlStep.cpp new file mode 100755 index 0000000..3737437 --- /dev/null +++ b/src/Step/ManifestXmlStep.cpp @@ -0,0 +1,175 @@ +// +// Open Service Platform +// Copyright (c) 2012 Samsung Electronics Co., Ltd. +// +// 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 ManifestStep.cpp + * @brief This is the implementation file for %ManifestStep class. + */ + +#include <FIoFile.h> + +#include <FBase_StringConverter.h> +#include <FApp_PackageInfoImpl.h> + +#include "InstallationContext.h" +#include "ManifestHandler.h" +#include "ManifestXmlStep.h" + +using namespace Osp::Base; +using namespace Osp::App; +using namespace Osp::Io; + +ManifestXmlStep::ManifestXmlStep(void) +:__state(STATE_MANIFEST_XML) +,__pContext(null) +{ +} + +ManifestXmlStep::~ManifestXmlStep(void) +{ +} + +InstallerError +ManifestXmlStep::Run(InstallationContext* pContext) +{ + InstallerError error = INSTALLER_ERROR_NONE; + AppLogTag(OSP_INSTALLER, "ManifestXmlStep - START"); + + __pContext = pContext; + + while (true) + { + switch (__state) + { + case STATE_MANIFEST_XML: + AppLogTag(OSP_INSTALLER, "[State] STATE_MANIFEST"); + error = OnStateManifestXml(); + break; + + case STATE_DONE: + AppLogTag(OSP_INSTALLER, "[State] STATE_DONE"); + error = OnStateDone(); + break; + + default: + break; + } + + if (error != INSTALLER_ERROR_NONE) + { + fprintf(stderr, "ManifestXmlStep::Run - ErrorType [%d]\n", error); + break; + } + + if (__state > STATE_DONE) + { + AppLogTag(OSP_INSTALLER, "ManifestXmlStep- END"); + break; + } + } + + return error; +} + +void +ManifestXmlStep::GoNextState(void) +{ + __state++; +} + +InstallerError +ManifestXmlStep::OnStateManifestXml(void) +{ + AppLogTag(OSP_INSTALLER, "ManifestXmlStep::OnStateManifest()"); + + InstallerError error = INSTALLER_ERROR_NONE; + bool ret = false; + char *pFilepath = null; + _PackageInfoImpl *pPackageInfoImpl = null; + File file; + const int bufSize = 32*1024; + char *p = new char[bufSize]; + memset(p, 0, sizeof(bufSize)); + result r = E_SUCCESS; + int size = 0; + + pFilepath = _StringConverter::CopyToCharArrayN(__pContext->GetManifestXmlPath()); + + r = file.Construct(__pContext->GetManifestXmlPath(), L"r"); + if (r != E_SUCCESS) + { + fprintf(stderr, "OnStateManifestXml - file.Construct is failed. [%ls]\n", __pContext->GetManifestXmlPath().GetPointer()); + AppLogTag(OSP_INSTALLER, "OnStateManifestXml - file.Construct is failed. [%ls]\n", __pContext->GetManifestXmlPath().GetPointer()); + } + + FileAttributes attr; + r = File::GetAttributes(__pContext->GetManifestXmlPath(), attr); + if (r != E_SUCCESS) + { + fprintf(stderr, "OnStateManifestXml - File::GetAttributes is failed. [%ls]\n", __pContext->GetManifestXmlPath().GetPointer()); + AppLogTag(OSP_INSTALLER, "OnStateManifestXml - File::GetAttributes is failed. [%ls]\n", __pContext->GetManifestXmlPath().GetPointer()); + } + TryCatch(!IsFailed(r), error = INSTALLER_ERROR_INVALID_PACKAGE, "[osp-installer] File::GetAttributes() failed"); + + size = file.Read(p, bufSize); + if (size <= 0) + { + fprintf(stderr, "OnStateManifestXml - file.Read is failed. [%ls]\n", __pContext->GetManifestXmlPath().GetPointer()); + AppLogTag(OSP_INSTALLER, "OnStateManifestXml - file.Read is failed. [%ls]\n", __pContext->GetManifestXmlPath().GetPointer()); + } + + if (strstr(p, "<Apps>") != null) + { + AppLogTag(OSP_INSTALLER, "ManifestXmlStep::OnStateManifest() - new manifest!"); + + ManifestHandler manifestHandler; + manifestHandler.Construct(__pContext); + ret = manifestHandler.Parse(pFilepath); + if (ret == false) + { + fprintf(stderr, "OnStateManifestXml - manifestHandler.Parse is failed. [%s]\n", pFilepath); + } + TryCatch(ret == true, error = INSTALLER_ERROR_INVALID_MANIFEST, "[osp-installer] manifestHandler.Parse() failed"); + + pPackageInfoImpl = __pContext->GetPackageInfoImpl(); + TryCatch(pPackageInfoImpl, error = INSTALLER_ERROR_INVALID_MANIFEST, "[osp-installer] pPackageInfoImpl is null"); + __pContext->SetAppId(pPackageInfoImpl->GetAppId()); + } + else + { + fprintf(stderr, "ManifestXmlStep::OnStateManifestXml - old manifest!! \n"); + AppLogTag(OSP_INSTALLER, "ManifestXmlStep::OnStateManifest() - error(INSTALLER_ERROR_INVALID_MANIFEST)"); + error = INSTALLER_ERROR_INVALID_MANIFEST; + } + +CATCH: + delete[] p; + + GoNextState(); + + delete[] pFilepath; + return error; +} + +InstallerError +ManifestXmlStep::OnStateDone(void) +{ + InstallerError error = INSTALLER_ERROR_NONE; + AppLogTag(OSP_INSTALLER, "ManifestXmlStep::OnStateDone()"); + + GoNextState(); + return error; +} |