/core/system.d

http://github.com/wilkie/djehuty · D · 135 lines · 88 code · 27 blank · 20 comment · 1 complexity · 76b1120ea8407c3fdba66e8ca34e2f27 MD5 · raw file

  1. /*
  2. * system.d
  3. *
  4. * This module implements a class that can be used to query information
  5. * about the system.
  6. *
  7. */
  8. module core.system;
  9. import scaffold.system;
  10. import scaffold.directory;
  11. import scaffold.time;
  12. import core.locale : LocaleId;
  13. import core.time;
  14. import core.timezone;
  15. import io.directory;
  16. import io.console;
  17. // Description: This class gives the developer a means to query common parameters about devices and configurations of the system.
  18. class System {
  19. static:
  20. public:
  21. class Displays {
  22. static:
  23. public:
  24. uint count() {
  25. return SystemGetDisplayCount();
  26. }
  27. uint primary() {
  28. return SystemGetPrimaryDisplay();
  29. }
  30. int width(uint index) {
  31. return SystemGetDisplayWidth(index);
  32. }
  33. int height(uint index) {
  34. return SystemGetDisplayHeight(index);
  35. }
  36. }
  37. class Display {
  38. static:
  39. public:
  40. int width() {
  41. return SystemGetDisplayWidth(Displays.primary);
  42. }
  43. int height() {
  44. return SystemGetDisplayHeight(Displays.primary);
  45. }
  46. }
  47. class Memory {
  48. static:
  49. public:
  50. ulong total() {
  51. return SystemGetTotalMemory();
  52. }
  53. ulong available() {
  54. return SystemGetAvailableMemory();
  55. }
  56. }
  57. class FileSystem {
  58. static:
  59. public:
  60. // Description: This function will return the Directory representing the current directory.
  61. // Returns: The Directory representing the working directory.
  62. Directory currentDir() {
  63. return Directory.open(DirectoryGetCWD());
  64. }
  65. // Description: This function will return the Directory representing the directory the executable is located in. It should not be relied on completely, as this information can be incorrect or non-existent.
  66. // Returns: The Directory representing the executable location.
  67. Directory applicationDir() {
  68. return Directory.open(DirectoryGetApp());
  69. }
  70. // Description: This function will return the Directory representing the system's temporary files directory. Persistance is not guaranteed.
  71. // Returns: The Directory representing the temp location.
  72. Directory tempDir() {
  73. Directory retdir = Directory.open(DirectoryGetTempData());
  74. if (retdir is null) {
  75. retdir = new Directory(DirectoryGetTempData());
  76. }
  77. return retdir;
  78. }
  79. // Description: This function will return the Directory representing the system's temporary files directory. Persistance is not guaranteed.
  80. // Returns: The Directory representing the temp location.
  81. Directory appDataDir() {
  82. return Directory.open(DirectoryGetAppData());
  83. }
  84. // Description: This function will return the Directory representing the system's temporary files directory. Persistance is not guaranteed.
  85. // Returns: The Directory representing the temp location.
  86. Directory userDataDir() {
  87. return Directory.open(DirectoryGetUserData());
  88. }
  89. // Description: This function will return the Directory representing the system's temporary files directory. Persistance is not guaranteed.
  90. // Returns: The Directory representing the temp location.
  91. Directory binaryDir() {
  92. return Directory.open(DirectoryGetBinary());
  93. }
  94. }
  95. class Locale {
  96. static:
  97. public:
  98. LocaleId id() {
  99. return SystemGetLocaleId();
  100. }
  101. TimeZone timezone() {
  102. return new TimeZone();
  103. }
  104. }
  105. long time() {
  106. return SystemTimeGet();
  107. }
  108. }