imgtools/romtools/readimage/src/image_reader.cpp
changeset 631 9435b9008a58
parent 590 360bd6b35136
equal deleted inserted replaced
630:31ef8a13d4f4 631:9435b9008a58
    94 		char ch = aFilePath[fullPath.length() - 1];
    94 		char ch = aFilePath[fullPath.length() - 1];
    95 		if(ch != SLASH_CHAR1 && ch != SLASH_CHAR2)
    95 		if(ch != SLASH_CHAR1 && ch != SLASH_CHAR2)
    96 			fullPath += SLASH_CHAR1 ;		
    96 			fullPath += SLASH_CHAR1 ;		
    97 	}
    97 	}
    98 	int startImagePath = (int)fullPath.length();
    98 	int startImagePath = (int)fullPath.length();
    99 	fullPath += aPath ;	 
    99 	fullPath += aPath ;	
   100 	
   100 	
   101 	// create specified directory where file needs to be extracted. 
   101 	// create specified directory where file needs to be extracted. 
   102 	// to lower
   102 	// to lower
   103 	char* data = const_cast<char*>(fullPath.data() + startImagePath);
   103 	char* data = const_cast<char*>(fullPath.data() + startImagePath);
   104 	for(; *data != 0 ; data++){
   104 	for(; *data != 0 ; data++){
   105 		if(*data >= 'A' && *data <= 'Z'){
   105 		if(*data >= 'A' && *data <= 'Z'){
   106 			*data |= 0x20 ;
   106 			*data |= 0x20 ;
   107 		}
   107 		}
   108 	}
   108 	}
   109 	CreateSpecifiedDir(fullPath);
   109 	CreateSpecifiedDir(fullPath);
   110 
       
   111 	data -- ;
   110 	data -- ;
   112 	if(*data != SLASH_CHAR1)
   111 	if(*data != SLASH_CHAR1)
   113 		fullPath += SLASH_CHAR1 ; 
   112 		fullPath += SLASH_CHAR1 ; 
   114 	
   113 	
   115 	// concatenate path information with the filename	
   114 	// concatenate path information with the filename	
   129 	else if(infile.is_open()) {
   128 	else if(infile.is_open()) {
   130 		// place the get pointer for the current input stream to offset bytes away from origin.
   129 		// place the get pointer for the current input stream to offset bytes away from origin.
   131 		infile.seekg(aOffset,ios_base::beg);
   130 		infile.seekg(aOffset,ios_base::beg);
   132 		//read number of bytes specified by the variable size 
   131 		//read number of bytes specified by the variable size 
   133 		//from the stream and place it on to buffer.
   132 		//from the stream and place it on to buffer.
   134 		infile.read(buffer,aSize);
   133 		if (aSize)
       
   134 			infile.read(buffer,aSize);
   135 		//close the input stream after reading.
   135 		//close the input stream after reading.
   136 		infile.close();
   136 		infile.close();
   137 	}
   137 	}
   138 	else 	{
   138 	else 	{
   139 		throw ImageReaderException(ImageReader::iImgFileName.c_str(), "Failed to open the image file");
   139 		throw ImageReaderException(ImageReader::iImgFileName.c_str(), "Failed to open the image file");
   140 	}
   140 	}
   141 
   141 
   142 	if(outfile.is_open()) {
   142 	if(outfile.is_open()) {
   143 		//writes number of bytes specified by the variable size 
   143 		//writes number of bytes specified by the variable size 
   144 		//from buffer to the current output stream.
   144 		//from buffer to the current output stream.
   145 		outfile.write(buffer,aSize);
   145 		if (aSize)
       
   146 			outfile.write(buffer,aSize);
   146 		//close the output stream after writing.
   147 		//close the output stream after writing.
   147 		outfile.close();
   148 		outfile.close();
   148 	}
   149 	}
   149 	else {
   150 	else {
   150 		throw ImageReaderException(aFileName, "Failed to extract the file");
   151 		throw ImageReaderException(aFileName, "Failed to extract the file");