uigraphics/AknIcon/MifToCdlIndex/MifHandler.cpp
changeset 0 05e9090e2422
equal deleted inserted replaced
-1:000000000000 0:05e9090e2422
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 // disable "identifier was truncated to '255' characters in the browser information" warning
       
    19 #pragma warning (disable:4786)
       
    20 
       
    21 // disable "decorated name length exceeded, name was truncated" warning	
       
    22 #pragma warning (disable:4503)
       
    23 
       
    24 #include "MifHandler.h"
       
    25 #include <fstream>
       
    26 #include <CdlCompilerToolkit/CdlTkUtil.h>
       
    27 using namespace std;
       
    28 using namespace CdlCompilerToolkit;
       
    29 
       
    30 void MifHandler::Read(const string& mifName)
       
    31 	{
       
    32 	ifstream file;
       
    33 	CdlTkUtil::OpenInput(file, mifName, ios::binary);
       
    34 
       
    35 	file.seekg(0, ios::end);
       
    36 	int fileSize = file.tellg();
       
    37 	file.seekg(0);
       
    38 
       
    39 	if (!file.read((char*)&iHeader.iV2, sizeof(iHeader.iV2)))
       
    40 		throw CdlTkAssert(mifName + " - header read failed");
       
    41 	if (iHeader.iV2.iVersion < 2)
       
    42 		throw CdlTkAssert(mifName + " - cannot convert old mif file");
       
    43 	if (iHeader.iV2.iVersion > 2)
       
    44 		throw CdlTkAssert(mifName + " - mif file already converted");
       
    45 	
       
    46 	iIndex.resize(iHeader.iV2.iArrayLen);
       
    47 	iIndexBytes = iHeader.iV2.iArrayLen * sizeof(MifIdx);
       
    48 	if (!file.read((char*)&iIndex[0], iIndexBytes))
       
    49 		throw CdlTkAssert(mifName + " - index read failed");
       
    50 
       
    51 	iDataBytes = fileSize - sizeof(iHeader.iV2) - iIndexBytes;
       
    52 	iData.resize(iDataBytes+1);
       
    53 	if (!file.read(&iData[0], iDataBytes))
       
    54 		throw CdlTkAssert(mifName + " - data read failed");
       
    55 
       
    56 	file.close();
       
    57 	}
       
    58 
       
    59 const MifIndex& MifHandler::Index()
       
    60 	{
       
    61 	return iIndex;
       
    62 	}
       
    63 
       
    64 void MifHandler::Modify(const string& dllUid)
       
    65 	{
       
    66 	int uid = CdlTkUtil::ParseInt(dllUid);
       
    67 	iHeader.iV2.iVersion = 3;
       
    68 	iHeader.iV2.iOffset = sizeof(iHeader);
       
    69 	iHeader.iV3.iIndexDllUid = uid;
       
    70 
       
    71 	// added on an extra header field, but removed the index table
       
    72 	int offsetShift = sizeof(MifHeaderV3) - iIndexBytes;
       
    73 
       
    74 	for (int i=0; i<iIndex.size(); i++)
       
    75 		{
       
    76 		MifIdx& index = iIndex[i];
       
    77 		if (index.iOffset > 0)
       
    78 			index.iOffset += offsetShift;
       
    79 		}
       
    80 	}
       
    81 
       
    82 void MifHandler::Write(const string& mifName)
       
    83 	{
       
    84 	BackupOriginal(mifName);
       
    85 	ofstream file;
       
    86 	CdlTkUtil::OpenOutput(file, mifName, ios::binary);
       
    87 
       
    88 	file.write((char*)&iHeader, sizeof(iHeader));
       
    89 	file.write(&iData[0], iDataBytes);
       
    90 
       
    91 	file.close();
       
    92 	}
       
    93 
       
    94 void MifHandler::BackupOriginal(const string& mifName)
       
    95 	{
       
    96 	CdlTkUtil::CopyFile(mifName, mifName+".orig", ios::binary);
       
    97 	}
       
    98 
       
    99