32 #include <wx/process.h> 33 #include <wx/config.h> 35 #include <wx/stdpaths.h> 40 int ProcessExecute(
const wxString& aCommandLine,
int aFlags, wxProcess *callback )
42 return (
int) wxExecute( aCommandLine, aFlags, callback );
52 Bracket_Windows =
'%',
65 const std::function<
bool( wxString* )>* aLocalResolver,
66 const std::function<
bool( wxString* )>* aFallbackResolver,
70 size_t sourceLen = aSource.length();
72 newbuf.Alloc( sourceLen );
74 for(
size_t i = 0; i < sourceLen; ++i )
76 if( aSource[i] ==
'$' && i + 1 < sourceLen && aSource[i+1] ==
'{' )
80 for( i = i + 2; i < sourceLen; ++i )
82 if( aSource[i] ==
'}' )
85 token.append( aSource[i] );
91 if( aLocalResolver && (*aLocalResolver)( &token ) )
93 newbuf.append( token );
97 newbuf.append( token );
99 else if( aFallbackResolver && (*aFallbackResolver)( &token ) )
101 newbuf.append( token );
106 newbuf.append(
"${" + token +
"}" );
111 newbuf.append( aSource[i] );
124 size_t strlen = str.length();
127 strResult.Alloc( strlen );
129 for(
size_t n = 0; n < strlen; n++ )
131 wxUniChar str_n = str[n];
133 switch( str_n.GetValue() )
137 #endif // __WINDOWS__ 142 if( str_n == wxT(
'%' ) )
143 bracket = Bracket_Windows;
145 #endif // __WINDOWS__ 146 if( n == strlen - 1 )
152 switch( str[n + 1].GetValue() )
170 wxUniChar str_m = str[m];
172 while( wxIsalnum( str_m ) || str_m == wxT(
'_' ) || str_m == wxT(
':' ) )
183 wxString strVarName( str.c_str() + n + 1, m - n - 1 );
187 bool expanded =
false;
188 wxString tmp = strVarName;
195 else if( wxGetEnv( strVarName, &tmp ) )
204 if ( bracket != Bracket_Windows )
207 strResult << str[n - 1];
209 strResult << str_n << strVarName;
215 if( m == strlen || str_m != (wxChar)bracket )
224 wxLogWarning(
_(
"Environment variables expansion failed: missing '%c' " 225 "at position %u in '%s'." ),
226 (
char)bracket, (
unsigned int) (m + 1), str.c_str() );
227 #endif // __WINDOWS__ 233 strResult << (wxChar)bracket;
246 if( n != strlen - 1 && (str[n + 1] == wxT(
'%' ) || str[n + 1] == wxT(
'$' )) )
261 if( strResult.StartsWith(
"~" ) )
262 strResult.Replace(
"~", wxGetHomeDir(),
false );
263 #endif // __WINDOWS__ 273 static std::mutex getenv_mutex;
275 std::lock_guard<std::mutex> lock( getenv_mutex );
289 if( url.GetError() == wxURL_NOERR )
298 const wxString& aBaseFilename,
302 wxString baseFilePath = wxFileName( aBaseFilename ).GetPath();
306 if( !aTargetFullFileName->MakeAbsolute( baseFilePath ) )
310 msg.Printf(
_(
"Cannot make path \"%s\" absolute with respect to \"%s\"." ),
311 aTargetFullFileName->GetPath(),
320 wxString outputPath( aTargetFullFileName->GetPath() );
322 if( !wxFileName::DirExists( outputPath ) )
325 if( wxFileName::Mkdir( outputPath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
329 msg.Printf(
_(
"Output directory \"%s\" created.\n" ), outputPath );
338 msg.Printf(
_(
"Cannot create output directory \"%s\".\n" ), outputPath );
351 #ifdef USE_KICAD_WXSTRING_HASH 354 return std::hash<std::wstring>{}( s.ToStdWstring() );
358 #ifdef USE_KICAD_WXPOINT_LESS_AND_HASH 361 auto xhash = std::hash<int>()( k.x );
366 return xhash ^ ( std::hash<int>()( k.y ) + 0x9e3779b9 + ( xhash << 6 ) + ( xhash >> 2 ) );
379 std::ostream&
operator<<( std::ostream& out,
const wxSize& size )
381 out <<
" width=\"" << size.GetWidth() <<
"\" height=\"" << size.GetHeight() <<
"\"";
386 std::ostream&
operator<<( std::ostream& out,
const wxPoint& pt )
388 out <<
" x=\"" << pt.x <<
"\" y=\"" << pt.y <<
"\"";
407 bool matchWild(
const char* pat,
const char* text,
bool dot_special )
423 if( dot_special && (*n ==
'.') )
519 #if wxUSE_DATETIME && defined(__WIN32__) && !defined(__WXMICROWIN__) 525 static wxInt64 EPOCH_OFFSET_IN_MSEC = wxLL(11644473600000);
528 static void ConvertFileTimeToWx( wxDateTime *dt,
const FILETIME &ft )
530 wxLongLong t( ft.dwHighDateTime, ft.dwLowDateTime );
532 t -= EPOCH_OFFSET_IN_MSEC;
534 *dt = wxDateTime( t );
537 #endif // wxUSE_DATETIME && __WIN32__ 549 long long TimestampDir(
const wxString& aDirPath,
const wxString& aFilespec )
551 long long timestamp = 0;
553 #if defined( __WIN32__ ) 558 std::wstring filespec( aDirPath.t_str() );
560 filespec += aFilespec.t_str();
562 WIN32_FIND_DATA findData;
563 wxDateTime lastModDate;
565 HANDLE fileHandle = ::FindFirstFile( filespec.data(), &findData );
567 if( fileHandle != INVALID_HANDLE_VALUE )
571 ConvertFileTimeToWx( &lastModDate, findData.ftLastWriteTime );
572 timestamp += lastModDate.GetValue().GetValue();
573 timestamp += findData.nFileSizeLow;
575 while ( FindNextFile( fileHandle, &findData ) != 0 );
578 FindClose( fileHandle );
582 std::string filespec( aFilespec.fn_str() );
583 std::string dir_path( aDirPath.fn_str() );
585 DIR* dir = opendir( dir_path.c_str() );
589 for( dirent* dir_entry = readdir( dir ); dir_entry; dir_entry = readdir( dir ) )
591 if( !
matchWild( filespec.c_str(), dir_entry->d_name, true ) )
594 std::string entry_path = dir_path +
'/' + dir_entry->d_name;
595 struct stat entry_stat;
597 if( wxCRT_Lstat( entry_path.c_str(), &entry_stat ) == 0 )
600 if( S_ISLNK( entry_stat.st_mode ) )
602 char buffer[ PATH_MAX + 1 ];
603 ssize_t pathLen = readlink( entry_path.c_str(), buffer, PATH_MAX );
607 struct stat linked_stat;
608 buffer[ pathLen ] =
'\0';
609 entry_path = dir_path + buffer;
611 if( wxCRT_Lstat( entry_path.c_str(), &linked_stat ) == 0 )
613 entry_stat = linked_stat;
623 if( S_ISREG( entry_stat.st_mode ) )
625 timestamp += entry_stat.st_mtime * 1000;
626 timestamp += entry_stat.st_size;
632 timestamp += (signed) std::hash<std::string>{}( std::string( dir_entry->d_name ) );
int ProcessExecute(const wxString &aCommandLine, int aFlags, wxProcess *callback)
Run a command in a child process.
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 ...
size_t operator()(const wxPoint &k) const
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.
bool operator()(const wxPoint &aA, const wxPoint &aB) const
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.
wxString KIwxExpandEnvVars(const wxString &str, const PROJECT *aProject)
std::ostream & operator<<(std::ostream &out, const wxSize &size)
Helper function to print the given wxSize to a stream.
size_t operator()(const wxString &s) const