Exemplo n.º 1
0
wxString wxGetUserHome( const wxString &user )
{
    struct passwd *who = (struct passwd *) NULL;

    if ( !user )
    {
        wxChar *ptr;

        if ((ptr = wxGetenv(wxT("HOME"))) != NULL)
        {
            return ptr;
        }

        if ((ptr = wxGetenv(wxT("USER"))) != NULL ||
                (ptr = wxGetenv(wxT("LOGNAME"))) != NULL)
        {
            who = getpwnam(wxSafeConvertWX2MB(ptr));
        }

        // make sure the user exists!
        if ( !who )
        {
            who = getpwuid(getuid());
        }
    }
    else
    {
        who = getpwnam (user.mb_str());
    }

    return wxSafeConvertMB2WX(who ? who->pw_dir : 0);
}
Exemplo n.º 2
0
wxString wxSystemOptions::GetOption(const wxString& name)
{
    wxString val;

    int idx = gs_optionNames.Index(name, false);
    if ( idx != wxNOT_FOUND )
    {
        val = gs_optionValues[idx];
    }
    else // not set explicitly
    {
        // look in the environment: first for a variable named "wx_appname_name"
        // which can be set to affect the behaviour or just this application
        // and then for "wx_name" which can be set to change the option globally
        wxString var(name);
        var.Replace(wxT("."), wxT("_"));  // '.'s not allowed in env var names
        var.Replace(wxT("-"), wxT("_"));  // and neither are '-'s

        wxString appname;
        if ( wxTheApp )
            appname = wxTheApp->GetAppName();

        if ( !appname.empty() )
            val = wxGetenv(wxT("wx_") + appname + wxT('_') + var);

        if ( val.empty() )
            val = wxGetenv(wxT("wx_") + var);
    }

    return val;
}
Exemplo n.º 3
0
CLocalPath GetDownloadDir()
{
#ifdef __WXMSW__
	// Old Vista has a profile directory for downloaded files,
	// need to get it using SHGetKnownFolderPath which we need to
	// load dynamically to preserve forward compatibility with the
	// upgrade to Windows XP.
	wxDynamicLibrary lib(_T("shell32.dll"));
	if (lib.IsLoaded() && lib.HasSymbol(_T("SHGetKnownFolderPath"))) {
		tSHGetKnownFolderPath pSHGetKnownFolderPath = (tSHGetKnownFolderPath)lib.GetSymbol(_T("SHGetKnownFolderPath"));

		PWSTR path;
		HRESULT result = pSHGetKnownFolderPath(VISTASHIT_FOLDERID_Downloads, 0, 0, &path);
		if(result == S_OK) {
			wxString dir = path;
			CoTaskMemFree(path);
			return CLocalPath(dir);
		}
	}
#elif !defined(__WXMAC__)
	// Code copied from wx, but for downloads directory.
	// Also, directory is now unescaped.
	{
		wxLogNull logNull;
		wxString homeDir = wxFileName::GetHomeDir();
		wxString configPath;
		if (wxGetenv(wxT("XDG_CONFIG_HOME")))
			configPath = wxGetenv(wxT("XDG_CONFIG_HOME"));
		else
			configPath = homeDir + wxT("/.config");
		wxString dirsFile = configPath + wxT("/user-dirs.dirs");
		if (wxFileExists(dirsFile)) {
			wxTextFile textFile;
			if (textFile.Open(dirsFile)) {
				size_t i;
				for (i = 0; i < textFile.GetLineCount(); i++) {
					wxString line(textFile[i]);
					int pos = line.Find(wxT("XDG_DOWNLOAD_DIR"));
					if (pos != wxNOT_FOUND) {
						wxString value = line.AfterFirst(wxT('='));
						value = ShellUnescape(value);
						if (!value.IsEmpty() && wxDirExists(value))
							return CLocalPath(value);
						else
							break;
					}
				}
			}
		}
	}
#endif
	return CLocalPath(wxStandardPaths::Get().GetDocumentsDir());
}
Exemplo n.º 4
0
CLocalPath GetDownloadDir()
{
#ifdef __WXMSW__
	// Unfortunately MinGW's import library lacks SHGetKnownFolderPath, even though it has it in its headers.
	wxDynamicLibrary lib(_T("shell32.dll"));
	if (lib.IsLoaded() && lib.HasSymbol(_T("SHGetKnownFolderPath"))) {
		tSHGetKnownFolderPath pSHGetKnownFolderPath = (tSHGetKnownFolderPath)lib.GetSymbol(_T("SHGetKnownFolderPath"));

		PWSTR path;
		HRESULT result = pSHGetKnownFolderPath(FOLDERID_Downloads, 0, 0, &path);
		if(result == S_OK) {
			std::wstring dir = path;
			CoTaskMemFree(path);
			return CLocalPath(dir);
		}
	}
#elif !defined(__WXMAC__)
	// Code copied from wx, but for downloads directory.
	// Also, directory is now unescaped.
	{
		wxLogNull logNull;
		wxString homeDir = wxFileName::GetHomeDir();
		wxString configPath;
		if (wxGetenv(wxT("XDG_CONFIG_HOME"))) {
			configPath = wxGetenv(wxT("XDG_CONFIG_HOME"));
		}
		else {
			configPath = homeDir + wxT("/.config");
		}
		wxString dirsFile = configPath + wxT("/user-dirs.dirs");
		if (wxFileExists(dirsFile)) {
			wxTextFile textFile;
			if (textFile.Open(dirsFile)) {
				size_t i;
				for (i = 0; i < textFile.GetLineCount(); i++) {
					wxString line(textFile[i]);
					int pos = line.Find(wxT("XDG_DOWNLOAD_DIR"));
					if (pos != wxNOT_FOUND) {
						wxString value = line.AfterFirst(wxT('='));
						value = ShellUnescape(value);
						if (!value.empty() && wxDirExists(value))
							return CLocalPath(value.ToStdWstring());
						else
							break;
					}
				}
			}
		}
	}
#endif
	return CLocalPath(wxStandardPaths::Get().GetDocumentsDir().ToStdWstring());
}
Exemplo n.º 5
0
// returns %ComputerName%, or $HOSTNAME, or "host"
//
bool wxGetHostName(wxChar *buf, int n)
{
    const wxChar *host = wxGetenv(wxT("ComputerName"));

    if (!host)
        host = wxGetenv(wxT("HOSTNAME"));

    if (!host)
        host = wxT("host");

    wxStrlcpy(buf, host, n);
    return true;
}
Exemplo n.º 6
0
// returns %UserName%, $USER or just "user"
//
bool wxGetUserId(wxChar *buf, int n)
{
    const wxChar *user = wxGetenv(wxT("UserName"));

    if (!user)
        user = wxGetenv(wxT("USER"));

    if (!user)
        user = wxT("user");

    wxStrlcpy(buf, user, n);
    return true;
}
Exemplo n.º 7
0
wxChar* wxGetUserHome ( const wxString &rUser )
#endif
{
    wxChar*    zHome;
    wxString   sUser1(rUser);

    wxChar *wxBuffer = new wxChar[256];
#ifndef __EMX__
    if (!sUser1.empty())
    {
        wxChar                      zTmp[64];

        if (wxGetUserId( zTmp
                        ,sizeof(zTmp)/sizeof(char)
                       ))
        {
            // Guests belong in the temp dir
            if (wxStricmp(zTmp, _T("annonymous")) == 0)
            {
                if ((zHome = wxGetenv(_T("TMP"))) != NULL    ||
                    (zHome = wxGetenv(_T("TMPDIR"))) != NULL ||
                    (zHome = wxGetenv(_T("TEMP"))) != NULL)
                    delete[] wxBuffer;
                    return *zHome ? zHome : (wxChar*)_T("\\");
            }
            if (wxStricmp(zTmp, WXSTRINGCAST sUser1) == 0)
                sUser1 = wxEmptyString;
        }
    }
#endif
    if (sUser1.empty())
    {
        if ((zHome = wxGetenv(_T("HOME"))) != NULL)
        {
            wxStrcpy(wxBuffer, zHome);
            wxUnix2DosFilename(wxBuffer);
#if wxUSE_UNICODE
            wxWCharBuffer retBuffer (wxBuffer);
            delete[] wxBuffer;
            return retBuffer;
#else
            wxStrcpy(zHome, wxBuffer);
            delete[] wxBuffer;
            return zHome;
#endif
        }
    }
    delete[] wxBuffer;
    return (wxChar*)wxEmptyString; // No home known!
}
Exemplo n.º 8
0
wxExtHelpController::wxExtHelpController(wxWindow* parentWindow)
                   : wxHelpControllerBase(parentWindow)
{
   m_MapList = NULL;
   m_NumOfEntries = 0;
   m_BrowserIsNetscape = false;

   wxChar *browser = wxGetenv(WXEXTHELP_ENVVAR_BROWSER);
   if (browser)
   {
      m_BrowserName = browser;
      browser = wxGetenv(WXEXTHELP_ENVVAR_BROWSERISNETSCAPE);
      m_BrowserIsNetscape = browser && (wxAtoi(browser) != 0);
   }
}
Exemplo n.º 9
0
// ---------------------------------------------------------------------------
const wxChar* wxGetHomeDir(
  wxString*                         pStr
)
{
    wxString&                       rStrDir = *pStr;

    // OS/2 has no idea about home,
    // so use the working directory instead.
    // However, we might have a valid HOME directory,
    // as is used on many machines that have unix utilities
    // on them, so we should use that, if available.

    // 256 was taken from os2def.h
#ifndef MAX_PATH
#  define MAX_PATH  256
#endif

    const wxChar *szHome = wxGetenv((wxChar*)"HOME");
    if ( szHome == NULL ) {
      // we're homeless, use current directory.
      rStrDir = wxT(".");
    }
    else
       rStrDir = szHome;

    return rStrDir.c_str();
}
Exemplo n.º 10
0
PangoContext* wxApp::GetPangoContext()
{
    static PangoContext *s_pangoContext = NULL;
    if ( !s_pangoContext )
    {
        Display *dpy = wxGlobalDisplay();

#ifdef HAVE_PANGO_XFT
        int xscreen = DefaultScreen(dpy);
        static int use_xft = -1;
        if (use_xft == -1)
        {
            wxString val = wxGetenv( L"GDK_USE_XFT" );
            use_xft = val == L"1";
        }

        if (use_xft)
            s_pangoContext = pango_xft_get_context(dpy, xscreen);
        else
#endif // HAVE_PANGO_XFT
            s_pangoContext = pango_x_get_context(dpy);

        if (!PANGO_IS_CONTEXT(s_pangoContext))
        {
            wxLogError( wxT("No pango context.") );
        }
    }

    return s_pangoContext;
}
Exemplo n.º 11
0
wxString ConsoleFinder::GetConsoleName()
{
	wxString cmd;
#ifdef __WXMSW__
	cmd = wxGetenv(wxT("COMSPEC"));
	if ( cmd.IsEmpty() ) {
		cmd = wxT("CMD.EXE");
	}
#else //non-windows
	//try to locate the default terminal
	wxString terminal;
	wxString where;
	if (ExeLocator::Locate(wxT("gnome-terminal"), where)) {
		terminal = wxT("gnome-terminal -e ");
	} else if (ExeLocator::Locate(wxT("konsole"), where)) {
		terminal = wxT("konsole");
    } else if (ExeLocator::Locate(wxT("terminal"), where)) {
		terminal = wxT("terminal -e");
    } else if (ExeLocator::Locate(wxT("lxterminal"), where)) {
		terminal = wxT("lxterminal -e");
	} else if (ExeLocator::Locate(wxT("xterm"), where)) {
		terminal = wxT("xterm -e ");
	}

	if (cmd.IsEmpty()) {
		cmd = wxT("xterm -e ");
	}

	cmd = terminal;
#endif
	return cmd;
}
Exemplo n.º 12
0
// Get hostname only (without domain name)
bool wxGetHostName(wxChar *WXUNUSED_IN_WINCE(buf),
                   int WXUNUSED_IN_WINCE(maxSize))
{
#if defined(__WXWINCE__)
    // TODO-CE
    return false;
#elif defined(__WIN32__) && !defined(__WXMICROWIN__)
    DWORD nSize = maxSize;
    if ( !::GetComputerName(buf, &nSize) )
    {
        wxLogLastError(wxT("GetComputerName"));

        return false;
    }

    return true;
#else
    wxChar *sysname;
    const wxChar *default_host = wxT("noname");

    if ((sysname = wxGetenv(wxT("SYSTEM_NAME"))) == NULL) {
        GetProfileString(WX_SECTION, eHOSTNAME, default_host, buf, maxSize - 1);
    } else
        wxStrncpy(buf, sysname, maxSize - 1);
    buf[maxSize] = wxT('\0');
    return *buf ? true : false;
#endif
}
Exemplo n.º 13
0
bool ProcUtils::Shell()
{
	wxString cmd;
#ifdef __WXMSW__
	wxChar *shell = wxGetenv(wxT("COMSPEC"));
	if ( !shell ) {
		shell = (wxChar*) wxT("\\COMMAND.COM");
	}

	// just the shell
	cmd = shell;
#elif defined(__WXMAC__)
	wxString path = wxGetCwd();
	cmd = wxString( wxT("osascript -e 'tell application \"Terminal\"' -e 'activate' -e 'do script with command \"cd ") + path + wxT("\"' -e 'end tell'") );
#else //non-windows
	//try to locate the default terminal
	wxString terminal;
	wxString where;
	if (Locate(wxT("gnome-terminal"), where)) {
		terminal = where;
	} else if (Locate(wxT("konsole"), where)) {
		terminal = where;
	} else if (Locate(wxT("xterm"), where)) {
		terminal = where;
	}
	cmd = terminal;
#endif
	return wxExecute(cmd, wxEXEC_ASYNC) != 0;
}
Exemplo n.º 14
0
// Execute a program in an Interactive Shell
bool wxShell(const wxString& command)
{
    wxString cmd;

#ifdef __WXWINCE__
    cmd = command;
#else
    wxChar *shell = wxGetenv(wxT("COMSPEC"));
    if ( !shell )
        shell = (wxChar*) wxT("\\COMMAND.COM");

    if ( !command )
    {
        // just the shell
        cmd = shell;
    }
    else
    {
        // pass the command to execute to the command processor
        cmd.Printf(wxT("%s /c %s"), shell, command.c_str());
    }
#endif

    return wxExecute(cmd, wxEXEC_SYNC) == 0;
}
Exemplo n.º 15
0
bool TerminalEmulator::ExecuteNoConsole(const wxString& commandToRun, const wxString& workingDirectory)
{
    if(m_process) {
        // another process is running
        return false;
    }

    wxString command;
#ifdef __WXMSW__
    wxString shell = wxGetenv("COMSPEC");
    if(shell.IsEmpty()) { shell = "CMD"; }

    command << shell << wxT(" /c \"");
    command << commandToRun << wxT("\"");

#else
    wxString tmpCmd = commandToRun;
    command << "/bin/sh -c '";
    // escape any single quoutes
    tmpCmd.Replace("'", "\\'");
    command << tmpCmd << "'";
#endif
    clLogMessage("TerminalEmulator::ExecuteNoConsole: " + command);
    m_process = ::CreateAsyncProcess(this, command, IProcessCreateWithHiddenConsole, workingDirectory);
    return m_process != NULL;
}
Exemplo n.º 16
0
void wxURL::Init(const wxString& url)
{
    m_protocol = NULL;
    m_error = wxURL_NOERR;
    m_url = url;
#if wxUSE_URL_NATIVE
    m_nativeImp = CreateNativeImpObject();
#endif

#if wxUSE_PROTOCOL_HTTP
    if ( ms_useDefaultProxy && !ms_proxyDefault )
    {
        SetDefaultProxy( wxGetenv(wxT("HTTP_PROXY")) );

        if ( !ms_proxyDefault )
        {
            // don't try again
            ms_useDefaultProxy = false;
        }
    }

    m_useProxy = ms_proxyDefault != NULL;
    m_proxy = ms_proxyDefault;
#endif // wxUSE_PROTOCOL_HTTP

}
Exemplo n.º 17
0
// Get full hostname (eg. DoDo.BSn-Germany.crg.de)
bool wxGetHostName( wxChar* zBuf, int nMaxSize )
{
    if (!zBuf) return false;

#if defined(wxUSE_NET_API) && wxUSE_NET_API
    char           zServer[256];
    char           zComputer[256];
    unsigned long  ulLevel = 0;
    unsigned char* zBuffer = NULL;
    unsigned long  ulBuffer = 256;
    unsigned long* pulTotalAvail = NULL;

    NetBios32GetInfo( (const unsigned char*)zServer
                     ,(const unsigned char*)zComputer
                     ,ulLevel
                     ,zBuffer
                     ,ulBuffer
                     ,pulTotalAvail
                    );
    strcpy(zBuf, zServer);
#else
    wxChar*        zSysname;
    const wxChar*  zDefaultHost = _T("noname");

    if ((zSysname = wxGetenv(_T("SYSTEM_NAME"))) == NULL &&
	(zSysname = wxGetenv(_T("HOSTNAME"))) == NULL)
    {
        ::PrfQueryProfileString( HINI_PROFILE
                                ,(PSZ)WX_SECTION
                                ,(PSZ)eHOSTNAME
                                ,(PSZ)zDefaultHost
                                ,(void*)zBuf
                                ,(ULONG)nMaxSize - 1
                               );
        zBuf[nMaxSize] = _T('\0');
    }
    else
    {
        wxStrlcpy(zBuf, zSysname, nMaxSize);
    }
#endif

    return *zBuf ? true : false;
}
Exemplo n.º 18
0
// adds %UserDnsDomain% to wxGetHostName()
//
bool wxGetFullHostName(wxChar *buf, int n)
{
    wxGetHostName(buf, n);

    const wxChar *domain = wxGetenv(wxT("UserDnsDomain"));

    if (domain)
        wxStrncat(wxStrncat(buf, wxT("."), n), domain, n);

    return true;
}
Exemplo n.º 19
0
void CrtTestCase::SetGetEnv()
{
#define TESTVAR_NAME wxT("WXTESTVAR")

    wxString val;
    wxSetEnv(TESTVAR_NAME, wxT("value"));
    CPPUNIT_ASSERT( wxGetEnv(TESTVAR_NAME, &val) );
    CPPUNIT_ASSERT_EQUAL( "value", val );
    CPPUNIT_ASSERT_EQUAL( "value", wxString(wxGetenv(TESTVAR_NAME)) );

    wxSetEnv(TESTVAR_NAME, wxT("something else"));
    CPPUNIT_ASSERT( wxGetEnv(TESTVAR_NAME, &val) );
    CPPUNIT_ASSERT_EQUAL( "something else", val );
    CPPUNIT_ASSERT_EQUAL( "something else", wxString(wxGetenv(TESTVAR_NAME)) );

    CPPUNIT_ASSERT( wxUnsetEnv(TESTVAR_NAME) );
    CPPUNIT_ASSERT( !wxGetEnv(TESTVAR_NAME, NULL) );
    CPPUNIT_ASSERT( !wxGetenv(TESTVAR_NAME) );

#undef TESTVAR_NAME
}
Exemplo n.º 20
0
bool wxGetEnv(const wxString& var, wxString *value)
{
    // wxGetenv is defined as getenv()
    wxChar *p = wxGetenv(var);
    if ( !p )
        return false;

    if ( value )
        *value = p;

    return true;
}
Exemplo n.º 21
0
wxString wxGetUserHome ( const wxString &rUser )
{
    wxChar*    zHome;
    wxString   sUser(rUser);

    wxString home;

#ifndef __EMX__
    if (!sUser.empty())
    {
        const wxString currentUser = wxGetUserId();

        // Guests belong in the temp dir
        if ( currentUser == "annonymous" )
        {
            zHome = wxGetenv(_T("TMP"));
            if ( !zHome )
                zHome = wxGetenv(_T("TMPDIR"));
            if ( !zHome )
                zHome = wxGetenv(_T("TEMP"));

            if ( zHome && *zHome )
                return zHome;
        }

        if ( sUser == currentUser )
            sUser.clear();
    }
#endif
    if (sUser.empty())
    {
        if ((zHome = wxGetenv(_T("HOME"))) != NULL)
        {
            home = zHome;
            home.Replace("/", "\\");
        }
    }

    return home;
}
Exemplo n.º 22
0
// Get user ID e.g. jacs
bool wxGetUserId(wxChar *WXUNUSED_IN_WINCE(buf),
                 int WXUNUSED_IN_WINCE(maxSize))
{
#if defined(__WXWINCE__)
    // TODO-CE
    return false;
#elif defined(__WIN32__) && !defined(__WXMICROWIN__)
    DWORD nSize = maxSize;
    if ( ::GetUserName(buf, &nSize) == 0 )
    {
        // actually, it does happen on Win9x if the user didn't log on
        DWORD res = ::GetEnvironmentVariable(wxT("username"), buf, maxSize);
        if ( res == 0 )
        {
            // not found
            return false;
        }
    }

    return true;
#else   // __WXMICROWIN__
    wxChar *user;
    const wxChar *default_id = wxT("anonymous");

    // Can't assume we have NIS (PC-NFS) or some other ID daemon
    // So we ...
    if ( (user = wxGetenv(wxT("USER"))) == NULL &&
         (user = wxGetenv(wxT("LOGNAME"))) == NULL )
    {
        // Use wxWidgets configuration data (comming soon)
        GetProfileString(WX_SECTION, eUSERID, default_id, buf, maxSize - 1);
    }
    else
    {
        wxStrncpy(buf, user, maxSize - 1);
    }

    return *buf ? true : false;
#endif
}
Exemplo n.º 23
0
void SjTools::ExploreFile_(const wxString& location__, const wxString& program__)
{
    // convert file to directory
    wxString location = location__;
    if( !::wxDirExists(location) )
    {
        location = location.BeforeLast(wxT('/'));
    }

    // does the file or the directory exist?
    if( !::wxFileExists(location) && !wxDirExists(location) )
    {
        wxLogError(_("The file \"%s\" does not exist."), location.c_str());
        return;
    }

	// create command line
	wxString cmd;
	if( program__ == wxT("xdg-open") )
	{
		wxString xdg_open;
		if ( wxGetenv(wxT("PATH")) &&
			 wxFindFileInPath(&xdg_open, wxGetenv(wxT("PATH")), wxT("xdg-open")) )
		{
			cmd = xdg_open + wxT(" \"") + location + wxT("\"");
		}
	}
	else
	{
		cmd = program__;
		cmd.Replace(wxT("<folder>"), location);
	}

	// execute command
	if( wxExecute(cmd, wxEXEC_ASYNC) == 0 ) { // the window may not be focused, however, this is an issue with the environment, not a problem of Silverjuke
		wxLogError(_("Cannot execute \"%s\"."), cmd.c_str());
		return;
	}
}
Exemplo n.º 24
0
wxString wxStandardPaths::GetDocumentsDir() const
{
    {
        wxLogNull logNull;
        wxString homeDir = wxFileName::GetHomeDir();
        wxString configPath;
        if (wxGetenv(wxT("XDG_CONFIG_HOME")))
            configPath = wxGetenv(wxT("XDG_CONFIG_HOME"));
        else
            configPath = homeDir + wxT("/.config");
        wxString dirsFile = configPath + wxT("/user-dirs.dirs");
        if (wxFileExists(dirsFile))
        {
            wxTextFile textFile;
            if (textFile.Open(dirsFile))
            {
                size_t i;
                for (i = 0; i < textFile.GetLineCount(); i++)
                {
                    wxString line(textFile[i]);
                    int pos = line.Find(wxT("XDG_DOCUMENTS_DIR"));
                    if (pos != wxNOT_FOUND)
                    {
                        wxString value = line.AfterFirst(wxT('='));
                        value.Replace(wxT("$HOME"), homeDir);
                        value.Trim(true);
                        value.Trim(false);
                        if (!value.IsEmpty() && wxDirExists(value))
                            return value;
                        else
                            break;
                    }
                }
            }
        }
    }

    return wxStandardPathsBase::GetDocumentsDir();
}
Exemplo n.º 25
0
// ----------------------------------------------------------------------------
wxString MouseSap::FindAppPath(const wxString& argv0, const wxString& cwd, const wxString& appVariableName)
// ----------------------------------------------------------------------------
{
    // Find the absolute path where this application has been run from.
    // argv0 is wxTheApp->argv[0]
    // cwd is the current working directory (at startup)
    // appVariableName is the name of a variable containing the directory for this app, e.g.
    // MYAPPDIR. This is checked first.

    wxString str;

    // Try appVariableName
    if (!appVariableName.IsEmpty())
    {
        str = wxGetenv(appVariableName);
        if (!str.IsEmpty())
            return str;
    }

#if defined(__WXMAC__) && !defined(__DARWIN__)
    // On Mac, the current directory is the relevant one when
    // the application starts.
    return cwd;
#endif

    if (wxIsAbsolutePath(argv0))
        return wxPathOnly(argv0);
    else
    {
        // Is it a relative path?
        wxString currentDir(cwd);
        if (currentDir.Last() != wxFILE_SEP_PATH)
            currentDir += wxFILE_SEP_PATH;

        str = currentDir + argv0;
        if (wxFileExists(str))
            return wxPathOnly(str);
    }

    // OK, it's neither an absolute path nor a relative path.
    // Search PATH.

    wxPathList pathList;
    pathList.AddEnvList(wxT("PATH"));
    str = pathList.FindAbsoluteValidPath(argv0);
    if (!str.IsEmpty())
        return wxPathOnly(str);

    // Failed
    return wxEmptyString;
}
Exemplo n.º 26
0
bool wxGetEnv(const wxString& var, wxString *value)
{
    // wxGetenv is defined as getenv()
    wxChar *p = wxGetenv(var);
    if ( !p )
        return FALSE;

    if ( value )
    {
        *value = p;
    }

    return TRUE;
}
Exemplo n.º 27
0
/* Contract Paths to be build upon an environment variable
   component:

   example: "/usr/openwin/lib", OPENWINHOME --> ${OPENWINHOME}/lib

   The call wxExpandPath can convert these back!
 */
wxChar *
wxContractPath (const wxString& filename,
                const wxString& envname,
                const wxString& user)
{
  static wxChar dest[_MAXPATHLEN];

  if (filename.empty())
    return NULL;

  wxStrcpy (dest, filename);
#ifdef __WINDOWS__
  wxUnix2DosFilename(dest);
#endif

  // Handle environment
  wxString val;
  wxChar *tcp;
  if (!envname.empty() && !(val = wxGetenv (envname)).empty() &&
     (tcp = wxStrstr (dest, val)) != NULL)
    {
        wxStrcpy (wxFileFunctionsBuffer, tcp + val.length());
        *tcp++ = wxT('$');
        *tcp++ = wxT('{');
        wxStrcpy (tcp, envname);
        wxStrcat (tcp, wxT("}"));
        wxStrcat (tcp, wxFileFunctionsBuffer);
    }

  // Handle User's home (ignore root homes!)
  val = wxGetUserHome (user);
  if (val.empty())
    return dest;

  const size_t len = val.length();
  if (len <= 2)
    return dest;

  if (wxStrncmp(dest, val, len) == 0)
  {
    wxStrcpy(wxFileFunctionsBuffer, wxT("~"));
    if (!user.empty())
           wxStrcat(wxFileFunctionsBuffer, user);
    wxStrcat(wxFileFunctionsBuffer, dest + len);
    wxStrcpy (dest, wxFileFunctionsBuffer);
  }

  return dest;
}
Exemplo n.º 28
0
char *wxGetUserHome( const wxString &user )
#endif
{
    struct passwd *who = (struct passwd *) NULL;

    if ( !user )
    {
        wxChar *ptr;

        if ((ptr = wxGetenv(wxT("HOME"))) != NULL)
        {
#if wxUSE_UNICODE
            wxWCharBuffer buffer( ptr );
            return buffer;
#else
            return ptr;
#endif
        }
        if ((ptr = wxGetenv(wxT("USER"))) != NULL || (ptr = wxGetenv(wxT("LOGNAME"))) != NULL)
        {
            who = getpwnam(wxConvertWX2MB(ptr));
        }

        // We now make sure the the user exists!
        if (who == NULL)
        {
            who = getpwuid(getuid());
        }
    }
    else
    {
      who = getpwnam (user.mb_str());
    }

    return wxConvertMB2WX(who ? who->pw_dir : 0);
}
Exemplo n.º 29
0
wxFileName wxFindAppFullName(const wxString& argv0, const wxString& cwd, const wxString& appVariableName)
{
    wxFileName fileName(argv0);
    wxString str;
    wxString path;

#if defined(__WXMSW__)
    if (!fileName.HasExt())
        fileName.SetExt(wxT("exe"));
#endif

    // Try appVariableName
    if (!appVariableName.IsEmpty())
        path = wxGetenv(appVariableName);

#if defined(__WXMAC__) && !defined(__DARWIN__)
    // On Mac, the current directory is the relevant one when
    // the application starts.
    if (path.IsEmpty())
        path = cwd;
#endif

    if (path.IsEmpty())
    {
        if (wxIsAbsolutePath(fileName.GetFullPath()))
            path = fileName.GetFullPath();
        else
        {
            // Is it a relative path?
            wxString currentDir(cwd);
            if (currentDir.Last() != wxFILE_SEP_PATH)
                currentDir += wxFILE_SEP_PATH;
            if (wxFileExists(currentDir + fileName.GetFullName()))
                path = currentDir;
        }
    }

    if (path.IsEmpty())
    {
        // OK, it's neither an absolute path nor a relative path.
        // Search PATH.
        wxPathList pathList;
        pathList.AddEnvList(wxT("PATH"));
        path = wxFileName(pathList.FindAbsoluteValidPath(fileName.GetFullName())).GetPath();
    }
    fileName.SetPath(path);
    return fileName;
}
Exemplo n.º 30
0
/* static */ bool wxTheme::CreateDefault()
{
    if ( ms_theme )
    {
        // we already have a theme
        return true;
    }

    wxString nameDefTheme;

    // use the environment variable first
    const wxChar *p = wxGetenv(_T("WXTHEME"));
    if ( p )
    {
        nameDefTheme = p;
    }
    else // use native theme by default
    {
        #if defined(__WXGTK__)
            nameDefTheme = _T("gtk");
        #elif defined(__WXX11__)
            nameDefTheme = _T("win32");
        #else
            nameDefTheme = _T("win32");
        #endif
    }

    wxTheme *theme = Create(nameDefTheme);

    // fallback to the first one in the list
    if ( !theme && ms_allThemes )
    {
        theme = ms_allThemes->ctor();
    }

    // abort if still nothing
    if ( !theme )
    {
        wxLogError(_("Failed to initialize GUI: no built-in themes found."));

        return false;
    }

    // Set the theme as current.
    wxTheme::Set(theme);

    return true;
}