⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 osdgeneratedlg.cpp

📁 可将其需要的文件转换成数组,主要应用在嵌入式或单片机编程中将要分析的文件生成一个数组参加程序编译
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		CFile::modeRead))
	{
		//need the file name
		if (fileDest.Open(OutTmp,
		CFile::modeCreate+CFile::modeWrite))
		{
			//*********************add the array name
			fileDest.Write("char ",5);
			if(CommonName.IsEmpty())
			{
				//Generate button can avoid this
				;//osd name empty error
			}
			CommonName+="[] = {";
			fileDest.Write(CommonName,CommonName.GetLength());
			//*******************add the context
			k=fileSource.GetLength();
			
			j=k/PartTemp+1;
			m=k%PartTemp;
			for(;j>0;j--)
			{
				if(j==1)
				{
					fileSource.Read(pChar,m);
					k=m;
				}
				else
				{
					k=PartTemp;
					fileSource.Read(pChar,k);
				}
				csTmp="\n";
				for(i=0;i<k;i++)
				{
					ctemp.Format("0x%x,",pChar[i]);
					csTmp+=ctemp;
				}
				if(j==1)
					csTmp.Delete(csTmp.GetLength(),1);
				fileDest.Write(csTmp,csTmp.GetLength());
			}
			//*****************add the length define
			fileDest.Write("\n};\n#define ",12);
			if(m_OsdSize.IsEmpty())
			{
				//Generate button can avoid this
				;//osd name empty error
			}
			SizeCnt=fileSource.GetLength()-1;
			CommonName.Format("\t%d",SizeCnt);
			fileDest.Write(CommonSize,CommonSize.GetLength());
			fileDest.Write(CommonName,CommonName.GetLength());
			//******************end
		}
		else
		{
			MessageBox("Osd or Res file Error!");//Creat Dest file error
			m_Information+="\r\n Error!";
			fileSource.Close();
			return 0;
		}
	}
	else
	{
		MessageBox("Source file Error!");//Open source error
		m_Information+="\r\n Error!";
		return 0;
	}
	fileSource.Close();
	fileDest.Close();
	return 1;
}

UINT GenerateThead(LPVOID MainClass)
{
	COsdGenerateDlg *pMainClass=(COsdGenerateDlg *) MainClass;
	while(pMainClass->GStep<2)
	{
		if(pMainClass->CustomFileCreate((char)pMainClass->GStep)==0)
		{//error
			pMainClass->GStep=3;
			pMainClass->PostMessage(UPDATE_MESSAGE,0,0);
			return 0;
		}
		pMainClass->SendMessage(UPDATE_MESSAGE,0,0);
	}
	return 0;
}

void COsdGenerateDlg::OnGenerate() 
{
	// TODO: Add your control notification handler code here
	CString sTmpSource,sTmpDest;
	CFile sCustomFile;
	//char cBuf[6000000];

	UpdateData();
	/*
	//need the file name
	char m_currentdir1[MAX_PATH];
	GetCurrentDirectory(MAX_PATH,m_currentdir1);
	strcat(m_currentdir1,"\\Xoceco.osd");
	sTmpSource=m_SourceDir+"\\"+m_OsdName+".osd";
	sTmpSource=m_OutDir+"\\"+m_OsdName+".h";
	strcat(m_currentdir,sTmp);
	
	CustomFileCreate();
	//need the file name
	CustomFileCreate(sTmpSource,sTmpDest,m_ResName,m_ResSize);
	
	//Write data to custom file
	char m_currentdir[MAX_PATH];
	GetCurrentDirectory(MAX_PATH,m_currentdir);
	strcat(m_currentdir,"\\udata.dat");
	*/
	/*
	if(PathIsDirectory(m_SourceDir)==FALSE)
	{
		MessageBox(m_SourceDir);
		MessageBox("Source File need rewrite!");
		return;
	}
	if((!PathIsDirectory(m_OsdSave))||(!PathIsDirectory(m_ResSave)))
	{
		MessageBox("Osd or Res save file is wrong!");
		return;
	}
	*/
	if((m_OsdSave.Right(2)!=".h")&&(m_OsdSave.Right(2)!=".H"))
	{
		MessageBox("Save file Error!");
		return;
	}
	if((m_SourceDir.Right(4)!=".osd")&&(m_OsdSave.Right(4)!=".OSD")
		&&(m_SourceDir.Right(4)!=".res")&&(m_OsdSave.Right(4)!=".RES")
		)
	{
		MessageBox("Source file Error!");
		return;
	}
	/*
	if((m_SourceDir.Right(4)==".osd")||(m_OsdSave.Right(4)==".OSD"))
	{
		if(PathFileExists(m_SourceDir)==FALSE)
		{
			MessageBox("OSD Source file isn't exist!");
		}
	}
	else((m_SourceDir.Right(4)==".res")&&(m_OsdSave.Right(4)==".RES"))
	{
		if(PathFileExists(m_SourceDir)==FALSE)
		{
			MessageBox("RES Source file isn't exist!");
		}
	}
	*/
	if(m_OsdName.IsEmpty()||m_OsdSize.IsEmpty()
		||m_ResName.IsEmpty()||m_ResSize.IsEmpty()
		||m_OsdSave.IsEmpty()||m_ResSave.IsEmpty()
		||m_SourceDir.IsEmpty()
		)
		{
		MessageBox("You forgot to submit some items!");
		return;
		}
	
	if (sCustomFile.Open(m_udatatmp,CFile::modeCreate+CFile::modeWrite))
	{
		sCustomFile.SeekToBegin();

		sCustomFile.Write(m_SourceDir,m_SourceDir.GetLength());
		sCustomFile.Write("\n",1);
		sCustomFile.Write(m_OsdSave,m_OsdSave.GetLength());
		sCustomFile.Write("\n",1);
		sCustomFile.Write(m_ResSave,m_ResSave.GetLength());
		sCustomFile.Write("\n",1);
		sCustomFile.Write(m_OsdName,m_OsdName.GetLength());
		sCustomFile.Write("\n",1);
		sCustomFile.Write(m_OsdSize,m_OsdSize.GetLength());
		sCustomFile.Write("\n",1);
		sCustomFile.Write(m_ResName,m_ResName.GetLength());
		sCustomFile.Write("\n",1);
		sCustomFile.Write(m_ResSize,m_ResSize.GetLength());
		sCustomFile.Write("\n",1);
	
		sCustomFile.Close();
	}
	m_Information.Empty();
	m_Information+="Converting Osd file! Please waiting...";
	GetDlgItem(IDC_GENERATE)->EnableWindow(0);
	GStep=0;
	UpdateData(FALSE);
	AfxBeginThread(GenerateThead,this);
	/*
	SendMessage(UPDATE_MESSAGE,0,0);
	//GetDlgItem(IDC_INFORMATION)->SetWindowText(m_Information);
	CustomFileCreate(0,&SizeCnt);
	CSize.Format("%d",SizeCnt);
	m_Information=m_Information+"\r\nOsd file size: "+CSize;
	m_Information+="\r\nConverting Res file! Please waiting...";
	//UpdateData(FALSE);
	SendMessage(UPDATE_MESSAGE,0,0);
	CustomFileCreate(1,&SizeCnt);
	CSize.Format("%d",SizeCnt);
	m_Information=m_Information+"\r\nRes file size: "+CSize;
	m_Information+="\r\nCompleted!";
	UpdateData(FALSE);
	*/
}

void COsdGenerateDlg::OnBrowseSource() 
{
	// TODO: Add your control notification handler code here
	//CFileDialog OpenFile(TRUE,NULL,NULL,OFN_HIDEREADONLY,"All   Files(*.*)|*.*||",NULL);//NULL
	CFileDialog OpenFile(TRUE,NULL,NULL,OFN_HIDEREADONLY,"*.osd or *.res|*.osd;*.res||",NULL);//NULL
	UpdateData();
	OpenFile.m_ofn.lpstrInitialDir=m_SourceDir;
	if(OpenFile.DoModal()==IDOK)
	{
		m_SourceDir=OpenFile.GetPathName();
	}
	UpdateData(FALSE);
}

void COsdGenerateDlg::OnBrowseOut() 
{
	// TODO: Add your control notification handler code here
}

void COsdGenerateDlg::OnBrowseRes() 
{
	// TODO: Add your control notification handler code here
	CFile ResTemp;
	CFileDialog OpenFile(FALSE,NULL,NULL,OFN_HIDEREADONLY,"All files|*.h||",NULL);//NULL
	UpdateData();
	OpenFile.m_ofn.lpstrInitialDir=m_ResSave;
	if(OpenFile.DoModal()==IDOK)
	{
		m_ResSave=OpenFile.GetPathName();
		if((m_ResSave.Right(2)!=".h")&&(m_ResSave.Right(2)!=".h"))
		{
			MessageBox("Need .h file!");
			m_ResSave.Empty();
			UpdateData(FALSE);
			return;
		}
		if (!ResTemp.Open(m_ResSave,
		CFile::modeCreate+CFile::modeWrite))
		{
			m_ResSave.Empty();
			MessageBox("Some wrong, Rewrite!");
		}
		ResTemp.Close();
	}
	UpdateData(FALSE);
}

void COsdGenerateDlg::OnBrowseOsd() 
{
	// TODO: Add your control notification handler code here
	//CString tmp;
	CFile OsdTemp;
	CFileDialog OpenFile(FALSE,NULL,NULL,OFN_HIDEREADONLY,"All files|*.h||",NULL);//NULL
	UpdateData();
	OpenFile.m_ofn.lpstrInitialDir=m_OsdSave;
	if(OpenFile.DoModal()==IDOK)
	{
		m_OsdSave=OpenFile.GetPathName();
		if((m_OsdSave.Right(2)!=".h")&&(m_OsdSave.Right(2)!=".H"))
		{
			MessageBox("Need .h file!");
			m_OsdSave.Empty();
			UpdateData(FALSE);
			return;
		}
		if (!OsdTemp.Open(m_OsdSave,
		CFile::modeCreate+CFile::modeWrite))
		{
			m_OsdSave.Empty();
			MessageBox("Some wrong, Rewrite!");
		}
		OsdTemp.Close();
	}
	UpdateData(FALSE);
}

void COsdGenerateDlg::OnUserMessage()
{
	CString CSize;

	switch(GStep)
	{
	case 0:
		GStep++;//1
		CSize.Format("%d",SizeCnt);
		m_Information=m_Information+"\r\nOsd file size: "+CSize;
		m_Information+="\r\nConverting Res file! Please waiting...";
		break;
	case 1:
		GStep++;//2
		CSize.Format("%d",SizeCnt);
		m_Information=m_Information+"\r\nRes file size: "+CSize;
		m_Information+="\r\nCompleted!";
		GetDlgItem(IDC_GENERATE)->EnableWindow(1);
		break;
	case 2:
		GStep=2;//2
		GetDlgItem(IDC_GENERATE)->EnableWindow(1);
		break;
	case 3:
		GStep=2;//2
		GetDlgItem(IDC_GENERATE)->EnableWindow(1);
		break;
	default:
		GStep=2;//2
		GetDlgItem(IDC_GENERATE)->EnableWindow(1);
		break;
	}
	UpdateData(FALSE);
	//MessageBox("aaa");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -