33 #include <wx/config.h> 35 #include <wx/msgdlg.h> 36 #include <wx/stdpaths.h> 51 Bracket_Windows =
'%',
64 const std::function<
bool( wxString* )>* aLocalResolver,
65 const std::function<
bool( wxString* )>* aFallbackResolver,
69 size_t sourceLen = aSource.length();
71 newbuf.Alloc( sourceLen );
73 for(
size_t i = 0; i < sourceLen; ++i )
75 if( aSource[i] ==
'$' && i + 1 < sourceLen && aSource[i+1] ==
'{' )
79 for( i = i + 2; i < sourceLen; ++i )
81 if( aSource[i] ==
'}' )
84 token.append( aSource[i] );
90 if( aLocalResolver && (*aLocalResolver)( &token ) )
92 newbuf.append( token );
96 newbuf.append( token );
98 else if( aFallbackResolver && (*aFallbackResolver)( &token ) )
100 newbuf.append( token );
105 newbuf.append( wxT(
"${" ) + token + wxT(
"}" ) );
110 newbuf.append( aSource[i] );
123 size_t strlen = str.length();
126 strResult.Alloc( strlen );
128 for(
size_t n = 0; n < strlen; n++ )
130 wxUniChar str_n = str[n];
132 switch( str_n.GetValue() )
136 #endif // __WINDOWS__ 141 if( str_n == wxT(
'%' ) )
142 bracket = Bracket_Windows;
144 #endif // __WINDOWS__ 145 if( n == strlen - 1 )
151 switch( str[n + 1].GetValue() )
173 wxUniChar str_m = str[m];
175 while( wxIsalnum( str_m ) || str_m == wxT(
'_' ) || str_m == wxT(
':' ) )
186 wxString strVarName( str.c_str() + n + 1, m - n - 1 );
190 bool expanded =
false;
191 wxString tmp = strVarName;
198 else if( wxGetEnv( strVarName, &tmp ) )
207 if ( bracket != Bracket_Windows )
210 strResult << str[n - 1];
212 strResult << str_n << strVarName;
218 if( m == strlen || str_m != (wxChar)bracket )
227 wxLogWarning(
_(
"Environment variables expansion failed: missing '%c' " 228 "at position %u in '%s'." ),
229 (
char)bracket, (
unsigned int) (m + 1), str.c_str() );
230 #endif // __WINDOWS__ 236 strResult << (wxChar)bracket;
249 if( n < strlen - 1 && (str[n + 1] == wxT(
'%' ) || str[n + 1] == wxT(
'$' )) )
271 static std::mutex getenv_mutex;
273 std::lock_guard<std::mutex> lock( getenv_mutex );
287 if( url.GetError() == wxURL_NOERR )
296 const wxString& aBaseFilename,
300 wxString baseFilePath = wxFileName( aBaseFilename ).GetPath();
304 if( !aTargetFullFileName->MakeAbsolute( baseFilePath ) )
308 msg.Printf(
_(
"Cannot make path '%s' absolute with respect to '%s'." ),
309 aTargetFullFileName->GetPath(),
318 wxString outputPath( aTargetFullFileName->GetPath() );
320 if( !wxFileName::DirExists( outputPath ) )
323 if( wxFileName::Mkdir( outputPath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
327 msg.Printf(
_(
"Output directory '%s' created." ), outputPath );
336 msg.Printf(
_(
"Cannot create output directory '%s'." ), outputPath );
362 bool matchWild(
const char* pat,
const char* text,
bool dot_special )
378 if( dot_special && (*n ==
'.') )
475 #if wxUSE_DATETIME && defined(__WIN32__) && !defined(__WXMICROWIN__) 481 static wxInt64 EPOCH_OFFSET_IN_MSEC = wxLL(11644473600000);
484 static void ConvertFileTimeToWx( wxDateTime* dt,
const FILETIME& ft )
486 wxLongLong t( ft.dwHighDateTime, ft.dwLowDateTime );
488 t -= EPOCH_OFFSET_IN_MSEC;
490 *dt = wxDateTime( t );
493 #endif // wxUSE_DATETIME && __WIN32__ 504 long long TimestampDir(
const wxString& aDirPath,
const wxString& aFilespec )
506 long long timestamp = 0;
508 #if defined( __WIN32__ ) 513 std::wstring filespec( aDirPath.t_str() );
515 filespec += aFilespec.t_str();
517 WIN32_FIND_DATA findData;
518 wxDateTime lastModDate;
520 HANDLE fileHandle = ::FindFirstFile( filespec.data(), &findData );
522 if( fileHandle != INVALID_HANDLE_VALUE )
526 ConvertFileTimeToWx( &lastModDate, findData.ftLastWriteTime );
527 timestamp += lastModDate.GetValue().GetValue();
530 timestamp += findData.nFileSizeLow;
532 while ( FindNextFile( fileHandle, &findData ) != 0 );
535 FindClose( fileHandle );
539 std::string filespec( aFilespec.fn_str() );
540 std::string dir_path( aDirPath.fn_str() );
542 DIR* dir = opendir( dir_path.c_str() );
546 for( dirent* dir_entry = readdir( dir ); dir_entry; dir_entry = readdir( dir ) )
548 if( !
matchWild( filespec.c_str(), dir_entry->d_name, true ) )
551 std::string entry_path = dir_path +
'/' + dir_entry->d_name;
552 struct stat entry_stat;
554 if( wxCRT_Lstat( entry_path.c_str(), &entry_stat ) == 0 )
557 if( S_ISLNK( entry_stat.st_mode ) )
559 char buffer[ PATH_MAX + 1 ];
560 ssize_t pathLen = readlink( entry_path.c_str(), buffer, PATH_MAX );
564 struct stat linked_stat;
565 buffer[ pathLen ] =
'\0';
566 entry_path = dir_path + buffer;
568 if( wxCRT_Lstat( entry_path.c_str(), &linked_stat ) == 0 )
570 entry_stat = linked_stat;
580 if( S_ISREG( entry_stat.st_mode ) )
582 timestamp += entry_stat.st_mtime * 1000;
585 timestamp += entry_stat.st_size;
591 timestamp += (signed) std::hash<std::string>{}( std::string( dir_entry->d_name ) );
608 wxMessageDialog dialog(
nullptr,
_(
"This operating system is not supported " 609 "by KiCad and its dependencies." ),
610 _(
"Unsupported Operating System" ),
611 wxOK | wxICON_EXCLAMATION );
613 dialog.SetExtendedMessage(
_(
"Any issues with KiCad on this system cannot " 614 "be reported to the official bugtracker." ) );
Container for project specific data.
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject)
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
const wxString ExpandEnvVarSubstitutions(const wxString &aString, PROJECT *aProject)
Replace any environment variable & text variable references with their values.
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
This file contains miscellaneous commonly used macros and functions.
bool EnsureFileDirectoryExists(wxFileName *aTargetFullFileName, const wxString &aBaseFilename, REPORTER *aReporter)
Make aTargetFullFileName absolute and create the path of this file if it doesn't yet exist.
const wxString ResolveUriByEnvVars(const wxString &aUri, PROJECT *aProject)
Replace any environment and/or text variables in file-path uris (leaving network-path URIs alone).
Base window classes and related definitions.
virtual bool TextVarResolver(wxString *aToken) const
long long TimestampDir(const wxString &aDirPath, const wxString &aFilespec)
A copy of ConvertFileTimeToWx() because wxWidgets left it as a static function private to src/common/...
bool matchWild(const char *pat, const char *text, bool dot_special)
Performance enhancements to file and directory operations.
bool WarnUserIfOperatingSystemUnsupported()
Checks if the operating system is explicitly unsupported and displays a disclaimer message box.
wxString KIwxExpandEnvVars(const wxString &str, const PROJECT *aProject)