BsPlatformUtility.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #pragma once
  2. namespace BansheeEngine
  3. {
  4. /** @addtogroup General
  5. * @{
  6. */
  7. struct MACAddress;
  8. /** Possible type of platform file dialogs. */
  9. enum class FileDialogType
  10. {
  11. OpenFile = 0x0,
  12. OpenFolder = 0x1,
  13. Save = 0x2,
  14. Multiselect = 0x10000,
  15. TypeMask = 0xFFFF
  16. };
  17. /** Provides access to various operating system specific utility functions. */
  18. class BS_UTILITY_EXPORT PlatformUtility
  19. {
  20. public:
  21. /**
  22. * Terminates the current process.
  23. *
  24. * @param[in] force True if the process should be forcefully terminated with no cleanup.
  25. */
  26. static void terminate(bool force = false);
  27. /**
  28. * Queries the internal system performance counter you can use for very precise time measurements. Value is in
  29. * milliseconds.
  30. *
  31. * @note Thread safe.
  32. */
  33. static double queryPerformanceTimerMs();
  34. /**
  35. * Adds a string to the clipboard.
  36. *
  37. * @note Thread safe.
  38. */
  39. static void copyToClipboard(const WString& string);
  40. /**
  41. * Reads a string from the clipboard and returns it. If there is no string in the clipboard it returns an empty
  42. * string.
  43. *
  44. * @note
  45. * Both wide and normal strings will be read, but normal strings will be converted to a wide string before returning.
  46. * @note
  47. * Thread safe.
  48. */
  49. static WString copyFromClipboard();
  50. /**
  51. * Converts a keyboard key-code to a Unicode character.
  52. *
  53. * @note
  54. * Normally this will output a single character, but it can happen it outputs multiple in case a accent/diacritic
  55. * character could not be combined with the virtual key into a single character.
  56. */
  57. static WString keyCodeToUnicode(UINT32 keyCode);
  58. /**
  59. * Populates the provided buffer with a MAC address of the first available adapter, if one exists. If no adapters
  60. * exist, returns false.
  61. */
  62. static bool getMACAddress(MACAddress& address);
  63. /** Creates a new universally unique identifier and returns it as a string. */
  64. static String generateUUID();
  65. /**
  66. * Opens the provided file or folder using the default application for that file type, as specified by the operating
  67. * system.
  68. *
  69. * @param[in] path Absolute path to the file or folder to open.
  70. */
  71. static void open(const Path& path);
  72. /**
  73. * Displays a platform specific file/folder open/save dialog.
  74. *
  75. * @param[in] type Type of dialog to open.
  76. * @param[in] defaultPath Initial path the dialog will be set to once opened.
  77. * @param[in] filterList Semi-colon separated list of file names or types to display in the dialog, e.g. "exe;txt;png".
  78. * Ignored if dialog is to display folders instead of files.
  79. * @param[out] paths Output list of selected file or folder paths (if any).
  80. * @return True if file was selected and false if selection was canceled.
  81. */
  82. static bool openBrowseDialog(FileDialogType type, const Path& defaultPath, const WString& filterList,
  83. Vector<Path>& paths);
  84. };
  85. /** Represents a MAC (ethernet) address. */
  86. struct MACAddress
  87. {
  88. UINT8 value[6];
  89. };
  90. /** @} */
  91. }