165 lpath.
m_Alias = wxS(
"${KIPRJMOD}" );
170 wxUniChar psep = fndummy.GetPathSeparator();
171 std::list< wxString > epaths;
175 for(
const wxString& currPath : epaths )
177 wxString currPathVarFormat = currPath;
178 currPathVarFormat.Prepend( wxS(
"${" ) );
179 currPathVarFormat.Append( wxS(
"}" ) );
183 if( pathVal.empty() )
189 fndummy.Assign( pathVal,
"" );
204 lpath.
m_Alias = currPathVarFormat;
214 std::list< SEARCH_PATH >::const_iterator sPL =
m_paths.begin();
218 wxLogTrace(
MASK_3D_RESOLVER, wxS(
" + %s : '%s'\n" ), (*sPL).m_Alias.GetData(),
219 (*sPL).m_Pathexp.GetData() );
243 std::vector<const EMBEDDED_FILES*> aEmbeddedFilesStack )
247 if( aFileName.empty() )
248 return wxEmptyString;
254 wxString tname = aFileName;
258 tname.Replace(
"\\",
"/" );
270 if( aEmbeddedFilesStack.empty() )
272 wxLogTrace( wxT(
"KICAD_EMBED" ),
273 wxT(
"No EMBEDDED_FILES object provided for kicad_embed URI" ) );
274 return wxEmptyString;
280 int ii = (int) aEmbeddedFilesStack.size() - 1;
281 wxFileName temp_file = aEmbeddedFilesStack[ii--]->GetTemporaryFileName(
path );
283 while( !temp_file.IsOk() && ii >= 0 )
284 temp_file = aEmbeddedFilesStack[ii--]->GetTemporaryFileName(
path );
286 if( !temp_file.IsOk() )
288 wxLogTrace( wxT(
"KICAD_EMBED" ), wxT(
"Failed to get temp file '%s' for kicad_embed URI" ),
path );
289 return wxEmptyString;
292 wxLogTrace( wxT(
"KICAD_EMBED" ), wxT(
"Opening embedded file '%s' as '%s'" ), tname, temp_file.GetFullPath() );
294 return temp_file.GetFullPath();
297 wxFileName tmpFN( tname );
301 if( tmpFN.FileExists() )
304 tname = tmpFN.GetFullPath();
308 if( aFileName.StartsWith( wxS(
"${" ) ) || aFileName.StartsWith( wxS(
"$(" ) ) )
317 if( aFileName.StartsWith(
"${" ) || aFileName.StartsWith(
"$(" ) )
321 if( tname == aFileName )
323 bool useBrace = aFileName.StartsWith(
"${" );
324 size_t aliasEnd = aFileName.find( useBrace ?
'}' :
')' );
327 if( aliasEnd != wxString::npos && aliasEnd > 2 )
329 wxString alias = aFileName.substr( 2, aliasEnd - 2 );
332 size_t relStart = aliasEnd + 1;
334 if( relStart < aFileName.length()
335 && ( aFileName[relStart] ==
'/' || aFileName[relStart] ==
'\\' ) )
342 if( relStart < aFileName.length() )
343 relpath = aFileName.substr( relStart );
347 if(
path.m_Alias.StartsWith( wxS(
"${" ) ) ||
path.m_Alias.StartsWith( wxS(
"$(" ) ) )
350 if(
path.m_Alias == alias && !
path.m_Pathexp.empty() )
352 wxFileName fpath( wxFileName::DirName(
path.m_Pathexp ) );
353 wxString fullPath = fpath.GetPathWithSep() + relpath;
357 if( wxFileName::FileExists( fullPath ) )
359 wxFileName tmp( fullPath );
362 fullPath = tmp.GetFullPath();
374 wxString errmsg =
"[3D File Resolver] No such path; ensure the environment var is "
376 errmsg.append(
"\n" );
377 errmsg.append( tname );
378 errmsg.append(
"\n" );
382 return wxEmptyString;
394 if( !
m_paths.begin()->m_Pathexp.empty() && !tname.StartsWith(
":" ) )
396 tmpFN.Assign(
m_paths.begin()->m_Pathexp,
"" );
397 wxString fullPath = tmpFN.GetPathWithSep() + tname;
401 if( wxFileName::FileExists( fullPath ) )
403 tmpFN.Assign( fullPath );
405 tname = tmpFN.GetFullPath();
412 if( !aWorkingPath.IsEmpty() && !tname.StartsWith(
":" ) )
414 wxString tmp = aWorkingPath;
415 tmp.Append( tmpFN.GetPathSeparator() );
419 if( tmpFN.MakeAbsolute() && tmpFN.FileExists() )
421 tname = tmpFN.GetFullPath();
427 if( !tname.StartsWith( wxS(
":" ) ) )
430 wxString fullPath( wxString::Format( wxS(
"${%s}" ),
432 fullPath.Append( fpath.GetPathSeparator() );
433 fullPath.Append( tname );
435 fpath.Assign( fullPath );
439 tname = fpath.GetFullPath();
456 wxString errmsg =
"[3D File Resolver] No such path";
457 errmsg.append( wxS(
"\n" ) );
458 errmsg.append( tname );
459 errmsg.append( wxS(
"\n" ) );
463 return wxEmptyString;
469 if(
path.m_Alias.StartsWith( wxS(
"${" ) ) ||
path.m_Alias.StartsWith( wxS(
"$(" ) ) )
472 if(
path.m_Alias == alias && !
path.m_Pathexp.empty() )
474 wxFileName fpath( wxFileName::DirName(
path.m_Pathexp ) );
475 wxString fullPath = fpath.GetPathWithSep() + relpath;
479 if( wxFileName::FileExists( fullPath ) )
483 wxFileName tmp( fullPath );
486 tname = tmp.GetFullPath();
496 wxString errmsg =
"[3D File Resolver] No such path; ensure the path alias is defined";
497 errmsg.append(
"\n" );
498 errmsg.append( tname.substr( 1 ) );
499 errmsg.append(
"\n" );
503 return wxEmptyString;
652 wxString fname = aFullPathName;
659 std::list< SEARCH_PATH >::const_iterator sL =
m_paths.begin();
666 if( sL->m_Pathexp.empty() )
675 if( sL->m_Alias.StartsWith( wxS(
"${" ) ) || sL->m_Alias.StartsWith( wxS(
"$(" ) ) )
685 fpath.Assign( tpath, wxT(
"" ) );
689 fpath.Assign( sL->m_Pathexp, wxT(
"" ) );
692 wxString fps = fpath.GetPathWithSep();
695 idx = fname.find( fps );
699 fname = fname.substr( fps.size() );
703 fname.Replace( wxT(
"\\" ), wxT(
"/" ) );
706 if( sL->m_Alias.StartsWith( wxS(
"${" ) ) || sL->m_Alias.StartsWith( wxS(
"$(" ) ) )
710 tname.Append( wxS(
"/" ) );
711 tname.append( fname );
717 tname.append( sL->m_Alias );
718 tname.append( wxS(
"}/" ) );
719 tname.append( fname );
733 fname.Replace( wxT(
"\\" ), wxT(
"/" ) );
747 wxString& anAlias, wxString& aRelPath )
const
752 size_t searchStart = 0;
754 if( aFileName.StartsWith( wxT(
":" ) ) )
757 size_t tagpos = aFileName.find( wxT(
":" ), searchStart );
759 if( tagpos == wxString::npos || tagpos == searchStart )
762 if( tagpos + 1 >= aFileName.length() )
765 anAlias = aFileName.substr( searchStart, tagpos - searchStart );
766 aRelPath = aFileName.substr( tagpos + 1 );
783 if( aFileName.empty() )
786 if( aFileName.StartsWith( wxT(
"file://" ) )
789 size_t prefixLength = aFileName.StartsWith( wxT(
"file://" ) ) ? 7 : 14;
790 if( aFileName.length() > prefixLength && aFileName[prefixLength] !=
'/' )
796 wxString filename = aFileName;
798 size_t aliasStart = aFileName.StartsWith(
':' ) ? 1 : 0;
799 size_t aliasEnd = aFileName.find(
':', aliasStart );
803 filename.Replace( wxT(
"/" ), wxT(
"\\" ) );
806 if( aliasEnd != wxString::npos )
808 size_t pos1 = filename.find( wxT(
":\\" ) );
810 if( pos1 != wxString::npos && ( pos1 != aliasEnd || pos1 != 1 ) )
814 if( pos1 != wxString::npos )
815 aliasEnd = wxString::npos;
818 filename.Replace( wxT(
"\\" ), wxT(
"/" ) );
822 if( aliasEnd == aFileName.length() -1 )
825 if( aliasEnd != wxString::npos )
828 if( aliasEnd == aliasStart )
831 lpath = filename.substr( aliasStart, aliasEnd );
834 if( wxString::npos != lpath.find_first_of( wxT(
"{}[]()%~<>\"='`;:.,&?/\\|$" ) ) )
838 lpath = aFileName.substr( aliasEnd + 1 );
846 aliasEnd = wxString::npos;
848 if( aFileName.StartsWith( wxS(
"${" ) ) )
849 aliasEnd = aFileName.find(
'}' );
850 else if( aFileName.StartsWith( wxS(
"$(" ) ) )
851 aliasEnd = aFileName.find(
')' );
853 if( aliasEnd != wxString::npos )
854 lpath = aFileName.substr( aliasEnd + 1 );
862 wxString lpath_no_sep = lpath;
865 lpath_no_sep.Replace(
"/",
" " );
866 lpath_no_sep.Replace(
"\\",
" " );
869 if( lpath_no_sep.Length() > 1 && lpath_no_sep[1] ==
':' )
870 lpath_no_sep[1] =
' ';
873 if( wxString::npos != lpath_no_sep.find_first_of( wxFileName::GetForbiddenChars() ) )