Hybrid Xml generator is implemented.
authorDongeup Ham <dongeup.ham@samsung.com>
Wed, 12 Dec 2012 09:47:04 +0000 (18:47 +0900)
committerDongeup Ham <dongeup.ham@samsung.com>
Wed, 12 Dec 2012 09:47:04 +0000 (18:47 +0900)
Change-Id: Id1456da1a95b6f03b888d78eb3b5e571b495631f

inc/InstallerDefs.h
src/Manager/ConfigurationManager.cpp [changed mode: 0644->0755]
src/Manager/ConfigurationManager.h [changed mode: 0644->0755]
src/Util/InstallerUtil.cpp [changed mode: 0644->0755]
src/Util/InstallerUtil.h [changed mode: 0644->0755]

index db8252e..b1996c7 100755 (executable)
@@ -21,7 +21,7 @@
 #ifndef _INSTALLER_DEFS_H_
 #define _INSTALLER_DEFS_H_
 
-#define OSP_INSTALLER_VERSION "osp-installer version = [2012/12/12]_RC[1]"
+#define OSP_INSTALLER_VERSION "osp-installer version = [2012/12/12]_RC[2]"
 
 #define DIR_BIN                                L"/bin"
 #define DIR_INFO                       L"/info"
@@ -83,7 +83,7 @@
 
 #define DIR_MEMORYCARD_OSP_APPLICATIONS                        L"/opt/storage/sdcard/apps"
 #define DIR_MEMORYCARD_OSP_APPLICATIONS_TEMP   L"/opt/storage/sdcard/apps/__@@osp_tmp@@__"
-#define DIR_MEMORYCARD_INSTALLATION                            L"/opt/storage/sdcard/installtosdcard"
+#define DIR_MEMORYCARD_INSTALLATION                                            L"/opt/storage/sdcard/installtosdcard"
 
 static const int BLOCK_SIZE = 4096;
 
old mode 100644 (file)
new mode 100755 (executable)
index d4b482b..203d51b
@@ -265,7 +265,21 @@ ConfigurationManager::CreateFile(InstallationContext* pContext)
 
        if (hybridService == true)
        {
-               CreateHybridServiceDesktopFile(pContext);
+               String webXmlPath = pXmlPath;
+               webXmlPath += L".wgt";
+               InstallerUtil::Copy(pXmlPath, webXmlPath);
+
+               pkgmgr_parser_parse_manifest_for_uninstallation(pXmlPath, null);
+               CreateSystemXmlFile(pContext);
+
+               String serviceXmlPath = pXmlPath;
+               serviceXmlPath += L".tpk";
+               InstallerUtil::Copy(pXmlPath, serviceXmlPath);
+               InstallerUtil::Remove(pXmlPath);
+
+               MergeToSystemXmlFile(pXmlPath, webXmlPath, serviceXmlPath);
+               InstallerUtil::Remove(webXmlPath);
+               InstallerUtil::Remove(serviceXmlPath);
        }
        else
        {
@@ -279,19 +293,16 @@ ConfigurationManager::CreateFile(InstallationContext* pContext)
        AppLogTag(OSP_INSTALLER, "sync() - END");
        AppLogTag(OSP_INSTALLER, "------------------------------------------");
        
-       if (hybridService == false)
+       AppLogTag(OSP_INSTALLER, "------------------------------------------");
+       AppLogTag(OSP_INSTALLER, "pkgmgr_parser_parse_manifest_for_installation() - START");
+       err = pkgmgr_parser_parse_manifest_for_installation(pXmlPath, null);
+       if (err != 0)
        {
-               AppLogTag(OSP_INSTALLER, "------------------------------------------");
-               AppLogTag(OSP_INSTALLER, "pkgmgr_parser_parse_manifest_for_installation() - START");
-               err = pkgmgr_parser_parse_manifest_for_installation(pXmlPath, null);
-               if (err != 0)
-               {
-                       AppLogTag(OSP_INSTALLER, "pkgmgr_parser_parse_manifest_for_installation() is failed. error = [%d][%s]", err, pXmlPath);
-                       fprintf(stderr, "pkgmgr_parser_parse_manifest_for_installation is failed. error = [%d][%s]\n", err, pXmlPath);
-               }
-               AppLogTag(OSP_INSTALLER, "pkgmgr_parser_parse_manifest_for_installation() - END");
-               AppLogTag(OSP_INSTALLER, "------------------------------------------");
+               AppLogTag(OSP_INSTALLER, "pkgmgr_parser_parse_manifest_for_installation() is failed. error = [%d][%s]", err, pXmlPath);
+               fprintf(stderr, "pkgmgr_parser_parse_manifest_for_installation is failed. error = [%d][%s]\n", err, pXmlPath);
        }
+       AppLogTag(OSP_INSTALLER, "pkgmgr_parser_parse_manifest_for_installation() - END");
+       AppLogTag(OSP_INSTALLER, "------------------------------------------");
 
        res = true;
 
@@ -628,6 +639,75 @@ ConfigurationManager::CreateHybridServiceDesktopFile(InstallationContext* pConte
 }
 
 bool
+ConfigurationManager::MergeToSystemXmlFile(const String& systemXmlPath, const String& webXmlPath, const String& serviceXmlPath)
+{
+       result r = E_SUCCESS;
+
+       FileAttributes webXmlAttr;
+       r = File::GetAttributes(webXmlPath, webXmlAttr);
+       TryReturn(!IsFailed(r), false, "[osp-installer] File::GetAttributes() failed, webXmlPath=%ls", webXmlPath.GetPointer());
+
+       FileAttributes serviceAttr;
+       r = File::GetAttributes(serviceXmlPath, serviceAttr);
+       TryReturn(!IsFailed(r), false, "[osp-installer] File::GetAttributes() failed, serviceXmlPath=%ls", serviceXmlPath.GetPointer());
+
+       long long webXmlFileSize = webXmlAttr.GetFileSize();
+       long long serviceXmlFileSize = serviceAttr.GetFileSize();
+       long long mergedSize = webXmlFileSize + serviceXmlFileSize;
+
+       File webXml;
+       r = webXml.Construct(webXmlPath, L"r");
+       TryReturn(!IsFailed(r), false, "[osp-installer] webXmlPath.Construct is failed");
+
+       std::unique_ptr<char[]> pMergedBuf(new char[mergedSize + 1]);
+       TryReturn(pMergedBuf, false, "[osp-installer] pMergedBuf is null");
+       memset(pMergedBuf.get(), 0, mergedSize + 1);
+
+       int readBytes = webXml.Read(pMergedBuf.get(), webXmlFileSize);
+       TryReturn(readBytes >= 0, false, "[osp-installer] webXml.Read is failed");
+
+       File serviceXml;
+       r = serviceXml.Construct(serviceXmlPath, L"r");
+       TryReturn(!IsFailed(r), false, "[osp-installer] serviceXmlPath.Construct is failed");
+
+       std::unique_ptr<char[]> pServiceBuf(new char[serviceXmlFileSize + 1]);
+       TryReturn(pServiceBuf, false, "[osp-installer] pServiceBuf is null");
+       memset(pServiceBuf.get(), 0, serviceXmlFileSize + 1);
+
+       readBytes = serviceXml.Read(pServiceBuf.get(), serviceXmlFileSize);
+       TryReturn(readBytes >= 0, false, "[osp-installer] serviceXml.Read is failed");
+
+       char* pManifestTag = strcasestr(pMergedBuf.get(), "</manifest>");
+       TryReturn(pManifestTag, false, "[osp-installer] pManifestTag is null");
+
+       char* pAppTagStart = strcasestr(pServiceBuf.get(), "<ui-application");
+       TryReturn(pAppTagStart, false, "[osp-installer] pAppTagStart is null");
+
+       char* pAppTagEnd = strcasestr(pServiceBuf.get(), "</ui-application>");
+       TryReturn(pAppTagEnd, false, "[osp-installer] pAppTagEnd is null");
+
+       int serviceAppLen = pAppTagEnd - pAppTagStart + strlen("</ui-application>");
+
+       memcpy(pManifestTag, pAppTagStart, serviceAppLen);
+
+       char* pManifestEndTag = pManifestTag + serviceAppLen;
+       strcpy(pManifestEndTag, "\n</manifest>");
+
+       int fileSize = pManifestEndTag - pMergedBuf.get() + strlen("\n</manifest>");
+
+       File systemXml;
+       r = systemXml.Construct(systemXmlPath, L"w");
+       TryReturn(!IsFailed(r), false, "[osp-installer] systemXmlPath.Construct is failed");
+
+       systemXml.Write(pMergedBuf.get(), fileSize);
+
+       AppLogTag(OSP_INSTALLER, "pMergedBuf.get()=0x%0x, length=%d", pMergedBuf.get(), fileSize);
+       InstallerUtil::DumpLogData(pMergedBuf.get(), fileSize);
+
+       return true;
+}
+
+bool
 ConfigurationManager::CreateInfoFile(const String& filePath, const String* pContext)
 {
        result r = E_SUCCESS;
old mode 100644 (file)
new mode 100755 (executable)
index 71314f5..3f409e8
@@ -54,6 +54,8 @@ public:
 private:
        bool CreateSystemXmlFile(InstallationContext* pContext);
        bool CreateHybridServiceDesktopFile(InstallationContext* pContext);
+       bool MergeToSystemXmlFile(const Tizen::Base::String& systemXmlPath, const Tizen::Base::String& webXmlPath,const Tizen::Base::String& serviceXmlPath);
+
        bool CreateInfoFile(const Tizen::Base::String& filePath, const Tizen::Base::String* pContext);
        bool CreateImeSymlink(const Tizen::Base::String& binaryPath, const Tizen::Base::String& packageName);
        bool FindPrivilege(InstallationContext* pContext, const Tizen::Base::String& privilege) const;
old mode 100644 (file)
new mode 100755 (executable)
index 4f17f8b..b668d30
@@ -476,3 +476,114 @@ InstallerUtil::DumpLog(const char* pBuf)
 
        return true;
 }
+
+#define LOG_PRINT_LINE_MAX 20
+#define LOG_BUFFER_COUNT_MAX 4096
+bool
+InstallerUtil::DumpLogData(char *pData, int dataLen)
+{
+       const char      *szData = (const char*)pData;
+       char            ch = 0;
+       int                     i = 0, j = 0, idx = 0, idx2 = 0, high = 0, low = 0, temp = 0;
+
+       char            buf[LOG_PRINT_LINE_MAX + 2]                     = {0};
+       char            buf2[(LOG_PRINT_LINE_MAX + 2) * 3]      = {0};
+       char            buf_out[sizeof(buf) + sizeof(buf2) + 1] = {0};
+
+
+       if (dataLen > LOG_BUFFER_COUNT_MAX)
+       {
+               dataLen = LOG_BUFFER_COUNT_MAX;
+       }
+
+       // 16 characters by 20 line are proper. // too many logs decrease performance.
+//     if (dataLen > 16*20)
+//             dataLen = 16*20;
+
+       AppLogTag(OSP_INSTALLER, "------------------------------------------");
+
+       while (i < (int)dataLen)
+       {
+               ch      = szData[i];
+
+               /* make ascii table */
+               if (ch >= 32 && ch <= 128)
+               {
+                       buf[idx++]      = ch;
+               }
+               else
+                       buf[idx++]      = '.';
+
+               // make binary table
+               high = (ch & 0xf0)>>4;
+               low = ch & 0x0f;
+
+               buf2[idx2++]    = LogChangeHexToStr(high);
+               buf2[idx2++]    = LogChangeHexToStr(low);
+               buf2[idx2++]    = ' ';
+
+               if (idx >= LOG_PRINT_LINE_MAX)
+               {
+                       memcpy(buf_out, buf2, idx2);
+
+                       buf_out[idx2++] = ' ';
+                       buf_out[idx2++] = ' ';
+
+                       memcpy(buf_out + idx2, buf, idx);
+                       buf_out[idx2+idx]       = '\0';
+
+                       idx             = 0;
+                       idx2    = 0;
+
+                       AppLogTag(OSP_INSTALLER, "%s\n", buf_out);
+               }
+
+               i++;
+       }
+
+       // last line
+       if (idx > 0)
+       {
+               memcpy(buf_out, buf2, idx2);
+               temp    = idx2;
+
+               for (j = 0; j < (LOG_PRINT_LINE_MAX * 3) - temp; j++)
+               {
+                       buf_out[idx2++] = ' ';
+               }
+
+               buf_out[idx2++] = ' ';
+               buf_out[idx2++] = ' ';
+
+               memcpy(buf_out+idx2, buf, idx);
+               buf_out[idx2+idx]       = '\0';
+
+               AppLogTag(OSP_INSTALLER, "%s\n", buf_out);
+       }
+
+       AppLogTag(OSP_INSTALLER, "------------------------------------------");
+
+       return TRUE;
+}
+
+char
+InstallerUtil::LogChangeHexToStr(int hex)
+{
+       char ch = '0';
+
+       const static char       hexValues[]     = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 0};
+
+
+       if (hex >= 0 && hex <= 0x0F)
+       {
+               ch      = hexValues[hex];
+       }
+       else
+       {
+               AppLogTag(OSP_INSTALLER, "LogChangeHexToStr: Error! [Hex Val: %d]\n", hex);
+       }
+
+       return ch;
+}
+
+
old mode 100644 (file)
new mode 100755 (executable)
index c7c04c9..f00523c
@@ -62,8 +62,10 @@ public:
        static bool CreateSymlinkForAppDirectory(const Tizen::Base::String& inPath, Tizen::Base::String& outPath);
 
        static bool DumpLog(const char* pBuf);
+       static bool DumpLogData(char *pData, int dataLen);
 
 private:
+       static char LogChangeHexToStr(int hex);
        InstallerUtil(const InstallerUtil& value);
        InstallerUtil& operator =(const InstallerUtil& source);