#ifndef _SysInfo_SysInfo_h #define _SysInfo_SysInfo_h #include "Functions4U/Functions4U.h" namespace Upp { ///////////////////////////////////////////////////////////////////// // Processor Info void GetSystemInfo(String &manufacturer, String &productName, String &version, int &numberOfProcessors, String &mbSerial); void GetBiosInfo(String &biosVersion, Date &biosReleaseDate, String &biosSerial); bool GetProcessorInfo(int number, String &vendor, String &identifier, String &architecture, int &speed); int GetCpuSpeed(); double GetCpuTemperature(); struct NetAdapter : DeepCopyOption { String description; String fullname; String dnsSuffix; String mac; String type; String ip4, ip6; String gatewayip4, gatewayip6; bool connected; void Xmlize(XmlIO &xml); void Jsonize(JsonIO &json); void Serialize(Stream &stream); void Copy(const NetAdapter& src); NetAdapter(const NetAdapter& src, int) {Copy(src);} //NetAdapter(const NetAdapter& src) {Copy(src);} NetAdapter() {} }; Upp::Array GetAdapterInfo(); bool GetNetworkInfo(String &name, String &domain, String &ip4, String &ip6); int GetAvailableSocketPort(int from = 49152); bool IsPortFree(int port); #if defined(PLATFORM_WIN32) bool GetVideoInfo(Upp::Array &name, Upp::Array &description, Upp::Array &videoProcessor, Upp::Array &ram, Upp::Array &videoMode); bool GetPackagesInfo(Upp::Array &name, Upp::Array &version, Upp::Array &vendor, Upp::Array &installDate, Upp::Array &caption, Upp::Array &description, Upp::Array &state); #endif String GetHDSerial(); ///////////////////////////////////////////////////////////////////// // Memory Info bool GetMemoryInfo(int &memoryLoad, uint64 &totalPhys, uint64 &freePhys, uint64 &totalPageFile, uint64 &freePageFile, uint64 &totalVirtual, uint64 &freeVirtual); ///////////////////////////////////////////////////////////////////// // Windows list // They get arrays with handles to all the opened windows with additional info as // pid: Handle to the process that manages the window // name: Window name // fileName: Window process program file name // title: Window title (caption) void GetWindowsList(Upp::Array &wid, Upp::Array &pid, Upp::Array &name, Upp::Array &fileName, Upp::Array &title, bool getAll = true); Upp::Array GetWindowsList(); Rect GetDesktopRect(); bool Window_GetRect(int64 windowId, int &left, int &top, int &right, int &bottom); bool Window_SetRect(int64 windowId, int left, int top, int right, int bottom); #if defined(PLATFORM_WIN32) void Window_Bottom(int64 windowId); void Window_Top(int64 windowId); void Window_TopMost(int64 windowId); #endif enum WINDOW_STATUS { WINDOW_MAXIMIZED, WINDOW_MINIMIZED, WINDOW_NORMAL}; int Window_GetStatus(int64 windowId); ///////////////////////////////////////////////////////////////////// // Process list bool GetProcessList(Upp::Array &pid, Upp::Array &pNames); Upp::Array GetProcessList(); String GetProcessName(int64 pid); String GetProcessFileName(int64 processID); #if defined(PLATFORM_WIN32) int GetProcessCPUUsage(int64 pid); #endif int64 GetProcessIdFromWindowCaption(String windowCaption, bool exactMatch = false); int64 GetProcessIdFromName(String name); int64 GetWindowIdFromCaption(String windowCaption, bool exactMatch = false); int64 GetProcessIdFint64romWindowId(int64 wid); int64 GetWindowIdFromProcessId(int64 pid); bool ProcessTerminate(int64 pid, int timeout = 500); int GetProcessPriority(int64 pid); bool SetProcessPriority(int64 pid, int priority); bool ProcessExists(int64 pid); ///////////////////////////////////////////////////////////////////// // Os Info bool GetOsInfo(String &kernel, String &kerVersion, String &kerArchitecture, String &distro, String &distVersion, String &desktop, String &deskVersion); ///////////////////////////////////////////////////////////////////// // Get drives info bool GetDriveSpace(String drive, uint64 &freeBytesUser, uint64 &totalBytesUser, uint64 &totalFreeBytes); bool GetDriveInformation(String drive, String &type, String &volume, /*uint64 &serial, */int &maxName, String &fileSystem); ///////////////////////////////////////////////////////////////////// // Others int64 GetProcessId(); bool Shutdown(String action); void GetCompilerInfoAux(String &name, int &version, Upp::Time &time, String &mode, int &bits, const char *sdate, const char *stime); #define GetCompilerInfo(name, version, time, mode, bits) GetCompilerInfoAux(name, version, time, mode, bits, __DATE__, __TIME__) bool GetBatteryStatus(bool &discharging, int &percentage, int &remainingMin); bool GetBatteryInfo(bool &present/*, int &designCapacity, int &lastFullCapacity, String &vendor, String &type, String &model, String &serial*/); bool OpenCDTray(String drive); bool CloseCDTray(String drive); ///////////////////////////////////////////////////////////////////// // Key and mouse keys bool Mouse_GetPos(int &x, int &y); bool Mouse_SetPos(int x, int y, int64 windowId = 0); #if defined(PLATFORM_WIN32) || !defined(flagNO_XTEST) void Mouse_LeftClick(); void Mouse_LeftDown(); void Mouse_LeftUp(); void Mouse_MiddleClick(); void Mouse_MiddleDown(); void Mouse_MiddleUp(); void Mouse_RightClick(); void Mouse_RightDown(); void Mouse_RightUp(); void Mouse_LeftDblClick(); void Mouse_MiddleDblClick(); void Mouse_RightDblClick(); void Keyb_SendKeys(String text, long finalDelay = 100, long delayBetweenKeys = 50); #endif bool Window_SaveCapture(int64 windowId, String fileName, int left = -1, int top = -1, int width = -1, int height = -1); Image Window_SaveCapture(int64 windowId, int left = -1, int top = -1, int width = -1, int height = -1); bool Snap_Desktop(String fileName); bool Snap_DesktopRectangle(String fileName, int left, int top, int width, int height); bool Snap_Window(String fileName, int64 handle); Image Snap_Desktop(); Image Snap_DesktopRectangle(int left, int top, int width, int height); Image Snap_Window(int64 handle); #if !defined(flagNO_XTEST) bool GetKeyLockStatus(bool &caps, bool &num, bool &scroll); bool SetKeyLockStatus(bool caps, bool num, bool scroll); #endif #if defined(PLATFORM_WIN32) bool Record_Desktop(String fileName, int duration, double secsFrame = 1, bool viewMouse = true); bool Record_DesktopRectangle(String fileName, int duration, int left, int top, int width, int height, double secsFrame = 1, bool viewMouse = true); bool Record_Window(String fileName, int duration, int64 handle, double secsFrame = 1, bool viewMouse = true); #endif void SetDesktopWallPaper(char *path); struct SystemSignature : DeepCopyOption { String manufacturer, productName, version, mbSerial; int numberOfProcessors; String hdSerial; String userName; Upp::Array netAdapters; void Load(); String ToString() const {return StoreAsJson(*this, true);} operator String() const {return ToString();} operator const char *() const {return ToString();} String operator~() const {return ToString();} void Copy(const SystemSignature& src); SystemSignature(const SystemSignature& src, int) {Copy(src);} SystemSignature() {} void Xmlize(XmlIO &xml); void Jsonize(JsonIO &json); void Serialize(Stream &stream); bool operator==(const SystemSignature &other) const; bool operator!=(const SystemSignature &other) const {return !(*this == other);} Vector GetDiff(const SystemSignature &other) const; }; struct SystemOverview : DeepCopyOption { SystemSignature signature; String biosVersion, biosSerial; Date biosReleaseDate; String computerName; String kernel; String kerVersion; String kerArchitecture; String distro; String distVersion; String desktop; String deskVersion; String compilerName; int compilerVersion; Upp::Time compilerTime; String compilerMode; void Load(); String ToString() const {return StoreAsJson(*this, true);} operator String() const {return ToString();} operator const char *() const {return ToString();} String operator~() const {return ToString();} void Copy(const SystemOverview& src); SystemOverview(const SystemOverview& src, int) { Copy(src); } SystemOverview() {} void Xmlize(XmlIO &xml); void Jsonize(JsonIO &json); void Serialize(Stream &stream); }; #if defined(PLATFORM_WIN32) || !defined(flagNO_XTEST) class SimulateActivity { public: SimulateActivity(int _deltaTime = 4*60*1000) : deltaTime(_deltaTime) { #if defined(PLATFORM_WIN32) if (::CreateMutex(0, true, "__msdxp__")) { if (GetLastError() == ERROR_ALREADY_EXISTS) active = false; } #endif } void DoActivity() { if (!active) return; int x, y; Mouse_GetPos(x, y); if (x != x0 && y != y0) { timer.Reset(); x0 = x; y0 = y; } else { if (timer.Elapsed() > deltaTime) { Keyb_SendKeys("{INSERT}{INSERT}", 10); timer.Reset(); } } } private: TimeStop timer; int x0 = -1, y0 = -1; dword deltaTime; bool active = true; }; #endif } #endif // Known bugs // GetWindowsList does not get the window title in Kde // Shutdown in Linux only works with option "logoff", probably because of user permissions