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;
279 wxFileName temp_file = aEmbeddedFilesStack[0]->GetTemporaryFileName(
path );
282 while( !temp_file.IsOk() && ii < (
int) aEmbeddedFilesStack.size() )
283 temp_file = aEmbeddedFilesStack[ii++]->GetTemporaryFileName(
path );
285 if( !temp_file.IsOk() )
287 wxLogTrace( wxT(
"KICAD_EMBED" ),
288 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'" ),
293 tname, temp_file.GetFullPath() );
295 return temp_file.GetFullPath();
298 wxFileName tmpFN( tname );
302 if( tmpFN.FileExists() )
305 tname = tmpFN.GetFullPath();
309 if( aFileName.StartsWith( wxS(
"${" ) ) || aFileName.StartsWith( wxS(
"$(" ) ) )
318 if( aFileName.StartsWith(
"${" ) || aFileName.StartsWith(
"$(" ) )
322 if( tname == aFileName )
324 bool useBrace = aFileName.StartsWith(
"${" );
325 size_t aliasEnd = aFileName.find( useBrace ?
'}' :
')' );
328 if( aliasEnd != wxString::npos && aliasEnd > 2 )
330 wxString alias = aFileName.substr( 2, aliasEnd - 2 );
333 size_t relStart = aliasEnd + 1;
335 if( relStart < aFileName.length()
336 && ( aFileName[relStart] ==
'/' || aFileName[relStart] ==
'\\' ) )
343 if( relStart < aFileName.length() )
344 relpath = aFileName.substr( relStart );
348 if(
path.m_Alias.StartsWith( wxS(
"${" ) ) ||
path.m_Alias.StartsWith( wxS(
"$(" ) ) )
351 if(
path.m_Alias == alias && !
path.m_Pathexp.empty() )
353 wxFileName fpath( wxFileName::DirName(
path.m_Pathexp ) );
354 wxString fullPath = fpath.GetPathWithSep() + relpath;
358 if( wxFileName::FileExists( fullPath ) )
360 wxFileName tmp( fullPath );
363 fullPath = tmp.GetFullPath();
375 wxString errmsg =
"[3D File Resolver] No such path; ensure the environment var is "
377 errmsg.append(
"\n" );
378 errmsg.append( tname );
379 errmsg.append(
"\n" );
383 return wxEmptyString;
395 if( !
m_paths.begin()->m_Pathexp.empty() && !tname.StartsWith(
":" ) )
397 tmpFN.Assign(
m_paths.begin()->m_Pathexp,
"" );
398 wxString fullPath = tmpFN.GetPathWithSep() + tname;
402 if( wxFileName::FileExists( fullPath ) )
404 tmpFN.Assign( fullPath );
406 tname = tmpFN.GetFullPath();
413 if( !aWorkingPath.IsEmpty() && !tname.StartsWith(
":" ) )
415 wxString tmp = aWorkingPath;
416 tmp.Append( tmpFN.GetPathSeparator() );
420 if( tmpFN.MakeAbsolute() && tmpFN.FileExists() )
422 tname = tmpFN.GetFullPath();
428 if( !tname.StartsWith( wxS(
":" ) ) )
431 wxString fullPath( wxString::Format( wxS(
"${%s}" ),
433 fullPath.Append( fpath.GetPathSeparator() );
434 fullPath.Append( tname );
436 fpath.Assign( fullPath );
440 tname = fpath.GetFullPath();
457 wxString errmsg =
"[3D File Resolver] No such path";
458 errmsg.append( wxS(
"\n" ) );
459 errmsg.append( tname );
460 errmsg.append( wxS(
"\n" ) );
464 return wxEmptyString;
470 if(
path.m_Alias.StartsWith( wxS(
"${" ) ) ||
path.m_Alias.StartsWith( wxS(
"$(" ) ) )
473 if(
path.m_Alias == alias && !
path.m_Pathexp.empty() )
475 wxFileName fpath( wxFileName::DirName(
path.m_Pathexp ) );
476 wxString fullPath = fpath.GetPathWithSep() + relpath;
480 if( wxFileName::FileExists( fullPath ) )
484 wxFileName tmp( fullPath );
487 tname = tmp.GetFullPath();
497 wxString errmsg =
"[3D File Resolver] No such path; ensure the path alias is defined";
498 errmsg.append(
"\n" );
499 errmsg.append( tname.substr( 1 ) );
500 errmsg.append(
"\n" );
504 return wxEmptyString;
653 wxString fname = aFullPathName;
660 std::list< SEARCH_PATH >::const_iterator sL =
m_paths.begin();
667 if( sL->m_Pathexp.empty() )
676 if( sL->m_Alias.StartsWith( wxS(
"${" ) ) || sL->m_Alias.StartsWith( wxS(
"$(" ) ) )
686 fpath.Assign( tpath, wxT(
"" ) );
690 fpath.Assign( sL->m_Pathexp, wxT(
"" ) );
693 wxString fps = fpath.GetPathWithSep();
696 idx = fname.find( fps );
700 fname = fname.substr( fps.size() );
704 fname.Replace( wxT(
"\\" ), wxT(
"/" ) );
707 if( sL->m_Alias.StartsWith( wxS(
"${" ) ) || sL->m_Alias.StartsWith( wxS(
"$(" ) ) )
711 tname.Append( wxS(
"/" ) );
712 tname.append( fname );
718 tname.append( sL->m_Alias );
719 tname.append( wxS(
"}/" ) );
720 tname.append( fname );
734 fname.Replace( wxT(
"\\" ), wxT(
"/" ) );
748 wxString& anAlias, wxString& aRelPath )
const
753 size_t searchStart = 0;
755 if( aFileName.StartsWith( wxT(
":" ) ) )
758 size_t tagpos = aFileName.find( wxT(
":" ), searchStart );
760 if( tagpos == wxString::npos || tagpos == searchStart )
763 if( tagpos + 1 >= aFileName.length() )
766 anAlias = aFileName.substr( searchStart, tagpos - searchStart );
767 aRelPath = aFileName.substr( tagpos + 1 );
784 if( aFileName.empty() )
787 if( aFileName.StartsWith( wxT(
"file://" ) )
790 size_t prefixLength = aFileName.StartsWith( wxT(
"file://" ) ) ? 7 : 14;
791 if( aFileName.length() > prefixLength && aFileName[prefixLength] !=
'/' )
797 wxString filename = aFileName;
799 size_t aliasStart = aFileName.StartsWith(
':' ) ? 1 : 0;
800 size_t aliasEnd = aFileName.find(
':', aliasStart );
804 filename.Replace( wxT(
"/" ), wxT(
"\\" ) );
807 if( aliasEnd != wxString::npos )
809 size_t pos1 = filename.find( wxT(
":\\" ) );
811 if( pos1 != wxString::npos && ( pos1 != aliasEnd || pos1 != 1 ) )
815 if( pos1 != wxString::npos )
816 aliasEnd = wxString::npos;
819 filename.Replace( wxT(
"\\" ), wxT(
"/" ) );
823 if( aliasEnd == aFileName.length() -1 )
826 if( aliasEnd != wxString::npos )
829 if( aliasEnd == aliasStart )
832 lpath = filename.substr( aliasStart, aliasEnd );
835 if( wxString::npos != lpath.find_first_of( wxT(
"{}[]()%~<>\"='`;:.,&?/\\|$" ) ) )
839 lpath = aFileName.substr( aliasEnd + 1 );
847 aliasEnd = wxString::npos;
849 if( aFileName.StartsWith( wxS(
"${" ) ) )
850 aliasEnd = aFileName.find(
'}' );
851 else if( aFileName.StartsWith( wxS(
"$(" ) ) )
852 aliasEnd = aFileName.find(
')' );
854 if( aliasEnd != wxString::npos )
855 lpath = aFileName.substr( aliasEnd + 1 );
863 wxString lpath_no_sep = lpath;
866 lpath_no_sep.Replace(
"/",
" " );
867 lpath_no_sep.Replace(
"\\",
" " );
870 if( lpath_no_sep.Length() > 1 && lpath_no_sep[1] ==
':' )
871 lpath_no_sep[1] =
' ';
874 if( wxString::npos != lpath_no_sep.find_first_of( wxFileName::GetForbiddenChars() ) )