LIB3MFMETHODIMP CCOMModelTexture2D::WriteToFileUTF8(_In_z_ LPCSTR pszFilename) { try { if (pszFilename == nullptr) throw CNMRException(NMR_ERROR_INVALIDPOINTER); CModelTexture2DResource * pTextureResource = getTexture2D(); __NMRASSERT(pTextureResource); PImportStream pTextureAttachment = pTextureResource->getTextureStream(); if (pTextureAttachment.get() != nullptr) { std::string sUTF8FileName(pszFilename); std::wstring sUTF16FileName = fnUTF8toUTF16(sUTF8FileName); pTextureAttachment->writeToFile(sUTF16FileName.c_str()); } else { throw CNMRException(NMR_ERROR_NOTEXTURESTREAM); } return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
LIB3MFMETHODIMP CCOMModelTexture2D::ReadFromFileUTF8(_In_z_ LPCSTR pszFilename) { try { if (pszFilename == nullptr) throw CNMRException(NMR_ERROR_INVALIDPOINTER); CModelTexture2DResource * pTextureResource = getTexture2D(); __NMRASSERT(pTextureResource); std::string sUTF8FileName(pszFilename); PImportStream pImportStream = fnCreateImportStreamInstance(sUTF8FileName.c_str()); CModel * pModel = pTextureResource->getModel(); __NMRASSERT(pModel); pModel->removeAttachment(pTextureResource->getPath()); pModel->addAttachment(pTextureResource->getPath(), PACKAGE_TEXTURE_RELATIONSHIP_TYPE, pImportStream); return handleSuccess(); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }
LIB3MFMETHODIMP CCOMModelWriter::WriteToFileUTF8(_In_z_ LPCSTR pwszFilename) { try { if (pwszFilename == nullptr) throw CNMRException(NMR_ERROR_INVALIDPOINTER); if (m_pModelWriter.get() == nullptr) throw CNMRException(NMR_ERROR_RESOURCENOTFOUND); // Convert to UTF16 std::string sUTF8FileName(pwszFilename); std::wstring sUTF16FileName = fnUTF8toUTF16(sUTF8FileName); PExportStream pStream = fnCreateExportStreamInstance(sUTF16FileName.c_str()); m_pModelWriter->exportToStream(pStream); return handleSuccess(); } catch (CNMRException_Windows & WinException) { return handleNMRException(&WinException); } catch (CNMRException & Exception) { return handleNMRException(&Exception); } catch (...) { return handleGenericException(); } }