1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#ifndef PLATFORM_MISC_H
#define PLATFORM_MISC_H
#include <string>
#include <vector>
namespace Platform
{
/**
* Returns the path to the original PWD/CWD dir from where the user started the execution.
* For security reasons we change the CWD to Spring's write-dir (most of the time it's the home-dir), so we need to cache the PWD/CWD.
* @return path to the CWD, with trailing path separator
*/
const std::string& GetOrigCWD();
const std::string& SetOrigCWD();
/**
* Returns the path to the current users dir for storing application settings.
* examples:
* - "/home/pablo"
* - "/root"
* - "C:\Users\USER\AppData\Local"
* - "C:\Users\USER\Local Settings\Application Data"
* - "C:\Documents and Settings\USER\Local Settings\App Data"
* - "C:\Dokumente und Einstellungen\USER\Anwendungsdaten"
* @return path to the current users home dir, without trailing path separator
*/
std::string GetUserDir();
/**
* Returns the path to the main binary of the running process,
* including the file name.
* examples:
* examples when calling from the engine:
* - "/usr/games/bin/spring"
* - "/home/user/spring/spring"
* - "C:\Program Files\Spring\spring.exe"
* examples when calling from the synchronization library:
* - "/usr/games/bin/springlobby"
* - "/home/user/springlobby/springlobby"
* - "C:\Program Files\SpringLobby\springlobby.exe"
* @return path to the main binary of the running process file or ""
*/
std::string GetProcessExecutableFile();
/**
* Returns the path to the main binary of the running process,
* excluding the file name.
* @see GetProcessExecutableFile()
* @return path to the main binary of the running process dir or ""
*/
std::string GetProcessExecutablePath();
/**
* Returns the path to the module/shared library, including the file name.
* If moduleName is "", the path to the current library is returned.
* examples when calling from the engine:
* - "/usr/games/bin/spring"
* - "/home/user/spring/spring"
* - "C:\Program Files\Spring\spring.exe"
* examples when calling from the synchronization library:
* - "/usr/lib/libunitsync.so"
* - "/home/user/spring/libunitsync.so"
* - "C:\Program Files\Spring\unitsync.dll"
* @param moduleName eg. "spring" or "unitsync", "" for current
* @return path to the current module file or ""
*/
std::string GetModuleFile(std::string moduleName = "");
/**
* Returns the path to a module/shared library, excluding the file name.
* If moduleName is "", the path to the current library is returned.
* @see GetModuleFile()
* @param moduleName eg. "spring" or "unitsync", "" for current
* @return path to the current module dir (with trailing path separator) or ""
*/
std::string GetModulePath(const std::string& moduleName = "");
std::string GetOS();
std::string GetOSFamily();
std::string GetWordSizeStr();
bool Is64Bit();
bool Is32BitEmulation();
bool IsRunningInGDB();
uint64_t FreeDiskSpace(const std::string& path);
uint32_t NativeWordSize(); // compiled process code
uint32_t SystemWordSize(); // host operating system
uint32_t DequeChunkSize();
/**
* Executes a native binary, file and args have to be not escaped!
* http://linux.die.net/man/3/execvp
* @param file path to an executable, eg. "/usr/bin/games/spring"
* @param args arguments to the executable, eg. {"-f". "/tmp/test.txt"}
* @return error message, or "" on success
*/
std::string ExecuteProcess(const std::string& file, std::vector<std::string> args, bool asSubprocess = false);
}
#endif // PLATFORM_MISC_H
|