コード例 #1
0
ファイル: ReplaceDlg.cpp プロジェクト: derekdreery/frhed
//-------------------------------------------------------------------
// Translate the text in the string to binary data and store in the array.
int ReplaceDlg::transl_text_to_binary(SimpleArray<BYTE> &out)
{
    BYTE *pcOut;
    int destlen = create_bc_translation(&pcOut,
                                        strReplaceWithData, strReplaceWithData.StrLen(),
                                        iCharacterSet, iBinaryMode);
    if (destlen)
        out.Adopt(pcOut, destlen - 1, destlen);
    return destlen;
}
コード例 #2
0
ファイル: ReplaceDlg.cpp プロジェクト: derekdreery/frhed
//-------------------------------------------------------------------
bool ReplaceDlg::find_and_select_data(int finddir, bool case_sensitive)
{
    BYTE *tofind;
    // Create a translation from bytecode to char array of finddata.
    int destlen = create_bc_translation(&tofind, strToReplaceData,
                                        strToReplaceData.StrLen(), iCharacterSet, iBinaryMode);
    int i = iGetStartOfSelection();
    int n = iGetEndOfSelection() - i + 1;
    int j;
    if (finddir >= 0)
    {
        i += finddir * n;
        // Find forward.
        j = findutils_FindBytes(&m_dataArray[i],
                                m_dataArray.GetLength() - i - 1,
                                tofind,	destlen, 1, case_sensitive);
        if (j != -1)
            i += j;
    }
    else
    {
        // Find backward.
        j = findutils_FindBytes(&m_dataArray[0],
                                min(iCurByte + (destlen - 1), m_dataArray.GetLength()),
                                tofind, destlen, -1, case_sensitive);
        if (j != -1)
            i = j;
    }
    bool done = false;
    if (j != -1)
    {
        // NEW: Select found interval.
        bSelected = true;
        iStartOfSelection = iCurByte = i;
        iEndOfSelection = iStartOfSelection + destlen - 1;
        done = true;
    }
    delete [] tofind;
    return done;
}
コード例 #3
0
ファイル: PasteDlg.cpp プロジェクト: derekdreery/frhed
/**
 * @brief Paste the bytes.
 * @param [in] hDlg Handle to dialog.
 * @return TRUE if paste succeeded, FALSE if failed.
 */
BOOL PasteDlg::Apply(HWindow *pDlg)
{
	bPasteAsText = pDlg->IsDlgButtonChecked(IDC_PASTE_BINARY) == BST_CHECKED;
	iPasteTimes = pDlg->GetDlgItemInt(IDC_PASTE_TIMES);
	if (iPasteTimes <= 0)
	{
		MessageBox(pDlg, GetLangString(IDS_PASTE_ATLEAST_ONCE), MB_ICONERROR);
		return FALSE;
	}
	iPasteSkip = pDlg->GetDlgItemInt(IDC_PASTE_SKIPBYTES);
	HEdit *pwndEdit1 = static_cast<HEdit *>(pDlg->GetDlgItem(IDC_PASTE_CLIPBOARD));
	int destlen = pwndEdit1->GetWindowTextLength() + 1;
	char *pcPastestring = new char[destlen];
	destlen = pwndEdit1->GetWindowTextA(pcPastestring, destlen);
	if (!bPasteAsText)
	{
		char *pc = 0;
		destlen = create_bc_translation((BYTE **)&pc, pcPastestring,
			static_cast<int>(strlen(pcPastestring)), iCharacterSet, iBinaryMode);
		delete [] pcPastestring;
		pcPastestring = pc;
	}
	if (destlen == 0)
	{
		MessageBox(pDlg, GetLangString(IDS_PASTE_WAS_EMPTY), MB_ICONERROR);
		delete [] pcPastestring;
		return FALSE;
	}
	WaitCursor wc1;
	SimpleArray<BYTE> olddata;
	if (bSelected || pDlg->IsDlgButtonChecked(IDC_PASTE_INSERT))
	{
		// Insert at iCurByte. Bytes there will be pushed up.
		if (bSelected)
		{
			iCurByte = iGetStartOfSelection();
			int iEndByte = iGetEndOfSelection();
			olddata.AppendArray(&m_dataArray[iCurByte], iEndByte - iCurByte + 1 + (iPasteTimes - 1) * iPasteSkip);
			m_dataArray.RemoveAt(iCurByte, iEndByte - iCurByte + 1);//Remove extraneous data
			bSelected = false; // Deselect
		}
		else
		{
			olddata.AppendArray(&m_dataArray[iCurByte], (iPasteTimes - 1) * iPasteSkip);
		}
		int i = iCurByte;
		for (int k = 0 ; k < iPasteTimes ; k++)
		{
			if (!m_dataArray.InsertAtGrow(i, (BYTE*)pcPastestring, 0, destlen))
			{
				MessageBox(pDlg, GetLangString(IDS_PASTE_NO_MEM), MB_ICONERROR);
				break;
			}
			i += destlen + iPasteSkip;
		}
		bFilestatusChanged = true;
		resize_window();
	}
	else
	{
		// Overwrite.
		// Enough space for writing?
		// m_dataArray.GetLength()-iCurByte = number of bytes from including curbyte to end.
		if (m_dataArray.GetLength() - iCurByte < (iPasteSkip + destlen) * iPasteTimes)
		{
			MessageBox(pDlg, GetLangString(IDS_PASTE_NO_SPACE), MB_ICONERROR);
			delete [] pcPastestring;
			return TRUE;
		}
		olddata.AppendArray(&m_dataArray[iCurByte], (iPasteTimes - 1) * (iPasteSkip + destlen) + destlen);
		// Overwrite data.
		for (int k = 0 ; k < iPasteTimes ; k++)
		{
			for (int i = 0 ; i < destlen ; i++)
			{
				m_dataArray[iCurByte + k * (iPasteSkip + destlen) + i] = pcPastestring[i];
			}
		}
		bFilestatusChanged = true;
		repaint();
	}
	push_undorecord(iCurByte, olddata, olddata.GetLength(), &m_dataArray[iCurByte], (iPasteTimes - 1) * (iPasteSkip + destlen) + destlen);
	delete [] pcPastestring;
	return TRUE;
}
コード例 #4
0
ファイル: PasteDlg.cpp プロジェクト: alistairmcmillan/frhed
/**
 * @brief Paste the bytes.
 * @param [in] hDlg Handle to dialog.
 * @return TRUE if paste succeeded, FALSE if failed.
 */
BOOL PasteDlg::Apply(HWND hDlg)
{
	bPasteAsText = (IsDlgButtonChecked(hDlg, IDC_PASTE_BINARY) == BST_CHECKED);
	iPasteTimes = GetDlgItemInt(hDlg, IDC_PASTE_TIMES, 0, TRUE);
	if (iPasteTimes <= 0)
	{
		LangString atleastOnce(IDS_PASTE_ATLEAST_ONCE);
		MessageBox(hDlg, atleastOnce, MB_ICONERROR);
		return FALSE;
	}
	iPasteSkip = GetDlgItemInt(hDlg, IDC_PASTE_SKIPBYTES, 0, TRUE);
	HWND hwndEdit1 = GetDlgItem(hDlg, IDC_PASTE_CLIPBOARD);
	int destlen = GetWindowTextLength(hwndEdit1) + 1;
	TCHAR *pcPastestring = new TCHAR[destlen];
	destlen = GetWindowText(hwndEdit1, pcPastestring, destlen);
	if (!bPasteAsText)
	{
		BYTE *pc = 0;
		destlen = create_bc_translation(&pc, pcPastestring,
			_tcslen(pcPastestring), iCharacterSet, iBinaryMode);
		delete [] pcPastestring;
		pcPastestring = (TCHAR *) pc;
	}
	if (destlen == 0)
	{
		LangString zeroLenArray(IDS_PASTE_WAS_EMPTY);
		MessageBox(hDlg, zeroLenArray, MB_ICONERROR);
		delete [] pcPastestring;
		return FALSE;
	}

	// Choose to paste as Unicode text or ansi text regardless of build configuration,
	// TODO: UI not yet implemented.
	// ex) bool bPasteAsUnicode = IsDlgButtonChecked(hDlg, IDC_PASTE_AS_UNICODE))
	bool bPasteAsUnicode = false;
	BYTE *pasteData = (BYTE*) pcPastestring;
	int pasteSize = destlen * sizeof TCHAR;

	if (bPasteAsUnicode)
	{
		pasteData = new BYTE[destlen * sizeof WCHAR];
		pasteSize = WideCharToMultiByte(CP_ACP, 0, pcPastestring, destlen,
				(LPSTR) pasteData, destlen, NULL, NULL);
		if ( pasteSize > 0 ) {
			delete [] pcPastestring;
			pcPastestring = (TCHAR *) pasteData; // delete me later.
		}
	}

	WaitCursor wc1;
	if (bSelected || IsDlgButtonChecked(hDlg, IDC_PASTE_INSERT))
	{
		// Insert at iCurByte. Bytes there will be pushed up.
		if (bSelected)
		{
			iCurByte = iGetStartOfSelection();
			int iEndByte = iGetEndOfSelection();
			m_dataArray.RemoveAt(iCurByte, iEndByte - iCurByte + 1);//Remove extraneous data
			bSelected = false; // Deselect
		}
		int i = iCurByte;
		for (int k = 0 ; k < iPasteTimes ; k++)
		{
			if (!m_dataArray.InsertAtGrow(i, pasteData, 0, destlen))
			{
				LangString noMem(IDS_PASTE_NO_MEM);
				MessageBox(hDlg, noMem, MB_ICONERROR);
				break;
			}
			i += destlen + iPasteSkip;
		}
		iFileChanged = TRUE;
		bFilestatusChanged = true;
		resize_window();
	}
	else
	{
		// Overwrite.
		// Enough space for writing?
		// m_dataArray.GetLength()-iCurByte = number of bytes from including curbyte to end.
		if (m_dataArray.GetLength() - iCurByte < (iPasteSkip + destlen) * iPasteTimes)
		{
			LangString noSpace(IDS_PASTE_NO_SPACE);
			MessageBox(hDlg, noSpace, MB_ICONERROR);
			delete [] pcPastestring;
			return TRUE;
		}
		// Overwrite data.
		for (int k = 0 ; k < iPasteTimes ; k++)
		{
			for (int i = 0 ; i < destlen ; i++)
			{
				m_dataArray[iCurByte + k * (iPasteSkip + destlen) + i] = pasteData[i];
			}
		}
		iFileChanged = TRUE;
		bFilestatusChanged = true;
		repaint();
	}
	delete [] pcPastestring;
	return TRUE;
}