secureswitools/swisistools/source/dumpsislib/dumpsis.cpp
changeset 60 245df5276b97
parent 0 ba25891c3a9e
equal deleted inserted replaced
53:ae54820ef82c 60:245df5276b97
     1 /*
     1 /*
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    26 #include <sys/stat.h>
    26 #include <sys/stat.h>
    27 #include <algorithm>
    27 #include <algorithm>
    28 #include <functional>
    28 #include <functional>
    29 #include <set>
    29 #include <set>
    30 
    30 
    31 
       
    32 #include "dumpsis.h"
    31 #include "dumpsis.h"
    33 #include "siscontroller.h"
    32 #include "siscontroller.h"
    34 #include "exception.h"
    33 #include "exception.h"
       
    34 #include "utf8_wrapper.h"
    35 
    35 
    36 CDumpSis::CDumpSis(const std::wstring& aSISFileName, bool aVerbose)
    36 CDumpSis::CDumpSis(const std::wstring& aSISFileName, bool aVerbose)
    37 		: 	iController(NULL),
    37 		: 	iController(NULL),
    38 			iSisFileName(aSISFileName),
    38 			iSisFileName(aSISFileName),
    39 			iVerbose(aVerbose),
    39 			iVerbose(aVerbose),
    66 	{
    66 	{
    67 	std::wistringstream inStream (std::ios::in | std::ios::out);
    67 	std::wistringstream inStream (std::ios::in | std::ios::out);
    68 	std::wostream outStream (inStream.rdbuf ());
    68 	std::wostream outStream (inStream.rdbuf ());
    69 
    69 
    70 	outStream << wchar_t(0xfeff);
    70 	outStream << wchar_t(0xfeff);
       
    71 
    71 	if(iIsStub)
    72 	if(iIsStub)
    72 		{
    73 		{
    73 		iController->AddPackageEntry (outStream, iVerbose);
    74 		iController->AddPackageEntry (outStream, iVerbose);
    74 		}
    75 		}
    75 	else
    76 	else
    76 		{
    77 		{
    77 		iSisContents.AddPackageEntry (outStream, iVerbose);
    78 		iSisContents.AddPackageEntry (outStream, iVerbose);
    78 		}
    79 		}
    79 	
    80 	
    80 	std::wstring str = inStream.str();
    81 	std::wstring str = inStream.str();
       
    82 #ifndef __TOOLS2_LINUX__
    81 	WriteToFile(aPkgFileName, reinterpret_cast<const TUint8*>(str.c_str()), str.length()*2);
    83 	WriteToFile(aPkgFileName, reinterpret_cast<const TUint8*>(str.c_str()), str.length()*2);
       
    84 #else
       
    85 	TUint32 size = str.size();
       
    86 	const wchar_t * source = str.c_str();
       
    87 
       
    88 	unsigned short int* buffer = new unsigned short int[size*2];
       
    89 
       
    90 	// Using a temp variable in place of buffer as ConvertUTF32toUTF16 modifies the source pointer passed.
       
    91 	unsigned short int* temp = buffer;
       
    92 
       
    93 	//Converting to UTF-16 because makesis do not support UTF-32.	
       
    94 	ConvertUTF32toUTF16(&source, source + size, &temp,  temp + (size*2), lenientConversion);
       
    95 
       
    96 	TUint32 buflen = temp-buffer;
       
    97 	// Appending NULL to the converted buffer.
       
    98 	*temp = NULL;
       
    99 
       
   100 	WriteToFile(aPkgFileName, reinterpret_cast<const TUint8*>(buffer), buflen*2);
       
   101 	delete[] buffer;
       
   102 #endif
    82 	}
   103 	}
    83 
   104 
    84 void CDumpSis::CreatePackage(const CSISController& aSisController, const std::wstring& aPkgFileName)
   105 void CDumpSis::CreatePackage(const CSISController& aSisController, const std::wstring& aPkgFileName)
    85 	{
   106 	{
    86 	std::wistringstream inStream (std::ios::in | std::ios::out);
   107 	std::wistringstream inStream (std::ios::in | std::ios::out);
    87 	std::wostream outStream (inStream.rdbuf ());
   108 	std::wostream outStream (inStream.rdbuf ());
    88 
   109 
    89 	outStream << wchar_t(0xfeff);
   110 	outStream << wchar_t(0xfeff);
    90 	aSisController.AddPackageEntry (outStream, iVerbose);
   111 	aSisController.AddPackageEntry (outStream, iVerbose);
    91 	std::wstring str = inStream.str();
   112 	std::wstring str = inStream.str();
       
   113 #ifndef __TOOLS2_LINUX__
    92 	WriteToFile(aPkgFileName, reinterpret_cast<const TUint8*>(str.c_str()), str.length()*2);
   114 	WriteToFile(aPkgFileName, reinterpret_cast<const TUint8*>(str.c_str()), str.length()*2);
       
   115 #else
       
   116 	TUint32 size = str.size();
       
   117 	const wchar_t * source = str.c_str();
       
   118 	
       
   119 	unsigned short int* buffer = new unsigned short int[size*2];
       
   120 	
       
   121 	// Using a temp variable in place of buffer as ConvertUTF32toUTF16 modifies the source pointer passed.
       
   122 	unsigned short int* temp = buffer;
       
   123 	
       
   124 	//Converting to UTF-16 because makesis do not support UTF-32.	
       
   125 	ConvertUTF32toUTF16(&source, source + size, &temp,	temp + (size*2), lenientConversion);
       
   126 	
       
   127 	TUint32 buflen = temp-buffer;
       
   128 	// Appending NULL to the converted buffer.
       
   129 	*temp = NULL;
       
   130 	
       
   131 	WriteToFile(aPkgFileName, reinterpret_cast<const TUint8*>(buffer), buflen*2);
       
   132 	delete[] buffer;
       
   133 #endif
    93 	}
   134 	}
    94 
   135 
    95 void CDumpSis::ExtractFiles(const std::wstring& aTargetDir, TExtractionLevel aLevel)
   136 void CDumpSis::ExtractFiles(const std::wstring& aTargetDir, TExtractionLevel aLevel)
    96 	{
   137 	{
    97 	std::wstring targetDir = aTargetDir;
   138 	std::wstring targetDir = aTargetDir;