wxString nwxFileUtil::SetupFileName( const wxString &sOriginalFile, const wxString &_sExt) { wxString sFile(sOriginalFile); wxString sExt(_sExt); size_t nLen = sExt.Len(); if(nLen && !sExt.StartsWith(".")) { wxString s("."); s.Append(sExt); sExt = s; nLen++; } nwxString::SetFileExtension(&sFile,sExt); if(wxFileName::FileExists(sFile)) { wxString sBaseFile(sFile); int i = 1; if(nLen) { sBaseFile.Truncate(sBaseFile.Len() - nLen); } sBaseFile.Append("_"); for(bool bNotDone = true; bNotDone; bNotDone = wxFileName::FileExists(sFile)) { sFile = sBaseFile; sFile.Append(nwxString::FormatNumber(i++)); sFile.Append(sExt); } } return sFile; }
// ----------------------------------------------------------------------------- // CATBase::SearchFileWithExtension // Searches files with given extension from path. // ----------------------------------------------------------------------------- bool CATBase::SearchFileWithExtension( const char* pPathAndExt, bool bPrintErrors, string& sErrorLog ) { LOG_FUNC_ENTRY("CATBase::SearchFileWithExtension"); WIN32_FIND_DATA FindFileData; HANDLE hFind; string sTemp( pPathAndExt ); //Find file hFind = FindFirstFile( sTemp.c_str(), &FindFileData ); if (hFind == INVALID_HANDLE_VALUE) { string sErrorString( "No " ); //Get extension string sExt( pPathAndExt ); sExt.erase( 0, sExt.find_last_of( "." ) ); sErrorString.append( sExt ); sErrorString.append( " files in directory: " ); string sWithoutExt( pPathAndExt ); sWithoutExt.erase( sWithoutExt.find_last_of( "." )-1, string::npos ); sErrorString.append( sWithoutExt ); if( bPrintErrors ) { //string sTemp( pPathAndExt ); //printf( "Can not find: %s.\n", pPathAndExt ); printf( sErrorString.c_str() ); } else { //Add line change if sErrorString not empty if( !sErrorLog.empty() ) sErrorString.insert( 0, "\n" ); sErrorLog.append( sErrorString ); } return false; } else { FindClose(hFind); return true; } }
// Parameters: lpszFilePath can be the path or just the file; we just use the root and throw the rest away // WHY BOTH LANG AND ITS MFS? Because if we call CCarlaLanguage::getMFS(), then all processor DLLs have to // include the ccarlaLanguage code. Not good. So the caller, which is always in carlaStudio, must supply this CProcessStatus::CProcessStatus(LPCTSTR lpszFile, const CProcessingPrefs* pProcPrefs, // int iCurrentSeqFunction, CCarlaLanguage* pInputLang, // these are here so we can compile dlls that us this code without including CModelFilesSet* pInputMFS, CCarlaLanguage* pOuputLang, CModelFilesSet* pOutputMFS) : m_pProcPrefs(pProcPrefs), m_pProgessDlg(NULL), m_iProcNumber(0), m_iTotalProcessCount(0), m_sFileNameRoot(getFileName(lpszFile)), m_iCurrentSeqFunction(-1), m_pInputLang(pInputLang), m_pOutputLang(pOuputLang), m_pInputMFS(pInputMFS), m_pOutputMFS(pOutputMFS), m_pSrcDicts(TRUE), // jdh 3/14/2000 plug leak m_pTarDicts(TRUE) // jdh 3/14/2000 plug leak { if(pInputLang) ASSERTX(pInputMFS); if(pOuputLang) ASSERTX(pOutputMFS); ASSERTX(pInputLang || pOuputLang); CString sPath(lpszFile); CString sExt(sPath.Right(3)); #ifndef hab240 sExt.MakeLower(); #endif // hab240 if(sExt == _T("ana") || sExt == _T("anx")) // jdh 20June2000 added sANAPath = sPath; else // assume its text (mar 12, beta 7) sRAWPath = sPath; // else // THROWSTRING2("CProcessStatus doesn't know how to handle a file with extension ",sExt); loadOriginalDictsArrayFromLang(); }
int CDirList::ExtToType(const wxString &_sExt) { int nRtn = _sExt.IsEmpty() ? CDirList::FILE_FSA : 0; if(!nRtn) { wxString sExt("*."); sExt.Append(_sExt); sExt.MakeLower(); INITMAP(); for(FILE_MAP::iterator itr = g_mapFileSpec.begin(); itr != g_mapFileSpec.end(); ++itr) { if(!itr->second.CmpNoCase(sExt)) { nRtn = itr->first; break; } } } return nRtn; }
// Plugin factory function DECLDIR MeshData* LoadData(const char* sFile) { std::string fname(sFile), sExt(".obj"); if( fname.find(sExt, (fname.length() - sExt.length()) ) == std::string::npos ) return nullptr; std::vector< unsigned int > vertexIndices, uvIndices, normalIndices; std::vector< glm::vec3 > temp_vertices; std::vector< glm::vec3 > temp_normals; std::vector< glm::vec2 > temp_uvs; FILE *file = fopen(sFile, "r"); if( file == NULL ){ printf("Impossible to open the file !\n"); return nullptr; } while( 1 ) { char lineHeader[128]; // read the first word of the line int res = fscanf(file, "%s", lineHeader); if (res == EOF) break; // EOF = End Of File. Quit the loop. // else : parse lineHeader if ( strcmp( lineHeader, "v" ) == 0 ) { glm::vec3 vertex; fscanf(file, "%f %f %f\n", &vertex.x, &vertex.y, &vertex.z ); temp_vertices.push_back(vertex); } else if ( strcmp( lineHeader, "vn" ) == 0 ) { glm::vec3 normal; fscanf(file, "%f %f %f\n", &normal.x, &normal.y, &normal.z ); temp_normals.push_back(normal); } else if ( strcmp( lineHeader, "vt" ) == 0 ) { glm::vec2 uv; fscanf(file, "%f %f\n", &uv.x, &uv.y ); temp_uvs.push_back(uv); } else if ( strcmp( lineHeader, "f" ) == 0 ) { std::string vertex1, vertex2, vertex3; unsigned int vertexIndex[3], uvIndex[3], normalIndex[3]; int matches = fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", &vertexIndex[0], &uvIndex[0], &normalIndex[0], &vertexIndex[1], &uvIndex[1], &normalIndex[1], &vertexIndex[2], &uvIndex[2], &normalIndex[2] ); if (matches != 9) { printf("File can't be read by our simple parser : ( Try exporting with other options\n"); return nullptr; } vertexIndices.push_back(vertexIndex[0]); vertexIndices.push_back(vertexIndex[1]); vertexIndices.push_back(vertexIndex[2]); uvIndices .push_back(uvIndex[0]); uvIndices .push_back(uvIndex[1]); uvIndices .push_back(uvIndex[2]); normalIndices.push_back(normalIndex[0]); normalIndices.push_back(normalIndex[1]); normalIndices.push_back(normalIndex[2]); } } if( vertexIndices.size() != uvIndices.size() && uvIndices.size() != normalIndices.size() ) // incorrect printf("File can't be read by our simple parser : ( Not the same ammount of indices of all elements\n"); std::vector<float> vertices; std::vector<unsigned int> indices; vertices.reserve( vertexIndices.size() * 8 ); indices.reserve( vertexIndices.size() ); // For each vertex of each triangle for( unsigned int i(0); i < vertexIndices.size(); ++i ) { unsigned int vertexIndex = vertexIndices[i]; glm::vec3 vertex = temp_vertices[ vertexIndex-1 ]; vertices.push_back(vertex.x); vertices.push_back(vertex.y); vertices.push_back(vertex.z); unsigned int normalIndex = normalIndices[i]; glm::vec3 normal = temp_normals[ normalIndex-1 ]; vertices.push_back(normal.x); vertices.push_back(normal.y); vertices.push_back(normal.z); unsigned int uvIndex = uvIndices[i]; glm::vec2 uv = temp_uvs[ uvIndex-1 ]; vertices.push_back(uv.x); vertices.push_back(1 - uv.y); //convert UV coord: in obj the origin is top left but the engine uses bottom left indices.push_back(i); } //copy index and vertex buffer float *copiedVertices = new float[vertices.size()]; for (unsigned int i(0); i < vertices.size(); ++i) copiedVertices[i] = vertices[i]; unsigned int *copiedIndices = new unsigned int[indices.size()]; for (unsigned int i(0); i < indices.size(); ++i) copiedIndices[i] = indices[i]; MeshData *pMD = new MeshData(); pMD->iCount = indices.size(); pMD->iData = copiedIndices; pMD->vCount = vertices.size(); pMD->vData = copiedVertices; return pMD; }
bool CDirList::CreateFileName(bool bForce) { bool bDone = false; if((!bForce) && m_sFileName.Len()) { bDone = true; } // else if(!wxFileName::Mkdir(m_sDirSave,0755,wxPATH_MKDIR_FULL)) // { // bDone = false; // } else { wxString sPathBase = GetSavePath(true); if(!sPathBase.IsEmpty()) { wxString sName(sPathBase); wxString sPath; nwxFileUtil::NoEndWithSeparator(&sName); wxFileName fn(sName); sName = fn.GetFullName(); sName.Replace(" ","_",true); if(sName.IsEmpty()) { wxASSERT_MSG( false,"Problem with CDirList::CreateFileName()"); sName = "run_"; } else { sName.Append("_"); } wxString sFullName; wxString sExt(EXT_BATCH); int nAdd = 0; sPathBase.Append(sName); bool bDoneLoop = false; while(!bDoneLoop) { sPath = sPathBase; sPath.Append(GetTimeStamp(nAdd)); sPath.Append(sExt); sFullName = nwxFileUtil::SetupFileName(sPath,sExt); if(sFullName.IsEmpty()) { bDoneLoop = true; // end loop wxASSERT_MSG(false, "sFullName is Empty in CDirList::CreateFileName()"); } else if(wxFileName::FileExists(sFullName)) { nAdd++; } else { wxFile xFile(sFullName.wc_str(),wxFile::write_excl); if(!xFile.IsOpened()) { wxString s("Cannot create file: "); s.Append(sFullName); wxASSERT_MSG(false,s); } else { m_sFileName = sFullName; bDone = true; } bDoneLoop = true; } } } else { wxASSERT_MSG( false,"empty path in CDirList::CreateFileName()"); } } return bDone; }
//--------------------------------------------------------------------------- void TRtfConverterList::GetConverterList(HKEY regRoot, AnsiString regPath, AnsiString appName, bool import) { // allocate string list for subkeys TStringList* subKeys = new TStringList(); // Registry key path and data value names AnsiString sRegPath = regPath; AnsiString sName("Name"); AnsiString sExt("Extensions"); AnsiString sPath("Path"); // modify Registry key path for import or export if (import) sRegPath += AnsiString("Import"); else sRegPath += AnsiString("Export"); // allocate a Registry object TRegistry* reg = new TRegistry(); try { // open Registry key and get subkeys reg->RootKey = regRoot; reg->OpenKey(sRegPath, false); reg->GetKeyNames(subKeys); reg->CloseKey(); // for each subkey for (int i = 0; i < subKeys->Count; i++) { AnsiString currKey, name, ext, path; // append it to the import/export key currKey = sRegPath + AnsiString("\\") + subKeys->Strings[i]; // open that key and retrieve "Name," "Path", & "Extensions" values try { reg->OpenKey(currKey, false); name = reg->ReadString(sName); path = reg->ReadString(sPath); AnsiString tempExt = reg->ReadString(sExt); // extensions are returned as a space-delimited, null-terminated // string; parse extensions and format as filters char* s = tempExt.c_str(); while (*s) { AnsiString temp = NextExt(s); if (!temp.Length()) continue; if (ext.Length()) ext += ";"; ext += AnsiString("*.") + temp; } } // catch errors and continue catch (...) {} // close the subkey reg->CloseKey(); // duplicates are possible -- look through the descriptions // and, if a match is found, compare the library paths, extensions, // and format classes... if all are the same as the existing entry, // then skip this one. bool skipIt = false; for (int j = 0; j < FRawDescription->Count; j++) if (!(FRawDescription->Strings[j].AnsiCompareIC(name)) && !(LibraryPath->Strings[j].AnsiCompareIC(path)) && !(FormatClass->Strings[j].AnsiCompareIC(subKeys->Strings[i])) && !(Filters->Strings[j].AnsiCompareIC(ext))) skipIt = true; // and add the values to the string lists if (!skipIt && name.Length() && ext.Length() && path.Length()) { AnsiString rawName = name; if (appName.Length()) name += AnsiString(" - ") + appName; int ndx = Description->Add(name); FRawDescription->Insert(ndx, rawName); LibraryPath->Insert(ndx, path); FormatClass->Insert(ndx, subKeys->Strings[i]); Filters->Insert(ndx, ext); } } } // ignore errors catch (...) {} // free local storage delete reg; delete subKeys; }