void CThhylDlg::OnSaveraw() { if (!m_filestatus.IsValid()) return; CString filter((LPCTSTR)IDS_DLGFILTERALL); CString rawfile(m_rpyfile); filepath_utils::ChangeFileExtension(rawfile, _T("bin")); CFileDialogWZ dlg(FALSE, NULL, rawfile, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST, filter, this); DWORD rawsize = 0; m_pRpyAnalyzer->GetDecodedDataPointer(&rawsize); CString title; title.Format(_T("保存 raw 数据(raw 数据大小: %d, rpy 文件大小: %d)"), (int)rawsize, (int)m_dwRpySize); dlg.m_ofn.lpstrTitle = title; if (dlg.DoModal() == IDOK) { // dump if (!m_pRpyAnalyzer->DumpRPYData( dlg.GetPathName() )) // dumping is not supported? // for current version, this should not happen. MessageBox(_T("ERR01"), g_title, MB_ICONEXCLAMATION); } }
void go(size_t const dims[3], std::string const &rawPath, std::string const &outPath) { char *rawData{ nullptr }; try { size_t const bytes{ dims[0] * dims[1] * dims[2] * sizeof(Ty) }; rawData = new char[ bytes ]; std::cout << "Allocated " << bytes << " bytes." << std::endl; } catch (std::runtime_error &e) { std::cerr << "Could not allocate memory: " << e.what() << std::endl; rawData = nullptr; } if (! rawData) return; std::ifstream rawfile(rawPath, std::ios::binary); if (! rawfile.is_open()) { std::cerr << "Could not open raw file: " << rawPath << std::endl; return; } rawfile.read(rawData, dims[0] * dims[1] * dims[2] * sizeof(Ty)); rawfile.close(); std::ofstream outfile(outPath, std::ios::binary); if (! outfile.is_open()) { std::cerr << "Could not open output file: " << outPath << std::endl; return; } start<Ty>(reinterpret_cast<Ty const *>(rawData), outfile, dims); outfile.flush(); outfile.close(); delete [] rawData; }