void CDfuFileMgrDlg::OnClose() { for (int i=0;i<m_Images.GetSize();i++) { HANDLE Image=(HANDLE)m_Images.GetAt(i); STDFUFILES_DestroyImage(&Image); } CDialog::OnClose(); }
void CDfuFileMgrDlg::OnButtondelete() { if(m_Images.GetSize() == 0) { AfxMessageBox("Image list is empty. No image to delete"); return; } int Sel=m_ListFiles.GetCurSel(); if (Sel!=LB_ERR) { m_ListFiles.DeleteString(Sel); HANDLE Image=(HANDLE)m_Images.GetAt(Sel); m_Images.RemoveAt(Sel,1); STDFUFILES_DestroyImage(&Image); if(m_ListFiles.GetCount() > 0) m_ListFiles.SetCurSel(0); } }
void CDfuFileMgrDlgExtract::OnButtonopen() { TCHAR szFilters[]= "Dfu Files (*.dfu)|*.dfu|All Files (*.*)|*.*||"; char Path[MAX_PATH]; char Tmp[MAX_PATH]; char *pTmp; GetModuleFileName(NULL, Path, MAX_PATH); strrev(Path); pTmp = strchr(Path, '\\'); strrev(pTmp); lstrcpy(Tmp, pTmp); lstrcpy(Path, Tmp); lstrcat(Path, "*.dfu"); CFileDialog* dlg; dlg = new CFileDialog(TRUE, _T("dfu"), _T("*.dfu"), OFN_FILEMUSTEXIST, szFilters, this); UpdateData(TRUE); m_ListFiles.ResetContent(); if (dlg->DoModal()==IDOK) { BYTE Alts; WORD Vid; WORD Pid; WORD Bcd; if (m_hFile!=0) STDFUFILES_CloseDFUFile(m_hFile); if (STDFUFILES_OpenExistingDFUFile((LPSTR)(LPCSTR)dlg->GetPathName(), &m_hFile, &Vid, &Pid, &Bcd, &Alts) == STDFUFILES_NOERROR) { BYTE Alt; CString Tmp, Tmp1; m_Pid.Format("%04X", Pid); m_Vid.Format("%04X", Vid); m_Bcd.Format("%04X", Bcd); m_FileBaseName=dlg->GetPathName().Left(dlg->GetPathName().GetLength()-4); m_DfuFile = dlg->GetPathName(); UpdateData(FALSE); for (BYTE i=0;i<Alts;i++) { HANDLE Image; CString Tmp; if (STDFUFILES_ReadImageFromDFUFile(m_hFile, i, &Image)==STDFUFILES_NOERROR) { char Name[512]; STDFUFILES_GetImageAlternate(Image, &Alt); STDFUFILES_GetImageName(Image, Name); STDFUFILES_DestroyImage(&Image); Tmp.Format("Image for Target ID %02i", Alt); if (Name[0]!='\0') { Tmp+=" ("; Tmp+=Name; Tmp+=")"; } m_ListFiles.AddString(Tmp); } else { AfxMessageBox("Unable to read images in file..."); break; } if(m_ListFiles.GetCount()>0) m_ListFiles.SetCurSel(0); } } else AfxMessageBox("Error... Maybe bad or old file format"); } }
void CDfuFileMgrDlgExtract::OnButtonextract() { if (m_hFile==0) return; int Sel=m_ListFiles.GetCurSel(); if (Sel==-1) return; UpdateData(TRUE); HANDLE Image; if (STDFUFILES_ReadImageFromDFUFile(m_hFile, Sel, &Image)==STDFUFILES_NOERROR) { BYTE Alt; STDFUFILES_GetImageAlternate(Image, &Alt); CString FileName; FileName.Format("%s_%02i", m_FileBaseName, Alt); CString sFile; if (m_ExtractFormat==2) { DWORD NbEl; if (STDFUFILES_GetImageNbElement(Image, &NbEl)==STDFUFILES_NOERROR) { CString Status; BOOL bSuccess=TRUE; for (DWORD i=0;i<NbEl;i++) { DFUIMAGEELEMENT Element={0}; if (STDFUFILES_GetImageElement(Image, i, &Element)==STDFUFILES_NOERROR) { Element.Data=new BYTE[Element.dwDataLength]; if (STDFUFILES_GetImageElement(Image, i, &Element)==STDFUFILES_NOERROR) { CFile File; CFileException ex; sFile.Format("%s_%08X.bin", FileName, Element.dwAddress); if (File.Open(sFile, CFile::modeCreate | CFile::modeWrite, &ex)) { File.Write(Element.Data, Element.dwDataLength); File.Close(); Status=Status+sFile; Status+=" was created !\n"; } else { CString Err; bSuccess=FALSE; Err.Format("IoError %08xh", ex.m_lOsError); AfxMessageBox(Err); delete[]Element.Data; break; } } else { AfxMessageBox("Unable to access element in image..."); bSuccess=FALSE; delete[]Element.Data; break; } delete[]Element.Data; } else { AfxMessageBox("Unable to access element in image..."); bSuccess=FALSE; break; } } if (bSuccess) AfxMessageBox(Status); } else AfxMessageBox("Unable to access element in image..."); } else { if (m_ExtractFormat==0) FileName+=".s19"; else if (m_ExtractFormat==1) FileName+=".hex"; if (STDFUFILES_ImageToFile((LPSTR)(LPCSTR)FileName, Image)==STDFUFILES_NOERROR) { FileName+=" was created !"; AfxMessageBox(FileName); } else AfxMessageBox("Error while creating file..."); } STDFUFILES_DestroyImage(&Image); } else AfxMessageBox("Unable to read file..."); }