imgtools/romtools/readimage/src/image_handler.cpp
changeset 590 360bd6b35136
parent 0 044383f39525
child 626 ac03b93ca9c4
equal deleted inserted replaced
588:c7c26511138f 590:360bd6b35136
    38 string ImageReader::iPattern = "";
    38 string ImageReader::iPattern = "";
    39 
    39 
    40 string SisUtils::iOutputPath = ".";
    40 string SisUtils::iOutputPath = ".";
    41 string SisUtils::iExtractPath = ".";
    41 string SisUtils::iExtractPath = ".";
    42 
    42 
    43 ImageHandler::ImageHandler() : iReader(NULL) ,iOptions(0), iSisUtils(NULL)
    43 ImageHandler::ImageHandler() : iReader(NULL) ,iOptions(0), iSisUtils(NULL) {
    44 {
    44 }
    45 }
    45 
    46 
    46 ImageHandler::~ImageHandler() {
    47 ImageHandler::~ImageHandler()
       
    48 {
       
    49 	if(iReader)
    47 	if(iReader)
    50 		delete iReader;
    48 		delete iReader;
    51 
    49 
    52 	if(iSisUtils)
    50 	if(iSisUtils)
    53 		delete iSisUtils;
    51 		delete iSisUtils;
    54 }
    52 }
    55 
    53 
    56 
    54 
    57 void ImageHandler::ProcessArgs(int argc, char**argv)
    55 void ImageHandler::ProcessArgs(int argc, char*argv[]) {
    58 {
    56 	if( argc < 2) {
    59 	if( argc < 2)
       
    60 	{
       
    61 		throw ImageReaderUsageException("", "");
    57 		throw ImageReaderUsageException("", "");
    62 	}
    58 	}
    63 
    59 
    64 	bool aOutFileGiven = false;
    60 	bool aOutFileGiven = false;
    65 	int aPos = 1;
    61 	int index = 1; 
    66 
    62 	
    67 	while( argc > aPos )
    63 	while( argc > index ) {
    68 	{
    64 		char* arg = argv[index]; 
    69 		if(argv[aPos][0] == '-')
    65 		if(arg[0] == '-') {
    70 		{
    66 			switch(0x20 | arg[1]) {
    71 			switch(argv[aPos][1])
    67 			case 'd': 
    72 			{
       
    73 			case 'd':
       
    74 			case 'D':
       
    75 				//dump header info
    68 				//dump header info
    76 				iOptions |= DUMP_HDR_FLAG;
    69 				iOptions |= DUMP_HDR_FLAG;
    77 				break;
    70 				break;
    78 			case 'e':
    71 			case 'e': 
    79 			case 'E':
    72 				iOptions |= DUMP_E32_IMG_FLAG; 
    80 				iOptions |= DUMP_E32_IMG_FLAG;
    73 				++index ;
    81 				if(argv[aPos+1])
    74 				if(index < argc) {
    82 					ImageReader::iE32ImgFileName = string(argv[aPos+1]);
    75 					arg = argv[index];
       
    76 					ImageReader::iE32ImgFileName = string(arg);
       
    77 				}
    83 				else 
    78 				else 
    84 					throw ImageReaderUsageException("Usage error", argv[aPos]);
    79 					throw ImageReaderUsageException("Usage error", arg);
    85 				aPos++;
    80 				
    86 				break;
    81 				break;
    87 			case 'h':
    82 			case 'h': 
    88 			case 'H':
       
    89 				PrintUsage();
    83 				PrintUsage();
    90 				exit(EXIT_SUCCESS);
    84 				exit(EXIT_SUCCESS);
    91 			case 'o':
    85 			case 'o':  
    92 			case 'O':
    86 				if(arg[2]) {
    93 				{
    87 					if((stricmp(arg,"-OUTDIR")==0)) {
    94 					if(argv[aPos][2])
    88 						++index;
    95 					{
    89 						if(index < argc) {
    96 						if((stricmp(argv[aPos],"-OUTDIR")==0))
    90 							arg = argv[index];
    97 						{
    91 							SisUtils::iOutputPath = string(arg);
    98 							if(argv[aPos+1])
       
    99 							{
       
   100 								SisUtils::iOutputPath = string(argv[aPos+1]);
       
   101 							}
       
   102 							else
       
   103 								throw ImageReaderUsageException("Usage Error", argv[aPos]);
       
   104 
       
   105 							aPos++;
       
   106 						}
    92 						}
   107 						else
    93 						else
   108 							throw ImageReaderUsageException("Usage Error", argv[aPos]);
    94 							throw ImageReaderUsageException("Usage Error", arg); 
   109 					}
    95 					}
   110 					else
    96 					else
   111 					{
    97 						throw ImageReaderUsageException("Usage Error", arg);
   112 						aOutFileGiven = true;
    98 				}
   113 						if( argv[aPos+1] )
    99 				else {
   114 						{
   100 					aOutFileGiven = true;
   115 							// unless using iOutFile.c_str() immediately after 
   101 					++index;				
   116 							// iOutFile = argv[aPos+1];
   102 					if( index < argc ) {
   117 							// iOutFile will not be assign correctly,
   103 						// unless using iOutFile.c_str() immediately after 
   118 							// is it a defect of gcc 3.4.5 ?
   104 						// iOutFile = argv[index+1];
   119 							iOutFile = string(argv[aPos+1]);						
   105 						// iOutFile will not be assign correctly,
   120 							aPos++;
   106 						// is it a defect of gcc 3.4.5 ? 
   121 						}
   107 						arg = argv[index];
   122 					}
   108 						iOutFile = string(arg); 
   123 				}
       
   124 				break;
       
   125 			case 'r':
       
   126 			case 'R':
       
   127 				{
       
   128 					if(argv[aPos][2])
       
   129 						throw ImageReaderUsageException("Usage Error", argv[aPos]);
       
   130 
       
   131 					iOptions |= RECURSIVE_FLAG;
       
   132 				}
       
   133 				break;
       
   134 			case 's':
       
   135 			case 'S':
       
   136 				{
       
   137 					if(argv[aPos][2])
       
   138 					{
       
   139 						if(stricmp(argv[aPos],"-SIS2IBY")==0)
       
   140 						{
       
   141 							iOptions |= MODE_SIS2IBY;
       
   142 						}
       
   143 						else
       
   144 							throw ImageReaderUsageException("Usage Error", argv[aPos]);
       
   145 					}
   109 					}
   146 					else
   110 					else
   147 						iOptions |= DUMP_DIR_ENTRIES_FLAG;
   111 						throw ImageReaderUsageException("Usage Error", arg); 
   148 				}
   112 				}
   149 				break;
   113 				 
   150 			case 't':
   114 				break;
   151 			case 'T':
   115 			case 'r': 				 
   152 				{
   116 				if(arg[2])
   153 					if((stricmp(argv[aPos],"-TMPDIR")==0))
   117 					throw ImageReaderUsageException("Usage Error", arg);
   154 					{
   118 				iOptions |= RECURSIVE_FLAG;				 
   155 						if(argv[aPos+1])
   119 				break;
   156 						{
   120 			case 's': 				
   157 							SisUtils::iExtractPath = string(argv[aPos+1]);
   121 				if(arg[2]) {
   158 						}
   122 					if(stricmp(arg,"-SIS2IBY")==0) {
   159 						else
   123 						iOptions |= MODE_SIS2IBY;
   160 							throw ImageReaderUsageException("Usage Error", argv[aPos]);
       
   161 
       
   162 						aPos++;
       
   163 					}
   124 					}
   164 					else
   125 					else
   165 						throw ImageReaderUsageException("Usage Error", argv[aPos]);
   126 						throw ImageReaderUsageException("Usage Error", arg);
   166 				}
   127 				}
   167 				break;
   128 				else
   168 			case 'v':
   129 					iOptions |= DUMP_DIR_ENTRIES_FLAG;
   169 			case 'V':
   130 				
   170 				{
   131 				break;
   171 					if(argv[aPos][2])
   132 			case 't': 				 
   172 						throw ImageReaderUsageException("Usage Error", argv[aPos]);
   133 				if((stricmp(argv[index],"-TMPDIR")==0)) {
   173 
   134 					++index;
   174 					iOptions |= DUMP_VERBOSE_FLAG;
   135 					if( index < argc ) {  
   175 				}
   136 						arg = argv[index];
   176 				break;
   137 						SisUtils::iExtractPath = string(arg);
   177 			case 'l':
       
   178 			case 'L':
       
   179 				{
       
   180 					if(argv[aPos+1])
       
   181 					{
       
   182 						ImageReader::iLogFileName = string(argv[aPos+1]);
       
   183 					}
   138 					}
   184 					else
   139 					else
   185 						throw ImageReaderUsageException("Usage error", argv[aPos]);
   140 						throw ImageReaderUsageException("Usage Error", arg); 
   186 					iOptions |= LOG_IMAGE_CONTENTS_FLAG;
   141 				}
   187 					aPos++;
   142 				else
   188 				}
   143 					throw ImageReaderUsageException("Usage Error", arg);
   189 				break;
   144 				 
   190 			case 'x':
   145 				break;
   191 			case 'X':
   146 			case 'v':  
   192 				{
   147 				if(arg[2])
   193 					if(argv[aPos+1] && (!argv[aPos][2]))
   148 					throw ImageReaderUsageException("Usage Error", arg);
   194 					{
   149 				iOptions |= DUMP_VERBOSE_FLAG; 
   195 						ImageReader::iPattern = string(argv[aPos+1]);
   150 				break;
   196 					}
   151 			case 'l': 
   197 					else
   152 				++index;
   198 						throw ImageReaderUsageException("Usage error", argv[aPos]);
   153 				if(index < argc) {
   199 
   154 					arg = argv[index];
   200 					iOptions |= EXTRACT_FILE_SET_FLAG;
   155 					ImageReader::iLogFileName = string(arg);
   201 					aPos++;
   156 				}
   202 				}
   157 				else
   203 				break;
   158 					throw ImageReaderUsageException("Usage error", arg);
   204 			case 'z':
   159 				iOptions |= LOG_IMAGE_CONTENTS_FLAG;
   205 			case 'Z':
   160 				 
   206 				{
   161 				break;
   207 					if(argv[aPos+1])
   162 			case 'x': 
   208 						ImageReader::iZdrivePath = string(argv[aPos+1]);
   163 				++index;
   209 					else
   164 				if(index < argc && 0 == arg[2]) {
   210 						throw ImageReaderUsageException("Usage error", argv[aPos]);
   165 					arg = argv[index];
   211 					
   166 					ImageReader::iPattern = string(arg);
   212 					iOptions |= EXTRACT_FILES_FLAG;
   167 				}
   213 					aPos++;
   168 				else
   214 				}
   169 					throw ImageReaderUsageException("Usage error", arg);
       
   170 
       
   171 				iOptions |= EXTRACT_FILE_SET_FLAG; 
       
   172 				 
       
   173 				break;
       
   174 			case 'z': 
       
   175 				++index;
       
   176 				if(index < argc ){
       
   177 					arg = argv[index];
       
   178 					ImageReader::iZdrivePath = string(arg);
       
   179 				}
       
   180 				else
       
   181 					throw ImageReaderUsageException("Usage error", arg);					
       
   182 				iOptions |= EXTRACT_FILES_FLAG; 
       
   183 				
   215 				break;
   184 				break;
   216 			default:
   185 			default:
   217 				throw ImageReaderUsageException("Invalid command", argv[aPos]);
   186 				throw ImageReaderUsageException("Invalid command", arg);
   218 				break;
   187 				break;
   219 			}
   188 			}
   220 		}
   189 		}
   221 		else
   190 		else {
   222 		{
   191 			if(!iInputFileName.empty()) {
   223 			if(!iInputFileName.empty())
       
   224 			{
       
   225 				throw ImageReaderUsageException("Invalid command", "Multiple input file not supported");
   192 				throw ImageReaderUsageException("Invalid command", "Multiple input file not supported");
   226 			}
   193 			}
   227 
   194 
   228 			SetInputFile(argv[aPos]);
   195 			SetInputFile(string(arg));
   229 		}
   196 		}
   230 		aPos++;
   197 		index++;
   231 	}
   198 	}
   232 
   199 
   233 	if( aOutFileGiven && !(iOptions & MODE_SIS2IBY) )
   200 	if( aOutFileGiven && !(iOptions & MODE_SIS2IBY) ) {
   234 	{
   201 		ofstream* rdout = new ofstream(iOutFile.c_str(), ios_base::out | ios_base::trunc);
   235 		ofstream* rdout = new ofstream(iOutFile.c_str(), ios::out | ios::trunc);
       
   236 		if( !rdout->is_open()){
   202 		if( !rdout->is_open()){
   237 			delete rdout ;
   203 			delete rdout ;
   238 			rdout = NULL ;
   204 			rdout = NULL ;
   239 			throw ImageReaderException((char*)iOutFile.c_str(), "Unable to open File");
   205 			throw ImageReaderException(iOutFile.c_str(), "Unable to open File");
   240 		}
   206 		}
   241 		out = rdout ;
   207 		out = rdout ;
   242 	}
   208 	}
   243 
   209 
   244 	// Disable -z option if -x option is passed
   210 	// Disable -z option if -x option is passed
   245 	if( (iOptions & EXTRACT_FILE_SET_FLAG) && (iOptions & EXTRACT_FILES_FLAG) )
   211 	if( (iOptions & EXTRACT_FILE_SET_FLAG) && (iOptions & EXTRACT_FILES_FLAG) ) {
   246 	{
       
   247 		iOptions &= ~(EXTRACT_FILES_FLAG);
   212 		iOptions &= ~(EXTRACT_FILES_FLAG);
   248 	}
   213 	}
   249 
   214 
   250 	// -r option should be used along with -x option
   215 	// -r option should be used along with -x option
   251 	if( (iOptions & RECURSIVE_FLAG) && !(iOptions & EXTRACT_FILE_SET_FLAG) )
   216 	if( (iOptions & RECURSIVE_FLAG) && !(iOptions & EXTRACT_FILE_SET_FLAG) ) {
   252 	{
       
   253 		throw ImageReaderUsageException("Usage error", "-r should be used with -x");
   217 		throw ImageReaderUsageException("Usage error", "-r should be used with -x");
   254 	}
   218 	}
   255 }
   219 }
   256 
   220 
   257 EImageType ImageHandler::ReadMagicWord()
   221 EImageType ImageHandler::ReadMagicWord() {
   258 {
       
   259  
       
   260 #if defined(__TOOLS2__) || defined(__MSVCDOTNET__)
       
   261 	ifstream file(iInputFileName.c_str(), ios_base::in | ios_base::binary );
   222 	ifstream file(iInputFileName.c_str(), ios_base::in | ios_base::binary );
   262 #else
       
   263 	ifstream file(iInputFileName.c_str(), ios::in | ios::binary | ios::nocreate);
       
   264 #endif
       
   265 	
   223 	
   266 	EImageType retVal = EUNKNOWN_IMAGE;
   224 	EImageType retVal = EUNKNOWN_IMAGE;
   267 
   225 
   268 	if( !file.is_open() )
   226 	if( !file.is_open() ) {
   269 	{
   227 		throw ImageReaderException(iInputFileName.c_str(), "Cannot open file ");
   270 		throw ImageReaderException((char*)iInputFileName.c_str(), "Cannot open file ");
       
   271 	}
   228 	}
   272 
   229 
   273 	TUint8 magicWords[16];
   230 	TUint8 magicWords[16];
   274 	file.read(reinterpret_cast<char*>(magicWords),16);
   231 	file.read(reinterpret_cast<char*>(magicWords),16);
   275 
   232 
   282 		retVal = EROM_IMAGE; 
   239 		retVal = EROM_IMAGE; 
   283 	}
   240 	}
   284 	else {
   241 	else {
   285 		E32ImageFile	aE32;
   242 		E32ImageFile	aE32;
   286 		TUint32			aSz;
   243 		TUint32			aSz;
   287 		file.seekg(0,ios::end);
   244 		file.seekg(0,ios_base::end);
   288 		aSz = file.tellg();
   245 		aSz = file.tellg();
   289 		file.seekg(0,ios::beg);			 
   246 		file.seekg(0,ios_base::beg);			 
   290 		aE32.Adjust(aSz);
   247 		aE32.Adjust(aSz);
   291 		aE32.iFileSize = aSz;
   248 		aE32.iFileSize = aSz;
   292 		file  >> aE32;
   249 		file  >> aE32;
   293 	
   250 	
   294 		if(aE32.iError == KErrNone){
   251 		if(aE32.iError == KErrNone){
   295 			retVal = EE32_IMAGE;
   252 			retVal = EE32_IMAGE;
   296 		}
   253 		}
   297 		else {
   254 		else {
   298 			TExtensionRomHeader exRomHeader;
   255 			TExtensionRomHeader exRomHeader;
   299 			file.seekg(0, ios::beg);
   256 			file.seekg(0, ios_base::beg);
   300 			file.read(reinterpret_cast<char*>(&exRomHeader), sizeof(TExtensionRomHeader));
   257 			file.read(reinterpret_cast<char*>(&exRomHeader), sizeof(TExtensionRomHeader));
   301 			TUint zeroTime = time(0);
   258 			TUint zeroTime = time(0);
   302 			// aExtensionRomHeader.iTime and aExtensionRomHeader.iKernelTime are 
   259 			// aExtensionRomHeader.iTime and aExtensionRomHeader.iKernelTime are 
   303 			// in microseconds. So convert them to seconds and see if these are 
   260 			// in microseconds. So convert them to seconds and see if these are 
   304 			// valid times e.g. a time(in seconds) after midnight Jan 1st, 1970
   261 			// valid times e.g. a time(in seconds) after midnight Jan 1st, 1970
   316 			}
   273 			}
   317 		}		 
   274 		}		 
   318 	}   
   275 	}   
   319 	
   276 	
   320 	if(retVal == EUNKNOWN_IMAGE){
   277 	if(retVal == EUNKNOWN_IMAGE){
   321 		file.seekg(0,ios::beg);
   278 		file.seekg(0,ios_base::beg);
   322         retVal = ReadBareImage(file);
   279         retVal = ReadBareImage(file);
   323 	}
   280 	}
   324 
   281 
   325 	file.close();
   282 	file.close();
   326 
   283 
   332  * @fn ImageHandler::ReadBareImage
   289  * @fn ImageHandler::ReadBareImage
   333  * @brief this function processes image type under the condition of that if an image is given without header which means the image is not self-described
   290  * @brief this function processes image type under the condition of that if an image is given without header which means the image is not self-described
   334  * @return type of the image.
   291  * @return type of the image.
   335  * @note this function is introduced for handling issues raised by DEF129908
   292  * @note this function is introduced for handling issues raised by DEF129908
   336  */
   293  */
   337 EImageType ImageHandler::ReadBareImage(ifstream& aIfs)
   294 EImageType ImageHandler::ReadBareImage(ifstream& aIfs) {
   338 {
       
   339     TRomHeader romHdr ; 
   295     TRomHeader romHdr ; 
   340     aIfs.read(reinterpret_cast<char*>(&romHdr),sizeof(TRomHeader)); 
   296     aIfs.read(reinterpret_cast<char*>(&romHdr),sizeof(TRomHeader)); 
   341 
   297 
   342     return ((romHdr.iRomBase >= KRomBase ) && 
   298     return ((romHdr.iRomBase >= KRomBase ) && 
   343 		(romHdr.iRomRootDirectoryList > KRomBase ) &&
   299 		(romHdr.iRomRootDirectoryList > KRomBase ) &&
   345 	   (romHdr.iRomRootDirectoryList < KRomBaseMaxLimit)) ? EBAREROM_IMAGE : EUNKNOWN_IMAGE;
   301 	   (romHdr.iRomRootDirectoryList < KRomBaseMaxLimit)) ? EBAREROM_IMAGE : EUNKNOWN_IMAGE;
   346      
   302      
   347 }
   303 }
   348 
   304 
   349 
   305 
   350 void ImageHandler::HandleInputFiles()
   306 void ImageHandler::HandleInputFiles() {
   351 {
   307 	if(!(iOptions & MODE_SIS2IBY)) {
   352 	if(!(iOptions & MODE_SIS2IBY))
       
   353 	{
       
   354 		EImageType imgType = ReadMagicWord();
   308 		EImageType imgType = ReadMagicWord();
   355 		
   309 		
   356 		switch(imgType)
   310 		switch(imgType)
   357 		{
   311 		{
   358 		case EROFS_IMAGE:
   312 		case EROFS_IMAGE:
   359 		case EROFX_IMAGE:
   313 		case EROFX_IMAGE:
   360 			iReader = new RofsImageReader((char*)iInputFileName.c_str());
   314 			iReader = new RofsImageReader(iInputFileName.c_str());
   361 			break;
   315 			break;
   362 		case EROM_IMAGE:
   316 		case EROM_IMAGE:
   363 			iReader = new RomImageReader((char*)iInputFileName.c_str());
   317 			iReader = new RomImageReader(iInputFileName.c_str());
   364 			break;
   318 			break;
   365         case EBAREROM_IMAGE:
   319         case EBAREROM_IMAGE:
   366             iReader = new RomImageReader((char*)iInputFileName.c_str(), EBAREROM_IMAGE);
   320             iReader = new RomImageReader(iInputFileName.c_str(), EBAREROM_IMAGE);
   367             break;
   321             break;
   368 		case EROMX_IMAGE:
   322 		case EROMX_IMAGE:
   369 			iReader = new RomImageReader((char*)iInputFileName.c_str(), EROMX_IMAGE);
   323 			iReader = new RomImageReader(iInputFileName.c_str(), EROMX_IMAGE);
   370 			break;
   324 			break;
   371 		case EE32_IMAGE:
   325 		case EE32_IMAGE:
   372 			iReader = new E32ImageReader((char*)iInputFileName.c_str());
   326 			iReader = new E32ImageReader(iInputFileName.c_str());
   373 			break;
   327 			break;
   374 		default:
   328 		default:
   375 			{
   329 			{
   376             throw ImageReaderException((char*)iInputFileName.c_str(), "Unknown Type of Image file");
   330             throw ImageReaderException(iInputFileName.c_str(), "Unknown Type of Image file");
   377 			}
   331 			}
   378 			break;
   332 			break;
   379 		}
   333 		}
   380 
   334 
   381 		if(iReader)
   335 		if(iReader) {
   382 		{
       
   383 			iReader->ReadImage();
   336 			iReader->ReadImage();
   384 			iReader->ProcessImage();
   337 			iReader->ProcessImage();
   385 			iReader->Validate();
   338 			iReader->Validate();
   386 			iReader->SetDisplayOptions( iOptions );
   339 			iReader->SetDisplayOptions( iOptions );
   387 			iReader->ExtractImageContents();
   340 			iReader->ExtractImageContents();
   388 			iReader->Dump();
   341 			iReader->Dump();
   389 		}
   342 		}
   390 	}
   343 	}
   391 	else
   344 	else {
   392 	{
   345 		if(iInputFileName.empty()) {
   393 		if(iInputFileName.empty())
       
   394 		{
       
   395 			throw SisUtilsException("Usage Error", "No SIS file passed");
   346 			throw SisUtilsException("Usage Error", "No SIS file passed");
   396 		}
   347 		}
   397 
   348 
   398 		iSisUtils = new Sis2Iby((char*)iInputFileName.c_str());
   349 		iSisUtils = new Sis2Iby(iInputFileName.c_str());
   399 
   350 
   400 		if(iSisUtils)
   351 		if(iSisUtils) {
   401 		{
   352 			if(iOptions & DUMP_VERBOSE_FLAG) {
   402 			if(iOptions & DUMP_VERBOSE_FLAG)
       
   403 			{
       
   404 				iSisUtils->SetVerboseMode();
   353 				iSisUtils->SetVerboseMode();
   405 			}
   354 			}
   406 
   355 
   407 			iSisUtils->ProcessSisFile();
   356 			iSisUtils->ProcessSisFile();
   408 			iSisUtils->GenerateOutput();
   357 			iSisUtils->GenerateOutput();
   409 		}
   358 		}
   410 		else
   359 		else {
   411 		{
       
   412 			throw SisUtilsException("Error:", "Cannot create Sis2Iby object");
   360 			throw SisUtilsException("Error:", "Cannot create Sis2Iby object");
   413 		}
   361 		}
   414 	}
   362 	}
   415 }
   363 }
   416 
   364 
   417 void ImageHandler::PrintVersion()
   365 void ImageHandler::PrintVersion() {
   418 {
       
   419 	*out << "\nReadimage - reader for Rom, Rofs and E32 images V";
   366 	*out << "\nReadimage - reader for Rom, Rofs and E32 images V";
   420 	out->width(1);
   367 	out->width(1);
   421 	*out << MajorVersion << ".";
   368 	*out << MajorVersion << ".";
   422 	out->width(2);
   369 	out->width(2);
   423 	out->fill('0');
   370 	out->fill('0');
   425 	out->width(3);
   372 	out->width(3);
   426 	*out << Build  << ") " << endl;
   373 	*out << Build  << ") " << endl;
   427 	*out << Copyright;
   374 	*out << Copyright;
   428 }
   375 }
   429 
   376 
   430 void ImageHandler::PrintUsage()
   377 void ImageHandler::PrintUsage() {
   431 {
       
   432 	PrintVersion();
   378 	PrintVersion();
   433 	const char aUsage[] = 
   379 	const char aUsage[] = 
   434 		"Usage: readImage [options] [<-sis2iby> [sis-options]] <filename>\n\n"
   380 		"Usage: readImage [options] [<-sis2iby> [sis-options]] <filename>\n\n"
   435 		"Options: With no options, it prints the files and directories in image\n"
   381 		"Options: With no options, it prints the files and directories in image\n"
   436 		"       -o      output file name\n"
   382 		"       -o      output file name\n"
   449 		"       -outdir xxx   generates the iby file(s) to xxx location\n"
   395 		"       -outdir xxx   generates the iby file(s) to xxx location\n"
   450 		"       -v            verbose output\n";
   396 		"       -v            verbose output\n";
   451 	*out << aUsage << endl;
   397 	*out << aUsage << endl;
   452 }
   398 }
   453 
   399 
   454 int main(int argc, char** argv)
   400 int main(int argc, char* argv[]) {
   455 {
       
   456 	ImageHandler aIh;
   401 	ImageHandler aIh;
   457 	int retVal = EXIT_SUCCESS;
   402 	int retVal = EXIT_SUCCESS;
   458 	try
   403 	try {
   459 	{
       
   460 		aIh.ProcessArgs(argc, argv);
   404 		aIh.ProcessArgs(argc, argv);
   461 		aIh.HandleInputFiles();
   405 		aIh.HandleInputFiles();
   462 	}
   406 	}
   463 	catch(ImageReaderUsageException& aIre)
   407 	catch(ImageReaderUsageException& aIre) {
   464 	{
   408 		if(argc >= 2) {
   465 		if(argc >= 2)
       
   466 		{
       
   467 			//This is a usage error and has to be reported
   409 			//This is a usage error and has to be reported
   468 			//Otherwise, it is called just to display the usage
   410 			//Otherwise, it is called just to display the usage
   469 			aIre.Report();
   411 			aIre.Report();
   470 		}
   412 		}
   471 		aIh.PrintUsage();
   413 		aIh.PrintUsage();
   472 		retVal = EXIT_FAILURE;
   414 		retVal = EXIT_FAILURE;
   473 	}
   415 	}
   474 	catch(ImageReaderException& aIre)
   416 	catch(ImageReaderException& aIre) {
   475 	{
       
   476 		aIre.Report();
   417 		aIre.Report();
   477 		retVal = EXIT_FAILURE;
   418 		retVal = EXIT_FAILURE;
   478 	}
   419 	}
   479 	catch(SisUtilsException& aSUe)
   420 	catch(SisUtilsException& aSUe) {
   480 	{
       
   481 		aSUe.Report();
   421 		aSUe.Report();
   482 		retVal = EXIT_FAILURE;
   422 		retVal = EXIT_FAILURE;
   483 	}
   423 	}
   484 	
   424 	
   485 	if(out != &cout){
   425 	if(out != &cout){