BsPlatformUtility.h 3.3 KB

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