Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
UppHub
Status & Roadmap
FAQ
Authors & License
Forums
Funding U++
Search on this site











SourceForge.net Logo

SourceForge.net Logo

GitHub Logo

Discord Logo

Application & environment utility

A number of utility functions to obtain information about your application and system environment.

 

 

Function List

 

String GetExeFilePath()

Returns the absolute path towards the application's binary.

 


 

String GetEnv(const char *id)

Returns the value of the environment variable id.

 


 

bool SetEnv(const char *name, const char *value)

Sets the value of the environment variable name to value.

 


 

String GetExeDirFile(const char *fp)

Returns the absolute path of a file that is found in the folder where you application's binary resides.

fp..................................................the name of the file

 


 

String GetHomeDirectory()

Returns the absolute path of current user's home folder.

 


 

String GetHomeDirFile(const char *fp)

Returns the absolute path of a file that is found in the current user's home folder.

fp..................................................the name of the file

 


 

String GetExeTitle()

Returns the title of the application.

 


 

String GetAppFolder()

[MacOS only]

This funtion returns the path to the application folder, if the the executable is in one.

 


 

String GetAppName()

Returns the name of the application. Default value is GetExeTitle, but it can be changed with SetAppName. This values is used e.g. as the name of configuration folder.

 


 

void SetAppName(const String& name)

Overrides the name of the application.

 


 

void SetConfigGroup(const char *group)

In POSIX systems, ConfigFile function default path is inside ".cache" directory. This function allows to set a name of subdirectory of this directory where the another subdirectory named GetAppName() specific to the application will store the configuration. Setting group empty just removes whole level. Default value is "u++".

 


 

String GetConfigGroup()

Returns current config group.

 


 

String GetTempDirectory()

Return the temporary directory.

 


 

String TempFile(const char *filename)

Returns the absolute path of a file in temporary directory.

 


 

String GetExeFolder()

Return the directory of application executable.

 


 

void UseHomeDirectoryConfig(bool b = true)

Sets the search path for configuration to either the current users' home folder or to the folder where the application's binary resides.

b...................................................use home folder (true) or application folder (false)

 


 

void SetConfigDirectory(const String& s)

Overrides the directory where configuration files are stored.

 


 

String ConfigFile(const char *file)

Returns the absolute path of a configuration file. The directory depends on host platform and other settings. If one was set with SetConfigDirectory, it is used. Otherwise, in POSIX, function searches for .config folder starting with directory of binary, then goes up until root. If none is found, XDG_CONFIG_HOME is used. If that does not exist, ~/.config is used. Function then appends GetAppName() to this directory and makes sure it exists (with RealizeDirectory). In Win32, this is either the directory of .exe file, or if UseHomeDirectoryConfig is set, user's home directory.

 


 

String ConfigFile()

Returns the default configuration file from the configuration files search path. The default configuration file is called [GetAppName()].cfg.

 


 

const Vector<String>& CommandLine()

Return a vector of strings containing the command line parameters. This array does not contain main's argv[0], so the number of elements is argc - 1.

 


 

void CommandLineRemove(int i, int count = 1)

Removes commandline argument(s).

 


 

String GetArgv0()

Returns the argv[0] argument to main (contains the name of executable).

 


 

const VectorMap<String, String>& Environment()

Returns a vector of strings with system environment variables.

 


 

void SetExitCode(int code)

Sets the exit code that will be returned on application exit.

code.............................................the exit code

 


 

int GetExitCode()

Gets the exit code that will be returned on application exit.

 


 

bool IsMainRunning()

Return true if the applications execution has reached and not yet exited the main function.

 


 

String GetDataFile(const char *filename)

This function is designed to retrieve the path of file that contains application specific data. Behaviour depends on whether application was started from 'theide' - in that case theide passes a reference to main package directory through environment variable "UPP_MAIN__" and the resulting file is in this directory. When started standalone, the function is equivalent to GetExeDirFile. Alternatively, application can call SetDataPath to define the directory.

 


 

String LoadDataFile(const char *filename)

Same as LoadFile(GetDataFile(filename)).

 


 

void SetDataPath(const char *path)

Defines explicit directory to be used with GetDataFile.

 


 

String GetComputerName()

Returns the name of computer.

 


 

String GetUserName()

Returns current user.

 


 

String GetDesktopManager()

Returns current GUI identifier. Predefined values are "windows", "gnome", "kde". If X11 desktop manager is not in this list, the value of "DESKTOP_SESSION" environment variable is returned.

 


 

void LaunchWebBrowser(const String& url)

Opens an URL in the default Web Browser.

url................................................the URL that will be opened in the browser

 


 

void SetHomeDirectory(const char *dir)

Sets the current user's home folder.

dir................................................the URL that will be opened in the browser

 


 

bool CpuMMX()

Returns true if CPU has MMX support.

 

 


 

bool CpuSSE()

Returns true if CPU has SSE support.

 


 

bool CpuSSE2()

Returns true if CPU has SSE2 support.

 


 

bool CpuSSE3()

Returns true if CPU has SSE3 support.

 


 

bool CpuHypervisor()

Checks whether CPU has hypervisor flag set. If it has, the program is running in virtual machine. Unfortunately, opposite is not true - some VMs run without this flag set.

 


 

int CPU_Cores()

Returns the number of cores the CPU has.

 

 

Do you want to contribute?