From f50725771059bc65a5037f7bca6bf8874e011c05 Mon Sep 17 00:00:00 2001 From: Dongeup Ham Date: Mon, 29 Oct 2012 16:07:34 +0900 Subject: [PATCH] Implementation for fonts and improve for installer utilities. Change-Id: Iec6d88b9a7766570a2cdab9a64a12402dfdd79c4 --- inc/InstallerDefs.h | 9 +- src/Context/InstallationContext.cpp | 70 ++++++++ src/Context/InstallationContext.h | 31 ++++ src/Manager/ConfigurationManager.cpp | 42 +++-- src/Manager/PermissionManager.cpp | 324 ++++++++++------------------------- src/Step/ManifestXmlStep.cpp | 104 +++++------ src/Util/InstallerUtil.cpp | 84 +++++++-- src/Util/InstallerUtil.h | 1 + src/XmlHandler/ManifestGenerator.cpp | 2 + src/XmlHandler/ManifestHandler.cpp | 107 +++++++++++- src/XmlHandler/ManifestHandler.h | 5 + 11 files changed, 459 insertions(+), 320 deletions(-) diff --git a/inc/InstallerDefs.h b/inc/InstallerDefs.h index 4f598ab..7251021 100755 --- a/inc/InstallerDefs.h +++ b/inc/InstallerDefs.h @@ -28,12 +28,15 @@ #define DIR_ICONS L"/icons" #define DIR_LIB L"/lib" #define DIR_SETTING L"/setting" +#define DIR_CONTENTS L"/contents" #define SLP_DIR_BIN L"/bin" #define SLP_DIR_RES L"/res" #define SLP_DIR_DATA L"/data" #define SLP_APP_PATH L"/opt/apps" +#define SLP_FONT_PATH L"/opt/share/fonts" + #define DIR_DESKTOP L"/opt/share/applications/%S.desktop" #define PACKAGE_NAME_PREFIX_ORG L"org.tizen." #define PACKAGE_NAME_RULE_ORG L"org.tizen.%ls#%s" @@ -47,8 +50,8 @@ #define TYPE_INFO_FILE L"/info/type.info" #define PACKAGE_XML_FILE L"/info/manifest.xml" -#define SIGNATURE1_XML_FILE L"/signature1.xml" -#define AUTHOR_SIGNATURE_XML_FILE L"/author-signature.xml" +#define SIGNATURE1_XML_FILE L"/signature1.xml" +#define AUTHOR_SIGNATURE_XML_FILE L"/author-signature.xml" #define UISCALABILITY_INFO L"1 %ls %ls %ls" @@ -75,7 +78,7 @@ #define DIR_MEMORYCARD_OSP_APPLICATIONS_TEMP L"/opt/storage/sdcard/apps/__@@osp_tmp@@__" #define OSP_INSTALLER "osp-installer" -#define OSP_INSTALLER_VERSION "osp-installer version = 2012/10/24" +#define OSP_INSTALLER_VERSION "osp-installer version = 2012/10/29" enum InstallationSetStep { diff --git a/src/Context/InstallationContext.cpp b/src/Context/InstallationContext.cpp index d0ab876..0a7fab1 100755 --- a/src/Context/InstallationContext.cpp +++ b/src/Context/InstallationContext.cpp @@ -52,6 +52,7 @@ InstallationContext::InstallationContext(void) ,__storage(INSTALLATION_STORAGE_INTERNAL) ,__pPrivilegeList(null) ,__pLiveBoxList(null) +,__pContentInfoList(null) ,__pAuthorCertPath(null) ,__pDistributorCertPath(null) ,__rootCertType(ROOT_CERTIFICATE_NONE) @@ -424,6 +425,18 @@ InstallationContext::SetLiveBoxList(ArrayList* pLiveBoxList) __pLiveBoxList = pLiveBoxList; } +ArrayList* +InstallationContext::GetContentInfoList(void) const +{ + return __pContentInfoList; +} + +void +InstallationContext::SetContentInfoList(ArrayList* pContentInfoList) +{ + __pContentInfoList = pContentInfoList; +} + X509CertificatePath* InstallationContext::GetAuthorCertPath(void) const { @@ -571,3 +584,60 @@ LiveboxInfo::GetSizeList(void) const { return __pSizeList; } + +ContentInfo::ContentInfo(void) +:__pNameList(null) +{ + __pNameList = new (std::nothrow) HashMap; + TryReturn(__pNameList, , "[osp-installer] __pNameList is null."); + __pNameList->Construct(); +} + +ContentInfo::~ContentInfo(void) +{ + __pNameList->RemoveAll(true); + delete __pNameList; +} + +result +ContentInfo::SetContentId(const String& contentId) +{ + __contentId = contentId; + return E_SUCCESS; +} + +const String& +ContentInfo::GetContentId(void) const +{ + return __contentId; +} + +result +ContentInfo::SetIcon(const String& icon) +{ + __icon = icon; + return E_SUCCESS; +} + +const String& +ContentInfo::GetIcon(void) const +{ + return __icon; +} + +result +ContentInfo::AddName(const String& language, const String& name) +{ + result r = E_SUCCESS; + + r = __pNameList->Add(language, name); + + return r; +} + +HashMap* +ContentInfo::GetNameList(void) const +{ + return __pNameList; +} + diff --git a/src/Context/InstallationContext.h b/src/Context/InstallationContext.h index b8c7d60..f423eb7 100755 --- a/src/Context/InstallationContext.h +++ b/src/Context/InstallationContext.h @@ -116,6 +116,9 @@ public: Osp::Base::Collection::ArrayList* GetLiveBoxList(void) const; void SetLiveBoxList(Osp::Base::Collection::ArrayList* pLiveBoxList); + Osp::Base::Collection::ArrayList* GetContentInfoList(void) const; + void SetContentInfoList(Osp::Base::Collection::ArrayList* pContentInfoList); + Osp::Security::Cert::X509CertificatePath* GetAuthorCertPath(void) const; void SetAuthorCertPath(Osp::Security::Cert::X509CertificatePath* pAuthorCertPath); @@ -160,6 +163,7 @@ private: Osp::Base::Collection::ArrayList* __pPrivilegeList; Osp::Base::Collection::ArrayList* __pLiveBoxList; + Osp::Base::Collection::ArrayList* __pContentInfoList; Osp::Security::Cert::X509CertificatePath* __pAuthorCertPath; Osp::Security::Cert::X509CertificatePath* __pDistributorCertPath; RootCertificateType __rootCertType; @@ -205,4 +209,31 @@ private: }; // LiveboxInfo +class ContentInfo + : public Osp::Base::Object +{ +public: + ContentInfo(void); + virtual ~ContentInfo(void); + + result SetContentId(const Osp::Base::String& contentId); + const Osp::Base::String& GetContentId(void) const; + + result SetIcon(const Osp::Base::String& icon); + const Osp::Base::String& GetIcon(void) const; + + result AddName(const Osp::Base::String& language, const Osp::Base::String& name); + Osp::Base::Collection::HashMap* GetNameList(void) const; + +private: + ContentInfo(const ContentInfo& value); + ContentInfo& operator =(const ContentInfo& source); + + Osp::Base::String __icon; + Osp::Base::String __contentId; + + Osp::Base::Collection::HashMap* __pNameList; + +}; // ContentInfo + #endif // _INSTALLATION_CONTEXT_H_ diff --git a/src/Manager/ConfigurationManager.cpp b/src/Manager/ConfigurationManager.cpp index 363345e..fca0e02 100755 --- a/src/Manager/ConfigurationManager.cpp +++ b/src/Manager/ConfigurationManager.cpp @@ -65,6 +65,7 @@ ConfigurationManager::CreateFile(InstallationContext* pContext) char* pXmlPath = null; int err = 0; bool hybridService = pContext->IsHybridService(); + ArrayList* pContentInfoList = null; _PackageInfoImpl *pPackageInfoImpl = null; pPackageInfoImpl = pContext->GetPackageInfoImpl(); @@ -213,22 +214,43 @@ ConfigurationManager::CreateFile(InstallationContext* pContext) } } - int res = -1; - res = chmod(pBinaryPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); - if (res != 0) - { - AppLogTag(OSP_INSTALLER, "Fail to set permission(755)[%s], res=%d.\n", pBinaryPath, res); - } - else - { - AppLogTag(OSP_INSTALLER, "Success to set permission(755)[%s], res=%d.\n", pBinaryPath, res); - } + InstallerUtil::ChangeMode(pBinaryPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); delete[] pBinaryPath; pBinaryPath = null; } } + pContentInfoList = pContext->GetContentInfoList(); + if (pContentInfoList) + { + int contentCount = pContentInfoList->GetCount(); + for (int i = 0 ; i < contentCount; i++) + { + ContentInfo* pContentInfo = static_cast(pContentInfoList->GetAt(i)); + if (pContentInfo) + { + String contentId = pContentInfo->GetContentId(); + String oldPath = rootPath + DIR_CONTENTS + L"/" + contentId; + + if (File::IsFileExist(SLP_FONT_PATH) == false) + { + Directory::Create(SLP_FONT_PATH, false); + InstallerUtil::ChangeMode(SLP_FONT_PATH, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + } + + String newPath = SLP_FONT_PATH; + newPath += L"/" + pContext->GetAppId(); + Directory::Create(newPath, false); + InstallerUtil::ChangeMode(newPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + + newPath += L"/"; + newPath += contentId; + InstallerUtil::CreateSymlink(oldPath, newPath); + } + } + } + //if (pContext->IsPreloaded() == true) //{ // xmlPath.Format(1024, DIR_RO_PACKAGE_SYSTEM_MANIFEST, pContext->GetAppId().GetPointer()); diff --git a/src/Manager/PermissionManager.cpp b/src/Manager/PermissionManager.cpp index 5a2835c..676f04f 100755 --- a/src/Manager/PermissionManager.cpp +++ b/src/Manager/PermissionManager.cpp @@ -49,26 +49,6 @@ PermissionManager::~PermissionManager(void) { } -//bool -//PermissionManager::ChangeOwner(const Osp::Base::String& filePath) -//{ -// int res = -1; -// char* pFilePath = null; -// -// pFilePath = _StringConverter::CopyToCharArrayN(filePath); -// TryReturn(pFilePath, false, "[osp-installer] pFilePath is null"); -// -// res = chown(pFilePath, APP_OWNER_ID, APP_GROUP_ID); -// if (res != 0) -// { -// AppLogTag(OSP_INSTALLER, "Fail to change owner[%s], res=[%d]", pFilePath, res); -// } -// -// delete[] pFilePath; -// -// return true; -//} - bool PermissionManager::ChangeHomeDirectoryOwner(const String& rootPath, int depth) { @@ -169,172 +149,84 @@ PermissionManager::ApplyHomeDirectoryPolicy(const String& rootPath) return true; } -//bool -//PermissionManager::ChangeMode(const String& filePath, int mode) -//{ -// int res = -1; -// char* pFilePath = null; -// -// pFilePath = _StringConverter::CopyToCharArrayN(filePath); -// TryReturn(pFilePath, false, "[osp-installer] pFilePath is null"); -// -// res = chmod(pFilePath, mode); -// if (res != 0) -// { -// AppLogTag(OSP_INSTALLER, "Fail to change mode, path=[%s], mode=[%o], res=[%d]", pFilePath, mode, res); -// } -// -// delete[] pFilePath; -// -// return true; -//} - bool PermissionManager::SetDirectory(InstallationContext* pContext) { - char destPath[772] = {0}; - int res = -1; - int err = 0; + result r = E_SUCCESS; + + String destPath; String appRootPath; _PackageInfoImpl *pPackageInfoImpl = null; FileAttributes attribute; - result r = E_SUCCESS; pPackageInfoImpl = pContext->GetPackageInfoImpl(); appRootPath = pPackageInfoImpl->GetAppRootPath(); - // set permission(755) to default folders(AppRootPath) - sprintf(destPath, "%ls", appRootPath.GetPointer()); - r = File::GetAttributes(destPath, attribute); - if (r == E_SUCCESS) - { - res = chmod(destPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); - if (res != 0) - { - AppLogTag(OSP_INSTALLER, "Fail to set permission(755)[%s], res=[%d].\n", destPath, res); - } - else - { - AppLogTag(OSP_INSTALLER, "Success to set permission(755)[%s], res=%d.\n", destPath, res); - } - } + // appRoot(rx for app) + InstallerUtil::ChangeOwner(appRootPath); + InstallerUtil::ChangeMode(appRootPath, S_IRUSR | S_IXUSR); - // set permission(755) to default folders(BIN, INFO, DATA, RES) - sprintf(destPath, "%ls%ls", appRootPath.GetPointer(), DIR_BIN); - r = File::GetAttributes(destPath, attribute); - if (r == E_SUCCESS) - { - res = chmod(destPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); - if (res) - { - AppLogTag(OSP_INSTALLER, "Fail to set permission(755)[%s], res=%d.\n", destPath, res); - } - else - { - AppLogTag(OSP_INSTALLER, "Success to set permission(755)[%s], res=%d.\n", destPath, res); - } - } + // appRoot/bin(no permission for app) + destPath = appRootPath + DIR_BIN; + InstallerUtil::ChangeDirectoryPermission(destPath, S_IRUSR | S_IXUSR); - sprintf(destPath, "%ls%ls", appRootPath.GetPointer(), DIR_INFO); - r = File::GetAttributes(destPath, attribute); - if (r == E_SUCCESS) - { - res = chmod(destPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); - if (res != 0) - { - AppLogTag(OSP_INSTALLER, "Fail to set permission(755)[%s], res=%d.\n", destPath, res); - } - else - { - AppLogTag(OSP_INSTALLER, "Success to set permission(755)[%s], res=%d.\n", destPath, res); - } - } + // appRoot/info(rx for app) + destPath = appRootPath + DIR_INFO; + InstallerUtil::ChangeDirectoryPermission(destPath, S_IRUSR | S_IXUSR); - sprintf(destPath, "%ls%ls", appRootPath.GetPointer(), DIR_RES); - r = File::GetAttributes(destPath, attribute); - if (r == E_SUCCESS) - { - ChangeHomeDirectoryOwner(destPath, 0); - InstallerUtil::ChangeMode(destPath, S_IRUSR | S_IXUSR); - } + // appRoot/res(rx for app) + destPath = appRootPath + DIR_RES; + InstallerUtil::ChangeDirectoryPermission(destPath, S_IRUSR | S_IXUSR); - sprintf(destPath, "%ls%ls", appRootPath.GetPointer(), DIR_DATA); - r = File::GetAttributes(destPath, attribute); - if (r == E_SUCCESS) - { - res = chmod(destPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); - if (res != 0) - { - AppLogTag(OSP_INSTALLER, "Fail to set permission(755)[%s], res=%d.\n", destPath, res); - } - else - { - AppLogTag(OSP_INSTALLER, "Success to set permission(755)[%s], res=%d.\n", destPath, res); - } - } + // appRoot/lib(rwx for app) + destPath = appRootPath + DIR_LIB; + InstallerUtil::ChangeDirectoryPermission(destPath, S_IRUSR | S_IXUSR); - sprintf(destPath, "%ls%ls", appRootPath.GetPointer(), DIR_LIB); - r = File::GetAttributes(destPath, attribute); - if (r == E_SUCCESS) - { - res = chmod(destPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); - if (res != 0) - { - AppLogTag(OSP_INSTALLER, "Fail to set permission(755)[%s], res=%d.\n", destPath, res); - } - else - { - AppLogTag(OSP_INSTALLER, "Success to set permission(755)[%s], res=%d.\n", destPath, res); - } - } + // appRoot/icons(rx for app) + destPath = appRootPath + DIR_ICONS; + InstallerUtil::ChangeDirectoryPermission(destPath, S_IRUSR | S_IXUSR); - sprintf(destPath, "%ls%ls", appRootPath.GetPointer(), DIR_ICONS); - r = File::GetAttributes(destPath, attribute); - if (r == E_SUCCESS) - { - ChangeHomeDirectoryOwner(destPath, 0); - InstallerUtil::ChangeMode(destPath, S_IRUSR | S_IWUSR | S_IXUSR); - } + // appRoot/contents(rx for app) + destPath = appRootPath + DIR_CONTENTS; + InstallerUtil::ChangeDirectoryPermission(destPath, S_IRUSR | S_IXUSR); - sprintf(destPath, "%ls%ls", appRootPath.GetPointer(), DIR_SETTING); + // appRoot/setting(rwx for app) + destPath = appRootPath + DIR_SETTING; r = File::GetAttributes(destPath, attribute); if (r == E_SUCCESS) { String appVersion = pPackageInfoImpl->GetAppVersion(); - char src[772] = {0}; - char dest[772] = {0}; - - sprintf(src, "%s/%s.%ls.%s", destPath, "setting", appVersion.GetPointer(), "xml"); - sprintf(dest, "%s/%s", destPath, "setting.xml"); + String srcPath; + String settingXmlPath; - unlink(dest); + srcPath = destPath + L"/setting." + appVersion + L".xml"; + settingXmlPath = destPath + L"/setting.xml"; - if (File::IsFileExist(src) == true) - { - err = symlink(src, dest); - AppLogTag(OSP_INSTALLER, "[%s]->[%s]\n", dest, src); - } - else - { - AppLogTag(OSP_INSTALLER, "[%s] is not existed.\n", src); - } + InstallerUtil::Remove(settingXmlPath); + InstallerUtil::CreateSymlink(srcPath, settingXmlPath); - ChangeHomeDirectoryOwner(destPath, 0); - InstallerUtil::ChangeMode(destPath, S_IRUSR | S_IWUSR | S_IXUSR); + InstallerUtil::ChangeDirectoryPermission(destPath, S_IRWXU); } - ApplyHomeDirectoryPolicy(appRootPath); + // appRoot/data(rwx for app) + destPath = appRootPath + DIR_DATA; + if (File::IsFileExist(destPath) == false) + { + r = Directory::Create(destPath, false); + TryReturn(!IsFailed(r), INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] Directory::Create() failed"); + } + InstallerUtil::ChangeDirectoryPermission(destPath, S_IRWXU); - String packageId = pContext->GetAppId(); + String appId = pContext->GetAppId(); String apiVersion = pPackageInfoImpl->GetAppApiVersion(); - AppLogTag(OSP_INSTALLER, "Osp::Io > installed path: %ls, packageId: %ls, API version: %ls", - appRootPath.GetPointer(), packageId.GetPointer(), apiVersion.GetPointer()); + AppLogTag(OSP_INSTALLER, "Osp::Io > installed path: %ls, appId: %ls, API version: %ls", + appRootPath.GetPointer(), appId.GetPointer(), apiVersion.GetPointer()); if (apiVersion.CompareTo(L"3.0") < 0) { AppLogTag(OSP_INSTALLER, "Osp::Io > API version <= 2.0"); - if (_FileImpl::PrepareDataCaging(appRootPath, packageId) == false) + if (_FileImpl::PrepareDataCaging(appRootPath, appId) == false) { AppLogTag(OSP_INSTALLER, "Osp::Io > _FileImpl::PrepareDataCaging() failed"); return false; @@ -346,13 +238,15 @@ PermissionManager::SetDirectory(InstallationContext* pContext) { AppLogTag(OSP_INSTALLER, "Osp::Io > API version >= 3.0"); - if (_FileImpl::CreateOspApplicationDirectories(appRootPath, packageId) == false) + if (_FileImpl::CreateOspApplicationDirectories(appRootPath, appId) == false) { AppLogTag(OSP_INSTALLER, "Osp::Io > _FileImpl::CreateOspApplicationDirectories() failed."); return false; } } + // Create AppId.ExecutableName directory + // This will be removed. CreateSystemDirectory(pContext, appRootPath); return true; @@ -361,8 +255,7 @@ PermissionManager::SetDirectory(InstallationContext* pContext) bool PermissionManager::SetFile(InstallationContext* pContext) { - char destPath[772] = {0}; - int res = -1; + String destPath; _PackageInfoImpl *pPackageInfoImpl = null; _PackageAppInfoImpl* pAppInfoImpl = null; @@ -381,17 +274,19 @@ PermissionManager::SetFile(InstallationContext* pContext) if (pAppInfoImpl) { // set permission(755) to bin file. - sprintf(destPath, "%ls%ls/%ls", appRootPath.GetPointer(), DIR_BIN, (pAppInfoImpl->GetName()).GetPointer()); - strcat(destPath, ".exe"); - res = chmod(destPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); - if (res != 0) - { - AppLogTag(OSP_INSTALLER, "Fail to set permission(755)[%s], res=%d.\n", destPath, res); - } - else - { - AppLogTag(OSP_INSTALLER, "Success to set permission(755)[%s], res=%d.\n", destPath, res); - } + // sprintf(destPath, "%ls%ls/%ls", appRootPath.GetPointer(), DIR_BIN, (pAppInfoImpl->GetName()).GetPointer()); + // strcat(destPath, ".exe"); + destPath = appRootPath + DIR_BIN + L"/" + pAppInfoImpl->GetName() + L".exe"; + InstallerUtil::ChangeMode(destPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + // res = chmod(destPath, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); +// if (res != 0) +// { +// AppLogTag(OSP_INSTALLER, "Fail to set permission(755)[%s], res=%d.\n", destPath, res); +// } +// else +// { +// AppLogTag(OSP_INSTALLER, "Success to set permission(755)[%s], res=%d.\n", destPath, res); +// } } } @@ -404,7 +299,6 @@ PermissionManager::CreateSystemDirectory(InstallationContext* pContext, const Os _PackageInfoImpl *pPackageInfoImpl = null; _PackageAppInfoImpl* pAppInfoImpl = null; ArrayList* pAppList = null; - int err = 0; pPackageInfoImpl = pContext->GetPackageInfoImpl(); TryReturn(pPackageInfoImpl, false, "[osp-installer] pPackageInfoImpl is null."); @@ -417,30 +311,11 @@ PermissionManager::CreateSystemDirectory(InstallationContext* pContext, const Os pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pAppList->GetAt(i)); if (pAppInfoImpl) { - result r = E_SUCCESS; - String packageName = pAppInfoImpl->GetPackageName(); - String destPath; - String appRootPath; - appRootPath = pPackageInfoImpl->GetAppRootPath(); - char src[772] = {0}; - char dest[772] = {0}; - - destPath.Format(1024, L"%ls/%ls", SLP_APP_PATH, packageName.GetPointer()); - - sprintf(src, "%ls", appRootPath.GetPointer()); - sprintf(dest, "%ls", destPath.GetPointer()); - - unlink(dest); - - FileAttributes attr; - r = File::GetAttributes(destPath, attr); - if (r == E_SUCCESS) - { - InstallerUtil::Remove(destPath); - AppLogTag(OSP_INSTALLER, "Directory is removed. [%ls]\n", destPath.GetPointer()); - } - - err = symlink(src, dest); + String destPath = SLP_APP_PATH; + destPath += L"/" + pAppInfoImpl->GetPackageName(); + + InstallerUtil::Remove(destPath); + InstallerUtil::CreateSymlink(pPackageInfoImpl->GetAppRootPath(), destPath); } } @@ -450,56 +325,35 @@ PermissionManager::CreateSystemDirectory(InstallationContext* pContext, const Os bool PermissionManager::SetSymLink(InstallationContext* pContext) { - char srcPath[772] = {0}; - char destPath[772] = {0}; - int err = 0; - String appRootPath; - _PackageInfoImpl *pPackageInfoImpl = null; + String oldPath; + String newPath; - pPackageInfoImpl = pContext->GetPackageInfoImpl(); - appRootPath = pPackageInfoImpl->GetAppRootPath(); + _PackageInfoImpl* pPackageInfoImpl = pContext->GetPackageInfoImpl(); + String appRootPath = pPackageInfoImpl->GetAppRootPath(); - sprintf(srcPath, "%ls%ls", appRootPath.GetPointer(), DIR_RES); - if (File::IsFileExist(srcPath) == true) - { - sprintf(destPath, "%ls%s", appRootPath.GetPointer(), "/Res"); - err = symlink("./res", destPath); - } + oldPath = appRootPath + DIR_RES; + newPath = appRootPath + L"/Res"; + InstallerUtil::CreateSymlink(oldPath, newPath); - sprintf(srcPath, "%ls%ls", appRootPath.GetPointer(), DIR_DATA); - if (File::IsFileExist(srcPath) == true) - { - sprintf(destPath, "%ls%s", appRootPath.GetPointer(), "/Home"); - err = symlink("./data", destPath); - } + oldPath = appRootPath + DIR_DATA; + newPath = appRootPath + L"/Home"; + InstallerUtil::CreateSymlink(oldPath, newPath); - sprintf(srcPath, "%ls%s", appRootPath.GetPointer(), "/res/screen-size-normal"); - if (File::IsFileExist(srcPath) == true) - { - sprintf(destPath, "%ls%s", appRootPath.GetPointer(), "/Res/ScreenSize-Normal"); - err = symlink(srcPath, destPath); - } + oldPath = appRootPath + DIR_RES + L"/screen-size-normal"; + newPath = appRootPath + L"/Res/ScreenSize-Normal"; + InstallerUtil::CreateSymlink(oldPath, newPath); - sprintf(srcPath, "%ls%s", appRootPath.GetPointer(), "/res/screen-density-high"); - if (File::IsFileExist(srcPath) == true) - { - sprintf(destPath, "%ls%s", appRootPath.GetPointer(), "/Res/ScreenDensity-High"); - err = symlink(srcPath, destPath); - } + oldPath = appRootPath + DIR_RES + L"screen-density-high"; + newPath = appRootPath + L"/Res/ScreenDensity-High"; + InstallerUtil::CreateSymlink(oldPath, newPath); - sprintf(srcPath, "%ls%s", appRootPath.GetPointer(), "/res/screen-density-middle"); - if (File::IsFileExist(srcPath) == true) - { - sprintf(destPath, "%ls%s", appRootPath.GetPointer(), "/Res/ScreenDensity-Middle"); - err = symlink(srcPath, destPath); - } + oldPath = appRootPath + DIR_RES + L"/screen-density-middle"; + newPath = appRootPath + L"/Res/ScreenDensity-Middle"; + InstallerUtil::CreateSymlink(oldPath, newPath); - sprintf(srcPath, "%ls%s", appRootPath.GetPointer(), "/res/screen-density-low"); - if (File::IsFileExist(srcPath) == true) - { - sprintf(destPath, "%ls%s", appRootPath.GetPointer(), "/Res/ScreenDensity-Low"); - err = symlink(srcPath, destPath); - } + oldPath = appRootPath + DIR_RES + L"/screen-density-low"; + newPath = appRootPath + L"/Res/ScreenDensity-Low"; + InstallerUtil::CreateSymlink(oldPath, newPath); return true; } diff --git a/src/Step/ManifestXmlStep.cpp b/src/Step/ManifestXmlStep.cpp index 3737437..02d1889 100755 --- a/src/Step/ManifestXmlStep.cpp +++ b/src/Step/ManifestXmlStep.cpp @@ -19,6 +19,8 @@ * @brief This is the implementation file for %ManifestStep class. */ +#include + #include #include @@ -97,70 +99,76 @@ ManifestXmlStep::OnStateManifestXml(void) InstallerError error = INSTALLER_ERROR_NONE; bool ret = false; - char *pFilepath = null; + // char *pFilepath = null; _PackageInfoImpl *pPackageInfoImpl = null; - File file; - const int bufSize = 32*1024; - char *p = new char[bufSize]; - memset(p, 0, sizeof(bufSize)); + String manifestXmlPath; + +// File file; +// const int bufSize = 32*1024; +// char *p = new char[bufSize]; +// memset(p, 0, sizeof(bufSize)); result r = E_SUCCESS; - int size = 0; +// int size = 0; - pFilepath = _StringConverter::CopyToCharArrayN(__pContext->GetManifestXmlPath()); + // pFilepath = _StringConverter::CopyToCharArrayN(__pContext->GetManifestXmlPath()); + manifestXmlPath = __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()); - } +// 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); + r = File::GetAttributes(manifestXmlPath, 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, "") != 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 + TryReturn(!IsFailed(r), INSTALLER_ERROR_INVALID_PACKAGE, "[osp-installer] File::GetAttributes() failed"); + + std::unique_ptr pFilepath(_StringConverter::CopyToCharArrayN(manifestXmlPath)); + TryReturn(pFilepath, INSTALLER_ERROR_INVALID_PACKAGE, "[osp-installer] pFilepath is null"); + +// 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, "") != null) +// { + AppLogTag(OSP_INSTALLER, "manifest file=(%ls)", manifestXmlPath.GetPointer()); + + ManifestHandler manifestHandler; + manifestHandler.Construct(__pContext); + ret = manifestHandler.Parse(pFilepath.get()); + if (ret == false) { - fprintf(stderr, "ManifestXmlStep::OnStateManifestXml - old manifest!! \n"); - AppLogTag(OSP_INSTALLER, "ManifestXmlStep::OnStateManifest() - error(INSTALLER_ERROR_INVALID_MANIFEST)"); - error = INSTALLER_ERROR_INVALID_MANIFEST; + fprintf(stderr, "OnStateManifestXml - manifestHandler.Parse is failed. [%s]\n", pFilepath.get()); } - -CATCH: - delete[] p; + TryReturn(ret == true, INSTALLER_ERROR_INVALID_MANIFEST, "[osp-installer] manifestHandler.Parse() failed"); + + pPackageInfoImpl = __pContext->GetPackageInfoImpl(); + TryReturn(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; + // delete[] pFilepath; return error; } diff --git a/src/Util/InstallerUtil.cpp b/src/Util/InstallerUtil.cpp index c1b4163..a6ba9e2 100755 --- a/src/Util/InstallerUtil.cpp +++ b/src/Util/InstallerUtil.cpp @@ -48,43 +48,38 @@ InstallerUtil::~InstallerUtil(void) bool InstallerUtil::Remove(const Osp::Base::String& filePath) { - bool res = false; - char* pFilePath = null; - struct stat fileinfo; - int err = 0; + int err = -1; result r = E_SUCCESS; + struct stat fileinfo; - pFilePath = _StringConverter::CopyToCharArrayN(filePath); - TryCatch(pFilePath, r = GetLastResult(), "[osp-installer] pFilePath is null"); - - err = lstat(pFilePath, &fileinfo); - TryCatch(err >= 0, res = false, "[osp-installer] lstat() failed, pFilePath=%s", pFilePath); + std::unique_ptr pFilePath(_StringConverter::CopyToCharArrayN(filePath)); + TryReturn(pFilePath, false, "[osp-installer] pFilePath is null"); + err = lstat(pFilePath.get(), &fileinfo); + TryReturn(err >= 0, false, "[osp-installer] lstat() failed, filepath=%s", pFilePath.get()); if (S_ISLNK(fileinfo.st_mode)) { - AppLogTag(OSP_INSTALLER, "remove symlink, pFilePath=%s", pFilePath); - err = unlink(pFilePath); - TryCatch(err >= 0, res = false, "[osp-installer] unlink() failed, pFilePath=%s", pFilePath); + AppLogTag(OSP_INSTALLER, "remove symlink, pFilePath=%s", pFilePath.get()); + err = unlink(pFilePath.get()); + TryReturn(err >= 0, false, "[osp-installer] unlink() failed, filepath=%s", pFilePath.get()); } else if (S_ISDIR(fileinfo.st_mode)) { AppLogTag(OSP_INSTALLER, "remove directory, filePath=%ls", filePath.GetPointer()); r = Directory::Remove(filePath, true); - TryCatch(!IsFailed(r), res = false, "[osp-installer] Directory::Remove() failed, filePath=%ls", filePath.GetPointer()); + TryReturn(!IsFailed(r), false, "[osp-installer] Directory::Remove() failed, filePath=%ls", filePath.GetPointer()); } else { AppLogTag(OSP_INSTALLER, "remove file, filePath=%ls", filePath.GetPointer()); r = File::Remove(filePath); - TryCatch(!IsFailed(r), res = false, "[osp-installer] File::Remove() failed, filePath=%ls", filePath.GetPointer()); + TryReturn(!IsFailed(r), false, "[osp-installer] File::Remove() failed, filePath=%ls", filePath.GetPointer()); } - res = true; + AppLogTag(OSP_INSTALLER, "[%ls] is removed.", filePath.GetPointer()); -CATCH: - delete [] pFilePath; - return res; + return true; } bool @@ -124,6 +119,10 @@ bool InstallerUtil::CreateSymlink(const String& oldPath, const String& newPath) { int err = -1; + bool res = false; + + res = File::IsFileExist(oldPath); + TryReturn(res == true, false, "[osp-installer] file not found, oldPath=(%ls).", oldPath.GetPointer()); std::unique_ptr pOldPath(_StringConverter::CopyToCharArrayN(oldPath)); TryReturn(pOldPath, false, "[osp-installer] pOldPath is null"); @@ -166,6 +165,55 @@ InstallerUtil::ChangeOwner(const String& filePath) } bool +InstallerUtil::ChangeDirectoryPermission(const String& filePath, int mode) +{ + result r = E_SUCCESS; + + std::unique_ptr pDir(new Directory); + TryReturn(pDir, false, "[osp-installer] pDir is null."); + + r = pDir->Construct(filePath); + TryReturn(!IsFailed(r), false, "[osp-installer] pDir->Construct() failed, filePath=[%ls].", filePath.GetPointer()); + + std::unique_ptr pDirEnum(pDir->ReadN()); + TryReturn(pDirEnum, false, "[osp-installer] pDirEnum is null."); + + while (pDirEnum->MoveNext() == E_SUCCESS) + { + DirEntry entry = pDirEnum->GetCurrentDirEntry(); + + String entryName = entry.GetName(); + String entryDir = filePath; + entryDir += L"/"; + entryDir += entryName; + + if (entryName == L".") + { + InstallerUtil::ChangeOwner(entryDir); + InstallerUtil::ChangeMode(entryDir, mode); + continue; + } + else if (entryName == L"..") + { + continue; + } + + if (entry.IsDirectory() == false) + { + InstallerUtil::ChangeOwner(entryDir); + InstallerUtil::ChangeMode(entryDir, mode); + } + else + { + ChangeDirectoryPermission(entryDir, mode); + InstallerUtil::ChangeMode(entryDir, mode); + } + } + + return true; +} + +bool InstallerUtil::IsDrmFile(const Osp::Base::String& packagePath) { AppLogTag(OSP_INSTALLER, "IsDrmFile() called, packagePath=%ls", packagePath.GetPointer()); diff --git a/src/Util/InstallerUtil.h b/src/Util/InstallerUtil.h index a01cae1..245fcce 100755 --- a/src/Util/InstallerUtil.h +++ b/src/Util/InstallerUtil.h @@ -48,6 +48,7 @@ public: static bool CreateSymlink(const Osp::Base::String& oldPath, const Osp::Base::String& newPath); static bool ChangeMode(const Osp::Base::String& filePath, int mode); static bool ChangeOwner(const Osp::Base::String& filePath); + static bool ChangeDirectoryPermission(const Osp::Base::String& filePath, int mode); static bool IsDrmFile(const Osp::Base::String& packagePath); static bool DecryptPackage(const Osp::Base::String& packagePath); diff --git a/src/XmlHandler/ManifestGenerator.cpp b/src/XmlHandler/ManifestGenerator.cpp index c03822e..82027c3 100755 --- a/src/XmlHandler/ManifestGenerator.cpp +++ b/src/XmlHandler/ManifestGenerator.cpp @@ -493,4 +493,6 @@ ManifestGenerator::WriteAppControl(_PackageAppInfoImpl* pAppInfoImpl) const __pWriter->EndElement(); } } + + return true; } diff --git a/src/XmlHandler/ManifestHandler.cpp b/src/XmlHandler/ManifestHandler.cpp index 7c2c773..3561bee 100755 --- a/src/XmlHandler/ManifestHandler.cpp +++ b/src/XmlHandler/ManifestHandler.cpp @@ -40,6 +40,7 @@ ManifestHandler::ManifestHandler(void) :__pContext(null) ,__pPrivilegeList(null) ,__pLiveBoxList(null) +,__pContentInfoList(null) ,__pPackageInfoImpl(null) ,__pPackageAppInfoImpl(null) ,__pAppControlInfoImpl(null) @@ -50,6 +51,7 @@ ManifestHandler::ManifestHandler(void) ,__pLaunchConditionImpl(null) ,__pNotificationImpl(null) ,__pLiveboxInfo(null) +,__pContentInfo(null) ,__pDefaultIconType(null) ,__isDefaultMainmenu(false) ,__isDefaultSetting(false) @@ -147,6 +149,14 @@ ManifestHandler::OnStartElement(const char *pName) { status = OnLiveBoxElement(); } + else if (strcasecmp(pName, "Contents") == 0) + { + status = OnContentsElement(); + } + else if (strcasecmp(pName, "Content") == 0) + { + status = OnContentElement(); + } if (!status) { @@ -183,7 +193,6 @@ ManifestHandler::OnEndElement(const char *pName) __isDefaultName = false; AppLogTag(OSP_INSTALLER, "", pName); } - else if (strcasecmp(pName, "AppControl") == 0) { __pPackageAppInfoImpl->AddAppControl(__pAppControlInfoImpl); @@ -232,11 +241,6 @@ ManifestHandler::OnEndElement(const char *pName) else if (strcasecmp(pName, "Apps") == 0) { AppLogTag(OSP_INSTALLER, "", pName); - if (__isDefaultAppDetected == false) - { - fprintf(stderr, "__isDefaultAppDetected is false.\n"); - } - TryReturn(__isDefaultAppDetected, false, "[osp-installer][Error] Default App is not detected..."); } else if (strcasecmp(pName, "UiScalability") == 0) { @@ -254,12 +258,33 @@ ManifestHandler::OnEndElement(const char *pName) __pLiveBoxList = null; AppLogTag(OSP_INSTALLER, "", pName); } + else if (strcasecmp(pName, "Contents") == 0) + { + __pContext->SetContentInfoList(__pContentInfoList); + __pContentInfoList = null; + AppLogTag(OSP_INSTALLER, "", pName); + } else if (strcasecmp(pName, "LiveBox") == 0) { __pLiveBoxList->Add(*__pLiveboxInfo); __pLiveboxInfo = null; AppLogTag(OSP_INSTALLER, "", pName); } + else if (strcasecmp(pName, "Content") == 0) + { + __pContentInfoList->Add(*__pContentInfo); + __pContentInfo = null; + AppLogTag(OSP_INSTALLER, "", pName); + } + else if (strcasecmp(pName, "Manifest") == 0) + { + if (__isDefaultAppDetected == false) + { + fprintf(stderr, "__isDefaultAppDetected is false.\n"); + } + TryReturn(__isDefaultAppDetected, false, "[osp-installer][Error] Default App is not detected..."); + AppLogTag(OSP_INSTALLER, "", pName); + } if (!status) { @@ -433,6 +458,57 @@ ManifestHandler::OnLiveBoxElement(void) } bool +ManifestHandler::OnContentsElement(void) +{ + __pContentInfoList = new ArrayList; + TryReturn(__pContentInfoList, false, "[osp-installer] __pContentInfoList is null"); + + AppLogTag(OSP_INSTALLER, ""); + + return true; +} + +bool +ManifestHandler::OnContentElement(void) +{ + TryReturn(__pContentInfo == null, false, "[osp-installer] __pContentInfo is not null"); + + XmlAttribute *pAttr = null; + char *pDefault = null; + + __pContentInfo = new ContentInfo; + TryReturn(__pContentInfo, false, "[osp-installer] __pLiveboxInfo is null"); + + pAttr = GetAttribute(); + TryReturn(pAttr, true, "[osp-installer] pAttr is null"); + + char* pId = pAttr->Find("Id"); + if (pId) + { + __pContentInfo->SetContentId(pId); + } + + char* pEntryName = pAttr->Find("EntryName"); + if (pEntryName) + { + __pContentInfo->SetContentId(pEntryName); + } + + pDefault = pAttr->Find("Default"); + if (pDefault) + { + if (strcasecmp(pDefault, "True") == 0) + { + __isDefaultAppDetected = true; + } + } + + AppLogTag(OSP_INSTALLER, "", pId, pEntryName); + + return true; +} + +bool ManifestHandler::OnUiScalabilityElement(void) { XmlAttribute *pAttr = null; @@ -591,6 +667,12 @@ bool ManifestHandler::OnTypeValue(const char *pCharacters) { __pPackageInfoImpl->SetAppType(pCharacters); + + if (strcasecmp(pCharacters, "Contents") == 0) + { + __pPackageInfoImpl->SetAppApiVersion("3.0"); + } + AppLogTag(OSP_INSTALLER, "%s", pCharacters); return true; @@ -660,6 +742,11 @@ ManifestHandler::OnIconValue(const char *pCharacters) TryReturn(__pLiveboxInfo, false, "[osp-installer] __pLiveboxInfo is null"); __pLiveboxInfo->SetIcon(icon); } + else if (FindElement("Content") == true) + { + TryReturn(__pContentInfo, false, "[osp-installer] __pContentInfo is null"); + __pContentInfo->SetIcon(icon); + } else { if (strcasecmp(pAttrValue1, "MainMenu") == 0) @@ -734,6 +821,14 @@ ManifestHandler::OnNameValue(const char *pCharacters) StringUtil::Utf8ToString(pCharacters, *pValue); __pLiveboxInfo->AddName(*(new String(pAttrValue)), *pValue); } + else if (FindElement("Content") == true) + { + TryReturn(__pContentInfo, false, "[osp-installer] __pContentInfo is null"); + + String* pValue = new String; + StringUtil::Utf8ToString(pCharacters, *pValue); + __pContentInfo->AddName(*(new String(pAttrValue)), *pValue); + } else { if (strcasecmp(pAttrValue, "eng-GB") == 0 || strcasecmp(pAttrValue, "eng-US") == 0) diff --git a/src/XmlHandler/ManifestHandler.h b/src/XmlHandler/ManifestHandler.h index 6801d0b..59ab3c2 100755 --- a/src/XmlHandler/ManifestHandler.h +++ b/src/XmlHandler/ManifestHandler.h @@ -53,10 +53,13 @@ private: virtual bool OnStartElement(const char *pName); virtual bool OnEndElement(const char *pName); virtual bool OnCharacters(const char *pCharacters); + bool OnPrivilegesElement(void); bool OnPrivilegesEndElement(void); bool OnLiveBoxesElement(void); bool OnLiveBoxElement(void); + bool OnContentsElement(void); + bool OnContentElement(void); bool OnUiScalabilityElement(void); bool OnUiThemeElement(void); bool OnIconsElement(void); @@ -91,6 +94,7 @@ private: InstallationContext* __pContext; Osp::Base::Collection::ArrayList* __pPrivilegeList; Osp::Base::Collection::ArrayList* __pLiveBoxList; + Osp::Base::Collection::ArrayList* __pContentInfoList; Osp::App::_PackageInfoImpl* __pPackageInfoImpl; Osp::App::_PackageAppInfoImpl* __pPackageAppInfoImpl; Osp::App::_AppControlInfoImpl* __pAppControlInfoImpl; @@ -101,6 +105,7 @@ private: Osp::App::_LaunchConditionInfoImpl* __pLaunchConditionImpl; Osp::App::_NotificationInfoImpl* __pNotificationImpl; LiveboxInfo* __pLiveboxInfo; + ContentInfo* __pContentInfo; char* __pDefaultIconType; bool __isDefaultMainmenu; -- 2.7.4