MCPcopy Create free account
hub / github.com/assimp/assimp / DoExport

Function DoExport

tools/assimp_view/MessageProc.cpp:935–1012  ·  view source on GitHub ↗

------------------------------------------------------------------------------- Export function -------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

933// Export function
934//-------------------------------------------------------------------------------
935void DoExport(size_t formatId) {
936 if (!g_szFileName[0]) {
937 MessageBox(g_hDlg, "No model loaded", "Export", MB_ICONERROR);
938 return;
939 }
940 Exporter exp;
941 const aiExportFormatDesc* const e = exp.GetExportFormatDescription(formatId);
942 ai_assert(e);
943
944 char szFileName[MAX_PATH*2];
945 DWORD dwTemp = sizeof(szFileName);
946 if(ERROR_SUCCESS == RegQueryValueEx(g_hRegistry,"ModelExportDest",nullptr,nullptr,(BYTE*)szFileName, &dwTemp)) {
947 ai_assert(strlen(szFileName) <= MAX_PATH);
948
949 // invent a nice default file name
950 char* sz = std::max(strrchr(szFileName,'\\'),strrchr(szFileName,'/'));
951 if (sz) {
952 strncpy(sz,std::max(strrchr(g_szFileName,'\\'),strrchr(g_szFileName,'/')),MAX_PATH);
953 }
954 }
955 else {
956 // Key was not found. Use the folder where the asset comes from
957 strncpy(szFileName,g_szFileName,MAX_PATH);
958 }
959
960 // fix file extension
961 { char * const sz = strrchr(szFileName,'.');
962 if(sz) {
963 ai_assert((sz - &szFileName[0]) + strlen(e->fileExtension) + 1 <= MAX_PATH);
964 strcpy(sz+1,e->fileExtension);
965 }
966 }
967
968 // build the stupid info string for GetSaveFileName() - can't use sprintf() because the string must contain binary zeros.
969 char desc[256] = {0};
970 char* c = strcpy(desc,e->description) + strlen(e->description)+1;
971 c += sprintf(c,"*.%s",e->fileExtension)+1;
972 strcpy(c, "*.*\0"); c += 4;
973
974 ai_assert(c - &desc[0] <= 256);
975
976 const std::string ext = "."+std::string(e->fileExtension);
977 OPENFILENAME sFilename1 = {
978 sizeof(OPENFILENAME),
979 g_hDlg,GetModuleHandle(nullptr),
980 desc, nullptr, 0, 1,
981 szFileName, MAX_PATH, nullptr, 0, nullptr,
982 "Export asset",
983 OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR,
984 0, 1, ext.c_str(), 0, nullptr, nullptr
985 };
986 if(::GetSaveFileName(&sFilename1) == 0) {
987 return;
988 }
989
990 // Now store the file in the registry unless the user decided to stay in the model directory
991 const std::string sFinal = szFileName, sub = sFinal.substr(0,sFinal.find_last_of("\\/"));
992 if (strncmp(sub.c_str(),g_szFileName,sub.length())) {

Callers 1

MessageProcFunction · 0.70

Calls 5

InstanceClass · 0.85
maxFunction · 0.50
ExportMethod · 0.45
AddEntryMethod · 0.45

Tested by

no test coverage detected