1SysInfo 2 3 4Running files and commands 5 6String GetExtExecutable(const String ext) 7Gets the program that will open by default the files with extension ext. 8 9 Example: 10 GetExtExecutable("html") -> "Firefox.exe" 11 12 13bool LaunchFile(const String file) 14Opens the file file with the adecuated program defined in the OS by default. 15 16 Example: 17 LaunchFile("c:\\My spreadsheet.txt"). It will open default program (probably Notepad) with document "My spreadsheet.txt". 18 19 20Obtaining special folders 21 22String GetDesktopFolder() 23Gets the default Desktop folder path. 24 25 26String GetProgramsFolder() 27Gets the default programs folder path. 28 29 30String GetAppDataFolder() 31Gets the default application data folder path. 32 33 34String GetMusicFolder() 35Gets the default music files folder path. 36 37 38String GetPicturesFolder() 39Gets the default picture files folder path. 40 41 42String GetVideoFolder() 43Gets the default video files folder path. 44 45 46String GetPersonalFolder() 47Gets the default personal files folder path. 48 49 50String GetTemplatesFolder() 51Gets the default templates files folder path. 52 53 54String GetDownloadFolder() 55Gets the default file download folder path. 56 57 58String GetRootFolder() 59Gets the default root folder path. 60 61 62String GetTempFolder() 63Gets the default temp files folder path. 64 65 66String GetOsFolder() 67Gets the default operating system files folder path. 68 69 70String GetSystemFolder() 71Gets the default system files folder path. 72 73 74Hardware, BIOS, OS and Distro info 75 76void GetSystemInfo(String &manufacturer, String &productName, String &version, int &numberOfProcessors) 77Returns hardware information including computer manufacturer, productName, version and numberOfProcessors. 78 79 80void GetBiosInfo(String &biosVersion, Date &biosReleaseDate) 81Returns bios information including biosVersion and biosReleaseDate. 82 83 84bool GetProcessorInfo(int number, String &vendor, String &identifier, String &architecture, int &speed) 85Returns information about the different cpu cores. 86number is the core number to get the information 87vendor is the core vendor 88identifier is the core identifier 89architecture is the core architecture (32, 64) 90speed.is the core speed in MHz. 91 92 93int GetCpuSpeed() 94Gets the real time main CPU speed in MHz. 95 This data is directly calculated by the function. 96 97 98bool GetVideoInfo(Array <Value> &name, Array <Value> &description, Array <Value> &videoProcessor, Array <Value> &ram, Array <Value> &videoMode) 99If true gets information about video systems installed: 100name is the video system name 101description is the video description 102videoProcessor is the processor used 103ram is the available memory in the video hardware in Mb 104videoMode is the video mode actually selected including screen resolution and number of colors 105 106 107bool GetPackagesInfo(Array <Value> &name, Array <Value> &version, Array <Value> &vendor, Array <Value> &installDate, Array <Value> &caption, Array <Value> &description, Array <Value> &state) 108If true gets information about installed software: 109name 110version 111vendor 112installDate 113caption is a summary of the software description 114description 115state is the status of the software. Values are: 116 - "Bad Configuration" 117 - "Invalid Argument" 118 - "Unknown Package" 119 - "Advertised" 120 - "Absent" 121 - "Ok" 122 123 124bool GetMemoryInfo(int &memoryLoad, uint64 &totalPhys, uint64 &freePhys, uint64 &totalPageFile, uint64 &freePageFile, uint64 &totalVirtual, uint64 &freeVirtual) 125Gets information about the system memory: 126memoryLoad is the percent of memory in use 127totalPhys is the total physical memory 128freePhys is the free physical memory 129totalPageFile is the total paging file 130freePageFile is the free paging file 131totalVirtual is the total virtual memory 132freeVirtual is the free virtual memory. 133 134 135bool GetOsInfo(String &kernel, String &kerVersion, String &kerArchitecture, String &distro, String &distVersion, String &desktop, String &deskVersion) 136Gets many information to identify the operating system and Desktop where the application is being run. 137kernel: Kernel name 138kerVersion: Kernel version 139kerArchitecture: Kernel architecture 140distro: Distro name 141distVersion: Distro version 142desktop: Desktop manager name 143deskVersion.: Desktop manager version 144 145 146String GetDesktopManagerNew() 147A more complete version of GetDesktopManager() based on GetOsInfo(). 148 149 150Array<String> GetDriveList() 151Returns an array with the paths to all drives, internal or external, identified in the system. 152 153 154bool GetDriveSpace(String drive, uint64 &freeBytesUser, uint64 &totalBytesUser, uint64 &totalFreeBytes) 155Gets drive space. 156freeBytesUser: Amount of free bytes available to the user 157totalBytesUser: Size of drive visible for the user 158totalFreeBytes: Amount of free bytes. 159 Returns false if drive is not mounted or it is not accessible 160 161 162bool GetDriveInformation(String drive, String &type, String &volume, int &maxName, String &fileSystem) 163Gets drive information 164type: Gets the type of the drive. 165Available types are "Hard", "Network", "Optical", "RAM", "Removable". 166volume: Gets the name of the drive 167maxName: Gets the maximum length permitted for a file name 168fileSystem: Gets the drive formatting system. 169 Returns false if drive is not mounted or it is not accessible 170 171 172void GetCompilerInfo(String &name, int &version, String &date) 173Returns compiling information, like compiler name, compiler version and program compilation date. 174 175 176bool GetBatteryStatus(bool &discharging, int &percentage, int &remainingMin) 177Gets battery information like if it is discharging or connected to the grid, percentage of charging where 100% means full charge, and number of expected computer running minutes in remainingMin. 178 Returns true if the values got are valid. 179 180 181bool GetBatteryInfo(bool &present ) 182Gets if battery is present or not. 183 Returns true if the values got are valid. 184 185 186void OpenCDTray() 187Ejects CD/DVD tray. 188 189 190void CloseCDTray() 191Closes CD/DVD tray if possible 192 193Process handling 194 195void GetWindowsList(Array<long> &wid, Array<long> &pid, Array<String> &name, Array<String> &fileName, Array<String> &title) 196Gets arrays with handles to all the opened windows with additional info as: 197wid: Handle to the the window 198pid: Handle to the process that manages the window 199name: Window name 200fileName: Window process program file name 201title: Window title (caption) 202 203 204Array<long> GetWindowsList() 205Gets an array with handles to all the opened windows. 206 207 208bool GetProcessList(Array<long> &pid, Array<String> &pNames) 209Gets arrays with handles to all the opened processes pid and process names pNames. 210 211 212Array<long> GetProcessList() 213Gets an array with handles to all the opened processes 214 215 216String GetProcessName(long pid) 217Returns the process name for a process with handle pid. 218 219 220String GetProcessFileName(long processID) 221Gets the program file name of a process with handle processID. 222 223 224long GetProcessIdFromWindowCaption(String windowCaption, bool exactMatch = false) 225Gets the process handle of a program with a window with title windowCaption. 226If exactMatch.is true it only returns the process handle of a process with a window title that is equal to windowCaption. If it is false then the handle is returned if only part of the window title matches with windowCaption. 227 228 229long GetWindowIdFromCaption(String windowCaption, bool exactMatch = false) 230Gets the window handle of a program with a window with title windowCaption. 231If exactMatch.is true it only returns the process handle of a process with a window title that is equal to windowCaption. If it is false then the handle is returned if only part of the window title matches with windowCaption. 232 233 234long GetProcessIdFromWindowId(long wid) 235Returns the process handle of a program with window handle wid. 236 237 238long GetWindowIdFromProcessId(long pid) 239Returns the window handle of a program with process handle pid. 240 241 242bool ProcessTerminate(long pid, int timeout = 500) 243Ends the program with handle pid. 244If after asking the process to end timeout is over, it will kill the process by different means in order of increasing "aggressivity". 245 For example in Posix it will send the process first a SIGTERM, if the process does not stop it will send a SIGKILL, and if the process remains running it will simply call WindowKill() to do the dirty job. 246 247 248int GetProcessPriority(long pid) 249Gets the process priority of the process with handle pid as a number from 0 (minimum) to 10 (maximum), if possible. 250 251 252bool SetProcessPriority(long pid, int priority) 253Sets the process priority to priority of the process with handle pid as a number from 0 (minimum) to 10 (maximum), if possible. 254 255 256bool ProcessExists(long pid) 257Returns true if a process with handle pid exists. 258 259long GetProcessId() 260Gets actual running process handle. 261 262 263bool Shutdown(String action) 264Tries to logoff, reboot or shutdown the actual running session. 265 Actual valid action values are "logoff", "reboot" and "shutdown". 266 267 268Windows handling 269 270bool Window_GetRect(long windowId, long &left, long &top, long &right, long &bottom) 271Giving this function the windowId, it returns the window location in the screen in left, top, right and bottom. 272 Returns true if the values got are valid. 273 274 275void Window_SetRect(long windowId, long left, long top, long right, long bottom) 276Giving this function the windowId, it sets the window location in the screen in left, top, right and bottom. 277 Returns true if the window is relocated correctly.. 278 279Mouse and keyboard handling 280 281bool Mouse_GetPos(long &x, long &y) 282Gets the mouse position x, y.in screen pixels where upper left corner is (0, 0). 283 Returns true if the operation has been done successfully. 284 285 286bool Mouse_SetPos(long x, long y, long windowId) 287Sets the mouse position to x y referenced to the upper left vertex of window with window handle windowId. 288 Returns true if the operation has been done successfully. 289 290 291void Mouse_LeftClick() 292Simulates by software a mouse click with the left button as if it would have been done with the mouse. 293 294 295void Mouse_MiddleClick() 296Simulates by software a mouse click with the middle button as if it would have been done with the mouse. 297 298 299void Mouse_RightClick() 300Simulates by software a mouse click with the right button as if it would have been done with the mouse. 301 302 303void Mouse_LeftDblClick() 304Simulates by software a mouse double click with the left button as if it would have been done with the mouse. 305 306 307void Mouse_MiddleDblClick() 308Simulates by software a mouse double click with the middle button as if it would have been done with the mouse. 309 310 311void Mouse_RightDblClick() 312Simulates by software a mouse double click with the right button as if it would have been done with the mouse. 313 314 315void Keyb_SendKeys(String text, long finalDelay = 100, long delayBetweenKeys = 50) 316Simulates by software a text entered using the keyboard as if it would have been entered with the keyboard. 317To really simulate manual key typing the function lets to enter delays between keys and after entering the text. 318text: Is the text to be entered 319finalDelay: Is the delay in ms that is forced after entering text 320delayBetweenKeys: Is the delay in ms that is forced between text keys. 321 322 323void GetKeyLockStatus(bool &caps, bool &num, bool &scroll) 324Gets the status of keys caps lock, num lock and scroll lock. 325 326 327void SetKeyLockStatus(bool caps, bool num, bool scroll) 328Sets the status of keys caps lock, num lock and scroll lock. 329 330Screen recording 331 332bool Snap_Desktop(String fileName) 333Saves the desktop in fileName.as an image file. 334 Allowed formats are: 335 - Posix: .xwd 336 - Windows: .bmp 337 338 339bool Snap_DesktopRectangle(String fileName, int left, int top, int width, int height) 340Saves a rectangle of the desktop defined by left, top, width and height.in fileName as an image file. 341 Allowed formats are: 342 - Posix: .xwd 343 - Windows: .bmp 344 345 346bool Snap_Window(String fileName, long handle) 347Saves a window defined by its handle in fileName as an image file. 348 Allowed formats are: 349 - Posix: .xwd 350 - Windows: .bmp 351 352 353bool Record_Desktop(String fileName, int duration, int secsFrame = 1, bool viewMouse = true) 354Records the desktop activity in fileName as a video file of duration in seconds with secsFrame seconds between frames and recording also mouse movement if viewMouse.is true. 355 Allowed formats are: 356 - Windows: Uncompressed .avi 357 358 359bool Record_DesktopRectangle(String fileName, int duration, int left, int top, int width, int height, int secsFrame = 1, bool viewMouse = true) 360Records the desktop activity in the rectangle defined by left, top, width and height. in fileName as a video file of duration in seconds with secsFrame seconds between frames and recording also mouse movement if viewMouse.is true. 361 Allowed formats are: 362 - Windows: Uncompressed .avi 363 364 365bool Record_Window(String fileName, int duration, long handle, int secsFrame = 1, bool viewMouse = true) 366Records the activity of a window defined by its handle in fileName as a video file of duration in seconds with secsFrame seconds between frames and recording also mouse movement if viewMouse.is true. 367 Allowed formats are: 368 - Windows: Uncompressed .avi 369 370Miscellaneous functions 371 372String LoadFile_Safe(String fileName) 373Same as LoadFile(fileName) but it works in Posix for files automatically generated by the OS. 374 375U++ LoadFile() functions prior to loading the file into a String, get the length of the file to dimension the String that will get the file. This is not valid for OS generated virtual files where the file length returned by the OS is 0 (for example files under folder /proc) 376 377LoadFile_Safe() just get the file bytes returned by the OS until the file end. 378 379 380void FileToTrashBin(const char *path) 381Deletes file path.by sending it to the Trash Bin. 382 383 384int64 TrashBinGetCount() 385Returns the number of items (files and directories) located in the Trash Bin. 386 387 388void TrashBinClear() 389Removes all the items (files and directories) located in the Trash Bin. 390 391 392void SetDesktopWallPaper(const char *path) 393Sets path.file as desktop wallpaper. Supports Gnome, Kde v3 and Windows desktops. 394 395In Gnome, path has to be .png 396In Kde, path has to be .png, .gif or .jpg 397In Windows, path has to be .bmp 398 399If path.is empty, the desktop wallpaper is removed. 400 401 402bool FileCat(const char *file, const char *appendFile) 403Appends at the end of file the contents of file appendFile. file will be modified and appendFile remains unchanged. 404 Returns true if the operations has been done succesfully. 405 406 407String Replace(String str, String find, String replace) 408Returns the resulting String obtained by replacing in str String find with replace all the times that find appears in str. 409 410 411int ReverseFind(const String& s, const String& toFind, int from = 0) 412Find in s the string toFind beginning in from in reverse order. 413Similar to Find() but searching to the beginning of the String. 414 415 416String FormatLong(long a) 417Returns the long number a converted into a String. 418 419 420template <class T> int Sign(T a) 421Returns 422 +1 if a. is positive 4230 if a is 0 and 424-1 if a is negative. 425 426 427String GetUpperFolder(String folderName) 428Returns the name of the upper folder over folderName. 429 430 431bool CreateFolderDeep(const char *dir) 432Creates folder dir, creating intermediate folders if necessary 433 434 435String SecondsToString(double seconds, bool decimals = false) 436Converts an amount of seconds to a String formatted as HH:MM:SS. 437 If decimals it includes decimals in seconds 438 It is opposite to StringToSeconds() 439 440 441const char *StrToTime(struct Upp::Time& d, const char *s) 442Scans a string for a Time. Order of day, month and year is specified using SetDateScan. In place of month both number and text is accepted - text must match abbreviated or full name of month. 443 Similar to StrToDate() but including both date and time. 444d Found time. 445s String to scan. 446Return value NULL if no time is found in s or pointer to character right after the date. 447 448 449double StringToSeconds(String str) 450It converts a String str formatted as HH:MM:SS to a returned amount of seconds. 451 It is opposite to SecondsToString() 452 453 454String BytesToString(uint64 bytes) 455Converts an amount of bytes to a short String. 456 457 458void DoEvents() 459A ProcessEvents just for old Visual Basic programmers. 460 461 462Array<String> SearchFile(String dir, String condFile, String text = "") 463Returns an Array of Strings containing the file names with full path of the files under folder dir that comply with condition (with wildcards) condFile and that contain inside the text text. 464