BsPlatformUtility.h 3.0 KB

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