169 lpath.
m_Alias = wxS(
"${KIPRJMOD}" );
174 wxUniChar psep = fndummy.GetPathSeparator();
175 std::list< wxString > epaths;
179 for(
const wxString& currPath : epaths )
181 wxString currPathVarFormat = currPath;
182 currPathVarFormat.Prepend( wxS(
"${" ) );
183 currPathVarFormat.Append( wxS(
"}" ) );
187 if( pathVal.empty() )
193 fndummy.Assign( pathVal,
"" );
208 lpath.
m_Alias = currPathVarFormat;
218 std::list< SEARCH_PATH >::const_iterator sPL =
m_paths.begin();
222 wxLogTrace(
MASK_3D_RESOLVER, wxS(
" + %s : '%s'\n" ), (*sPL).m_Alias.GetData(),
223 (*sPL).m_Pathexp.GetData() );
247 std::vector<const EMBEDDED_FILES*> aEmbeddedFilesStack )
251 if( aFileName.empty() )
252 return wxEmptyString;
258 wxString tname = aFileName;
262 tname.Replace(
"\\",
"/" );
274 if( aEmbeddedFilesStack.empty() )
276 wxLogTrace( wxT(
"KICAD_EMBED" ),
277 wxT(
"No EMBEDDED_FILES object provided for kicad_embed URI" ) );
278 return wxEmptyString;
283 wxFileName temp_file = aEmbeddedFilesStack[0]->GetTemporaryFileName(
path );
286 while( !temp_file.IsOk() && ii < (
int) aEmbeddedFilesStack.size() )
287 temp_file = aEmbeddedFilesStack[ii++]->GetTemporaryFileName(
path );
289 if( !temp_file.IsOk() )
291 wxLogTrace( wxT(
"KICAD_EMBED" ),
292 wxT(
"Failed to get temp file '%s' for kicad_embed URI" ),
path );
293 return wxEmptyString;
296 wxLogTrace( wxT(
"KICAD_EMBED" ), wxT(
"Opening embedded file '%s' as '%s'" ),
297 tname, temp_file.GetFullPath() );
299 return temp_file.GetFullPath();
302 wxFileName tmpFN( tname );
306 if( tmpFN.FileExists() )
309 tname = tmpFN.GetFullPath();
313 if( aFileName.StartsWith( wxS(
"${" ) ) || aFileName.StartsWith( wxS(
"$(" ) ) )
322 if( aFileName.StartsWith(
"${" ) || aFileName.StartsWith(
"$(" ) )
326 if( tname == aFileName )
328 bool useBrace = aFileName.StartsWith(
"${" );
329 size_t aliasEnd = aFileName.find( useBrace ?
'}' :
')' );
332 if( aliasEnd != wxString::npos && aliasEnd > 2 )
334 wxString alias = aFileName.substr( 2, aliasEnd - 2 );
337 size_t relStart = aliasEnd + 1;
339 if( relStart < aFileName.length()
340 && ( aFileName[relStart] ==
'/' || aFileName[relStart] ==
'\\' ) )
347 if( relStart < aFileName.length() )
348 relpath = aFileName.substr( relStart );
352 if(
path.m_Alias.StartsWith( wxS(
"${" ) ) ||
path.m_Alias.StartsWith( wxS(
"$(" ) ) )
355 if(
path.m_Alias == alias && !
path.m_Pathexp.empty() )
357 wxFileName fpath( wxFileName::DirName(
path.m_Pathexp ) );
358 wxString fullPath = fpath.GetPathWithSep() + relpath;
362 if( wxFileName::FileExists( fullPath ) )
364 wxFileName tmp( fullPath );
367 fullPath = tmp.GetFullPath();
379 wxString errmsg =
"[3D File Resolver] No such path; ensure the environment var is "
381 errmsg.append(
"\n" );
382 errmsg.append( tname );
383 errmsg.append(
"\n" );
387 return wxEmptyString;
399 if( !
m_paths.begin()->m_Pathexp.empty() && !tname.StartsWith(
":" ) )
401 tmpFN.Assign(
m_paths.begin()->m_Pathexp,
"" );
402 wxString fullPath = tmpFN.GetPathWithSep() + tname;
406 if( wxFileName::FileExists( fullPath ) )
408 tmpFN.Assign( fullPath );
410 tname = tmpFN.GetFullPath();
417 if( !aWorkingPath.IsEmpty() && !tname.StartsWith(
":" ) )
419 wxString tmp = aWorkingPath;
420 tmp.Append( tmpFN.GetPathSeparator() );
424 if( tmpFN.MakeAbsolute() && tmpFN.FileExists() )
426 tname = tmpFN.GetFullPath();
432 if( !tname.StartsWith( wxS(
":" ) ) )
435 wxString fullPath( wxString::Format( wxS(
"${%s}" ),
437 fullPath.Append( fpath.GetPathSeparator() );
438 fullPath.Append( tname );
440 fpath.Assign( fullPath );
444 tname = fpath.GetFullPath();
461 wxString errmsg =
"[3D File Resolver] No such path";
462 errmsg.append( wxS(
"\n" ) );
463 errmsg.append( tname );
464 errmsg.append( wxS(
"\n" ) );
468 return wxEmptyString;
474 if(
path.m_Alias.StartsWith( wxS(
"${" ) ) ||
path.m_Alias.StartsWith( wxS(
"$(" ) ) )
477 if(
path.m_Alias == alias && !
path.m_Pathexp.empty() )
479 wxFileName fpath( wxFileName::DirName(
path.m_Pathexp ) );
480 wxString fullPath = fpath.GetPathWithSep() + relpath;
484 if( wxFileName::FileExists( fullPath ) )
488 wxFileName tmp( fullPath );
491 tname = tmp.GetFullPath();
501 wxString errmsg =
"[3D File Resolver] No such path; ensure the path alias is defined";
502 errmsg.append(
"\n" );
503 errmsg.append( tname.substr( 1 ) );
504 errmsg.append(
"\n" );
508 return wxEmptyString;
657 wxString fname = aFullPathName;
664 std::list< SEARCH_PATH >::const_iterator sL =
m_paths.begin();
671 if( sL->m_Pathexp.empty() )
680 if( sL->m_Alias.StartsWith( wxS(
"${" ) ) || sL->m_Alias.StartsWith( wxS(
"$(" ) ) )
690 fpath.Assign( tpath, wxT(
"" ) );
694 fpath.Assign( sL->m_Pathexp, wxT(
"" ) );
697 wxString fps = fpath.GetPathWithSep();
700 idx = fname.find( fps );
704 fname = fname.substr( fps.size() );
708 fname.Replace( wxT(
"\\" ), wxT(
"/" ) );
711 if( sL->m_Alias.StartsWith( wxS(
"${" ) ) || sL->m_Alias.StartsWith( wxS(
"$(" ) ) )
715 tname.Append( wxS(
"/" ) );
716 tname.append( fname );
722 tname.append( sL->m_Alias );
723 tname.append( wxS(
"}/" ) );
724 tname.append( fname );
738 fname.Replace( wxT(
"\\" ), wxT(
"/" ) );
752 wxString& anAlias, wxString& aRelPath )
const
757 size_t searchStart = 0;
759 if( aFileName.StartsWith( wxT(
":" ) ) )
762 size_t tagpos = aFileName.find( wxT(
":" ), searchStart );
764 if( tagpos == wxString::npos || tagpos == searchStart )
767 if( tagpos + 1 >= aFileName.length() )
770 anAlias = aFileName.substr( searchStart, tagpos - searchStart );
771 aRelPath = aFileName.substr( tagpos + 1 );
788 if( aFileName.empty() )
791 if( aFileName.StartsWith( wxT(
"file://" ) )
794 size_t prefixLength = aFileName.StartsWith( wxT(
"file://" ) ) ? 7 : 14;
795 if( aFileName.length() > prefixLength && aFileName[prefixLength] !=
'/' )
801 wxString filename = aFileName;
803 size_t aliasStart = aFileName.StartsWith(
':' ) ? 1 : 0;
804 size_t aliasEnd = aFileName.find(
':', aliasStart );
808 filename.Replace( wxT(
"/" ), wxT(
"\\" ) );
811 if( aliasEnd != wxString::npos )
813 size_t pos1 = filename.find( wxT(
":\\" ) );
815 if( pos1 != wxString::npos && ( pos1 != aliasEnd || pos1 != 1 ) )
819 if( pos1 != wxString::npos )
820 aliasEnd = wxString::npos;
823 filename.Replace( wxT(
"\\" ), wxT(
"/" ) );
827 if( aliasEnd == aFileName.length() -1 )
830 if( aliasEnd != wxString::npos )
833 if( aliasEnd == aliasStart )
836 lpath = filename.substr( aliasStart, aliasEnd );
839 if( wxString::npos != lpath.find_first_of( wxT(
"{}[]()%~<>\"='`;:.,&?/\\|$" ) ) )
843 lpath = aFileName.substr( aliasEnd + 1 );
851 aliasEnd = wxString::npos;
853 if( aFileName.StartsWith( wxS(
"${" ) ) )
854 aliasEnd = aFileName.find(
'}' );
855 else if( aFileName.StartsWith( wxS(
"$(" ) ) )
856 aliasEnd = aFileName.find(
')' );
858 if( aliasEnd != wxString::npos )
859 lpath = aFileName.substr( aliasEnd + 1 );
867 wxString lpath_no_sep = lpath;
870 lpath_no_sep.Replace(
"/",
" " );
871 lpath_no_sep.Replace(
"\\",
" " );
874 if( lpath_no_sep.Length() > 1 && lpath_no_sep[1] ==
':' )
875 lpath_no_sep[1] =
' ';
878 if( wxString::npos != lpath_no_sep.find_first_of( wxFileName::GetForbiddenChars() ) )