1 #include "pathlistfactory.h" 2 3 #include <wx/string.h> 4 #include "../defines.h" //to get HAVEWX?? 5 #include "platform.h" 6 #ifdef __WXMSW__ 7 #include <wx/msw/registry.h> 8 #include <wx/stream.h> 9 #endif 10 #include <wx/filefn.h> 11 #include <wx/filename.h> 12 #include <wx/stdpaths.h> 13 #include <wx/dir.h> 14 15 const wxChar sep = wxFileName::GetPathSeparator(); 16 const wxString sepstring = wxString(sep); 17 fromSinglePath(wxString path)18wxPathList PathlistFactory::fromSinglePath(wxString path) 19 { 20 wxPathList pl; 21 pl.Add( path ); 22 return pl; 23 } 24 ConfigFileSearchPaths()25wxPathList PathlistFactory::ConfigFileSearchPaths() 26 { 27 wxPathList pl; 28 29 pl.AddEnvList( _T( "%ProgramFiles%" ) ); 30 31 pl.AddEnvList( _T( "LDPATH" ) ); 32 pl.AddEnvList( _T( "LD_LIBRARY_PATH" ) ); 33 34 pl.Add( _T( "/usr/local/lib/spring" ) ); 35 pl.Add( _T( "/usr/local/lib64" ) ); 36 pl.Add( _T( "/usr/local/games" ) ); 37 pl.Add( _T( "/usr/local/games/lib" ) ); 38 pl.Add( _T( "/usr/local/lib" ) ); 39 pl.Add( _T( "/usr/lib64" ) ); 40 pl.Add( _T( "/usr/lib" ) ); 41 pl.Add( _T( "/usr/lib/spring" ) ); 42 pl.Add( _T( "/usr/games" ) ); 43 pl.Add( _T( "/usr/games/lib64" ) ); 44 pl.Add( _T( "/usr/games/lib" ) ); 45 46 pl = AdditionalSearchPaths( pl ); 47 48 return pl; 49 } 50 UikeysLocations()51wxPathList PathlistFactory::UikeysLocations() 52 { 53 wxPathList pl; 54 pl.AddEnvList( _T("%ProgramFiles%") ); 55 pl.AddEnvList( _T("XDG_DATA_DIRS") ); 56 pl = AdditionalSearchPaths( pl ); 57 return pl; 58 } 59 AdditionalSearchPaths(wxPathList & pl)60wxPathList PathlistFactory::AdditionalSearchPaths(wxPathList &pl) 61 { 62 wxPathList ret; 63 wxStandardPathsBase& sp = wxStandardPathsBase::Get(); 64 65 pl.Add( wxFileName::GetCwd() ); 66 pl.Add( sp.GetExecutablePath().BeforeLast( sep ) ); 67 pl.Add( wxFileName::GetHomeDir() ); 68 pl.Add( wxGetOSDirectory() ); 69 70 #ifdef __WXMSW__ 71 pl.Add( sp.GetDocumentsDir() + sepstring + wxT("My Games") + sepstring + wxT("Spring") ); 72 //maybe add more here like: 73 //Appdata + \Spring 74 //Mydocs + \Spring 75 #endif 76 77 for ( size_t i = 0; i < pl.GetCount(); i++ ) 78 { 79 wxString path = pl[i]; 80 if ( !path.EndsWith( sepstring ) ) 81 path += sepstring; 82 ret.Add( path ); 83 ret.Add( path + _T( "Spring" ) + sepstring ); 84 ret.Add( path + _T( "spring" ) + sepstring ); 85 ret.Add( path + _T( "games" ) + sepstring + _T( "Spring" ) + sepstring ); 86 ret.Add( path + _T( "games" ) + sepstring + _T( "spring" ) + sepstring ); 87 } 88 89 // search in ~/.spring/engine/ , too 90 #ifdef __WXMSW__ 91 const wxString userdir = sp.GetDocumentsDir() + sep + _T("My Games") + sep + _T("Spring") + sep + _T("engine");; 92 #else 93 const wxString userdir = wxFileName::GetHomeDir() + sep + _T(".spring") + sep + _T("engine"); 94 #endif 95 wxDir dir(userdir); 96 97 if ( dir.IsOpened() ) { 98 wxString filename; 99 bool cont = dir.GetFirst(&filename, wxEmptyString, wxDIR_DIRS|wxDIR_HIDDEN); 100 while ( cont ) 101 { 102 ret.Add(userdir + sepstring + filename); 103 cont = dir.GetNext(&filename); 104 } 105 } 106 107 return ret; 108 } 109