bool wxFileTypeImpl::GetIcon(wxIconLocation *iconLoc) const { wxString strIcon = wxAssocQueryString(wxASSOCSTR_DEFAULTICON, m_ext); if ( !strIcon.empty() ) { wxString strFullPath = strIcon.BeforeLast(wxT(',')), strIndex = strIcon.AfterLast(wxT(',')); // index may be omitted, in which case BeforeLast(',') is empty and // AfterLast(',') is the whole string if ( strFullPath.empty() ) { strFullPath = strIndex; strIndex = wxT("0"); } // if the path contains spaces, it can be enclosed in quotes but we // must not pass a filename in that format to any file system function, // so remove them here. if ( strFullPath.StartsWith('"') && strFullPath.EndsWith('"') ) strFullPath = strFullPath.substr(1, strFullPath.length() - 2); if ( iconLoc ) { iconLoc->SetFileName(wxExpandEnvVars(strFullPath)); iconLoc->SetIndex(wxAtoi(strIndex)); } return true; } // no such file type or no value or incorrect icon entry return false; }
const wxString S3D_MASTER::GetShape3DFullFilename() { wxString shapeName; // Expand any environment variables embedded in footprint's m_Shape3DName field. // To ensure compatibility with most of footprint's m_Shape3DName field, // if the m_Shape3DName is not an absolute path the default path // given by the environment variable KISYS3DMOD will be used if( m_Shape3DName.StartsWith( wxT("${") ) ) shapeName = wxExpandEnvVars( m_Shape3DName ); else shapeName = m_Shape3DName; wxFileName fn( shapeName ); if( fn.IsAbsolute() || shapeName.StartsWith( wxT(".") ) ) return shapeName; wxString default_path; wxGetEnv( KISYS3DMOD, &default_path ); if( default_path.IsEmpty() ) return shapeName; if( !default_path.EndsWith( wxT("/") ) && !default_path.EndsWith( wxT("\\") ) ) default_path += wxT("/"); default_path += shapeName; return default_path; }
// string reading helper wxString wxConfigBase::ExpandEnvVars(const wxString& str) const { wxString tmp; // Required for BC++ if (IsExpandingEnvVars()) tmp = wxExpandEnvVars(str); else tmp = str; return tmp; }
const wxString ExpandEnvVarSubstitutions( const wxString& aString ) { // wxGetenv( wchar_t* ) is not re-entrant on linux. // Put a lock on multithreaded use of wxGetenv( wchar_t* ), called from wxEpandEnvVars(), static MUTEX getenv_mutex; MUTLOCK lock( getenv_mutex ); // We reserve the right to do this another way, by providing our own member // function. return wxExpandEnvVars( aString ); }
bool wxFileTypeImpl::GetIcon(wxIconLocation *iconLoc) const { wxString strIconKey; strIconKey << m_strFileType << wxT("\\DefaultIcon"); // suppress possible error messages wxLogNull nolog; wxRegKey key(wxRegKey::HKCR, strIconKey); if ( key.Open(wxRegKey::Read) ) { wxString strIcon; // it's the default value of the key if ( key.QueryValue(wxEmptyString, strIcon) ) { // the format is the following: <full path to file>, <icon index> // NB: icon index may be negative as well as positive and the full // path may contain the environment variables inside '%' wxString strFullPath = strIcon.BeforeLast(wxT(',')), strIndex = strIcon.AfterLast(wxT(',')); // index may be omitted, in which case BeforeLast(',') is empty and // AfterLast(',') is the whole string if ( strFullPath.empty() ) { strFullPath = strIndex; strIndex = wxT("0"); } if ( iconLoc ) { iconLoc->SetFileName(wxExpandEnvVars(strFullPath)); iconLoc->SetIndex(wxAtoi(strIndex)); } return true; } } // no such file type or no value or incorrect icon entry return false; }
void S3D_MASTER::SetShape3DName( const wxString& aShapeName ) { m_ShapeType = FILE3D_NONE; m_Shape3DName = aShapeName; if( m_Shape3DName.empty() ) return; wxFileName fn = m_Shape3DName; m_Shape3DNameExtension = fn.GetExt(); if( m_Shape3DNameExtension == wxT( "wrl" ) || m_Shape3DNameExtension == wxT( "x3d" ) ) m_ShapeType = FILE3D_VRML; else if( m_Shape3DNameExtension == wxT( "idf" ) ) m_ShapeType = FILE3D_IDF; else m_ShapeType = FILE3D_UNKNOWN; // Expand any environment variables embedded in footprint's m_Shape3DName field. // To ensure compatibility with most of footprint's m_Shape3DName field, // if the m_Shape3DName is not an absolute path the default path // given by the environment variable KISYS3DMOD will be used if( m_Shape3DName.StartsWith( wxT("${") ) ) m_Shape3DFullFilename = wxExpandEnvVars( m_Shape3DName ); else m_Shape3DFullFilename = m_Shape3DName; if( NULL != TheKiway ) { m_Shape3DFullFilename = TheKiway->Prj().Get3DCacheManager()->GetResolver() ->ResolvePath( m_Shape3DFullFilename ); } return; }
void DIALOG_CONFIG_EQUFILES::OnEditEquFile( wxCommandEvent& event ) { wxString editorname = Pgm().GetEditorName(); if( editorname.IsEmpty() ) { wxMessageBox( _( "No editor defined in Kicad. Please chose it" ) ); return; } wxArrayInt selections; m_ListEquiv->GetSelections( selections ); wxString fullFileNames, tmp; for( unsigned ii = 0; ii < selections.GetCount(); ii++ ) { tmp = m_ListEquiv->GetString( selections[ii] ); fullFileNames << wxT( " \"" ) << wxExpandEnvVars( tmp ) << wxT( "\"" ); m_ListChanged = true; } ExecuteFile( this, editorname, fullFileNames ); }
const wxChar* wxGetHomeDir(wxString *pstr) { wxString& strDir = *pstr; // first branch is for Cygwin #if defined(__UNIX__) && !defined(__WINE__) const wxChar *szHome = wxGetenv("HOME"); if ( szHome == NULL ) { // we're homeless... wxLogWarning(_("can't find user's HOME, using current directory.")); strDir = wxT("."); } else strDir = szHome; // add a trailing slash if needed if ( strDir.Last() != wxT('/') ) strDir << wxT('/'); #ifdef __CYGWIN__ // Cygwin returns unix type path but that does not work well static wxChar windowsPath[MAX_PATH]; cygwin_conv_to_full_win32_path(strDir, windowsPath); strDir = windowsPath; #endif #elif defined(__WXWINCE__) strDir = wxT("\\"); #else strDir.clear(); // If we have a valid HOME directory, as is used on many machines that // have unix utilities on them, we should use that. const wxChar *szHome = wxGetenv(wxT("HOME")); if ( szHome != NULL ) { strDir = szHome; } else // no HOME, try HOMEDRIVE/PATH { szHome = wxGetenv(wxT("HOMEDRIVE")); if ( szHome != NULL ) strDir << szHome; szHome = wxGetenv(wxT("HOMEPATH")); if ( szHome != NULL ) { strDir << szHome; // the idea is that under NT these variables have default values // of "%systemdrive%:" and "\\". As we don't want to create our // config files in the root directory of the system drive, we will // create it in our program's dir. However, if the user took care // to set HOMEPATH to something other than "\\", we suppose that he // knows what he is doing and use the supplied value. if ( wxStrcmp(szHome, wxT("\\")) == 0 ) strDir.clear(); } } if ( strDir.empty() ) { // If we have a valid USERPROFILE directory, as is the case in // Windows NT, 2000 and XP, we should use that as our home directory. szHome = wxGetenv(wxT("USERPROFILE")); if ( szHome != NULL ) strDir = szHome; } if ( !strDir.empty() ) { // sometimes the value of HOME may be "%USERPROFILE%", so reexpand the // value once again, it shouldn't hurt anyhow strDir = wxExpandEnvVars(strDir); } else // fall back to the program directory { // extract the directory component of the program file name wxSplitPath(wxGetFullModuleName(), &strDir, NULL, NULL); } #endif // UNIX/Win return strDir.c_str(); }
// Based on the MSW implementation // // Respects the following environment variables in this order: %HomeDrive% + // %HomePath%, %UserProfile%, $HOME. Otherwise takes program's directory if // wxApp has been initialised, otherwise returns ".". // const wxChar* wxGetHomeDir(wxString *home) { wxString& strDir = *home; strDir.clear(); // try HOMEDRIVE/PATH const wxChar *szHome = wxGetenv(wxT("HOMEDRIVE")); if ( szHome != NULL ) strDir << szHome; szHome = wxGetenv(wxT("HOMEPATH")); if ( szHome != NULL ) { strDir << szHome; // the idea is that under NT these variables have default values of // "%systemdrive%:" and "\\". As we don't want to create our config // files in the root directory of the system drive, we will create it // in our program's dir. However, if the user took care to set // HOMEPATH to something other than "\\", we suppose that he knows // what he is doing and use the supplied value. if ( wxStrcmp(szHome, wxT("\\")) == 0 ) strDir.clear(); } if ( strDir.empty() ) { // If we have a valid USERPROFILE directory, as is the case in // Windows NT, 2000 and XP, we should use that as our home directory. szHome = wxGetenv(wxT("USERPROFILE")); if ( szHome != NULL ) strDir = szHome; } if ( strDir.empty() ) { // If we have a valid HOME directory, as is used on many machines // that have unix utilities on them, we should use that. szHome = wxGetenv(wxT("HOME")); if ( szHome != NULL ) { strDir = szHome; // when msys sets %HOME% it uses '/' (cygwin uses '\\') strDir.Replace(wxT("/"), wxT("\\")); } } if ( !strDir.empty() ) { // sometimes the value of HOME may be "%USERPROFILE%", so reexpand the // value once again, it shouldn't hurt anyhow strDir = wxExpandEnvVars(strDir); } else // fall back to the program directory { if ( wxTheApp ) { wxString prog(wxTheApp->argv[0]); #ifdef __DJGPP__ // djgpp startup code switches the slashes around, so restore them prog.Replace(wxT("/"), wxT("\\")); #endif // it needs to be a full path to be usable if ( prog.compare(1, 2, wxT(":\\")) == 0 ) wxFileName::SplitPath(prog, &strDir, NULL, NULL); } if ( strDir.empty() ) { strDir = wxT("."); } } return strDir.c_str(); }
// read the .equ files and populate the list of equivalents int CVPCB_MAINFRAME::buildEquivalenceList( FOOTPRINT_EQUIVALENCE_LIST& aList, wxString * aErrorMessages ) { char Line[1024]; int error_count = 0; FILE* file; wxFileName fn; wxString tmp, error_msg; SEARCH_STACK& search = Kiface().KifaceSearch(); // Find equivalences in all available files, and populates the // equiv_List with all equivalences found in .equ files for( unsigned ii = 0; ii < m_EquFilesNames.GetCount(); ii++ ) { fn = wxExpandEnvVars( m_EquFilesNames[ii] ); tmp = search.FindValidPath( fn.GetFullPath() ); if( !tmp ) { error_count++; if( aErrorMessages ) { error_msg.Printf( _( "Equivalence file '%s' could not be found in the " "default search paths." ), GetChars( fn.GetFullName() ) ); if( ! aErrorMessages->IsEmpty() ) *aErrorMessages << wxT("\n\n"); *aErrorMessages += error_msg; } continue; } file = wxFopen( tmp, wxT( "rt" ) ); if( file == NULL ) { error_count++; if( aErrorMessages ) { error_msg.Printf( _( "Error opening equivalence file '%s'." ), GetChars( tmp ) ); if( ! aErrorMessages->IsEmpty() ) *aErrorMessages << wxT("\n\n"); *aErrorMessages += error_msg; } continue; } while( GetLine( file, Line, NULL, sizeof(Line) ) != NULL ) { char* text = Line; wxString value, footprint, wtext = FROM_UTF8( Line ); value = GetQuotedText( wtext ); if( text == NULL || ( *text == 0 ) || value.IsEmpty() ) continue; footprint = GetQuotedText( wtext ); if( footprint.IsEmpty() ) continue; value.Replace( wxT( " " ), wxT( "_" ) ); FOOTPRINT_EQUIVALENCE* equivItem = new FOOTPRINT_EQUIVALENCE(); equivItem->m_ComponentValue = value; equivItem->m_FootprintFPID = footprint; aList.push_back( equivItem ); } fclose( file ); } return error_count; }