Beispiel #1
0
wyBool
BlobMgmt::ExamineData()
{
	DWORD				dwbytestoread = 0;
	wyInt32				headersize = 0;
	wyWChar				*buff;
	wyString			datastr;
	wyInt32				fileformat = 0;
	wyString			dataformat;
			
	if(!m_piub->m_data)
		return wyFalse;

	//Finding the fileformat whether its utf-8, utf-16(ucs2) or ansi 
	fileformat = DetectFileFormat(m_piub->m_data, dwbytestoread, &headersize);
	
	if(fileformat == NCP_UTF16)
	{
		buff = (wyWChar *)(m_piub->m_data + headersize);

		buff[(dwbytestoread - headersize)/sizeof(wyWChar)] = 0;

		datastr.SetAs(buff);

		dataformat.SetAs("ucs2"); //For setting the combo box value

	}
	else if(fileformat != NCP_UTF8)
	{
		dataformat.SetAs("unicode (utf-8)");

		if(m_piub->m_data)
				datastr.SetAs(m_piub->m_data + headersize);
		// there is a chance that the data may be Utf8 without BOM, so we are checking for the pattern
		if(CheckForUtf8(datastr) == wyFalse)
		{
				datastr.SetAs(m_piub->m_data, wyFalse); 
				dataformat.SetAs("US-ascii/Ansi");
		}
	}
   	
	else
	{
		dataformat.SetAs("unicode (utf-8)");
		datastr.SetAs(m_piub->m_data + headersize);
	}

	m_encodingtype.SetAs(dataformat);
	InitEncodingType();

	//Sets the combo box
	SetComboBox(dataformat.GetAsWideChar());

	return wyTrue;	
}
Beispiel #2
0
bool CDatum::CreateFromFile (const CString &sFilespec, ESerializationFormats iFormat, CDatum *retdDatum, CString *retsError)

//	CreateFromFile
//
//	Loads a datum from a file.

	{
	//	Open the file

	CFileBuffer theFile;
	if (!theFile.OpenReadOnly(sFilespec))
		{
		*retsError = strPattern(ERR_CANT_OPEN_FILE, sFilespec);
		return false;
		}

	//	If unknown format, see if we can detect the format

	if (iFormat == formatUnknown)
		{
		if (!DetectFileFormat(sFilespec, theFile, &iFormat, retsError))
			return false;

		//	If format unknown, then error.

		if (iFormat == formatUnknown)
			{
			*retsError = strPattern(ERR_UNKNOWN_FORMAT, sFilespec);
			return false;
			}
		}

	//	Parse it

	if (!Deserialize(iFormat, theFile, retdDatum))
		{
		*retsError = strPattern(ERR_DESERIALIZE_ERROR, sFilespec);
		return false;
		}

	//	Done

	return true;
	}
Beispiel #3
0
/**
 * Attempt to open file in text or binary mode.
 * @param hwnd - parent window handle.
 * @param pszFileName - source file name.
 * @return true if file successfully opened and false otherwise.
 */
static BOOL OpenRegularFile(HWND hwnd, PCTSTR pszFileName)
{
	_ASSERTE(g_hFile == INVALID_HANDLE_VALUE);
	g_hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (g_hFile != INVALID_HANDLE_VALUE)
	{
		g_dwSignatureSize = DetectFileFormat(pszFileName, g_hFile, g_bTextFile, g_eEncoding);
		UINT uCtrlID;
		if (g_bTextFile)
		{
			uCtrlID = IDC_TEXTVIEW;
			SetTextView(hwnd);
		}
		else
		{
			uCtrlID = IDC_HEXVIEW;
			SetHexView(hwnd);
		}
		CheckRadioButton(hwnd, IDC_TEXTVIEW, IDC_HEXVIEW, uCtrlID);
		ShowFileFormatOptions(hwnd, TRUE);
		return TRUE;
	}
	return FALSE;
}